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
8 changes: 2 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@
"require": {
"ext-json": "*",
"guzzlehttp/psr7": "^2.7.1",
"php": ">=8.3",
"psr/http-client": "^1.0.3"
"php": ">=8.3"
},
"suggest": {
"php-http/curl-client": "CURL Client Adapter",
"tuupola/http-factory": "HTTP Factory"
"guzzlehttp/guzzle": "HTTP Client Adapter"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^v3.75.0",
"symfony/http-client": "^v7.2.4",
"nyholm/psr7": "^1.8.2",
"php-http/mock-client": "^1.6.1",
"phpunit/phpunit": "^12.1.5",
"vimeo/psalm": "^6.10.3"
Expand Down
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
vault:
image: vault:latest
image: hashicorp/vault:latest
container_name: vault
restart: unless-stopped
ports:
Expand All @@ -12,6 +12,4 @@ services:
VAULT_TOKEN: 'test'
cap_add:
- IPC_LOCK
healthcheck:
retries: 5
command: server -dev
20 changes: 9 additions & 11 deletions examples/BulkOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Examples;

use Http\Client\Curl\Client;
use VaultPHP\Authentication\Provider\Token;
use VaultPHP\Exceptions\VaultException;
use VaultPHP\Exceptions\VaultResponseException;
Expand All @@ -15,28 +14,27 @@
use VaultPHP\SecretEngines\Engines\Transit\EncryptionType;
use VaultPHP\VaultClient;

use GuzzleHttp\Client;

require_once __DIR__ . '/../vendor/autoload.php';

// setting up curl http client with SSL
$httpClient = new Client(null, null, [
CURLOPT_SSLCERT => './ssl.pem',
CURLOPT_SSLCERTTYPE => 'PEM',
CURLOPT_SSLCERTPASSWD => 'fooBar',
]);
// setup http client
$httpClient = new Client(['verify' => false]);

// provide hashicorp vault auth
// setup authentication provider
$authenticationProvider = new Token('test');

// initalize the vault request client
// initialize the vault request client
$vaultClient = new VaultClient(
$httpClient,
$authenticationProvider,
'https://127.0.0.1:8200'
'http://127.0.0.1:8200/transit/',
);

// choose your secret engine api
// create eg. Transit API instance
$transitApi = new Transit($vaultClient);


// do fancy stuff
try {
// create key
Expand Down
30 changes: 12 additions & 18 deletions examples/TransitEncryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Examples;

use Http\Client\Curl\Client;
use VaultPHP\Authentication\Provider\Token;
use VaultPHP\Exceptions\VaultException;
use VaultPHP\Exceptions\VaultResponseException;
Expand All @@ -14,29 +13,26 @@
use VaultPHP\SecretEngines\Engines\Transit\EncryptionType;
use VaultPHP\VaultClient;

use GuzzleHttp\Client;

require_once __DIR__ . '/../vendor/autoload.php';

// setting up curl http client with SSL
$httpClient = new Client(null, null, [
CURLOPT_SSLCERT => './ssl.pem',
CURLOPT_SSLCERTTYPE => 'PEM',
CURLOPT_SSLCERTPASSWD => 'fooBar',
]);
// setup http client
$httpClient = new Client(['verify' => false]);

// provide hashicorp vault auth
// setup authentication provider
$authenticationProvider = new Token('test');

// initalize the vault request client
// initialize the vault request client
$vaultClient = new VaultClient(
$httpClient,
$authenticationProvider,
'https://127.0.0.1:8200'
'http://127.0.0.1:8200/transit/',
);

// choose your secret engine api
// create eg. Transit API instance
$transitApi = new Transit($vaultClient);

// do fancy stuff
try {
// create key
$exampleKey = new CreateKeyRequest('exampleKeyName');
Expand All @@ -45,19 +41,17 @@

// list keys
$listKeyResponse = $transitApi->listKeys();
var_dump($listKeyResponse->getKeys());
var_dump($listKeyResponse->getKeys()); // ["exampleKeyName"]

// encrypt data
$encryptExample = new EncryptDataRequest('exampleKeyName', 'encryptMe');
$encryptResponse = $transitApi->encryptData($encryptExample);

var_dump($encryptResponse->getCiphertext());
var_dump($encryptResponse->getCiphertext()); // vault:v1:jt9yxqU2aHd+EIOZs1swB+C3jVLtvyXgpfdfbxi+thNafm0IDQ==

// decrypt data
$decryptExample = new DecryptDataRequest('exampleKeyName', $encryptResponse->getCiphertext());
$decryptResponse = $transitApi->decryptData($decryptExample);

var_dump($decryptResponse->getPlaintext());
var_dump($decryptResponse->getPlaintext()); // encryptMe

// update key config and allow deletion
$keyConfigExample = new UpdateKeyConfigRequest('exampleKeyName');
Expand All @@ -69,7 +63,7 @@

// list keys
$listKeyResponse = $transitApi->listKeys();
var_dump($listKeyResponse->getKeys());
var_dump($listKeyResponse->getKeys()); // []

} catch (VaultResponseException $exception) {
var_dump($exception->getMessage());
Expand Down
9 changes: 9 additions & 0 deletions src/VaultPHP/Response/MetaData.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ public function setLeaseDuration(mixed $lease_duration): void
$this->lease_duration = (int) $lease_duration;
}

/**
* @param array|null $warnings
* @return void
*/
public function setWarnings(array|null $warnings): void
{
$this->warnings = $warnings ?? [];
}


/**
* @return string|null
Expand Down