chambermaid 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +10 -2
- data/lib/chambermaid.rb +3 -1
- data/lib/chambermaid/base.rb +55 -0
- data/lib/chambermaid/parameter_store.rb +59 -0
- data/lib/chambermaid/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96de691a190b68ff6d24e2410f1191ac0f3ef29c534de37ae73b7e7a7f4d8530
|
4
|
+
data.tar.gz: 16b2fb406a93c823bba30938594294fdcad94a1588718327c57b1d10fddf7f0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d73421e3cdac6a8e835b745df14a2fe012f4785183e4cc28c4222358553a8ac29a12f5e7cd256af7d7bf2bfcbf5bf8cf2783d089dbb09e435d07f717a359269
|
7
|
+
data.tar.gz: 7d7a11dbb825742c23bd9a1d8b2ac10cabb44c92b66d6fea40ae828c01862611d97b5422efafd3f57f9c5826e39648240eb389f69d9d98acf0635118908c266a
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -22,15 +22,23 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
+
**Standalone**
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
Chambermaid.add_namespace("/my/param/namespace")
|
29
|
+
```
|
30
|
+
|
31
|
+
**Configuration Block**
|
32
|
+
|
25
33
|
```ruby
|
26
34
|
# config/initializers/chambermaid.rb
|
27
35
|
|
28
36
|
Chambermaid.configure do |config|
|
29
37
|
config.add_namespace("/my/param/namespace")
|
30
38
|
|
31
|
-
# Set `
|
39
|
+
# Set `overwrite_duplicates: true` to choose these params over existing
|
32
40
|
# ones in ENV when they are merged together
|
33
|
-
config.add_namespace("/my/important/namespace",
|
41
|
+
config.add_namespace("/my/important/namespace", overwrite_duplicates: true)
|
34
42
|
end
|
35
43
|
```
|
36
44
|
|
data/lib/chambermaid.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "chambermaid/parameter_store"
|
2
|
+
|
3
|
+
module Chambermaid
|
4
|
+
module Base
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def configure
|
8
|
+
yield self
|
9
|
+
end
|
10
|
+
|
11
|
+
# @todo
|
12
|
+
def configuration
|
13
|
+
raise "Namespaces must be defined" unless @namespaces
|
14
|
+
end
|
15
|
+
|
16
|
+
# @todo
|
17
|
+
def reload!
|
18
|
+
end
|
19
|
+
|
20
|
+
# Add an AWS SSM parameter namespace to ENV
|
21
|
+
#
|
22
|
+
# @param [String] path
|
23
|
+
# @param [Boolean] overwrite_duplicates
|
24
|
+
# true - replace any duplicate ENV keys with new params
|
25
|
+
# false - keep any existing duplicate ENV key values
|
26
|
+
#
|
27
|
+
# @raise
|
28
|
+
def add_namespace(path, overwrite_duplicates: false)
|
29
|
+
@namespaces ||= {}
|
30
|
+
raise "namespace already included in ENV" unless @namespaces[path].nil?
|
31
|
+
|
32
|
+
@namespaces[path] = ParameterStore.load!(path: path)
|
33
|
+
update_env!(
|
34
|
+
params: @namespaces[path].params,
|
35
|
+
overwrite_duplicates: overwrite_duplicates
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Inject into ENV
|
40
|
+
#
|
41
|
+
# @param [Hash] params
|
42
|
+
# @param [Boolean] overwrite_duplicates
|
43
|
+
# true - replace any duplicate ENV keys with new params
|
44
|
+
# false - keep any existing duplicate ENV key values
|
45
|
+
def update_env!(params:, overwrite_duplicates:)
|
46
|
+
if overwrite_duplicates
|
47
|
+
ENV.update(params)
|
48
|
+
else
|
49
|
+
current_env = ENV.to_h.dup
|
50
|
+
new_env = params.merge(current_env)
|
51
|
+
ENV.replace(new_env)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "aws-sdk-ssm"
|
2
|
+
|
3
|
+
module Chambermaid
|
4
|
+
class ParameterStore
|
5
|
+
def initialize(path:)
|
6
|
+
@path = path
|
7
|
+
end
|
8
|
+
|
9
|
+
def load!
|
10
|
+
fetch_ssm_params!
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.load!(path:)
|
14
|
+
store = new(path: path)
|
15
|
+
store.load!
|
16
|
+
store
|
17
|
+
end
|
18
|
+
|
19
|
+
def params
|
20
|
+
@params ||= @param_list.map { |p|
|
21
|
+
[p.name.split("/").last.upcase, p.value]
|
22
|
+
}.to_h
|
23
|
+
end
|
24
|
+
|
25
|
+
alias :to_h :params
|
26
|
+
|
27
|
+
def to_env
|
28
|
+
params.inject("") do |env_str, param|
|
29
|
+
env_str + "#{param[0]}=#{param[1]}\n"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def client
|
36
|
+
@client ||= Aws::SSM::Client.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def fetch_ssm_params!
|
40
|
+
@param_list = []
|
41
|
+
response = nil
|
42
|
+
loop do
|
43
|
+
response = fetch_ssm_param_batch!(response&.next_token)
|
44
|
+
@param_list.concat(response.parameters)
|
45
|
+
|
46
|
+
break unless response.next_token
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def fetch_ssm_param_batch!(next_token = nil)
|
51
|
+
client.get_parameters_by_path(
|
52
|
+
path: @path,
|
53
|
+
with_decryption: true,
|
54
|
+
recursive: true,
|
55
|
+
next_token: next_token
|
56
|
+
)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/chambermaid/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chambermaid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Zimmerman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-ssm
|
@@ -44,6 +44,8 @@ files:
|
|
44
44
|
- bin/setup
|
45
45
|
- chambermaid.gemspec
|
46
46
|
- lib/chambermaid.rb
|
47
|
+
- lib/chambermaid/base.rb
|
48
|
+
- lib/chambermaid/parameter_store.rb
|
47
49
|
- lib/chambermaid/version.rb
|
48
50
|
homepage: https://github.com/mileszim/chambermaid
|
49
51
|
licenses:
|