chambermaid 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +8 -2
- data/lib/chambermaid/base.rb +30 -13
- data/lib/chambermaid/parameter_store.rb +10 -0
- data/lib/chambermaid/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ceb4e76a467a39e91b32a40efff57e8fe8d213e28ea38c9742569af98eac7e0f
|
4
|
+
data.tar.gz: dfdb963dece1c57711fae828eaeebf53490ce2569f6fa339839d2c01a24787ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2997b5bf940b31802cb900d50b042820885da4209fff8e2231228994fbb3daf3efa4c979fb6a41f37a1512e3cea96440e3744b8ca2939dcd2543cc1287c1e960
|
7
|
+
data.tar.gz: cc518b62b452ea0c63e83b04fd3535345ed335a671fffd6fba6c184addfdaa45a9f29553a825d55e97921598300675e1c054d496dd30a850ca520968170f15be
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -36,12 +36,18 @@ Chambermaid.add_namespace("/my/param/namespace")
|
|
36
36
|
Chambermaid.configure do |config|
|
37
37
|
config.add_namespace("/my/param/namespace")
|
38
38
|
|
39
|
-
# Set `
|
39
|
+
# Set `overload: true` to choose these params over existing
|
40
40
|
# ones in ENV when they are merged together
|
41
|
-
config.add_namespace("/my/important/namespace",
|
41
|
+
config.add_namespace("/my/important/namespace", overload: true)
|
42
42
|
end
|
43
43
|
```
|
44
44
|
|
45
|
+
**Restore ENV to original state**
|
46
|
+
```ruby
|
47
|
+
Chambermaid.restore!
|
48
|
+
Chambermaid.reset! # alias of .restore!
|
49
|
+
```
|
50
|
+
|
45
51
|
## Development
|
46
52
|
|
47
53
|
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.
|
data/lib/chambermaid/base.rb
CHANGED
@@ -2,6 +2,11 @@ require "chambermaid/parameter_store"
|
|
2
2
|
|
3
3
|
module Chambermaid
|
4
4
|
module Base
|
5
|
+
def self.extended(base)
|
6
|
+
# Make a copy of ENV before we mess it all up
|
7
|
+
@@_original_env = ENV.to_h.dup
|
8
|
+
end
|
9
|
+
|
5
10
|
extend self
|
6
11
|
|
7
12
|
def configure
|
@@ -15,35 +20,47 @@ module Chambermaid
|
|
15
20
|
|
16
21
|
# @todo
|
17
22
|
def reload!
|
23
|
+
restore!
|
24
|
+
@namespaces.each do |ns|
|
25
|
+
ns[:store].reload!
|
26
|
+
update_env!(
|
27
|
+
params: ns[:store].params,
|
28
|
+
overload: ns[:overload]
|
29
|
+
)
|
30
|
+
end
|
18
31
|
end
|
19
32
|
|
33
|
+
# Restore ENV to its original state
|
34
|
+
def restore!
|
35
|
+
ENV.replace(@@_original_env)
|
36
|
+
end
|
37
|
+
alias :reset! :restore!
|
38
|
+
|
20
39
|
# Add an AWS SSM parameter namespace to ENV
|
21
40
|
#
|
22
41
|
# @param [String] path
|
23
|
-
# @param [Boolean]
|
42
|
+
# @param [Boolean] overload
|
24
43
|
# true - replace any duplicate ENV keys with new params
|
25
44
|
# false - keep any existing duplicate ENV key values
|
26
45
|
#
|
27
46
|
# @raise
|
28
|
-
def add_namespace(path,
|
29
|
-
@namespaces ||=
|
30
|
-
raise "namespace already included in ENV" unless @namespaces[path].nil?
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
overwrite_duplicates: overwrite_duplicates
|
36
|
-
)
|
47
|
+
def add_namespace(path, overload: false)
|
48
|
+
@namespaces ||= []
|
49
|
+
# raise "namespace already included in ENV" unless @namespaces[path].nil?
|
50
|
+
|
51
|
+
store = ParameterStore.load!(path: path)
|
52
|
+
@namespaces << { store: store, overload: overload }
|
53
|
+
update_env!(params: store.params, overload: overload)
|
37
54
|
end
|
38
55
|
|
39
56
|
# Inject into ENV
|
40
57
|
#
|
41
58
|
# @param [Hash] params
|
42
|
-
# @param [Boolean]
|
59
|
+
# @param [Boolean] overload
|
43
60
|
# true - replace any duplicate ENV keys with new params
|
44
61
|
# false - keep any existing duplicate ENV key values
|
45
|
-
def update_env!(params:,
|
46
|
-
if
|
62
|
+
def update_env!(params:, overload:)
|
63
|
+
if overload
|
47
64
|
ENV.update(params)
|
48
65
|
else
|
49
66
|
current_env = ENV.to_h.dup
|
@@ -10,6 +10,11 @@ module Chambermaid
|
|
10
10
|
fetch_ssm_params!
|
11
11
|
end
|
12
12
|
|
13
|
+
def reload!
|
14
|
+
clear_params!
|
15
|
+
fetch_ssm_params!
|
16
|
+
end
|
17
|
+
|
13
18
|
def self.load!(path:)
|
14
19
|
store = new(path: path)
|
15
20
|
store.load!
|
@@ -55,5 +60,10 @@ module Chambermaid
|
|
55
60
|
next_token: next_token
|
56
61
|
)
|
57
62
|
end
|
63
|
+
|
64
|
+
def clear_params!
|
65
|
+
@params = nil
|
66
|
+
@params_list = nil
|
67
|
+
end
|
58
68
|
end
|
59
69
|
end
|
data/lib/chambermaid/version.rb
CHANGED