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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.3','8.x']
php-versions: ['8.3','8.4','8.x']
name: Testing PHP ${{ matrix.php-versions }}
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .php-cs-fixer.cache

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

return (new Config())
->setParallelConfig(ParallelConfigFactory::detect()) // @TODO 4.0 no need to call this manually
->setRiskyAllowed(false)
->setRules([
'@auto' => true,
'@PhpCsFixer' => true
])
// 💡 by default, Fixer looks for `*.php` files excluding `./vendor/` - here, you can groom this config
->setFinder(
(new Finder())
// 💡 root folder to check
->in(__DIR__)
// 💡 additional files, eg bin entry file
// ->append([__DIR__.'/bin-entry-file'])
// 💡 folders to exclude, if any
// ->exclude([/* ... */])
// 💡 path patterns to exclude, if any
// ->notPath([/* ... */])
// 💡 extra configs
// ->ignoreDotFiles(false) // true by default in v3, false in v4 or future mode
// ->ignoreVCSIgnored(true) // true by default
)
;
86 changes: 43 additions & 43 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
{
"name": "mittwald/vault-php",
"type": "library",
"license": "MIT",
"homepage": "https://www.mittwald.de/",
"description": "A PHP client library for 'Vault by HashiCorp'",
"require": {
"ext-json": "*",
"guzzlehttp/psr7": "^2.7.1",
"php": ">=8.3"
},
"suggest": {
"guzzlehttp/guzzle": "HTTP Client Adapter"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^v3.75.0",
"php-http/mock-client": "^1.6.1",
"phpunit/phpunit": "^12.1.5",
"vimeo/psalm": "^6.10.3"
},
"authors": [
{
"name": "Marco Rieger",
"email": "m.rieger@mittwald.de"
}
],
"autoload": {
"psr-4": {
"VaultPHP\\": "src\\VaultPHP\\"
}
},
"autoload-dev": {
"psr-4": {
"Test\\VaultPHP\\": "tests\\VaultPHP\\"
}
},
"scripts": {
"test": "php ./vendor/bin/phpunit --configuration ./phpunit.xml.dist",
"pretty": "php ./vendor/bin/php-cs-fixer fix ./src"
},
"config": {
"allow-plugins": {
"php-http/discovery": false
}
"name": "mittwald/vault-php",
"type": "library",
"license": "MIT",
"homepage": "https://www.mittwald.de/",
"description": "A PHP client library for 'Vault by HashiCorp'",
"require": {
"ext-json": "*",
"guzzlehttp/psr7": "^2.7.1",
"php": ">=8.3"
},
"suggest": {
"guzzlehttp/guzzle": "HTTP Client Adapter"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^v3.91.2",
"php-http/mock-client": "^1.6.1",
"phpunit/phpunit": "^12.5.0",
"vimeo/psalm": "6.x-dev"
},
"authors": [
{
"name": "Marco Rieger",
"email": "m.rieger@mittwald.de"
}
],
"autoload": {
"psr-4": {
"VaultPHP\\": "src\\VaultPHP\\"
}
},
"autoload-dev": {
"psr-4": {
"Test\\VaultPHP\\": "tests\\VaultPHP\\"
}
},
"scripts": {
"test": "./vendor/bin/psalm --no-cache && php ./vendor/bin/phpunit --configuration ./phpunit.xml.dist",
"pretty": "php ./vendor/bin/php-cs-fixer fix ./src"
},
"config": {
"allow-plugins": {
"php-http/discovery": false
}
}
}
36 changes: 15 additions & 21 deletions src/VaultPHP/Authentication/AbstractAuthenticationProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace VaultPHP\Authentication;
Expand All @@ -12,45 +13,26 @@
use VaultPHP\VaultClient;

/**
* Class AbstractAuthenticationProvider
* @package VaultPHP\Authentication
* Class AbstractAuthenticationProvider.
*/
abstract class AbstractAuthenticationProvider implements AuthenticationProviderInterface
{
/** @var VaultClient|null */
private ?VaultClient $vaultClient = null;

/**
* @param VaultClient $VaultClient
* @return void
*/
#[\Override]
public function setVaultClient(VaultClient $VaultClient): void
{
$this->vaultClient = $VaultClient;
}

/**
* @throws VaultException
* @return VaultClient
*/
private function getVaultClient(): VaultClient
{
if (!$this->vaultClient) {
throw new VaultException('Trying to request the VaultClient before initialization');
}

return $this->vaultClient;
}

/**
* @throws InvalidRouteException
* @throws VaultHttpException
* @throws VaultException
* @throws InvalidDataException
* @throws VaultAuthenticationException
*/
protected function sendApiRequest(string $method, string $endpoint, string $returnClass, ResourceRequestInterface|array $data = []): mixed
protected function sendApiRequest(string $method, string $endpoint, string $returnClass, array|ResourceRequestInterface $data = []): mixed
{
return $this->getVaultClient()->sendApiRequest(
$method,
Expand All @@ -60,4 +42,16 @@ protected function sendApiRequest(string $method, string $endpoint, string $retu
false,
);
}

/**
* @throws VaultException
*/
private function getVaultClient(): VaultClient
{
if (!$this->vaultClient) {
throw new VaultException('Trying to request the VaultClient before initialization');
}

return $this->vaultClient;
}
}
14 changes: 3 additions & 11 deletions src/VaultPHP/Authentication/AuthenticationMetaData.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
<?php

declare(strict_types=1);

namespace VaultPHP\Authentication;

/**
* Class AuthenticationMetaData
* @package VaultPHP\Authentication
* Class AuthenticationMetaData.
*/
final class AuthenticationMetaData
{
/** @var string */
private string $token = '';

/**
* AuthenticationMetaData constructor.
* @param object|null $fromAuth
*/
public function __construct(?object $fromAuth = null)
{
Expand All @@ -23,19 +21,13 @@ public function __construct(?object $fromAuth = null)
}
}

/**
* @return string
*/
public function getClientToken(): string
{
return $this->token;
}

/**
* @return bool
*/
public function isClientTokenPresent(): bool
{
return !!$this->token;
return (bool) $this->token;
}
}
11 changes: 2 additions & 9 deletions src/VaultPHP/Authentication/AuthenticationProviderInterface.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
<?php

declare(strict_types=1);

namespace VaultPHP\Authentication;

use VaultPHP\VaultClient;

/**
* Interface AuthenticationProviderInterface
* @package VaultPHP\Authentication
* Interface AuthenticationProviderInterface.
*/
interface AuthenticationProviderInterface
{
/**
* @return AuthenticationMetaData|boolean
*/
public function authenticate(): AuthenticationMetaData|bool;

/**
* @param VaultClient $VaultClient
* @return void
*/
public function setVaultClient(VaultClient $VaultClient): void;
}
13 changes: 4 additions & 9 deletions src/VaultPHP/Authentication/Provider/AppRole.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace VaultPHP\Authentication\Provider;
Expand All @@ -13,24 +14,18 @@
use VaultPHP\Response\EndpointResponse;

/**
* Class AppRole
* @package VaultPHP\Authentication\Provider
* Class AppRole.
*/
final class AppRole extends AbstractAuthenticationProvider
{
/** @var string */
public const string endpoint = '/v1/auth/approle/login';
private string $roleId;

/** @var string */
private string $secretId;

/** @var string */
const string endpoint = '/v1/auth/approle/login';

/**
* AppRole constructor.
* @param string $roleId
* @param string $secretId
*/
public function __construct(string $roleId, string $secretId)
{
Expand All @@ -48,7 +43,7 @@ public function __construct(string $roleId, string $secretId)
* @throws VaultHttpException
*/
#[\Override]
public function authenticate(): bool|AuthenticationMetaData
public function authenticate(): AuthenticationMetaData|bool
{
/** @var EndpointResponse $response */
$response = $this->sendApiRequest(
Expand Down
16 changes: 5 additions & 11 deletions src/VaultPHP/Authentication/Provider/Kubernetes.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace VaultPHP\Authentication\Provider;
Expand All @@ -13,42 +14,35 @@
use VaultPHP\Response\EndpointResponse;

/**
* Class Kubernetes
* @package VaultPHP\Authentication\Provider
* Class Kubernetes.
*/
final class Kubernetes extends AbstractAuthenticationProvider
{
/** @var string */
private string $role;
/** @var string */
private string $jwt;
/** @var string */
private string $endpoint;

/**
* Kubernetes constructor.
* @param string $role
* @param string $jwt
*
* @param string $authPath - defaults to '/auth/kubernetes'
*/
public function __construct(string $role, string $jwt, string $authPath = 'auth/kubernetes')
{
$this->role = $role;
$this->jwt = $jwt;
$this->endpoint = '/v1/' . $authPath . '/login';
$this->endpoint = '/v1/'.$authPath.'/login';
}

/**
* @return AuthenticationMetaData|false
*
* @throws InvalidDataException
* @throws InvalidRouteException
* @throws VaultAuthenticationException
* @throws VaultException
* @throws VaultHttpException
*/
#[\Override]
public function authenticate(): false|AuthenticationMetaData
public function authenticate(): AuthenticationMetaData|false
{
/** @var EndpointResponse $response */
$response = $this->sendApiRequest(
Expand Down
Loading