param_store 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -1
- data/Gemfile.lock +15 -3
- data/README.md +144 -37
- data/lib/param_store/adapters/ejson_wrapper.rb +26 -0
- data/lib/param_store/adapters/env.rb +4 -2
- data/lib/param_store/adapters/secrets_manager.rb +46 -0
- data/lib/param_store/adapters/ssm.rb +25 -9
- data/lib/param_store/version.rb +1 -1
- data/lib/param_store/wrapper.rb +14 -11
- data/lib/param_store.rb +25 -5
- data/param_store.gemspec +0 -2
- metadata +6 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a193054830d20294dc6f7beac7466aefd0dc0f34371ddcf97542277e5bcc76c
|
4
|
+
data.tar.gz: 97afce05344af92e41b85d673c95d718f1ca8bfa3e2793f8d047bdfa718dad1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c92d7d8b694ec738a2ba1e34d4f0366ceb2e2180e6332afaec9aef022899fd54e4610abe845130209bc85cf4a982e7598954bda98cc616846b9f2d6f6580ae7e
|
7
|
+
data.tar.gz: ce6bbe962abbf9e76ca08e7f268b763b25e0b7ef4e98c8b4df83c0ff33604e72702af33b56967e7110ec35cb6b6d91d0be73b49475d2c06167ed39504635ff76
|
data/Gemfile
CHANGED
@@ -6,6 +6,9 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
|
6
6
|
gemspec
|
7
7
|
|
8
8
|
group :development, :test do
|
9
|
+
gem 'aws-sdk-secretsmanager', '~> 1'
|
10
|
+
gem 'aws-sdk-ssm', '~> 1'
|
11
|
+
gem 'ejson_wrapper', '~> 0.3.1'
|
9
12
|
gem 'pry-byebug'
|
10
13
|
end
|
11
14
|
|
@@ -13,4 +16,4 @@ group :test do
|
|
13
16
|
gem 'rspec', '~> 3.0'
|
14
17
|
gem 'rspec_junit_formatter'
|
15
18
|
gem 'stub_env'
|
16
|
-
end
|
19
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
param_store (0.0
|
5
|
-
aws-sdk-ssm (~> 1)
|
4
|
+
param_store (1.0.0)
|
6
5
|
|
7
6
|
GEM
|
8
7
|
remote: https://rubygems.org/
|
@@ -14,6 +13,12 @@ GEM
|
|
14
13
|
aws-partitions (~> 1.0)
|
15
14
|
aws-sigv4 (~> 1.0)
|
16
15
|
jmespath (~> 1.0)
|
16
|
+
aws-sdk-kms (1.13.0)
|
17
|
+
aws-sdk-core (~> 3, >= 3.39.0)
|
18
|
+
aws-sigv4 (~> 1.0)
|
19
|
+
aws-sdk-secretsmanager (1.20.0)
|
20
|
+
aws-sdk-core (~> 3, >= 3.39.0)
|
21
|
+
aws-sigv4 (~> 1.0)
|
17
22
|
aws-sdk-ssm (1.34.0)
|
18
23
|
aws-sdk-core (~> 3, >= 3.39.0)
|
19
24
|
aws-sigv4 (~> 1.0)
|
@@ -21,6 +26,10 @@ GEM
|
|
21
26
|
byebug (10.0.2)
|
22
27
|
coderay (1.1.2)
|
23
28
|
diff-lcs (1.3)
|
29
|
+
ejson (1.2.1)
|
30
|
+
ejson_wrapper (0.3.1)
|
31
|
+
aws-sdk-kms
|
32
|
+
ejson
|
24
33
|
jmespath (1.4.0)
|
25
34
|
method_source (0.9.2)
|
26
35
|
pry (0.12.2)
|
@@ -52,7 +61,10 @@ PLATFORMS
|
|
52
61
|
ruby
|
53
62
|
|
54
63
|
DEPENDENCIES
|
64
|
+
aws-sdk-secretsmanager (~> 1)
|
65
|
+
aws-sdk-ssm (~> 1)
|
55
66
|
bundler (~> 1.16)
|
67
|
+
ejson_wrapper (~> 0.3.1)
|
56
68
|
param_store!
|
57
69
|
pry-byebug
|
58
70
|
rake (~> 10.0)
|
@@ -61,4 +73,4 @@ DEPENDENCIES
|
|
61
73
|
stub_env
|
62
74
|
|
63
75
|
BUNDLED WITH
|
64
|
-
1.17.
|
76
|
+
1.17.3
|
data/README.md
CHANGED
@@ -2,10 +2,9 @@
|
|
2
2
|
|
3
3
|
# ParamStore
|
4
4
|
|
5
|
-
This gem goal is to <strike>DRY some code I have been copying around for a while</strike> make easy switching in between ENV
|
6
|
-
|
7
|
-
This gem is not a replacement for [dotenv](https://github.com/bkeepers/dotenv). I still use and recommend it in development, in case it is "safe" to save your keys in `.env` files. Otherwise, you could also use AWS Parameter Store for development.
|
5
|
+
This gem goal is to <strike>DRY some code I have been copying around for a while</strike> make easy switching in between ENV, [AWS Parameter Store (SSM)](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html), [AWS Secrets Manager](https://aws.amazon.com/secrets-manager/) and [EJSON](https://github.com/Shopify/ejson) for retrieving parameters.
|
8
6
|
|
7
|
+
This gem is not a replacement for [dotenv](https://github.com/bkeepers/dotenv). I still use and recommend it in development, in case it is "safe" to save your keys in `.env` files.
|
9
8
|
|
10
9
|
## Installation
|
11
10
|
|
@@ -17,46 +16,79 @@ gem 'param_store'
|
|
17
16
|
|
18
17
|
## Usage
|
19
18
|
|
20
|
-
|
19
|
+
### Configuring adapters
|
20
|
+
|
21
|
+
Available adapters: `:env`, `:aws_ssm`, `:aws_secrets_manager` and `:ejson_wrapper`.
|
21
22
|
|
22
23
|
```ruby
|
23
|
-
|
24
|
-
|
25
|
-
ParamStore.adapter = :aws_ssm
|
26
|
-
# default path for SSM Hierarchies
|
27
|
-
# see https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-paramstore-su-organize.html
|
28
|
-
ParamStore.path = '/Environment/Type of computer/Application/'
|
24
|
+
ParamStore.adapter = adapter
|
25
|
+
```
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
### Retrieving parameters
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# ParamStore.fetch is similar to Hash#fetch,
|
31
|
+
# If the key is not found and there's no default given, it will raise a `KeyError`
|
32
|
+
ParamStore.fetch('name')
|
33
|
+
ParamStore.fetch('name', 'default value')
|
34
|
+
ParamStore.fetch('name') { 'default value' }
|
33
35
|
```
|
34
36
|
|
35
|
-
|
37
|
+
### Copying from any adapter to ENV
|
36
38
|
|
37
39
|
```ruby
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
ParamStore.copy_to_env('name1', 'name2', 'name3')
|
41
|
+
|
42
|
+
ENV['name1'] # => value for name1
|
43
|
+
ENV['name2'] # => value for name2
|
44
|
+
ENV['name3'] # => value for name3
|
41
45
|
```
|
42
46
|
|
43
|
-
|
47
|
+
## Adapters
|
44
48
|
|
45
|
-
|
49
|
+
### ENV
|
46
50
|
|
47
51
|
```ruby
|
48
|
-
|
49
|
-
|
50
|
-
ParamStore.copy_to_env('key1', 'key2', 'key3')
|
52
|
+
ParamStore.adapter :env
|
53
|
+
```
|
51
54
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
### AWS Parameter Store (SSM)
|
56
|
+
|
57
|
+
Add to your Gemfile:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
gem 'aws-sdk-ssm', '~> 1'
|
61
|
+
```
|
62
|
+
|
63
|
+
Configure the adapter:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
ParamStore.adapter :aws_ssm, default_path: '/Prod/App/'
|
67
|
+
```
|
68
|
+
|
69
|
+
#### Retrieving parameters
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
ParamStore.fetch('name')
|
73
|
+
# => get parameter name, if default_path /Prod/App/ get parameter /Prod/App/name
|
74
|
+
ParamStore.fetch('name', path: '/Prod/App/')
|
75
|
+
# => get parameter /Prod/App/name
|
76
|
+
```
|
77
|
+
|
78
|
+
#### Copying from SSM adapter to ENV
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
ParamStore.copy_to_env('name1', 'name2', 'name3', path: '/Environment/Type of computer/Application/')
|
82
|
+
# path overrides default_path
|
83
|
+
|
84
|
+
ENV['name1'] # => value for name1
|
85
|
+
ENV['name2'] # => value for name2
|
86
|
+
ENV['name3'] # => value for name3
|
55
87
|
```
|
56
88
|
|
57
|
-
|
89
|
+
#### SSM client
|
58
90
|
|
59
|
-
By default
|
91
|
+
By default ParamStore will initiate `Aws::SSM::Client.new` without supplying any argument. If you want to control the initiation of the SSM client, you can define it by setting `ssm_client`.
|
60
92
|
|
61
93
|
|
62
94
|
```ruby
|
@@ -67,25 +99,100 @@ ParamStore.ssm_client = Aws::SSM::Client.new(
|
|
67
99
|
)
|
68
100
|
```
|
69
101
|
|
70
|
-
|
102
|
+
#### CLI
|
71
103
|
|
72
|
-
|
104
|
+
A few useful [aws ssm](https://docs.aws.amazon.com/cli/latest/reference/ssm/index.html) commands:
|
105
|
+
|
106
|
+
```sh
|
107
|
+
aws ssm get-parameters-by-path --path /Prod/ERP/SAP --with-decryption
|
108
|
+
aws ssm put-parameter --name /Prod/ERP/SAP --value ... --type SecureString
|
109
|
+
```
|
110
|
+
|
111
|
+
### Secrets Manager
|
112
|
+
|
113
|
+
Add to your Gemfile:
|
73
114
|
|
74
115
|
```ruby
|
75
|
-
|
76
|
-
# Bundler.require(*Rails.groups)
|
77
|
-
ParamStore.require_keys!('key1', 'key2', 'key3')
|
116
|
+
gem 'aws-sdk-secretsmanager', '~> 1'
|
78
117
|
```
|
79
118
|
|
80
|
-
|
119
|
+
Configure the adapter:
|
81
120
|
|
82
|
-
|
121
|
+
```ruby
|
122
|
+
ParamStore.adapter :aws_secrets_manager
|
123
|
+
# ParaStore.fetch('secret_id')
|
124
|
+
# => {\n \"password\":\"pwd\"\n}\n
|
83
125
|
|
84
|
-
|
85
|
-
|
86
|
-
|
126
|
+
ParamStore.adapter :aws_secrets_manager, default_secret_id: 'secret_id'
|
127
|
+
# ParaStore.fetch('password')
|
128
|
+
# => pwd
|
129
|
+
```
|
130
|
+
|
131
|
+
#### Retrieving parameters
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
ParamStore.fetch('secret_id')
|
135
|
+
ParamStore.fetch('password', secret_id: 'secret_id')
|
136
|
+
```
|
137
|
+
|
138
|
+
#### Copying from Secrets Manager adapter to ENV
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
ParamStore.copy_to_env('key1', 'key2', 'key3', secret_id: 'secret_id')
|
142
|
+
# secret_id overrides default_secret_id
|
143
|
+
|
144
|
+
ENV['key1'] # => value for key1
|
145
|
+
ENV['key2'] # => value for key2
|
146
|
+
ENV['key3'] # => value for key3
|
147
|
+
```
|
148
|
+
|
149
|
+
### EJSON
|
150
|
+
|
151
|
+
Add to your Gemfile:
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
gem 'ejson_wrapper', '~> 0.3.1'
|
155
|
+
```
|
156
|
+
|
157
|
+
Configure the adapter:
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
ParamStore.adapter(
|
161
|
+
:ejson_wrapper,
|
162
|
+
file_path: '...',
|
163
|
+
key_dir: '...',
|
164
|
+
private_key: '...',
|
165
|
+
use_kms: '...',
|
166
|
+
region: '...'
|
167
|
+
)
|
168
|
+
# see https://github.com/envato/ejson_wrapper#usage
|
169
|
+
```
|
170
|
+
|
171
|
+
#### Rails
|
172
|
+
|
173
|
+
If you are using ParamStore in prod and dotenv in dev:
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
# config/application.rb
|
177
|
+
# Bundler.require(*Rails.groups)
|
178
|
+
if Rails.env.production?
|
179
|
+
ParamStore.adapter(:aws_ssm)
|
180
|
+
ParamStore.copy_to_env('DATABASE_URL', require_keys: true, path: '/Prod/MyApp/')
|
181
|
+
else
|
182
|
+
Dotenv::Railtie.load
|
183
|
+
end
|
87
184
|
```
|
88
185
|
|
186
|
+
### Fail-fast
|
187
|
+
|
188
|
+
You can configure the required parameters for an app and fail at startup.
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
# config/application.rb
|
192
|
+
# Bundler.require(*Rails.groups)
|
193
|
+
ParamStore.require_keys!('key1', 'key2', 'key3')
|
194
|
+
# this will raise an error if any key is missing
|
195
|
+
```
|
89
196
|
|
90
197
|
## Development
|
91
198
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ParamStore
|
2
|
+
module Adapters
|
3
|
+
class EJSONWrapper
|
4
|
+
attr_reader :file_path, :options
|
5
|
+
|
6
|
+
def initialize(**opts)
|
7
|
+
@file_path = opts.delete(:file_path)
|
8
|
+
@options = opts
|
9
|
+
end
|
10
|
+
|
11
|
+
def fetch(key, *args, **_opts, &block)
|
12
|
+
decrypt.fetch(key, *args, &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
def fetch_all(*keys, **_opts)
|
16
|
+
decrypt.select { |key, _value| keys.flatten.include?(key) }
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def decrypt
|
22
|
+
@_decrypt ||= ::EJSONWrapper.decrypt(file_path, options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
module ParamStore
|
2
2
|
module Adapters
|
3
3
|
class Env
|
4
|
-
def
|
4
|
+
def initialize(**_opts); end
|
5
|
+
|
6
|
+
def fetch(key, *args, **_opts, &block)
|
5
7
|
ENV.fetch(key, *args, &block)
|
6
8
|
end
|
7
9
|
|
8
|
-
def fetch_all(*keys)
|
10
|
+
def fetch_all(*keys, **_opts)
|
9
11
|
keys = keys.flatten
|
10
12
|
keys.each_with_object({}) do |key, result|
|
11
13
|
result[key] = ENV[key]
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ParamStore
|
2
|
+
module Adapters
|
3
|
+
class SecretsManager
|
4
|
+
attr_reader :default_secret_id
|
5
|
+
|
6
|
+
def initialize(default_secret_id: nil)
|
7
|
+
@default_secret_id = default_secret_id
|
8
|
+
end
|
9
|
+
|
10
|
+
def fetch(key, *args, secret_id: nil, version_id: nil, version_stage: nil, &block)
|
11
|
+
get_key = secret_id || default_secret_id || key
|
12
|
+
|
13
|
+
if cache[get_key].nil? &&
|
14
|
+
string = get_secret_value(get_key, version_id, version_stage)
|
15
|
+
cache[get_key] = JSON.parse(string)
|
16
|
+
end
|
17
|
+
|
18
|
+
(
|
19
|
+
secret_id.nil? && default_secret_id.nil? ? cache : cache[get_key]
|
20
|
+
).fetch(key, *args, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def fetch_all(*keys, **opts)
|
24
|
+
# poor man's fetch all
|
25
|
+
# I couldn't find a batch get for secrets manager :/
|
26
|
+
keys.map { |key| fetch(key, {}, **opts) }.inject(:merge)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def get_secret_value(secret_id, version_id, version_stage)
|
32
|
+
ParamStore.secrets_manager_client.get_secret_value(
|
33
|
+
secret_id: secret_id,
|
34
|
+
version_id: version_id,
|
35
|
+
version_stage: version_stage
|
36
|
+
).secret_string
|
37
|
+
rescue Aws::SecretsManager::Errors::ResourceNotFoundException
|
38
|
+
# let the tmp.fetch below deal with key not found and defaults
|
39
|
+
end
|
40
|
+
|
41
|
+
def cache
|
42
|
+
@_cache ||= {}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,24 +1,40 @@
|
|
1
1
|
module ParamStore
|
2
2
|
module Adapters
|
3
3
|
class SSM
|
4
|
-
|
4
|
+
attr_reader :default_path
|
5
|
+
|
6
|
+
def initialize(default_path: nil)
|
7
|
+
@default_path = default_path
|
8
|
+
end
|
9
|
+
|
10
|
+
def fetch(key, *args, path: nil, &block)
|
11
|
+
key = prepend_path(path, key)
|
5
12
|
tmp = {}
|
6
|
-
|
7
|
-
|
8
|
-
tmp[key] = ParamStore.ssm_client.get_parameter(name: key, with_decryption: true).parameter.value
|
9
|
-
rescue Aws::SSM::Errors::ParameterNotFound
|
10
|
-
# let the tmp.fetch below deal with not found key and defaults
|
13
|
+
if string = get_parameter(key)
|
14
|
+
tmp[key] = string
|
11
15
|
end
|
12
16
|
tmp.fetch(key, *args, &block)
|
13
17
|
end
|
14
18
|
|
15
|
-
def fetch_all(*keys)
|
19
|
+
def fetch_all(*keys, path: nil)
|
16
20
|
keys = keys.flatten
|
17
|
-
keys = keys.map { |key|
|
21
|
+
keys = keys.map { |key| prepend_path(path, key) } if path
|
18
22
|
ParamStore.ssm_client.get_parameters(names: keys, with_decryption: true).parameters.each_with_object({}) do |param, result|
|
19
|
-
result[param.name.gsub(
|
23
|
+
result[param.name.gsub(path.to_s, '')] = param.value
|
20
24
|
end
|
21
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def get_parameter(key)
|
30
|
+
ParamStore.ssm_client.get_parameter(name: key, with_decryption: true).parameter.value
|
31
|
+
rescue Aws::SSM::Errors::ParameterNotFound
|
32
|
+
# let the tmp.fetch below deal with key not found and defaults
|
33
|
+
end
|
34
|
+
|
35
|
+
def prepend_path(path, key)
|
36
|
+
"#{path || default_path}#{key}"
|
37
|
+
end
|
22
38
|
end
|
23
39
|
end
|
24
40
|
end
|
data/lib/param_store/version.rb
CHANGED
data/lib/param_store/wrapper.rb
CHANGED
@@ -1,28 +1,31 @@
|
|
1
1
|
module ParamStore
|
2
2
|
class Wrapper
|
3
|
-
def initialize(adapter_class)
|
3
|
+
def initialize(adapter_class, **opts)
|
4
4
|
@adapter_class = adapter_class
|
5
|
+
@opts = opts
|
5
6
|
end
|
6
7
|
|
7
|
-
def fetch(key, *args, &block)
|
8
|
+
def fetch(key, *args, **opts, &block)
|
8
9
|
key = key.to_s
|
9
10
|
unless cache.key?(key)
|
10
11
|
# cache params to minimize number of requests
|
11
|
-
cache[key] = adapter_instance.fetch(key, *args, &block)
|
12
|
+
cache[key] = adapter_instance.fetch(key, *args, **opts, &block)
|
12
13
|
end
|
13
14
|
cache[key]
|
14
15
|
end
|
15
16
|
|
16
|
-
def copy_to_env(*keys,
|
17
|
-
|
17
|
+
def copy_to_env(*keys, **opts)
|
18
|
+
require_keys = opts.delete(:require_keys)
|
18
19
|
|
19
|
-
|
20
|
+
cache_all(*keys, **opts)
|
21
|
+
|
22
|
+
require_keys!(*keys, **opts) if require_keys
|
20
23
|
|
21
24
|
keys.each { |key| ENV[key] = cache[key] }
|
22
25
|
end
|
23
26
|
|
24
|
-
def require_keys!(*keys)
|
25
|
-
cache_all(*keys)
|
27
|
+
def require_keys!(*keys, **opts)
|
28
|
+
cache_all(*keys, **opts)
|
26
29
|
|
27
30
|
missing = keys.flatten.map!(&:to_s) - cache.keys
|
28
31
|
|
@@ -35,9 +38,9 @@ module ParamStore
|
|
35
38
|
|
36
39
|
attr_accessor :adapter, :cache
|
37
40
|
|
38
|
-
def cache_all(*keys)
|
41
|
+
def cache_all(*keys, **opts)
|
39
42
|
keys.flatten.map!(&:to_s)
|
40
|
-
adapter_instance.fetch_all(*keys).each do |key, value|
|
43
|
+
adapter_instance.fetch_all(*keys, **opts).each do |key, value|
|
41
44
|
cache[key] = value
|
42
45
|
end
|
43
46
|
end
|
@@ -47,7 +50,7 @@ module ParamStore
|
|
47
50
|
end
|
48
51
|
|
49
52
|
def adapter_instance
|
50
|
-
@_adapter_instance ||= @adapter_class.new
|
53
|
+
@_adapter_instance ||= @adapter_class.new(**@opts)
|
51
54
|
end
|
52
55
|
end
|
53
56
|
end
|
data/lib/param_store.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
require 'aws-sdk-ssm'
|
2
1
|
require 'forwardable'
|
3
2
|
|
4
3
|
require 'param_store/version'
|
5
4
|
require 'param_store/wrapper'
|
6
5
|
require 'param_store/adapters/env'
|
7
6
|
require 'param_store/adapters/ssm'
|
7
|
+
require 'param_store/adapters/secrets_manager'
|
8
|
+
require 'param_store/adapters/ejson_wrapper'
|
8
9
|
|
9
10
|
module ParamStore
|
10
11
|
extend SingleForwardable
|
@@ -17,16 +18,20 @@ module ParamStore
|
|
17
18
|
)
|
18
19
|
|
19
20
|
class << self
|
20
|
-
attr_accessor :path
|
21
21
|
attr_reader :adapter, :wrapper
|
22
|
+
attr_writer :ssm_client, :secrets_manager_client
|
22
23
|
|
23
24
|
def ssm_client
|
24
|
-
@
|
25
|
+
@ssm_client ||= Aws::SSM::Client.new
|
25
26
|
end
|
26
27
|
|
27
|
-
def
|
28
|
+
def secrets_manager_client
|
29
|
+
@secrets_manager_client ||= Aws::SecretsManager::Client.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def adapter(adapter, **opts)
|
28
33
|
@adapter = adapter
|
29
|
-
@wrapper = Wrapper.new(adapter_class(adapter))
|
34
|
+
@wrapper = Wrapper.new(adapter_class(adapter), **opts)
|
30
35
|
end
|
31
36
|
|
32
37
|
def adapter_class(adapter)
|
@@ -34,10 +39,25 @@ module ParamStore
|
|
34
39
|
when :env
|
35
40
|
Adapters::Env
|
36
41
|
when :aws_ssm
|
42
|
+
require_adapter_dependency(adapter, 'aws-sdk-ssm')
|
37
43
|
Adapters::SSM
|
44
|
+
when :aws_secrets_manager
|
45
|
+
require_adapter_dependency(adapter, 'aws-sdk-secretsmanager')
|
46
|
+
Adapters::SecretsManager
|
47
|
+
when :ejson_wrapper
|
48
|
+
require_adapter_dependency(adapter, 'ejson_wrapper')
|
49
|
+
Adapters::EJSONWrapper
|
38
50
|
else
|
39
51
|
raise "Invalid adapter: #{adapter}"
|
40
52
|
end
|
41
53
|
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def require_adapter_dependency(adapter, dependency)
|
58
|
+
require dependency
|
59
|
+
rescue LoadError
|
60
|
+
fail "#{adapter} requires #{dependency} to be installed separately. Please add gem '#{dependency}' to your Gemfile"
|
61
|
+
end
|
42
62
|
end
|
43
63
|
end
|
data/param_store.gemspec
CHANGED
@@ -21,8 +21,6 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ['lib']
|
23
23
|
|
24
|
-
spec.add_dependency 'aws-sdk-ssm', '~> 1'
|
25
|
-
|
26
24
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
27
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
28
26
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: param_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Cantero
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: aws-sdk-ssm
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,7 +59,9 @@ files:
|
|
73
59
|
- bin/console
|
74
60
|
- bin/setup
|
75
61
|
- lib/param_store.rb
|
62
|
+
- lib/param_store/adapters/ejson_wrapper.rb
|
76
63
|
- lib/param_store/adapters/env.rb
|
64
|
+
- lib/param_store/adapters/secrets_manager.rb
|
77
65
|
- lib/param_store/adapters/ssm.rb
|
78
66
|
- lib/param_store/version.rb
|
79
67
|
- lib/param_store/wrapper.rb
|
@@ -97,7 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
85
|
- !ruby/object:Gem::Version
|
98
86
|
version: '0'
|
99
87
|
requirements: []
|
100
|
-
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.7.6.2
|
101
90
|
signing_key:
|
102
91
|
specification_version: 4
|
103
92
|
summary: Easy switch in between ENV and AWS Parameter Store (SSM)
|