initial commit
This commit is contained in:
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
composer.phar
|
||||
/vendor/
|
||||
|
||||
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
|
||||
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
|
||||
# composer.lock
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 hpz937
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
37
README.md
Normal file
37
README.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# PhpVaultClient
|
||||
|
||||
## Installation
|
||||
|
||||
To use the `PhpVaultClient` class in your PHP project:
|
||||
|
||||
Setup this registry in your ~/.composer/config.json file:
|
||||
```json
|
||||
{
|
||||
"repositories": [{
|
||||
"type": "composer",
|
||||
"url": "https://git.hpz.pw/api/packages/hpz937/composer"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
To install the package using Composer, run the following command:
|
||||
```
|
||||
composer require hpz937/phpvaultclient
|
||||
```
|
||||
|
||||
### Usage:
|
||||
#### A secure encryption key can be generated with
|
||||
```bash
|
||||
openssl rand -hex 32
|
||||
```
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
$vaultClient = new Hpz\Phpvaultclient\PhpVaultClient();
|
||||
$vaultClient->login('username', 'password');
|
||||
$reponse = $vaultClient->getSecret('cpsql', 'encryption_key');
|
||||
var_dump($reponse);
|
||||
```
|
||||
23
composer.json
Normal file
23
composer.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "hpz/phpvaultclient",
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Hpz\\Phpvaultclient\\": "src/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Hpz937",
|
||||
"email": "hpz937@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"hpz937/restclient": "^1.0"
|
||||
},
|
||||
"repositories": [{
|
||||
"type": "composer",
|
||||
"url": "https://git.hpz.pw/api/packages/hpz937/composer"
|
||||
}
|
||||
]
|
||||
}
|
||||
45
composer.lock
generated
Normal file
45
composer.lock
generated
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "66b4946a7935b941d7825c6d654e1e8b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "hpz937/restclient",
|
||||
"version": "1.0.1",
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://git.hpz.pw/api/packages/hpz937/composer/files/hpz937%2Frestclient/1.0.1/hpz937-restclient.1.0.1.zip",
|
||||
"shasum": "7fa69977ae5ee35f9228ae512929e7558d911245"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Hpz937\\Restclient\\": "src/"
|
||||
}
|
||||
},
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Brad Cimbura",
|
||||
"email": "hpz937+code@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "Client library for interacting with REST apis",
|
||||
"time": "2024-07-25T20:33:53+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
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