wballard / starphleet

19 stars 37 forks source link

Add secrets #369

Closed shawnrushefsky closed 5 years ago

shawnrushefsky commented 5 years ago

This builds on the secrets function provided by @bhudgens. We have created a function fromJson that handles extracting one field from a json object, rather than having that functionality directly inside of secrets. This allows us to conveniently request a whole secret, and then assign its components to different env variables.

Usage:

fromJson '{"somekey": "somevalue"}' somekey
# prints somevalue

This is pretty similar to jq, except much less complex/complete, and has no dependencies beyond bash and python

We also wrote a function to get region from instance metadata if it can't be found in env or ~/.aws

Usage:

getRegionFromInstanceMetadata
# prints the region, i.e. us-east-1

So, all together, usage of secrets looks like:

SMASH_SECRET=$(secrets SMASH)

export SMASH="{\"driver\":\"mssql\",\"name\":\"smash\",\"config\":{\"server\":\"$(fromJson $SMASH_SECRET 'host')\",\"password\":\"$(fromJson $SMASH_SECRET 'password')\",\"userName\":\"$(fromJson $SMASH_SECRET 'username')\",\"options\":{\"port\":$(fromJson $SMASH_SECRET 'port')}}}"
shawnrushefsky commented 5 years ago

@bhudgens cleaned up those old comments, added a timeout to curl