Files
PhpVaultClient/src/PhpVaultClient.php
2024-09-25 11:41:58 -05:00

42 lines
1.0 KiB
PHP

<?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();
}
}