@@ -18,3 +18,48 @@ Easiest way is via composer. Just run `composer require codenamephp/platform.sec
1818
1919This package provides the basic interfaces for secrets, payloads and a client. Use this package in your actual implementation and
2020just build implementations against services.
21+
22+ ### Proxy
23+
24+ There is a simple, lightweight proxy system in place. This is used to load secrets lazily and ideally only once.
25+
26+ Example:
27+
28+ ``` php
29+ use de\codenamephp\platform\secretsManager\base\Secret\Proxy\String\Factory\WithClientAsClassMemberFactory;
30+ use de\codenamephp\platform\secretsManager\base\Secret\Sealed;
31+
32+ $client = new SomeClientImplementation();
33+ $factory = new WithClientAsClassMemberFactory($client);
34+
35+ $secret = $factory->build(new Sealed('someSecretName', 'some-project'));
36+ $multipleSecrets = $factory->buildMultiple(
37+ another: new Sealed('anotherSecretName', 'some-project'),
38+ more: new Sealed('moreSecretName', 'some-project'),
39+ ); //remember you can use parameter names as array keys for variadic
40+
41+ $allSecrets = [
42+ 'some' => $secret,
43+ ...$multipleSecrets, //simple spread is possible
44+ ];
45+ ```
46+
47+ The proxy interface extends \Stringable so it should be usable wherever a string would have been used.
48+
49+ #### A not when using with Deployer
50+
51+ Because of the way deployer fetches the secrets you should wrap the values in closures. This is because
52+ when fetching the configs Deployer does checks for closures and return them "as is". But the else path just
53+ passes the value to preg_replace and assumes an array callable so this will return null in the end.
54+
55+ ``` php
56+ $deployerFunctions->host('production')
57+ ->setHostname('some-host.com')
58+ ->set('database', static fn() => [ //this closure fixes the issue
59+ 'name' => 'some-db',
60+ ...$stringProxyFactory->buildMultiple(
61+ user: new Sealed('db_user', 'my-project'),
62+ password: new Sealed('db_password', 'my-project')
63+ ),
64+ ]);
65+ ```
0 commit comments