Skip to content

Commit 22d2573

Browse files
feat: Initial ArgoCD PHP Client Foundation
This commit establishes the foundational components for a PHP client for the ArgoCD API, refactored from the KnpLabs GitHub API client. Includes: - Core client structure (`Client.php`, `HttpClient/Builder.php`, `Api/AbstractApi.php`, `HttpClient/Message/ResponseMediator.php`). - Basic exception handling (`ArgoCD/Exception/` and `HttpClient/Plugin/ArgoCdExceptionThrower.php`). - Authentication mechanism via bearer tokens, with `HttpClient/Plugin/Authentication.php`. - Implemented `SessionService` for login/logout and user info. - Implemented `AccountService` for account and token management. - Initial data models for Session and Account services. - `AI.md` detailing the AI-assisted development process. - `reference/argocd_swagger.json` containing the ArgoCD OpenAPI spec. - Updated `README.md` for the ArgoCD client. I attempted to restructure the project to remove the 'argocd-php-client' sub-directory and update CI workflows for PHP 8.3+, but I encountered persistent errors related to file system access and state. These changes are therefore not included in this commit and will need to be revisited.
1 parent 414893c commit 22d2573

34 files changed

+8237
-169
lines changed

AI.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# AI-Assisted Development Context: PHP ArgoCD API Client
2+
3+
This document provides context on the development process of this PHP client for the ArgoCD API, which was significantly assisted by an AI agent named Jules.
4+
5+
## Project Goal
6+
7+
The primary goal of this project was to refactor an existing PHP client library originally designed for the GitHub API (KnpLabs/php-github-api) and adapt it to become a fully functional client for the ArgoCD REST API.
8+
9+
## Development Process
10+
11+
The development process involved a collaborative effort between a human developer and the AI agent, Jules. Key aspects of this process include:
12+
13+
* **Initial Request:** The human developer provided an issue statement outlining the need to fork the GitHub library, study its structure, and then refactor it to implement ArgoCD's OpenAPI specification (`https://raw.githubusercontent.com/argoproj/argo-cd/master/assets/swagger.json`).
14+
* **Codebase Analysis:** Jules explored the existing GitHub client's codebase using tools to list files and read their content to understand its architecture and patterns.
15+
* **OpenAPI Analysis:** Jules fetched and analyzed the ArgoCD OpenAPI specification to understand its endpoints, data structures, and service organization.
16+
* **Planning:** Based on the analysis, Jules created a detailed, multi-step plan to execute the refactoring. This plan was reviewed and approved by the human developer.
17+
* **Iterative Implementation:** Jules executed the plan step-by-step by delegating specific, actionable tasks to a "Worker" agent. These tasks included:
18+
* Creating new directory structures.
19+
* Initializing `composer.json` and managing dependencies.
20+
* Adapting core client classes (`Client.php`, `HttpClient/Builder.php`, `Api/AbstractApi.php`).
21+
* Implementing exception handling.
22+
* Generating PHP model classes based on OpenAPI definitions.
23+
* Implementing API service classes (e.g., `SessionService.php`, `AccountService.php`) with methods corresponding to ArgoCD API operations.
24+
* **Feedback Incorporation:** The human developer provided feedback at various stages (e.g., on directory structure, PHP version constraints), and Jules updated the plan and execution accordingly.
25+
26+
## Current State
27+
28+
As of the last AI interaction, the project has achieved the following:
29+
30+
* **Core Infrastructure:** A foundational client structure is in place, including the main `Client` class, HTTP client builder, abstract API class, and basic exception handling.
31+
* **Authentication:** The client can authenticate against an ArgoCD instance by exchanging username/password for a bearer token (via `SessionService`) or by using a pre-existing token.
32+
* **Initial API Services:**
33+
* `SessionService`: Implemented for login, logout, and user info.
34+
* `AccountService`: Implemented for managing accounts and tokens.
35+
* **Data Models:** PHP model classes corresponding to the implemented services' request/response structures have been created.
36+
* **Project Configuration:** `composer.json` has been set up, and the project directory has been structured. The ArgoCD OpenAPI specification has been added to `reference/argocd_swagger.json`.
37+
38+
Further development will involve implementing the remaining ArgoCD API services (like the extensive `ApplicationService`), adding comprehensive unit tests, and refining documentation.
39+
40+
## Acknowledgements
41+
42+
* The initial structure and patterns were derived from the excellent [KnpLabs/php-github-api](https://github.com/KnpLabs/php-github-api) library.
43+
* The target API is [ArgoCD](https://argo-cd.readthedocs.io/en/stable/), and its OpenAPI specification was used as the blueprint for API implementation.

README.md

Lines changed: 88 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,130 @@
1-
# PHP GitHub API
1+
# PHP ArgoCD API Client
22

3-
![Build Status](https://github.com/KnpLabs/php-github-api/actions/workflows/ci.yml/badge.svg)
4-
[![StyleCI](https://styleci.io/repos/3948501/shield?style=flat)](https://styleci.io/repos/3948501)
5-
[![Latest Stable Version](https://poser.pugx.org/knplabs/github-api/v/stable)](https://packagist.org/packages/knplabs/github-api)
6-
[![Total Downloads](https://poser.pugx.org/knplabs/github-api/downloads)](https://packagist.org/packages/knplabs/github-api)
7-
[![Monthly Downloads](https://poser.pugx.org/knplabs/github-api/d/monthly)](https://packagist.org/packages/knplabs/github-api)
8-
[![Daily Downloads](https://poser.pugx.org/knplabs/github-api/d/daily)](https://packagist.org/packages/knplabs/github-api)
3+
[![Build Status](https://github.com/your-vendor/argocd-php-client/actions/workflows/ci.yml/badge.svg)](https://github.com/your-vendor/argocd-php-client/actions/workflows/ci.yml) <!-- Placeholder CI Badge -->
4+
[![Latest Stable Version](https://poser.pugx.org/your-vendor/argocd-php-client/v/stable)](https://packagist.org/packages/your-vendor/argocd-php-client) <!-- Placeholder Packagist Badge -->
5+
[![Total Downloads](https://poser.pugx.org/your-vendor/argocd-php-client/downloads)](https://packagist.org/packages/your-vendor/argocd-php-client) <!-- Placeholder Packagist Badge -->
96

10-
A simple Object Oriented wrapper for GitHub API, written with PHP.
7+
A PHP client for interacting with the ArgoCD API. This library provides an object-oriented interface to the ArgoCD REST API.
118

12-
Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4](http://developer.github.com/v4). The object API (v3) is very similar to the RESTful API.
9+
This client's structure is based on the [KnpLabs/php-github-api](https://github.com/KnpLabs/php-github-api) library.
10+
11+
For more context on the AI-assisted development process of this library, please see [AI.md](AI.md).
1312

1413
## Features
1514

16-
* Light and fast thanks to lazy loading of API classes
17-
* Extensively tested and documented
15+
* Light and fast thanks to lazy loading of API classes.
16+
* Object-oriented interface to the ArgoCD API.
1817

1918
## Requirements
2019

21-
* PHP >= 7.2
22-
* A [PSR-17 implementation](https://packagist.org/providers/psr/http-factory-implementation)
23-
* A [PSR-18 implementation](https://packagist.org/providers/psr/http-client-implementation)
20+
* PHP ^8.3
21+
* A [PSR-17 implementation](https://packagist.org/providers/psr/http-factory-implementation) (e.g., `nyholm/psr7`)
22+
* A [PSR-18 implementation](https://packagist.org/providers/psr/http-client-implementation) (e.g., `symfony/http-client` or `guzzlehttp/guzzle`)
2423

2524
## Quick install
2625

2726
Via [Composer](https://getcomposer.org).
2827

29-
This command will get you up and running quickly with a Guzzle HTTP client.
30-
3128
```bash
32-
composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0
29+
composer require your-vendor/argocd-php-client
3330
```
3431

35-
## Advanced install
36-
37-
We are decoupled from any HTTP messaging client with help by [HTTPlug](https://httplug.io).
38-
39-
### Using a different http client
32+
You will also need to install implementations for PSR-17 (HTTP Factories) and PSR-18 (HTTP Client), for example:
4033

4134
```bash
42-
composer require knplabs/github-api:^3.0 symfony/http-client nyholm/psr7
43-
```
44-
45-
To set up the Github client with this HTTP client
46-
47-
```php
48-
use Github\Client;
49-
use Symfony\Component\HttpClient\HttplugClient;
50-
51-
$client = Client::createWithHttpClient(new HttplugClient());
35+
composer require symfony/http-client nyholm/psr7
5236
```
53-
54-
Read more about [using different clients in our docs](doc/customize.md).
55-
56-
## Framework integrations
57-
58-
### Laravel
59-
60-
To integrate this library in laravel [Graham Campbell](https://github.com/GrahamCampbell) created [graham-campbell/github](https://github.com/GrahamCampbell/Laravel-GitHub). See the [installation instructions](https://github.com/GrahamCampbell/Laravel-GitHub#installation) to get started in laravel.
61-
62-
## Basic usage of `php-github-api` client
63-
64-
```php
65-
<?php
66-
67-
// This file is generated by Composer
68-
require_once __DIR__ . '/vendor/autoload.php';
69-
70-
$client = new \Github\Client();
71-
$repositories = $client->api('user')->repositories('ornicar');
37+
Or for Guzzle:
38+
```bash
39+
composer require guzzlehttp/guzzle php-http/guzzle7-adapter
7240
```
7341

74-
From `$client` object, you have access to all available GitHub api endpoints.
75-
76-
## Cache usage
77-
78-
This example uses the PSR6 cache pool [redis-adapter](https://github.com/php-cache/redis-adapter). See http://www.php-cache.com/ for alternatives.
42+
## Basic Usage
7943

8044
```php
8145
<?php
8246

8347
// This file is generated by Composer
8448
require_once __DIR__ . '/vendor/autoload.php';
8549

86-
use Cache\Adapter\Redis\RedisCachePool;
87-
88-
$client = new \Redis();
89-
$client->connect('127.0.0.1', 6379);
90-
// Create a PSR6 cache pool
91-
$pool = new RedisCachePool($client);
92-
93-
$client = new \Github\Client();
94-
$client->addCache($pool);
95-
96-
// Do some request
97-
98-
// Stop using cache
99-
$client->removeCache();
50+
// 1. Instantiate the client with your ArgoCD server URL
51+
// Ensure your ArgoCD server URL is correct and accessible.
52+
// The client will automatically append /api/v1 if it's not present.
53+
$client = new ArgoCD\Client('https://your-argocd-server.example.com');
54+
55+
// 2. Authenticate
56+
// Option A: Using username and password (fetches a token via SessionService)
57+
try {
58+
$client->authenticate('your-username', 'your-password');
59+
echo "Successfully authenticated using username/password. Token: " . substr($client->getToken() ?? 'N/A', 0, 10) . "...\n";
60+
} catch (ArgoCD\Exception\RuntimeException $e) {
61+
die('Authentication failed: ' . $e->getMessage() . "\n");
62+
}
63+
64+
// Option B: Using a pre-existing token
65+
// try {
66+
// $client->authenticate('your-argocd-api-token');
67+
// echo "Successfully authenticated using pre-existing token.\n";
68+
// } catch (ArgoCD\Exception\InvalidArgumentException $e) {
69+
// die('Authentication failed with token: ' . $e->getMessage() . "\n");
70+
// }
71+
72+
73+
// 3. Access API services
74+
try {
75+
// Example: Get user info
76+
$userInfo = $client->sessionService()->getUserInfo();
77+
echo "Logged in as: " . $userInfo->getUsername() . "\n";
78+
echo "Logged in status: " . ($userInfo->isLoggedIn() ? 'true' : 'false') . "\n";
79+
80+
// Example: List accounts (requires admin privileges typically)
81+
// Note: Ensure the authenticated user has permissions for these operations.
82+
// try {
83+
// $accountsList = $client->accountService()->listAccounts();
84+
// echo "Listing accounts:\n";
85+
// if (count($accountsList->getItems()) > 0) {
86+
// foreach ($accountsList->getItems() as $account) {
87+
// echo " - Account Name: " . $account->getName() . ", Enabled: " . ($account->isEnabled() ? 'Yes' : 'No') . "\n";
88+
// }
89+
// } else {
90+
// echo "No accounts found or not enough permissions.\n";
91+
// }
92+
// } catch (ArgoCD\Exception\RuntimeException $e) {
93+
// echo "Could not list accounts: " . $e->getMessage() . "\n";
94+
// }
95+
96+
97+
} catch (ArgoCD\Exception\RuntimeException $e) {
98+
die('API Error: ' . $e->getMessage() . "\n");
99+
}
100+
101+
// Example: Delete the session (logout)
102+
// try {
103+
// $client->sessionService()->delete();
104+
// echo "Successfully logged out.\n";
105+
// } catch (ArgoCD\Exception\RuntimeException $e) {
106+
// die('Logout failed: ' . $e->getMessage() . "\n");
107+
// }
108+
109+
?>
100110
```
101111

102-
Using cache, the client will get cached responses if resources haven't changed since last time,
103-
**without** reaching the `X-Rate-Limit` [imposed by github](http://developer.github.com/v3/#rate-limiting).
104-
105-
106112
## Documentation
107113

108-
See the [`doc` directory](doc/) for more detailed documentation.
114+
Further documentation will be available as the library matures. For now, refer to the source code and the official [ArgoCD API documentation](https://cd.apps.argoproj.io/swagger-ui) (or the `reference/argocd_swagger.json` file in this repository).
109115

110116
## License
111117

112-
`php-github-api` is licensed under the MIT License - see the LICENSE file for details
118+
This library is licensed under the MIT License - see the LICENSE file for details.
113119

114120
## Maintainers
115121

116-
Please read [this post](https://knplabs.com/en/blog/news-for-our-foss-projects-maintenance) first.
117-
118-
This library is maintained by the following people (alphabetically sorted) :
119-
- [@acrobat](https://github.com/acrobat)
120-
- [@Nyholm](https://github.com/Nyholm)
122+
This library is currently maintained by:
123+
- [Your Name](https://github.com/your-vendor) (or your GitHub username)
121124

122125
## Contributors
123126

124-
- Thanks to [Thibault Duplessis aka. ornicar](https://github.com/ornicar) for his first version of this library.
125-
- Thanks to [Joseph Bielawski aka. stloyd](https://github.com/stloyd) for his contributions and support.
126-
- Thanks to [noloh](https://github.com/noloh) for his contribution on the Object API.
127-
- Thanks to [bshaffer](https://github.com/bshaffer) for his contribution on the Repo API.
128-
- Thanks to [Rolf van de Krol](https://github.com/rolfvandekrol) for his countless contributions.
129-
- Thanks to [Nicolas Pastorino](https://github.com/jeanvoye) for his contribution on the Pull Request API.
130-
- Thanks to [Edoardo Rivello](https://github.com/erivello) for his contribution on the Gists API.
131-
- Thanks to [Miguel Piedrafita](https://github.com/m1guelpf) for his contribution to the v4 & Apps API.
132-
- Thanks to [Emre DEGER](https://github.com/lexor) for his contribution to the Actions API.
133-
134-
Thanks to GitHub for the high quality API and documentation.
127+
* This project was significantly bootstrapped with the assistance of an AI agent. See [AI.md](AI.md) for more details.
128+
* Structure and patterns inspired by [KnpLabs/php-github-api](https://github.com/KnpLabs/php-github-api).
129+
* Thanks to the ArgoCD team for their excellent API and documentation.
130+
```

argocd-php-client/composer.json

Lines changed: 0 additions & 33 deletions
This file was deleted.

composer.json

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,33 @@
11
{
2-
"name": "knplabs/github-api",
2+
"name": "your-vendor/argocd-php-client",
3+
"description": "A PHP client for the ArgoCD API",
34
"type": "library",
4-
"description": "GitHub API v3 client",
5-
"homepage": "https://github.com/KnpLabs/php-github-api",
6-
"keywords": ["github", "gh", "api", "gist"],
75
"license": "MIT",
86
"authors": [
97
{
10-
"name": "KnpLabs Team",
11-
"homepage": "http://knplabs.com"
12-
},
13-
{
14-
"name": "Thibault Duplessis",
15-
"email": "thibault.duplessis@gmail.com",
16-
"homepage": "http://ornicar.github.com"
8+
"name": "Your Name",
9+
"email": "your.email@example.com"
1710
}
1811
],
1912
"require": {
20-
"php": "^7.2.5 || ^8.0",
21-
"ext-json": "*",
22-
"php-http/cache-plugin": "^1.7.1|^2.0",
13+
"php": "^8.3",
2314
"php-http/client-common": "^2.3",
2415
"php-http/discovery": "^1.12",
25-
"php-http/httplug": "^2.2",
26-
"php-http/multipart-stream-builder": "^1.1.2",
27-
"psr/cache": "^1.0|^2.0|^3.0",
2816
"psr/http-client-implementation": "^1.0",
2917
"psr/http-factory-implementation": "^1.0",
30-
"psr/http-message": "^1.0|^2.0",
31-
"symfony/polyfill-php80": "^1.17",
32-
"symfony/deprecation-contracts": "^2.2|^3.0"
18+
"psr/http-message": "^1.0 || ^2.0"
3319
},
3420
"require-dev": {
35-
"symfony/cache": "^5.1.8",
36-
"guzzlehttp/psr7": "^2.7",
37-
"http-interop/http-factory-guzzle": "^1.0",
38-
"guzzlehttp/guzzle": "^7.2",
39-
"php-http/mock-client": "^1.4.1",
40-
"phpstan/phpstan": "^0.12.57",
41-
"phpstan/extension-installer": "^1.0.5",
42-
"phpstan/phpstan-deprecation-rules": "^0.12.5",
43-
"phpunit/phpunit": "^8.5 || ^9.4",
44-
"symfony/phpunit-bridge": "^5.2"
21+
"phpunit/phpunit": "^9.5"
4522
},
4623
"autoload": {
47-
"psr-4": { "Github\\": "lib/Github/" }
48-
},
49-
"autoload-dev": {
50-
"psr-4": { "Github\\Tests\\": "test/Github/Tests/"}
51-
},
52-
"extra": {
53-
"branch-alias": {
54-
"dev-2.x": "2.20.x-dev",
55-
"dev-master": "3.16-dev"
24+
"psr-4": {
25+
"ArgoCD\\": "src/ArgoCD/"
5626
}
5727
},
58-
"config": {
59-
"allow-plugins": {
60-
"phpstan/extension-installer": true,
61-
"composer/package-versions-deprecated": true,
62-
"php-http/discovery": true
28+
"autoload-dev": {
29+
"psr-4": {
30+
"ArgoCD\\Tests\\": "tests/"
6331
}
6432
}
6533
}

0 commit comments

Comments
 (0)