1. Go to this page and download the library: Download lucasberto/laravel-vault library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Lucasberto\LaravelVault\Facades\Vault;
// List secrets (KV v2)
$secrets = Vault::listSecrets('path/to/secrets');
// List secrets (KV v1)
$secrets = Vault::listSecrets('path/to/secrets', 1);
// Get a secret (KV v2)
$secret = Vault::getSecret('path/to/secret');
// Using KV v1
$secret = Vault::getSecret('path/to/secret', 1);
// Store a secret (KV v2)
Vault::putSecret('path/to/secret', [
'username' => 'admin',
'password' => 'secret'
]);
// Store a secret (KV v1)
Vault::putSecret('path/to/secret', [
'username' => 'admin',
'password' => 'secret'
], 1);
// Delete a secret (KV v2)
Vault::deleteSecret('path/to/secret');
// Delete a secret (KV v1)
Vault::deleteSecret('path/to/secret', 1);
// Check if vault is unsealed
$isUnsealed = Vault::isUnsealed();
// Seal vault
$sealed = Vault::seal();
// Unseal vault (one call per key, after n calls, vault is unsealed)
Vault::unseal('key');
// Get vault health
$health = Vault::health();
// It is also possible to use a custom client (of type GuzzleHttp\Client)
$config = app()->config['vault']['servers']['main'];
$httpClient = new \GuzzleHttp\Client([
'base_uri' => $config['address'],
'headers' => [
'X-Vault-Token' => $config['token'],
],
'timeout' => $config['timeout'],
]);
$vaultClient = new Lucasberto\LaravelVault\VaultClient($config, $httpClient);
$vaultClient->getSecret('path/to/secret');
// Use default connection
$secret = Vault::getSecret('path/to/secret');
// Use specific connection
$secret = Vault::connection('secondary')->getSecret('path/to/secret');