Skip to content

Commit e7ed5ec

Browse files
committed
Added support for JSON type and global secrets.
1 parent e2191f9 commit e7ed5ec

4 files changed

Lines changed: 22 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 1.1.0
2+
* Added support for parsing secrets encoded as JSON.
3+
* Added support for scoping a secret to `global` prefix that will disregard env.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ For example, to access the secret `twlio-key`, `$secrets.fetch('twilio-key')`. T
3333
This gem expects your secret value to be a JSON object. The only required key is `value`. The following keys are optional:
3434
* `ttl` - Time to live in seconds. Describes how long the secret should live in in-memory cache.
3535
* `encoding` - Currently, only `base64` is supported as a value. If your `value` is base64 encoded, this will result in a returned secret that is base64 decoded.
36+
* `type` - Currently, only `json` is supported as a value. If your `value` is valid JSON, this will result in a returned secret that is symbolified ruby hash.
3637

3738
Example:
3839
```
@@ -60,6 +61,11 @@ $secrets.fetch('services/twilio/api-key')
6061
$secrets['services/twilio/api-key']
6162
```
6263

64+
To use a secret that is available in all envs, prepend the secret name with `global`
65+
```
66+
$secrets['global/config/api-key']
67+
```
68+
6369
## Development
6470

6571
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

lib/secrets-manager.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ def client
5656
end
5757

5858
def fetch(secret_path)
59-
resolved_path = secret_env + '/' + secret_path
59+
if secret_path.start_with?("global")
60+
resolved_path = secret_path
61+
else
62+
resolved_path = secret_env + '/' + secret_path
63+
end
6064

6165
cached_value = cache.find(resolved_path)
6266
return cached_value if cached_value
@@ -93,6 +97,13 @@ def parse_value(data)
9397
end
9498
end
9599

100+
if data[:type].present?
101+
case data[:type]
102+
when "json"
103+
value = JSON.parse(value, symbolize_names: true)
104+
end
105+
end
106+
96107
return value
97108
end
98109

lib/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module SecretsManager
2-
VERSION = "1.0.2"
2+
VERSION = "1.1.0"
33
end

0 commit comments

Comments
 (0)