chambermaid 0.3.2 → 1.0.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: fbcb610044b8dd8ff4487cb6729889f18dde9a32bd09b25620b53b6c6336a9e9
4
- data.tar.gz: 80abde8476c848335de1f9557f49557322a1463f36419fe8c986a53ee18cb816
3
+ metadata.gz: 22ceec060a8f34e8d44151977ff98af6ac3602b8967aca42a333a6e57ca5b398
4
+ data.tar.gz: f190c278b648d038fdd518cf2e8801f99036e9164a627682377384a8c9107932
5
5
  SHA512:
6
- metadata.gz: beb4b9d61c45e48bd48497e2cf27fec7cd5055447aac237324b298ba343b3d4bed49a46151aff364a90049ac31ae78b2c9dcf51b42cfa3cf000c3adde06a9552
7
- data.tar.gz: 4228d741b603f187e69d3c900efae0241808eccabd4e3227b745cfd4e75e9c570949071c5d46c079d3ecd34992704c0390cea0f6b174c8560c2ce8ba3fe361f9
6
+ metadata.gz: 1b338e0bf90f75194e420c225168fd4aa873d398155b232a29e1dfa29aba1518bd6531ede6436417d6c5abae71c5a0565157c43a6261bb232de8f25344b16bd8
7
+ data.tar.gz: d58b7402d7ab7648218205336ea5bd1df88d3fbbfeaa8680cd11f9666febf8c7a990a32eab5cfdbf6e1e1bb0bf40b39e4f42e7d4f5fc568f32aa6881f83c8e7d
@@ -0,0 +1,16 @@
1
+ name: commitlint
2
+ on:
3
+ - pull_request
4
+
5
+ jobs:
6
+ lint:
7
+ runs-on: ubuntu-latest
8
+ env:
9
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ with:
13
+ fetch-depth: 0
14
+ - uses: wagoid/commitlint-github-action@v1
15
+ with:
16
+ failOnWarnings: true
@@ -0,0 +1,50 @@
1
+ name: release
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+
7
+ jobs:
8
+ create-release:
9
+ runs-on: ubuntu-latest
10
+ env:
11
+ GITHUB_TOKEN: ${{ secrets.GHUB_PAT }}
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ with:
15
+ fetch-depth: 0
16
+ - uses: ridedott/release-me-action@master
17
+ id: get-version-number
18
+ with:
19
+ dry-run: true
20
+ release-rules:
21
+ '[{ "type": "release", "scope": "major", "release": "major" }]'
22
+ - uses: actions/setup-ruby@v1
23
+ with:
24
+ ruby-version: "2.6"
25
+ - run: gem install bundler -v 2.1.2
26
+ - name: Set version.rb and Gemfile.lock
27
+ run: |
28
+ printf "module Chambermaid\n VERSION = \"$NEW_VERSION\"\nend" > lib/chambermaid/version.rb
29
+ bundle install
30
+ env:
31
+ NEW_VERSION: ${{ steps.get-version-number.outputs.version }}
32
+ - run: bundle exec rake build
33
+ - uses: ridedott/release-me-action@master
34
+ with:
35
+ commit-assets: |
36
+ ./lib/chambermaid/version.rb
37
+ ./Gemfile.lock
38
+ release-assets: |
39
+ ./pkg/*.gem
40
+ release-rules:
41
+ '[{ "type": "release", "scope": "major", "release": "major" }]'
42
+ - name: publish to rubygems
43
+ run: |
44
+ mkdir -p ~/.gem
45
+ printf -- "---\n:rubygems_api_key: $GEM_HOST_API_KEY" > ~/.gem/credentials
46
+ chmod 0600 ~/.gem/credentials
47
+ gem push pkg/chambermaid-$NEW_VERSION.gem
48
+ env:
49
+ GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
50
+ NEW_VERSION: ${{ steps.get-version-number.outputs.version }}
@@ -0,0 +1,35 @@
1
+ ## [0.5.5](https://github.com/mileszim/chambermaid/compare/v0.5.4...v0.5.5) (2020-08-03)
2
+
3
+ ### Documentation
4
+
5
+ - add links to documentation and more info for rdoc ([3f7ec6d](https://github.com/mileszim/chambermaid/commit/3f7ec6ddb07478ceefef83403c1e5b9de447509a))
6
+
7
+ ## [0.5.4](https://github.com/mileszim/chambermaid/compare/v0.5.3...v0.5.4) (2020-08-03)
8
+
9
+ ### Bug Fixes
10
+
11
+ - **release:** chmod 0600 ~/.gem/credentials after generating ([ed85d5b](https://github.com/mileszim/chambermaid/commit/ed85d5b1d9b76762bcc50734c806a6e1cd224ad5))
12
+
13
+ ## [0.5.3](https://github.com/mileszim/chambermaid/compare/v0.5.2...v0.5.3) (2020-08-03)
14
+
15
+ ### Bug Fixes
16
+
17
+ - **release:** use bash end of args with printf ([fbc0ae2](https://github.com/mileszim/chambermaid/commit/fbc0ae28961c40f984e6685e5feb33799934f510))
18
+
19
+ ## [0.5.2](https://github.com/mileszim/chambermaid/compare/v0.5.1...v0.5.2) (2020-08-03)
20
+
21
+ ### Bug Fixes
22
+
23
+ - **release:** set rubygem api key into ~/.gem/credentials ([7faef58](https://github.com/mileszim/chambermaid/commit/7faef587631284c3bb89c22572b8bce9c31172d0))
24
+
25
+ ## [0.5.1](https://github.com/mileszim/chambermaid/compare/v0.5.0...v0.5.1) (2020-08-03)
26
+
27
+ ### Bug Fixes
28
+
29
+ - **release:** publish to rubygems on successful release ([e019c7d](https://github.com/mileszim/chambermaid/commit/e019c7df3f43c251a5542374cc9c869fc4b00d92))
30
+
31
+ # [0.5.0](https://github.com/mileszim/chambermaid/compare/v0.4.1...v0.5.0) (2020-08-03)
32
+
33
+ ### Features
34
+
35
+ - add commitlint and release workflow (#2) ([1159e69](https://github.com/mileszim/chambermaid/commit/1159e69e95701e4763fdbe08430d579c2a2a8440)), closes [#2](https://github.com/mileszim/chambermaid/issues/2)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chambermaid (0.3.2)
4
+ chambermaid (1.0.0)
5
5
  aws-sdk-ssm (~> 1.85)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -4,6 +4,8 @@ Companion RubyGem for [chamber](https://github.com/segmentio/chamber).
4
4
 
5
5
  Chambermaid injects AWS SSM params into your ENV. Plays nice with other ENV gems like dotenv.
6
6
 
7
+ - [RubyDocs](https://rubydoc.info/gems/chambermaid)
8
+
7
9
  ## Installation
8
10
 
9
11
  Add this line to your application's Gemfile:
@@ -35,13 +37,21 @@ Chambermaid.add_service("my-chamber-service")
35
37
  # config/initializers/chambermaid.rb
36
38
 
37
39
  Chambermaid.configure do |config|
40
+ # Load all values from SSM Namespace path
38
41
  config.add_namespace("/my/param/namespace")
42
+
43
+ # Load values from chamber-cli service
39
44
  config.add_service("my-chamber-service")
40
45
 
41
46
  # Set `overload: true` to choose these params over existing
42
47
  # ones in ENV when they are merged together
43
48
  config.add_namespace("/my/important/namespace", overload: true)
44
49
  end
50
+
51
+ # If this is standalone ruby (not a Rails environment),
52
+ # call `Chambermaid.load!` after the configuration block
53
+ #
54
+ # Chambermaid.load!
45
55
  ```
46
56
 
47
57
  **Reload SSM into ENV**
@@ -55,6 +65,80 @@ Chambermaid.restore!
55
65
  Chambermaid.reset! # alias of .restore!
56
66
  ```
57
67
 
68
+ **Configure Logging**
69
+ ```ruby
70
+ Chambermaid.configure do |config|
71
+ # ... other config ...
72
+
73
+ # Change log level
74
+ config.log_level = :debug
75
+
76
+ # Set custom logger instance
77
+ config.logger = MyCoolLogger.new
78
+ end
79
+
80
+ # Outside of config block
81
+ Chambermaid.log_level = :warn
82
+ ```
83
+
84
+ _Note: Chambermaid.logger is set to Rails.logger automatically if including inside a rails app_
85
+
86
+ ### AWS Authentication
87
+
88
+ Chambermaid expects your AWS credential configuration to live inside ENV on application load.
89
+
90
+ > **Note:** `AWS_DEFAULT_REGION` or `AWS_REGION` is **required**
91
+
92
+ You can use either:
93
+ * `AWS_ACCESS_KEY_ID`
94
+ * `AWS_SECRET_ACCESS_KEY`
95
+
96
+ or STS grants:
97
+ ```bash
98
+ $ aws-vault exec my-user -- bundle exec rails server
99
+ ```
100
+ > *See [aws-vault](https://github.com/99designs/aws-vault/blob/master/USAGE.md) docs for more info*
101
+
102
+ or a metadata endpoint grant:
103
+ * Available in attached Task or EC2 instance. *See [AWS Docs](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint.html) for more info.*
104
+ * Through aws-vault: `aws-vault exec -s my-user`
105
+
106
+ #### IAM Permissions Required
107
+
108
+ Since this is meant to work out of the box as a complement to [chamber cli](https://github.com/segmentio/chamber), it needs similar IAM permissions.
109
+
110
+ In this case, however, we can grant read-only to the namespace(s).
111
+ ```json
112
+ {
113
+ "Version": "2012-10-17",
114
+ "Statement": [
115
+ {
116
+ "Sid": "",
117
+ "Effect": "Allow",
118
+ "Action": "ssm:DescribeParameters",
119
+ "Resource": "*"
120
+ },
121
+ {
122
+ "Sid": "",
123
+ "Effect": "Allow",
124
+ "Action": [
125
+ "ssm:GetParametersByPath",
126
+ "ssm:GetParameters",
127
+ "ssm:GetParameter",
128
+ "kms:Decrypt"
129
+ ],
130
+ "Resource": [
131
+ "arn:aws:ssm:us-east-1:1234567890:parameter/my-chamber-service",
132
+ "arn:aws:kms:us-east-1:1234567890:key/258574a1-cfce-4530-9e3c-d4b07cd04115"
133
+ ]
134
+ }
135
+ ]
136
+ }
137
+ ```
138
+ > **Note:** `Resource` array MUST include the full ARN of the key id used for chamber cli
139
+ > *(Default alias is `parameter_store_key`)*
140
+
141
+
58
142
  ## Development
59
143
 
60
144
  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.
@@ -16,6 +16,8 @@ Gem::Specification.new do |spec|
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
17
  spec.metadata["source_code_uri"] = "https://github.com/mileszim/chambermaid"
18
18
  spec.metadata["changelog_uri"] = "https://github.com/mileszim/chambermaid/blob/master/CHANGELOG.md"
19
+ spec.metadata["documentation_uri"] = "https://rubydoc.info/gems/chambermaid"
20
+ spec.metadata["bug_tracker_uri"] = "https://github.com/mileszim/chambermaid/issues"
19
21
 
20
22
  # Specify which files should be added to the gem when it is released.
21
23
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -1,5 +1,6 @@
1
1
  require "chambermaid/base"
2
2
  require "chambermaid/version"
3
+ require "chambermaid/railtie" if defined?(Rails)
3
4
 
4
5
  module Chambermaid
5
6
  class Error < StandardError; end
@@ -1,3 +1,5 @@
1
+ require "logger"
2
+
1
3
  require "chambermaid/environment"
2
4
  require "chambermaid/namespace"
3
5
  require "chambermaid/parameter_store"
@@ -13,7 +15,6 @@ module Chambermaid
13
15
 
14
16
  def configure
15
17
  yield self
16
- load!
17
18
  end
18
19
 
19
20
  # @todo
@@ -104,6 +105,39 @@ module Chambermaid
104
105
  add_namespace(service)
105
106
  end
106
107
 
108
+ # !@attribute [r] logger
109
+ # @return [Logger]
110
+ def logger
111
+ @logger ||= Logger.new(STDOUT,
112
+ level: log_level,
113
+ progname: "Chambermaid"
114
+ )
115
+ end
116
+
117
+ # !@attribute [w] logger
118
+ # @return [Logger]
119
+ def logger=(val)
120
+ @logger = val
121
+ @logger.progname = "Chambermaid"
122
+ logger
123
+ end
124
+
125
+ # !@attribute [r] log_level
126
+ # @return [Symbol] (default = :info) current logger level
127
+ def log_level
128
+ return logger.level unless @logger.nil?
129
+ return @log_level unless @log_level.nil?
130
+ return :info
131
+ end
132
+
133
+ # !@attribute [w] log_level
134
+ # @return [Symbol] (default = :info) current logger level
135
+ def log_level=(val = :info)
136
+ @logger.level = val unless @logger.nil?
137
+ @log_level = val
138
+ val
139
+ end
140
+
107
141
  private
108
142
 
109
143
  def namespaces
@@ -1,4 +1,9 @@
1
1
  module Chambermaid
2
+ # Environment keeps a set of params available to load into ENV. It also
3
+ # maintains a copy of ENV at the time of its initialization, in order to
4
+ # restore it.
5
+ #
6
+ # @attr_reader [Hash] params
2
7
  class Environment < Hash
3
8
  attr_reader :params
4
9
 
@@ -35,16 +40,22 @@ module Chambermaid
35
40
  end
36
41
 
37
42
  # Inject into ENV without overwriting duplicates
43
+ #
44
+ # @return [Hash]
38
45
  def load!
39
46
  each { |k, v| ENV[k] ||= v }
40
47
  end
41
48
 
42
49
  # Inject into ENV and overwrite duplicates
50
+ #
51
+ # @return [Hash]
43
52
  def overload!
44
53
  each { |k, v| ENV[k] = v }
45
54
  end
46
55
 
47
56
  # Restore to original ENV
57
+ #
58
+ # @return [ENV]
48
59
  def unload!
49
60
  ENV.replace(@_original_env)
50
61
  end
@@ -1,4 +1,6 @@
1
1
  module Chambermaid
2
+ # Namespaces each contain a ParameterStore and Environment instance,
3
+ # along with the overload flag
2
4
  class Namespace
3
5
  # @param [String] path
4
6
  # @param [Boolean] overload
@@ -10,25 +12,48 @@ module Chambermaid
10
12
  @env = Environment.new({})
11
13
  end
12
14
 
15
+ # Create a namespace and immediately fetch and inject params to ENV
16
+ #
17
+ # @see Chambermaid::Namespace.load!
18
+ #
19
+ # @param [String] path
20
+ # @param [Boolean] overload
21
+ #
22
+ # @return [Chambermaid::Namespace]
13
23
  def self.load!(path:, overload: false)
14
24
  namespace = new(path: path, overload: overload)
15
25
  namespace.load!
16
26
  namespace
17
27
  end
18
28
 
29
+ # Load ParameterStore and inject into ENV
30
+ #
31
+ # @see Chambermaid::ParameterStore#load!
32
+ # @see Chambermaid::Environment#load!
33
+ # @see Chambermaid::Environment#overload!
19
34
  def load!
20
35
  @store.load!
21
36
  load_env!
22
37
  end
23
38
 
39
+ # Unload params from ENV, reload ParameterStore, and inject into ENV
40
+ #
41
+ # @see Chambermaid::Environment#unload!
42
+ # @see Chambermaid::ParameterStore#reload!
43
+ # @see Chambermaid::Environment#load!
44
+ # @see Chambermaid::Environment#overload!
24
45
  def reload!
25
46
  @env.unload!
26
47
  @store.reload!
27
48
  load_env!
28
49
  end
29
50
 
51
+ # Unload params from ENV
52
+ #
53
+ # @see Chambermaid::Environment#unload!
30
54
  def unload!
31
55
  @env.unload!
56
+ Chambermaid.logger.info("unloaded #{@env.size} params from ENV")
32
57
  end
33
58
 
34
59
  private
@@ -37,6 +62,7 @@ module Chambermaid
37
62
  def load_env!
38
63
  @env.replace(@store.params)
39
64
  @overload ? @env.overload! : @env.load!
65
+ Chambermaid.logger.info("loaded #{@env.size} params into ENV from `#{@path}`")
40
66
  end
41
67
  end
42
68
  end
@@ -1,30 +1,52 @@
1
1
  require "aws-sdk-ssm"
2
2
 
3
3
  module Chambermaid
4
+ # ParameterStore instances fetch all parameters under a namespace/path
5
+ # from AWS SSM
6
+ #
7
+ # @note AWS authentication requires configuration via ENV (IAM credentials/STS)
4
8
  class ParameterStore
9
+ # @param [String] path
5
10
  def initialize(path:)
6
11
  @path = path
7
12
  end
8
13
 
14
+ # Fetch and decrypt all parameters selected by a namespace/path string
15
+ #
16
+ # @return [Boolean]
9
17
  def load!
10
18
  fetch_ssm_params!
11
19
  end
12
20
 
21
+ # Clear cached parameters and re-fetch parameters from AWS SSM
22
+ #
23
+ # @return [Boolean]
13
24
  def reload!
14
25
  clear_params!
15
26
  fetch_ssm_params!
16
27
  end
17
28
 
29
+ # Returns true if parameters have been fetched from AWS SSM
30
+ #
31
+ # @return [Boolean]
18
32
  def loaded?
19
33
  !@params_list.empty?
20
34
  end
21
35
 
36
+ # Create a ParameterStore and fetch from AWS SSM immediately
37
+ #
38
+ # @see Chambermaid::ParameterStore#load!
39
+ #
40
+ # @return [Chambermaid::ParameterStore]
22
41
  def self.load!(path:)
23
42
  store = new(path: path)
24
43
  store.load!
25
44
  store
26
45
  end
27
46
 
47
+ # ENV formatted Hash of parameters loaded from AWS SSM
48
+ #
49
+ # @return [Hash]
28
50
  def params
29
51
  @params ||= @param_list.map { |p|
30
52
  [p.name.split("/").last.upcase, p.value]
@@ -40,14 +62,20 @@ module Chambermaid
40
62
  end
41
63
 
42
64
  def fetch_ssm_params!
65
+ Chambermaid.logger.debug("fetching AWS SSM parameters from `#{@path}`")
43
66
  @param_list = []
44
67
  response = nil
45
68
  loop do
46
69
  response = fetch_ssm_param_batch!(response&.next_token)
47
70
  @param_list.concat(response.parameters)
48
71
 
49
- break unless response.next_token
72
+ if response.next_token
73
+ Chambermaid.logger.debug("response.next_token found, continuing fetch")
74
+ else
75
+ break
76
+ end
50
77
  end
78
+ Chambermaid.logger.debug("fetched #{@param_list.size} parameters from `#{@path}`")
51
79
  end
52
80
 
53
81
  def fetch_ssm_param_batch!(next_token = nil)
@@ -0,0 +1,8 @@
1
+ module Chambermaid
2
+ class Railtie < Rails::Railtie
3
+ config.after_initialize do
4
+ Chambermaid.logger = Rails.logger
5
+ Chambermaid.load!
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Chambermaid
2
- VERSION = "0.3.2"
3
- end
2
+ VERSION = "1.0.0"
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.3.2
4
+ version: 1.0.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-08-02 00:00:00.000000000 Z
11
+ date: 2020-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-ssm
@@ -59,9 +59,12 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".github/workflows/commitlint.yml"
63
+ - ".github/workflows/release.yml"
62
64
  - ".gitignore"
63
65
  - ".rspec"
64
66
  - ".travis.yml"
67
+ - CHANGELOG.md
65
68
  - CODE_OF_CONDUCT.md
66
69
  - Gemfile
67
70
  - Gemfile.lock
@@ -76,6 +79,7 @@ files:
76
79
  - lib/chambermaid/environment.rb
77
80
  - lib/chambermaid/namespace.rb
78
81
  - lib/chambermaid/parameter_store.rb
82
+ - lib/chambermaid/railtie.rb
79
83
  - lib/chambermaid/version.rb
80
84
  homepage: https://github.com/mileszim/chambermaid
81
85
  licenses:
@@ -84,6 +88,8 @@ metadata:
84
88
  homepage_uri: https://github.com/mileszim/chambermaid
85
89
  source_code_uri: https://github.com/mileszim/chambermaid
86
90
  changelog_uri: https://github.com/mileszim/chambermaid/blob/master/CHANGELOG.md
91
+ documentation_uri: https://rubydoc.info/gems/chambermaid
92
+ bug_tracker_uri: https://github.com/mileszim/chambermaid/issues
87
93
  post_install_message:
88
94
  rdoc_options: []
89
95
  require_paths:
@@ -99,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
105
  - !ruby/object:Gem::Version
100
106
  version: '0'
101
107
  requirements: []
102
- rubygems_version: 3.1.2
108
+ rubygems_version: 3.0.3
103
109
  signing_key:
104
110
  specification_version: 4
105
111
  summary: Companion Ruby Gem for chamber cli