PHP code example of kebacorp / vaultsecret

1. Go to this page and download the library: Download kebacorp/vaultsecret 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/ */

    

kebacorp / vaultsecret example snippets




use KebaCorp\VaultSecret\VaultSecret;

// Get secret from file that contains json string
VaultSecret::getSecret('SECRET_KEY', 'path/secret.json');



use KebaCorp\VaultSecret\VaultSecret;
use KebaCorp\VaultSecret\VaultSecretParams;

// Set params
$vaultSecretParams = new VaultSecretParams();
$vaultSecretParams->setToken('vaultToken');
VaultSecret::setParams($vaultSecretParams);

// Get secret from Vault service
VaultSecret::getSecret('SECRET_KEY', 'http://localhost:8200/v1/kv2/data/secretName');



use KebaCorp\VaultSecret\template\TemplateCreator;
use KebaCorp\VaultSecret\VaultSecret;
use KebaCorp\VaultSecret\VaultSecretParams;

// Set params
$vaultSecretParams = new VaultSecretParams();
$vaultSecretParams->setToken('vaultToken');
VaultSecret::setParams($vaultSecretParams);

// Get secret from Vault service
VaultSecret::getSecret(
    'SECRET_KEY',
    'http://localhost:8200/v1/kv2/data/secretName',
    null,
    TemplateCreator::TEMPLATE_KV1
);



use KebaCorp\VaultSecret\VaultSecret;
use KebaCorp\VaultSecret\VaultSecretParams;

$vaultSecretParams = new VaultSecretParams();
$vaultSecretParams->setToken('vaultToken');
VaultSecret::setParams($vaultSecretParams);



use KebaCorp\VaultSecret\VaultSecret;
use KebaCorp\VaultSecret\VaultSecretParams;

$vaultSecretParams = new VaultSecretParams();
$vaultSecretParams->setIsSaveTemplate(true); // Not necessary
$vaultSecretParams->setSaveTemplateFilename(__DIR__ . '/jsonTemplates/template'); // Not necessary
VaultSecret::setParams($vaultSecretParams);



use KebaCorp\VaultSecret\VaultSecret;
use KebaCorp\VaultSecret\VaultSecretParams;

$vaultSecretParams = new VaultSecretParams();
$vaultSecretParams->setIsSaveTemplate(false);
VaultSecret::setParams($vaultSecretParams);



use KebaCorp\VaultSecret\VaultSecret;
use KebaCorp\VaultSecret\VaultSecretParams;

$vaultSecretParams = new VaultSecretParams();
$vaultSecretParams->setSource('http://localhost:8200/v1/kv2/data/secretName');
VaultSecret::setParams($vaultSecretParams);



use KebaCorp\VaultSecret\VaultSecret;
use KebaCorp\VaultSecret\VaultSecretParams;

$vaultSecretParams = new VaultSecretParams();
$vaultSecretParams->setSource('path/secret.json');
VaultSecret::setParams($vaultSecretParams);



use KebaCorp\VaultSecret\SecretMemoryCache;
use KebaCorp\VaultSecret\VaultSecret;
use KebaCorp\VaultSecret\VaultSecretParams;

// Use your cache object here
$myCacheObject = SecretMemoryCache::getInstance();

$vaultSecretParams = new VaultSecretParams();
$vaultSecretParams->setCache($myCacheObject);
VaultSecret::setParams($vaultSecretParams);

php composer.phar