chambermaid 0.3.1 → 0.5.5

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: 7d4fc9f48419122d6a28cc245555d39a2c3937214c678a1a4e7b3fbc772d6958
4
- data.tar.gz: f8490c672e5f4dc3d5a76c7b802c55a787d1b67b0eb3d7eabb5e9416d77e7b58
3
+ metadata.gz: bac5b5a18928996ec0eff656de94105639482b427795b54cddf825232ff83667
4
+ data.tar.gz: 4382e36051f155568e2a77a84a79bdb39d55eb0f9e640941aa6d0b85c1071661
5
5
  SHA512:
6
- metadata.gz: 705521c47a2553a9fc884fa0ab124086be78cbacd96eacaea1abf9e7b5df5b281eb85a1e2492468b9b5729a8edc5002e776629a613678975f42e5c4e835ba2dc
7
- data.tar.gz: 79ed8aade8ab8e820205b13a8fbc5037667629af32c37801a53b7abe09ff56c26c91e09c1d826662b04dfb31faf8b27097e47d5380e3713495d71da74f8e03a9
6
+ metadata.gz: e28ac0a2b70366e8f60b882ff2e6e62b5261f6d7056f0f95e4ffd2a4c15ba9431ba8ae3610cd7be6faa040207c6edf3a3a9e0ef11d99359c1f597b25250d19bd
7
+ data.tar.gz: 80f638eb0c1c445c73e37dda7e9c67c08c3009d012cb28ed8e203f5063675b79cac9cd60dc01847630eaa2ddc3c7c160be0bb9a999b5bf15d373530b1312dc25
@@ -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,46 @@
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
+ - uses: actions/setup-ruby@v1
21
+ with:
22
+ ruby-version: "2.6"
23
+ - run: gem install bundler -v 2.1.2
24
+ - name: Set version.rb and Gemfile.lock
25
+ run: |
26
+ printf "module Chambermaid\n VERSION = \"$NEW_VERSION\"\nend" > lib/chambermaid/version.rb
27
+ bundle install
28
+ env:
29
+ NEW_VERSION: ${{ steps.get-version-number.outputs.version }}
30
+ - run: bundle exec rake build
31
+ - uses: ridedott/release-me-action@master
32
+ with:
33
+ commit-assets: |
34
+ ./lib/chambermaid/version.rb
35
+ ./Gemfile.lock
36
+ release-assets: |
37
+ ./pkg/*.gem
38
+ - name: publish to rubygems
39
+ run: |
40
+ mkdir -p ~/.gem
41
+ printf -- "---\n:rubygems_api_key: $GEM_HOST_API_KEY" > ~/.gem/credentials
42
+ chmod 0600 ~/.gem/credentials
43
+ gem push pkg/chambermaid-$NEW_VERSION.gem
44
+ env:
45
+ GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
46
+ NEW_VERSION: ${{ steps.get-version-number.outputs.version }}
@@ -0,0 +1,29 @@
1
+ ## [0.5.4](https://github.com/mileszim/chambermaid/compare/v0.5.3...v0.5.4) (2020-08-03)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **release:** chmod 0600 ~/.gem/credentials after generating ([ed85d5b](https://github.com/mileszim/chambermaid/commit/ed85d5b1d9b76762bcc50734c806a6e1cd224ad5))
6
+
7
+ ## [0.5.3](https://github.com/mileszim/chambermaid/compare/v0.5.2...v0.5.3) (2020-08-03)
8
+
9
+ ### Bug Fixes
10
+
11
+ - **release:** use bash end of args with printf ([fbc0ae2](https://github.com/mileszim/chambermaid/commit/fbc0ae28961c40f984e6685e5feb33799934f510))
12
+
13
+ ## [0.5.2](https://github.com/mileszim/chambermaid/compare/v0.5.1...v0.5.2) (2020-08-03)
14
+
15
+ ### Bug Fixes
16
+
17
+ - **release:** set rubygem api key into ~/.gem/credentials ([7faef58](https://github.com/mileszim/chambermaid/commit/7faef587631284c3bb89c22572b8bce9c31172d0))
18
+
19
+ ## [0.5.1](https://github.com/mileszim/chambermaid/compare/v0.5.0...v0.5.1) (2020-08-03)
20
+
21
+ ### Bug Fixes
22
+
23
+ - **release:** publish to rubygems on successful release ([e019c7d](https://github.com/mileszim/chambermaid/commit/e019c7df3f43c251a5542374cc9c869fc4b00d92))
24
+
25
+ # [0.5.0](https://github.com/mileszim/chambermaid/compare/v0.4.1...v0.5.0) (2020-08-03)
26
+
27
+ ### Features
28
+
29
+ - add commitlint and release workflow (#2) ([1159e69](https://github.com/mileszim/chambermaid/commit/1159e69e95701e4763fdbe08430d579c2a2a8440)), closes [#2](https://github.com/mileszim/chambermaid/issues/2)
data/Gemfile CHANGED
@@ -2,6 +2,3 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in chambermaid.gemspec
4
4
  gemspec
5
-
6
- gem "rake", "~> 12.0"
7
- gem "rspec", "~> 3.0"
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chambermaid (0.3.1)
4
+ chambermaid (0.5.5)
5
5
  aws-sdk-ssm (~> 1.85)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  aws-eventstream (1.1.0)
11
- aws-partitions (1.348.0)
11
+ aws-partitions (1.349.0)
12
12
  aws-sdk-core (3.104.3)
13
13
  aws-eventstream (~> 1, >= 1.0.2)
14
14
  aws-partitions (~> 1, >= 1.239.0)
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
- # Chambermaid
1
+ # Chambermaid [![Gem Version](https://badge.fury.io/rb/chambermaid.svg)](https://badge.fury.io/rb/chambermaid) [![Build Status](https://travis-ci.com/mileszim/chambermaid.svg?branch=master)](https://travis-ci.com/mileszim/chambermaid)
2
2
 
3
3
  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,19 @@ 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
+ # Load after configuration
52
+ Chambermaid.load!
45
53
  ```
46
54
 
47
55
  **Reload SSM into ENV**
@@ -55,6 +63,24 @@ Chambermaid.restore!
55
63
  Chambermaid.reset! # alias of .restore!
56
64
  ```
57
65
 
66
+ **Configure Logging**
67
+ ```ruby
68
+ Chambermaid.configure do |config|
69
+ # ... other config ...
70
+
71
+ # Change log level
72
+ config.log_level = :debug
73
+
74
+ # Set custom logger instance
75
+ config.logger = MyCoolLogger.new
76
+ end
77
+
78
+ # Outside of config block
79
+ Chambermaid.log_level = :warn
80
+ ```
81
+
82
+ _Note: Chambermaid.logger is set to Rails.logger automatically if including inside a rails app_
83
+
58
84
  ## Development
59
85
 
60
86
  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.
@@ -28,4 +30,6 @@ Gem::Specification.new do |spec|
28
30
 
29
31
  # Gems
30
32
  spec.add_dependency("aws-sdk-ssm", "~> 1.85")
33
+ spec.add_development_dependency("rspec", "~> 3.0")
34
+ spec.add_development_dependency("rake", "~> 12.0")
31
35
  end
@@ -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.1"
3
- end
2
+ VERSION = "0.5.5"
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.1
4
+ version: 0.5.5
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
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.85'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
27
55
  description:
28
56
  email:
29
57
  - miles@asktrim.com
@@ -31,9 +59,12 @@ executables: []
31
59
  extensions: []
32
60
  extra_rdoc_files: []
33
61
  files:
62
+ - ".github/workflows/commitlint.yml"
63
+ - ".github/workflows/release.yml"
34
64
  - ".gitignore"
35
65
  - ".rspec"
36
66
  - ".travis.yml"
67
+ - CHANGELOG.md
37
68
  - CODE_OF_CONDUCT.md
38
69
  - Gemfile
39
70
  - Gemfile.lock
@@ -48,6 +79,7 @@ files:
48
79
  - lib/chambermaid/environment.rb
49
80
  - lib/chambermaid/namespace.rb
50
81
  - lib/chambermaid/parameter_store.rb
82
+ - lib/chambermaid/railtie.rb
51
83
  - lib/chambermaid/version.rb
52
84
  homepage: https://github.com/mileszim/chambermaid
53
85
  licenses:
@@ -56,6 +88,8 @@ metadata:
56
88
  homepage_uri: https://github.com/mileszim/chambermaid
57
89
  source_code_uri: https://github.com/mileszim/chambermaid
58
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
59
93
  post_install_message:
60
94
  rdoc_options: []
61
95
  require_paths:
@@ -71,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
105
  - !ruby/object:Gem::Version
72
106
  version: '0'
73
107
  requirements: []
74
- rubygems_version: 3.1.2
108
+ rubygems_version: 3.0.3
75
109
  signing_key:
76
110
  specification_version: 4
77
111
  summary: Companion Ruby Gem for chamber cli