@@ -16,12 +16,9 @@ class LaravelAwsSecretsManager
1616 protected $ debug ;
1717 protected $ enabledEnvironments ;
1818 protected $ listTag ;
19- protected $ variables ;
2019
2120 public function __construct ()
2221 {
23- $ this ->variables = config ('aws-secrets-manager.variables ' );
24-
2522 $ this ->listTagName = config ('aws-secrets-manager.tag-name ' );
2623 $ this ->listTagValue = config ('aws-secrets-manager.tag-value ' );
2724
@@ -47,12 +44,8 @@ public function loadSecrets()
4744
4845 //Only run this if the evironment is enabled in the config
4946 if (in_array (config ('app.env ' ), $ this ->enabledEnvironments )) {
50- if ($ this ->cache ) {
51- if (! $ this ->checkCache ()) {
52- //Cache has expired need to refresh the cache from Datastore
53- $ this ->getVariables ();
54- }
55- } else {
47+ if (! $ this ->checkCache ()) {
48+ //Cache has expired need to refresh the cache from Datastore
5649 $ this ->getVariables ();
5750 }
5851
@@ -68,7 +61,7 @@ public function loadSecrets()
6861
6962 protected function checkCache ()
7063 {
71- foreach ($ this ->variables as $ variable ) {
64+ foreach ($ this ->configVariables as $ variable => $ configPath ) {
7265 $ val = Cache::store ($ this ->cacheStore )->get ($ variable );
7366 if (! is_null ($ val )) {
7467 putenv ("$ variable= $ val " );
@@ -103,24 +96,19 @@ protected function getVariables()
10396 ]);
10497 } catch (\Exception $ e ) {
10598 Log::error ($ e ->getMessage ());
99+
106100 return ;
107101 }
108102
109- foreach ($ secrets as $ secret ) {
110- foreach ($ secret as $ item ) {
111- if (isset ($ item ['ARN ' ])) {
112- $ result = $ this ->client ->getSecretValue ([
113- 'SecretId ' => $ item ['ARN ' ],
114- ]);
115-
116- $ secretValues = json_decode ($ result ['SecretString ' ], true );
117- if (is_array ($ secretValues )) {
118- foreach ($ secretValues as $ key => $ secret ) {
119- putenv ("$ key= $ secret " );
120- $ this ->storeToCache ($ key , $ secret );
121- }
122- }
123- }
103+ foreach ($ secrets ['SecretList ' ] as $ secret ) {
104+ if (isset ($ secret ['ARN ' ])) {
105+ $ result = $ this ->client ->getSecretValue ([
106+ 'SecretId ' => $ secret ['ARN ' ],
107+ ]);
108+ $ key = $ result ['Name ' ];
109+ $ secret = $ result ['SecretString ' ];
110+ putenv ("$ key= $ secret " );
111+ $ this ->storeToCache ($ result ['Name ' ], $ result ['SecretString ' ]);
124112 }
125113 }
126114 }
0 commit comments