initial commit
This commit is contained in:
41
src/PhpVaultClient.php
Normal file
41
src/PhpVaultClient.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Hpz\Phpvaultclient;
|
||||
|
||||
use Hpz937\Restclient\RestClient;
|
||||
|
||||
class PhpVaultClient
|
||||
{
|
||||
private $vaultUrl = 'https://vault.bobscycle.com';
|
||||
private $restClient;
|
||||
private $token;
|
||||
|
||||
public function __construct($vaultUrl = null)
|
||||
{
|
||||
if ($vaultUrl) {
|
||||
$this->vaultUrl = $vaultUrl;
|
||||
}
|
||||
$this->restClient = new RestClient();
|
||||
}
|
||||
|
||||
public function login($username, $password)
|
||||
{
|
||||
$response = $this->restClient->post($this->vaultUrl . '/login', [
|
||||
'username' => $username,
|
||||
'password' => $password
|
||||
]);
|
||||
$this->token = $response->decodeJson()['token'];
|
||||
}
|
||||
|
||||
public function getSecret($secretPath, $key)
|
||||
{
|
||||
$this->restClient->setHeaders([
|
||||
'Content-Type: application/json',
|
||||
'Authorization: Bearer ' . $this->token
|
||||
]);
|
||||
$response = $this->restClient->post($this->vaultUrl . '/vault/' . $secretPath, [
|
||||
'key' => $key
|
||||
]);
|
||||
return $response->decodeJson();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user