Skip to content

Commit cb681d3

Browse files
author
kendavis2
committed
document wrappers
1 parent ba3836d commit cb681d3

1 file changed

Lines changed: 96 additions & 2 deletions

File tree

AWS_METHODS.md

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ $ stash get -t dev -o terraform
3232

3333
On start up containers can call a storage service directly using the *Stash* CLI and create a configuration file inside the container allowing the application to load it into memory.
3434

35-
**Requirement**: The stash.yml file used to sync the configuration must included in the Docker image where *Stash* can find it.
35+
**Requirement**: The stash.yml file used to sync the configuration must be included in the Docker image where *Stash* can find it.
3636

3737
Dockerfile (build)
3838
```bash
@@ -66,8 +66,12 @@ exec ./app
6666

6767
### Method 2: File Injection (Stash CLI)
6868

69+
**Supports**: ECS Fargate Containers
70+
6971
On start up containers can call a storage service directly using the *Stash* CLI and inject secrets into a configuration file inside the container allowing the application to load the file containing the secrets into memory. Secret tokens can be added to a configuration file that is checked into a repository.
7072

73+
**Requirement**: The stash.yml file used to sync the configuration must be included in the Docker image where *Stash* can find it.
74+
7175
The tokens are AWS Secret Manager secret names. Use double colons, `::`, to specify any field in the secret's json object.
7276

7377
.env (config)
@@ -105,7 +109,7 @@ stash inject $CONFIG_ENV/.env -l -s secrets-manager 1> secrets.env
105109
exec ./app
106110
```
107111

108-
### Method 3: Environment Injection (AWS)
112+
### Method 3: Environment Injection (Stash CLI)
109113

110114
**Supports**: ECS Fargate Containers
111115

@@ -148,3 +152,93 @@ for k, v := range config {
148152
log.Printf("%s=%s\n", k, v)
149153
}
150154
```
155+
156+
### Method 5: Direct Ingest (Stash CLI)
157+
158+
**Supports**: ECS Fargate Containers / Lambda Functions
159+
160+
CI/CD (install stash)
161+
```bash
162+
$ curl -L -o ./stash https://github.com/dabblebox/stash/releases/download/v0.3.0-rc/stash_linux_amd64
163+
$ chmod +x ./stash
164+
```
165+
166+
CI/CD (zip stash) - *lambda only*
167+
```
168+
$ zip -g lambda.zip stash.yml
169+
$ zip -g lambda.zip ./stash
170+
```
171+
172+
Code (get config)
173+
<details>
174+
<summary>NodeJS</summary>
175+
176+
```javascript
177+
const { exec } = require('child_process')
178+
179+
async function getConfig() {
180+
try {
181+
let result = await new Promise((resolve, reject) => {
182+
execCommand = `stash get -t ${process.env['CONFIG_ENV']} -t ${process.env['VERSION_TAG']} -o json`
183+
console.log(execCommand)
184+
exec(execCommand, (error, stdout, stderr) => {
185+
if (error) {
186+
console.log(`error: ${error.message}`)
187+
reject(error)
188+
}
189+
if (stderr) {
190+
console.log(`stash result: ${stderr}`)
191+
}
192+
if (!stdout) {
193+
reject(stderr)
194+
}
195+
resolve(stdout)
196+
})
197+
})
198+
199+
return JSON.parse(result)
200+
} catch (err) {
201+
console.error(`Failed to get config`)
202+
throw err
203+
}
204+
}
205+
```
206+
</details>
207+
208+
<details>
209+
<summary>C# .NET</summary>
210+
211+
</details>
212+
213+
<details>
214+
<summary>Python</summary>
215+
216+
```python
217+
import subprocess
218+
import json
219+
import shlex
220+
import os
221+
vals = {}
222+
keys = [
223+
"KEYS_HERE",
224+
]
225+
def init():
226+
cmd = "./stash get -t '{}' -o json".format(os.environ['stash_tags'])
227+
args = shlex.split(cmd)
228+
try:
229+
output = subprocess.check_output(
230+
args,
231+
stderr=subprocess.STDOUT,
232+
encoding='UTF-8',
233+
)
234+
except subprocess.CalledProcessError as e:
235+
print(e.output,e.returncode,cmd)
236+
raise(e)
237+
secrets = json.loads(output.split('downloaded')[1])
238+
for key in keys:
239+
v = secrets.get(key, None)
240+
if v is None:
241+
raise Exception('{} not found in secrets'.format(key))
242+
vals[key] = v
243+
```
244+
</details>

0 commit comments

Comments
 (0)