Skip to content

Latest commit

 

History

History
130 lines (96 loc) · 4.96 KB

File metadata and controls

130 lines (96 loc) · 4.96 KB

PHP ArgoCD API Client

Build Status Latest Stable Version Total Downloads

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.

Features

  • Light and fast thanks to lazy loading of API classes.
  • Object-oriented interface to the ArgoCD API.

Requirements

Quick install

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

Basic Usage

<?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");
// }

?>

Documentation

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).

License

This library is licensed under the MIT License - see the LICENSE file for details.

Maintainers

This library is currently maintained by:

Contributors

  • 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.