xternalsoft / laravel-patrowl
A clean, fluent, and developer-friendly PHP wrapper for the Patrowl API
Fund package maintenance!
Requires
- php: ^8.4
- illuminate/contracts: ^12.0||^13.0
- saloonphp/laravel-plugin: ^4.0
- saloonphp/pagination-plugin: ^2.0
- saloonphp/saloon: ^4.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/boost: ^2.2
- laravel/pao: ^1.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^11.0.0||10.0.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
README
A clean, fluent, and developer-friendly PHP wrapper for the Patrowl API. This package allows you to easily interact with assets, asset groups, and tags within the Patrowl ecosystem from your Laravel application.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
composer require xternalsoft/laravel-patrowl
You can publish and run the migrations with:
php artisan vendor:publish --tag="laravel-patrowl-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="laravel-patrowl-config"
This is the contents of the published config file:
return [ 'api_token' => env('PATROWL_API_TOKEN'), 'base_url' => env('PATROWL_API_BASE_URL', 'https://dashboard.cloud.patrowl.io/api/auth'), 'timeout' => 30, 'default_organization_id' => env('PATROWL_DEFAULT_ORGANIZATION_ID'), 'limit' => env('PATROWL_PAGINATION_LIMIT', 100), ];
Optionally, you can publish the views using
php artisan vendor:publish --tag="laravel-patrowl-views"
Usage
Configuration
Add your Patrowl API token and base URL to your .env file:
PATROWL_API_TOKEN=your-api-token PATROWL_API_BASE_URL=https://dashboard.cloud.patrowl.io/api/auth PATROWL_DEFAULT_ORGANIZATION_ID=1
Basic Usage
You can use the LaravelPatrowl facade to interact with the API:
use Xternalsoft\LaravelPatrowl\Facades\LaravelPatrowl; // Get all assets $assets = LaravelPatrowl::assets()->all(); foreach ($assets as $asset) { echo $asset->value; }
Managing Assets
Create an Asset
use Xternalsoft\LaravelPatrowl\Data\CreateAssetData; $data = new CreateAssetData( value: 'example.com', description: 'My new asset', organization: 1 ); $asset = LaravelPatrowl::assets()->create($data);
Add a Tag to an Asset
use Xternalsoft\LaravelPatrowl\Data\AddTagToAssetData; $data = new AddTagToAssetData( value: 'production', organization: 1 ); $response = LaravelPatrowl::assets()->addTag($assetId, $data); if ($response->successful()) { // Tag added successfully }
Remove a Tag from an Asset
$response = LaravelPatrowl::assets()->removeTag($assetId, $tagId);
Asset Groups
Create an Asset Group
use Xternalsoft\LaravelPatrowl\Data\CreateAssetGroupData; $data = new CreateAssetGroupData( title: 'My Production Assets', description: 'Assets in production environment', organization: 1, assets: [123, 456] // List of asset IDs to add after creation ); $group = LaravelPatrowl::assetGroups()->create($data);
List and Get Asset Groups
// List all asset groups $groups = LaravelPatrowl::assetGroups()->all(); // Get a specific group $group = LaravelPatrowl::assetGroups()->get($groupId);
Add a Tag to an Asset Group
use Xternalsoft\LaravelPatrowl\Data\AddTagToAssetData; $data = new AddTagToAssetData( value: 'critical-infrastructure', organization: 1 ); $response = LaravelPatrowl::assetGroups()->addTag($groupId, $data);
Asset Tags
// List all available tags $tags = LaravelPatrowl::assetTags()->all();
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.