Skip to content

Commit 517349b

Browse files
committed
Mono-repo rework
0 parents  commit 517349b

12 files changed

+767
-0
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Aaron Scherer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Secretary - Secrets Manager for PHP
2+
3+
Secrets are an important aspect of most applications you can build. How you store them, and keep them "secret" is a challenge.
4+
Luckily, there are tools you can use to keep them all safe.
5+
6+
Secretary is a tool to integrate your PHP application with these tools.
7+
8+
## Table of Contents
9+
10+
1. [Installation](#installation)
11+
2. [Api Documentation](#api-documentation)
12+
1. [Initializing](#constructor)
13+
1. [getSecret](#getSecret)
14+
1. [putSecret](#putSecret)
15+
1. [deleteSecret](#deleteSecret)
16+
17+
### Installation
18+
19+
```bash
20+
$ composer require secretary/core
21+
```
22+
23+
By itself, the core is useless. You will also need to add at least one adapter:
24+
25+
| Storage Engine | Badges |
26+
| -------------- | -------- |
27+
| [AWS Secrets Manager][aws-secrets-manager-adapter] | [![Latest Stable Version](https://poser.pugx.org/secretary/php-aws-secrets-manager-adapter/version)](https://packagist.org/packages/secretary/php-aws-secrets-manager-adapter) [![Total Downloads](https://poser.pugx.org/secretary/php-aws-secrets-manager-adapter/downloads)](https://packagist.org/packages/secretary/php-aws-secrets-manager-adapter) |
28+
| [HashiCorp Vault][hashicorp-vault-adapter] | [![Latest Stable Version](https://poser.pugx.org/secretary/php-hashicorp-vault-adapter/version)](https://packagist.org/packages/secretary/php-hashicorp-vault-adapter) [![Total Downloads](https://poser.pugx.org/secretary/php-hashicorp-vault-adapter/downloads)](https://packagist.org/packages/secretary/php-hashicorp-vault-adapter) |
29+
30+
There are also miscellaneous packages that add on to Secretary
31+
32+
| Package | Purpose | Badges |
33+
| ------- | ------- | ------ |
34+
| [PSR-6 Cache Adapter][psr-6-cache-adapter] | Allows for caching secrets using a PSR-6 Cache Interface | [![Latest Stable Version](https://poser.pugx.org/secretary/php-psr-6-cache-adapter/version)](https://packagist.org/packages/secretary/php-psr-6-cache-adapter) [![Total Downloads](https://poser.pugx.org/secretary/php-psr-6-cache-adapter/downloads)](https://packagist.org/packages/secretary/php-psr-6-cache-adapter) |
35+
| [PSR-16 Cache Adapter][psr-16-cache-adapter] | Allows for caching secrets using a PSR-16 Cache Interface | [![Latest Stable Version](https://poser.pugx.org/secretary/php-psr-16-cache-adapter/version)](https://packagist.org/packages/secretary/php-psr-16-cache-adapter) [![Total Downloads](https://poser.pugx.org/secretary/php-psr-16-cache-adapter/downloads)](https://packagist.org/packages/secretary/php-psr-16-cache-adapter) |
36+
| [Secretary Bundle][secretary-bundle] | Allows for integrating with the Symfony Framework | [![Latest Stable Version](https://poser.pugx.org/secretary/php-secretary-bundle/version)](https://packagist.org/packages/secretary/php-secretary-bundle) [![Total Downloads](https://poser.pugx.org/secretary/php-secretary-bundle/downloads)](https://packagist.org/packages/secretary/php-secretary-bundle) |
37+
38+
### Api Documentation
39+
40+
There's only one class you interface with in Secretary: [`Secretary\Manager`][Secretary\Manager::class]
41+
42+
<a name="constructor" />
43+
44+
##### Secretary\Manager->__construct(AdapterInterface $adapter)
45+
46+
Pass in your desired adapter.
47+
48+
```php
49+
<?php
50+
use Secretary\Manager;
51+
use Secretary\Adapter\AWS\SecretsManager\AWSSecretsManagerAdapter;
52+
53+
$manager = new Manager(
54+
new AWSSecretsManagerAdapter([
55+
'region' => 'us-east-1',
56+
'credentials' => [
57+
'accessKeyId' => 'myAccessKeyId',
58+
'secretAccessKey' => 'mySecretAccessKey'
59+
]
60+
])
61+
);
62+
```
63+
64+
Optionally, you may wrap your adapter, with one of the two cache adapters.
65+
66+
```php
67+
<?php
68+
use Secretary\Manager;
69+
use Secretary\Adapter\AWS\SecretsManager\AWSSecretsManagerAdapter;
70+
71+
use Secretary\Adapter\Cache\PSR6CacheAdapter;
72+
use Cache\Adapter\Apc\ApcCachePool;
73+
74+
$manager = new Manager(
75+
new PSR6CacheAdapter(
76+
new AWSSecretsManagerAdapter([
77+
'region' => 'us-east-1',
78+
'credentials' => [
79+
'accessKeyId' => 'myAccessKeyId',
80+
'secretAccessKey' => 'mySecretAccessKey'
81+
]
82+
]),
83+
new ApcCachePool()
84+
)
85+
);
86+
```
87+
88+
For mor information on the arguments and options for the adapters, view their respective documentation.
89+
90+
<a name="getSecret" />
91+
92+
##### Secretary\Manager->getSecret(string $key, ?array $options): Secret
93+
94+
Fetches a secret from the configured adapter. `$key` is the name of the secret (or path) you are trying to get.
95+
96+
Certain adapters will take custom options as well, like VersionId and VersionStage for the AWS SecretsManager Adapter
97+
98+
This will throw a `Secretary\SecretNotFoundException` if the secret cannot be found
99+
100+
```php
101+
$secret = $manager->getSecret('databases/redis/dsn');
102+
/*
103+
Secret {
104+
"path" = "databases/redis/dsn",
105+
"value" = "redis://localhost:6379"
106+
}
107+
*/
108+
```
109+
110+
Some adapters also support storing a key/value map as a secret's value.
111+
112+
```php
113+
$secret = $manager->getSecret('databases/redis');
114+
/*
115+
Secret {
116+
"path" = "databases/redis",
117+
"value" = [
118+
"dsn" => "redis://localhost:6379",
119+
"password" => "my_super_strong_password"
120+
]
121+
}
122+
*/
123+
```
124+
125+
<a name="putSecret" />
126+
127+
##### Secretary\Manager->putSecret(string $key, string|array $value, ?array $options): void
128+
129+
Puts a secret with the given `$value`, into the storage engine, under the given `$key`.
130+
131+
If the current adapter doesn't support arrays, and you pass one it, it will throw a `Secretary\ValueNotSupportedException`.
132+
133+
Again, some adapters allow passing in custom options to send along with the request.
134+
135+
```php
136+
$manager->putSecret('database/redis', 'postgres://localhost:5432');
137+
```
138+
139+
And for adapters that support a key/value map as a value:
140+
141+
```php
142+
$manager->putSecret('database/redis', ['dsn' => 'redis://localhost:6379', 'password' => 'my_super_strong_password']);
143+
```
144+
145+
<a name="deleteSecret" />
146+
147+
##### Secretary\Manager->deleteSecret(string $key, ?array $options): void
148+
149+
Deletes a secret from the storage engine using the given `$key`.
150+
151+
Again, some adapters allow passing in custom options to send along with the request.
152+
153+
```php
154+
$manager->deleteSecret('database/redis');
155+
```
156+
157+
##### Secretary\Manager->getAdapter(): AdapterInterface
158+
159+
Will return the adapter that was passed to this manager during construction.
160+
161+
aws-secrets-manager-adapter: https://github.com/secretary/php-aws-secrets-manager-adapter
162+
hashicorp-vault-adapter: https://github.com/secretary/php-hashicorp-vault-adapter
163+
psr-6-cache-adapter: https://github.com/secretary/php-psr-6-cache-adapter
164+
psr-16-cache-adapter: https://github.com/secretary/php-psr-16-cache-adapter
165+
secretary-bundle: https://github.com/secretary/php-secretary-bundle
166+
Secretary\Manager::class: https://github.com/secretary/php/blob/master/src/Core/src/Manager.php

composer.json

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "secretary/core",
3+
"description": "Secrets Manager for PHP",
4+
"type": "library",
5+
"license": "MIT",
6+
"keywords": [
7+
"secrets",
8+
"vault",
9+
"secretsmanager",
10+
"keyvault",
11+
"secretary"
12+
],
13+
"authors": [
14+
{
15+
"name": "Aaron Scherer",
16+
"email": "[email protected]"
17+
}
18+
],
19+
"minimum-stability": "stable",
20+
"require": {
21+
"php": "^7.1.0",
22+
"symfony/options-resolver": "^4.0 || ^3.0"
23+
},
24+
"require-dev": {
25+
"phpunit/phpunit": "^8.0",
26+
"mockery/mockery": "^1.2"
27+
},
28+
"suggest": {
29+
"secretary/aws-secrets-manager-adapter": "For reading secrets from AWS Secrets Manager",
30+
"secretary/hashicorp-vault-adapter": "For reading secrets from Hashicorp Vault",
31+
"secretary/psr6-cache-adapter": "For caching secrets using a PSR-6 Cache Interface",
32+
"secretary/psr16-cache-adapter": "For caching secrets using a PSR-16 SimpleCache Interface",
33+
"secretary/secretary-bundle": "For integrating Secretary with the Symfony Framework"
34+
},
35+
"autoload": {
36+
"psr-4": {
37+
"Secretary\\": "src/"
38+
}
39+
},
40+
"autoload-dev": {
41+
"psr-4": {
42+
"Secretary\\Tests\\": "tests/"
43+
}
44+
}
45+
}

phpunit.xml.dist

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.0/phpunit.xsd"
6+
colors="true"
7+
bootstrap="vendor/autoload.php"
8+
>
9+
<php>
10+
<ini name="error_reporting" value="-1"/>
11+
<ini name="memory_limit" value="-1"/>
12+
</php>
13+
14+
<testsuites>
15+
<testsuite name="Secretary Test Suite">
16+
<directory suffix="Test.php" phpVersion="7.1" phpVersionOperator=">=">./tests</directory>
17+
</testsuite>
18+
</testsuites>
19+
20+
<filter>
21+
<whitelist>
22+
<directory>src</directory>
23+
</whitelist>
24+
</filter>
25+
</phpunit>

src/Adapter/AbstractAdapter.php

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* @author Aaron Scherer <[email protected]>
6+
* @date 2019
7+
* @license http://opensource.org/licenses/MIT
8+
*/
9+
10+
11+
namespace Secretary\Adapter;
12+
13+
use Symfony\Component\OptionsResolver\OptionsResolver;
14+
15+
/**
16+
* Class AbstractAdapter
17+
*
18+
* @package Secretary\Adapter
19+
*/
20+
abstract class AbstractAdapter implements AdapterInterface
21+
{
22+
/**
23+
* {@inheritdoc}
24+
*/
25+
public function configureSharedOptions(OptionsResolver $resolver): void
26+
{
27+
}
28+
29+
/**
30+
* {@inheritdoc}
31+
*/
32+
public function configureGetSecretOptions(OptionsResolver $resolver): void
33+
{
34+
}
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
public function configurePutSecretOptions(OptionsResolver $resolver): void
40+
{
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
public function configureDeleteSecretOptions(OptionsResolver $resolver): void
47+
{
48+
}
49+
}

src/Adapter/AdapterInterface.php

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* @author Aaron Scherer <[email protected]>
6+
* @date 2019
7+
* @license http://opensource.org/licenses/MIT
8+
*/
9+
10+
namespace Secretary\Adapter;
11+
12+
use Secretary\Exception\SecretNotFoundException;
13+
use Symfony\Component\OptionsResolver\OptionsResolver;
14+
15+
/**
16+
* Interface AdapterInterface
17+
*
18+
* @package Secretary\Adapter
19+
*/
20+
interface AdapterInterface
21+
{
22+
/**
23+
* Get a secret by a key.
24+
*
25+
* @param string $key
26+
* @param array $options
27+
*
28+
* @return Secret
29+
* @throws SecretNotFoundException
30+
*/
31+
public function getSecret(string $key, ?array $options = []): Secret;
32+
33+
/**
34+
* Add \ Update a secret by a key.
35+
*
36+
* @param string $key
37+
* @param string|array $value
38+
* @param array $options
39+
*
40+
* @return void
41+
*/
42+
public function putSecret(string $key, $value, ?array $options = []): void;
43+
44+
/**
45+
* Delete a secret by a key.
46+
*
47+
*
48+
* @param string $key
49+
* @param array $options
50+
*
51+
* @return void
52+
*/
53+
public function deleteSecret(string $key, ?array $options = []): void;
54+
55+
/**
56+
* @param OptionsResolver $resolver
57+
*
58+
* @return void
59+
*/
60+
public function configureSharedOptions(OptionsResolver $resolver): void;
61+
62+
/**
63+
* @param OptionsResolver $resolver
64+
*
65+
* @return void
66+
*/
67+
public function configureGetSecretOptions(OptionsResolver $resolver): void;
68+
69+
/**
70+
* @param OptionsResolver $resolver
71+
*
72+
* @return void
73+
*/
74+
public function configurePutSecretOptions(OptionsResolver $resolver): void;
75+
76+
/**
77+
* @param OptionsResolver $resolver
78+
*
79+
* @return void
80+
*/
81+
public function configureDeleteSecretOptions(OptionsResolver $resolver): void;
82+
}

0 commit comments

Comments
 (0)