A PHP client for interacting with the ArgoCD API. This library provides an object-oriented interface to the ArgoCD REST API.
This client's structure is based on the KnpLabs/php-github-api library.
For more context on the AI-assisted development process of this library, please see AI.md.
- Light and fast thanks to lazy loading of API classes.
- Object-oriented interface to the ArgoCD API.
- PHP ^8.3
- A PSR-17 implementation (e.g.,
nyholm/psr7
) - A PSR-18 implementation (e.g.,
symfony/http-client
orguzzlehttp/guzzle
)
Via Composer.
composer require your-vendor/argocd-php-client
You will also need to install implementations for PSR-17 (HTTP Factories) and PSR-18 (HTTP Client), for example:
composer require symfony/http-client nyholm/psr7
Or for Guzzle:
composer require guzzlehttp/guzzle php-http/guzzle7-adapter
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
// 1. Instantiate the client with your ArgoCD server URL
// Ensure your ArgoCD server URL is correct and accessible.
// The client will automatically append /api/v1 if it's not present.
$client = new ArgoCD\Client('https://your-argocd-server.example.com');
// 2. Authenticate
// Option A: Using username and password (fetches a token via SessionService)
try {
$client->authenticate('your-username', 'your-password');
echo "Successfully authenticated using username/password. Token: " . substr($client->getToken() ?? 'N/A', 0, 10) . "...\n";
} catch (ArgoCD\Exception\RuntimeException $e) {
die('Authentication failed: ' . $e->getMessage() . "\n");
}
// Option B: Using a pre-existing token
// try {
// $client->authenticate('your-argocd-api-token');
// echo "Successfully authenticated using pre-existing token.\n";
// } catch (ArgoCD\Exception\InvalidArgumentException $e) {
// die('Authentication failed with token: ' . $e->getMessage() . "\n");
// }
// 3. Access API services
try {
// Example: Get user info
$userInfo = $client->sessionService()->getUserInfo();
echo "Logged in as: " . $userInfo->getUsername() . "\n";
echo "Logged in status: " . ($userInfo->isLoggedIn() ? 'true' : 'false') . "\n";
// Example: List accounts (requires admin privileges typically)
// Note: Ensure the authenticated user has permissions for these operations.
// try {
// $accountsList = $client->accountService()->listAccounts();
// echo "Listing accounts:\n";
// if (count($accountsList->getItems()) > 0) {
// foreach ($accountsList->getItems() as $account) {
// echo " - Account Name: " . $account->getName() . ", Enabled: " . ($account->isEnabled() ? 'Yes' : 'No') . "\n";
// }
// } else {
// echo "No accounts found or not enough permissions.\n";
// }
// } catch (ArgoCD\Exception\RuntimeException $e) {
// echo "Could not list accounts: " . $e->getMessage() . "\n";
// }
} catch (ArgoCD\Exception\RuntimeException $e) {
die('API Error: ' . $e->getMessage() . "\n");
}
// Example: Delete the session (logout)
// try {
// $client->sessionService()->delete();
// echo "Successfully logged out.\n";
// } catch (ArgoCD\Exception\RuntimeException $e) {
// die('Logout failed: ' . $e->getMessage() . "\n");
// }
?>
Further documentation will be available as the library matures. For now, refer to the source code and the official ArgoCD API documentation (or the reference/argocd_swagger.json
file in this repository).
This library is licensed under the MIT License - see the LICENSE file for details.
This library is currently maintained by:
- Your Name (or your GitHub username)
- This project was significantly bootstrapped with the assistance of an AI agent. See AI.md for more details.
- Structure and patterns inspired by KnpLabs/php-github-api.
- Thanks to the ArgoCD team for their excellent API and documentation.