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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07456ca91b66f62c0c8184a33622d02cf18075e56f75872b5ffa79ef243074fb
4
- data.tar.gz: 120815ce7e083a74b30ff62e4679e66e9b3217ab7022bec3b43eb971dd1a92f5
3
+ metadata.gz: 96de691a190b68ff6d24e2410f1191ac0f3ef29c534de37ae73b7e7a7f4d8530
4
+ data.tar.gz: 16b2fb406a93c823bba30938594294fdcad94a1588718327c57b1d10fddf7f0a
5
5
  SHA512:
6
- metadata.gz: 73ea6ab93523e9e4e8e472140a314c5fd6d0661ed95b0591f53db345e2bffa5aec455cfa426e873e1102ec2c7881bed0170d6d66c2f6032f2fde9fbb5cdafb55
7
- data.tar.gz: 1c0010e8ef0c9005a46a7831ec343dcaaf17a78dce974250225777dabd2f9be49ce41c8716b5b59c3b82cc77b46f79b7fa99b96b1ca7b125a83f29b00a14ea14
6
+ metadata.gz: 4d73421e3cdac6a8e835b745df14a2fe012f4785183e4cc28c4222358553a8ac29a12f5e7cd256af7d7bf2bfcbf5bf8cf2783d089dbb09e435d07f717a359269
7
+ data.tar.gz: 7d7a11dbb825742c23bd9a1d8b2ac10cabb44c92b66d6fea40ae828c01862611d97b5422efafd3f57f9c5826e39648240eb389f69d9d98acf0635118908c266a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chambermaid (0.0.1)
4
+ chambermaid (0.1.0)
5
5
  aws-sdk-ssm (~> 1.85)
6
6
 
7
7
  GEM
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 `priority: true` to choose these params over existing
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", priority: true)
41
+ config.add_namespace("/my/important/namespace", overwrite_duplicates: true)
34
42
  end
35
43
  ```
36
44
 
@@ -1,6 +1,8 @@
1
+ require "chambermaid/base"
1
2
  require "chambermaid/version"
2
3
 
3
4
  module Chambermaid
4
5
  class Error < StandardError; end
5
- # Your code goes here...
6
+
7
+ extend Base
6
8
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Chambermaid
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
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.1
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-07-31 00:00:00.000000000 Z
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: