jccp / vault
v4.0.0
2017-09-15 16:40 UTC
Requires
- php: >=7.0
- guzzlehttp/guzzle: ^6.2
Requires (Dev)
- mockery/mockery: ^0.9.9
- phpunit/phpunit: ^6.3
README
Vault SDK
支持
- 身份验证
- 令牌
- 身份验证角色
- 通用
- 读取
- 写入
示例
配置环境
默认客户端将使用环境变量 VAULT_ADDR 和 VAULT_TOKEN
export VAULT_ADDR=https://:8200
export VAULT_TOKEN=horde
读取和写入机密信息
$secrets = [
"foo" => "bar",
"baz" => "boo",
];
$config = new DefaultVaultConfig('https://:8200', new Tokens('horde'), '');
$vaultClient = new VaultClient(new Client());
$vaultClient->withConfig($config);
$vaultClient->write('secret/testing', $secrets);
$found = $vaultClient->read('secret/testing');
print_r($found['data']);
// Output:
// Array
// (
// [baz] => boo
// [foo] => bar
// )
使用AppRole登录
$roleId = "...";
$secretId = "...";
$secrets = [
"foo" => "bar",
"baz" => "boo",
];
$vaultClient = new VaultClient(new Client());
$auth = new AppRole($vaultClient);
$auth->with('theRoleId', 'theSecretId');
$config = new DefaultVaultConfig('https://:8200', $auth, '');
$vaultClient->withConfig($config);
$vaultClient->write('secret/testing', $secrets);
$found = $vaultClient->read('secret/testing');
print_r($found['data']);
// Output:
// Array
// (
// [baz] => boo
// [foo] => bar
// )