1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the secrecy/secrecy package. |
5
|
|
|
* |
6
|
|
|
* (c) Webtools Ltd <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Secrecy; |
15
|
|
|
|
16
|
|
|
use Secrecy\Adapter\AdapterInterface; |
17
|
|
|
|
18
|
|
|
class SecretManager |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var AdapterInterface |
22
|
|
|
*/ |
23
|
|
|
private $adapter; |
24
|
|
|
|
25
|
|
|
public function __construct(AdapterInterface $adapter) |
26
|
|
|
{ |
27
|
|
|
$this->adapter = $adapter; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Retrieve a secret with the given name. |
32
|
|
|
* |
33
|
|
|
* @throws Exception\SecretNotFoundException |
34
|
|
|
*/ |
35
|
|
|
public function get(string $name): string |
36
|
|
|
{ |
37
|
|
|
return $this->adapter->get($name); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Returns an iterable consisting of key => value pairs. |
42
|
|
|
* |
43
|
|
|
* @return array<String,String> |
44
|
|
|
*/ |
45
|
|
|
public function list(): iterable |
46
|
|
|
{ |
47
|
|
|
return $this->adapter->list(); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Create and persist an new secret. |
52
|
|
|
* |
53
|
|
|
* @throws Exception\SecretAlreadyExistsException |
54
|
|
|
*/ |
55
|
|
|
public function create(string $name, string $value): void |
56
|
|
|
{ |
57
|
|
|
$this->adapter->create($name, $value); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Update an existing secret. |
62
|
|
|
* |
63
|
|
|
* @throws Exception\SecretNotFoundException |
64
|
|
|
*/ |
65
|
|
|
public function update(string $name, string $value): void |
66
|
|
|
{ |
67
|
|
|
$this->adapter->update($name, $value); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Remove a secret with the given name. |
72
|
|
|
* |
73
|
|
|
* @throws Exception\SecretNotFoundException |
74
|
|
|
*/ |
75
|
|
|
public function remove(string $name): void |
76
|
|
|
{ |
77
|
|
|
$this->adapter->remove($name); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|