Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/configuration-variables-resolver/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"php": "^8.2",
"ext-json": "*",
"keboola/common-exceptions": "^1.1",
"keboola/php-api-client-base": "*@dev",
"keboola/service-client": "*@dev",
"keboola/storage-api-client": "^17.0|^18.0",
"keboola/storage-api-php-client-branch-wrapper": "^6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Keboola\ServiceClient\ServiceClient;
use Keboola\StorageApiBranch\ClientWrapper;
use Keboola\VaultApiClient\ApiClientConfiguration as VaultVariablesApiClientConfiguration;
use Keboola\VaultApiClient\Variables\VariablesApiClient;
use Psr\Log\LoggerInterface;

Expand All @@ -30,10 +29,13 @@ public function createResolver(
$token = $clientWrapper->getToken()->getTokenValue();
assert($token !== '');

$config = $this->vaultVariablesApiClientConfiguration;
$vaultVariablesApiClient = new VariablesApiClient(
baseUrl: $this->serviceClient->getVaultUrl(),
token: $token,
configuration: $this->vaultVariablesApiClientConfiguration,
logger: $this->logger,
backoffMaxTries: $config->backoffMaxTries,
userAgent: 'Keboola Vault PHP Client' . ($config->userAgent !== null ? ' - ' . $config->userAgent : ''),
);

$sharedCodeResolver = new SharedCodeResolver($clientWrapper, $this->logger);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Keboola\ConfigurationVariablesResolver;

/**
* Configuration for the vault VariablesApiClient.
*
* Re-introduced locally after vault-api-client dropped its own ApiClientConfiguration
* (flattened into individual constructor arguments). Keeps this lib's previous default
* of 10 retries and preserves the factory's config-object API for its consumers.
*/
class VaultVariablesApiClientConfiguration
{
private const DEFAULT_BACKOFF_RETRIES = 10;

/**
* @param int<0, max> $backoffMaxTries
*/
public function __construct(
public readonly ?string $userAgent = null,
public readonly int $backoffMaxTries = self::DEFAULT_BACKOFF_RETRIES,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace Keboola\ConfigurationVariablesResolver\Tests;

use Keboola\ConfigurationVariablesResolver\UnifiedConfigurationResolverFactory;
use Keboola\ConfigurationVariablesResolver\VaultVariablesApiClientConfiguration;
use Keboola\ServiceClient\ServiceClient;
use Keboola\StorageApi\BranchAwareClient;
use Keboola\StorageApiBranch\ClientWrapper;
use Keboola\StorageApiBranch\StorageApiToken;
use Keboola\VaultApiClient\ApiClientConfiguration as VaultVariablesApiClientConfiguration;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;

Expand Down Expand Up @@ -235,11 +235,9 @@ private function getFactory(): UnifiedConfigurationResolverFactory
$serviceClient = $this->createMock(ServiceClient::class);
$serviceClient->method('getVaultUrl')->willReturn($this->variablesApiMock->getServerUrl());

$vaultVariablesApiClientConfiguration = new VaultVariablesApiClientConfiguration();

return new UnifiedConfigurationResolverFactory(
$serviceClient,
$vaultVariablesApiClientConfiguration,
new VaultVariablesApiClientConfiguration(),
new NullLogger,
);
}
Expand Down
48 changes: 48 additions & 0 deletions libs/vault-api-client/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,58 @@
# Vault API Client

PHP client for the Keboola Vault API, built on top of `keboola/php-api-client-base`.

## Installation

```bash
composer require keboola/vault-api-client
```

## Usage

```php
use Keboola\VaultApiClient\Variables\Model\ListOptions;
use Keboola\VaultApiClient\Variables\Model\Variable;
use Keboola\VaultApiClient\Variables\VariablesApiClient;

$client = new VariablesApiClient(
baseUrl: 'https://vault.keboola.com',
token: 'your-storage-api-token',
);

// Create a variable
$variable = $client->createVariable(
key: 'MY_SECRET',
value: 'secret-value',
flags: [Variable::FLAG_ENCRYPTED],
attributes: ['branchId' => '123'],
);

// List variables
$variables = $client->listVariables(new ListOptions(offset: 0, limit: 50));

// List scoped variables for a branch
$branchVariables = $client->listScopedVariablesForBranch(branchId: '123');

// Delete a variable
$client->deleteVariable(hash: $variable->hash);
```

### Custom configuration

Pass retry, timeout, and logging options directly as constructor parameters:

```php
use Monolog\Logger;

$client = new VariablesApiClient(
baseUrl: 'https://vault.keboola.com',
token: 'your-storage-api-token',
backoffMaxTries: 3,
logger: new Logger('vault'),
);
```

## License

MIT licensed, see [LICENSE](./LICENSE) file.
7 changes: 7 additions & 0 deletions libs/vault-api-client/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
"email": "devel@keboola.com"
}
],
"repositories": {
"libs": {
"type": "path",
"url": "../../libs/*"
}
},
"autoload": {
"psr-4": {
"Keboola\\VaultApiClient\\": "src/"
Expand All @@ -22,6 +28,7 @@
"require": {
"php": "^8.2",
"guzzlehttp/guzzle": "^7.5",
"keboola/php-api-client-base": "*@dev",
"monolog/monolog": "^2.0|^3.0",
"webmozart/assert": "^1.11"
},
Expand Down
142 changes: 0 additions & 142 deletions libs/vault-api-client/src/ApiClient.php

This file was deleted.

27 changes: 0 additions & 27 deletions libs/vault-api-client/src/ApiClientConfiguration.php

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions libs/vault-api-client/src/Exception/ClientException.php

This file was deleted.

11 changes: 11 additions & 0 deletions libs/vault-api-client/src/Exception/VaultClientException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Keboola\VaultApiClient\Exception;

use Keboola\ApiClientBase\Exception\ClientException;

final class VaultClientException extends ClientException
{
}
Loading
Loading