Skip to content

Commit dbef635

Browse files
authored
Merge pull request #3 from TappNetwork/getVariables-fix-csw
Get variables fix
2 parents d2cd899 + 4132d3c commit dbef635

File tree

3 files changed

+21
-38
lines changed

3 files changed

+21
-38
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to `laravel-aws-secrets-manager` will be documented in this file
44

5+
## 1.0.1 - 2020-07-27
6+
7+
### Changed
8+
- config file to include aws api info
9+
10+
### Fixed
11+
- update results loop
12+
513
## 1.0.0 - 201X-XX-XX
614

715
- initial release

config/config.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,6 @@
3838
'production',
3939
],
4040

41-
/*
42-
|--------------------------------------------------------------------------
43-
| List of variables that are stored in Datastore
44-
|--------------------------------------------------------------------------
45-
|
46-
| List all of the keys that should be loaded from datastore -these must all exist. These variables will be loaded into the env()
47-
|
48-
*/
49-
50-
'variables' => [
51-
'APP_KEY',
52-
],
53-
5441
/*
5542
|--------------------------------------------------------------------------
5643
| Variables that require overwriting the config

src/LaravelAwsSecretsManager.php

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)