ftw-soft / rundeck-api-client
Rundeck's API client
Installs: 33 620
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: ^7.2 || ^8.0
- ext-json: *
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.0
- http-interop/http-factory-guzzle: ^1.0
- phpstan/phpstan: ^0.12.64
- phpunit/phpunit: ^8.5 || ^9.4
Suggests
- guzzlehttp/guzzle: A PSR-18 compatible HTTP Client (^7.0)
- http-interop/http-factory-guzzle: PSR-17 compatible HTTP Factories (^1.0)
README
A php client to access the Rundeck API, based on the official documentation. Not all API functions are represented by default.
Requirements
- PHP 7.2+ with enabled json extension
- Rundeck 2.1+
This client is based on PSR-17 and PSR-18 and therefore you need a compatible HTTP client and request factories.
We suggest Guzzle 7+ and http-interop/http-factory-guzzle
:
composer require guzzlehttp/guzzle:^7.0 http-interop/http-factory-guzzle:^1.0
Installation
composer require ftw-soft/rundeck-api-client
Basic client usage
<?php require_once __DIR__ . '/vendor/autoload.php'; use FtwSoft\Rundeck\Authentication\PasswordAuthentication; use FtwSoft\Rundeck\Authentication\TokenAuthentication; use FtwSoft\Rundeck\Client; use GuzzleHttp\Client as HttpClient; use Http\Factory\Guzzle\RequestFactory; use Http\Factory\Guzzle\StreamFactory; $httpClient = new HttpClient(); // --- Setup authentication --- # Password authentication $authentication = new PasswordAuthentication( 'https://rundeck.local', 'username', 'password', $httpClient, new RequestFactory(), new StreamFactory() ); # OR Token based authentication $authentication = new TokenAuthentication('secret-token'); // --- Initialize client --- $client = new Client( 'https://rundeck.local', $authentication, $httpClient, new RequestFactory(), new StreamFactory(), 36 // optional API version ); // Make a request $response = $client->request('GET', 'projects'); var_dump($response->getBody()->getContents());
Supported default scenarios
This package includes common request scenarios which are called "resources". The following resources are currently supported:
- Execution
- Job
- Project
- Projects
- System
- Token
- Tokens
- User
Each resource includes calls to the API and it's payload and/or response is represented by custom entity classes.
For example
<?php require_once __DIR__ . '/vendor/autoload.php'; use FtwSoft\Rundeck\Resource\Tokens as TokensResource; use FtwSoft\Rundeck\Client; use FtwSoft\Rundeck\Entity\TokenEntity; /** @var Client $client */ $tokensResource = new TokensResource($client); /** @var TokenEntity[] $tokens */ $tokens = $tokensResource->get(); foreach ($tokens as $token) { echo '===================================='; echo 'id: ', $token->getId(), PHP_EOL; echo 'user:', $token->getUser(), PHP_EOL; echo 'token: ', $token->getToken(), PHP_EOL; echo 'creator: ', $token->getCreator(), PHP_EOL; echo 'expire at: ', $token->getExpiration()->format(\DATE_ATOM), PHP_EOL; echo 'roles: ', implode(', ', $token->getRoles()), PHP_EOL; echo 'is expired: ', $token->isExpired() ? 'yes' : 'no', PHP_EOL; }
Feel free to add your own resources and entities to this package by creating a new pull request.