simple_parameter_store 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b2dc9f14a795d916ad62a2e0bc0c856af6f8ab1e50dc3e33e952b35334cb34d2
4
+ data.tar.gz: ffa943b5a34efac86836b506e40560b9bf3bc7c4fde5ccaeb96f5822db02fba2
5
+ SHA512:
6
+ metadata.gz: c793cdc5b16b1bed1b5f801fb5277a47848326c288191588fa16f6a21dd05debdd1d1fdf9e870c2225cecf4d55a48e493835ce13ffa692708d10201c8d6c235b
7
+ data.tar.gz: 4faa3f5f51d78c6c2b8f0dc385990efe021a741a92333fb458413cc283dcc4209e0ddc550752dd3131e1cc097c91df189f226acb82ed0befee4fda95c2d6b231
@@ -0,0 +1,19 @@
1
+ workflow "CI" {
2
+ on = "push"
3
+ resolves = [
4
+ "CI - Ruby 2.5",
5
+ "CI - Ruby 2.6"
6
+ ]
7
+ }
8
+
9
+ action "CI - Ruby 2.5" {
10
+ uses = "docker://ruby:2.5"
11
+ runs = "bash"
12
+ args = ["-c", "gem install bundler:2.0.1 && bundle && bundle exec rake test"]
13
+ }
14
+
15
+ action "CI - Ruby 2.6" {
16
+ uses = "docker://ruby:2.6"
17
+ runs = "bash"
18
+ args = ["-c", "gem install bundler:2.0.1 && bundle && bundle exec rake test"]
19
+ }
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Metrics/LineLength:
5
+ Max: 120
6
+
7
+ Metrics/MethodLength:
8
+ Exclude:
9
+ - 'test/**/*.rb'
10
+
11
+ Metrics/ClassLength:
12
+ Exclude:
13
+ - 'test/**/*.rb'
14
+
15
+ Metrics/AbcSize:
16
+ Exclude:
17
+ - 'test/**/*.rb'
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in simple_parameter_store.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ simple_parameter_store (0.1.0)
5
+ aws-sdk-ssm
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.0)
11
+ aws-eventstream (1.0.3)
12
+ aws-partitions (1.157.0)
13
+ aws-sdk-core (3.49.0)
14
+ aws-eventstream (~> 1.0, >= 1.0.2)
15
+ aws-partitions (~> 1.0)
16
+ aws-sigv4 (~> 1.1)
17
+ jmespath (~> 1.0)
18
+ aws-sdk-ssm (1.43.0)
19
+ aws-sdk-core (~> 3, >= 3.48.2)
20
+ aws-sigv4 (~> 1.1)
21
+ aws-sigv4 (1.1.0)
22
+ aws-eventstream (~> 1.0, >= 1.0.2)
23
+ jaro_winkler (1.5.2)
24
+ jmespath (1.4.0)
25
+ minitest (5.11.3)
26
+ parallel (1.17.0)
27
+ parser (2.6.3.0)
28
+ ast (~> 2.4.0)
29
+ rainbow (3.0.0)
30
+ rake (10.5.0)
31
+ rubocop (0.68.1)
32
+ jaro_winkler (~> 1.5.1)
33
+ parallel (~> 1.10)
34
+ parser (>= 2.5, != 2.5.1.1)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ ruby-progressbar (~> 1.7)
37
+ unicode-display_width (>= 1.4.0, < 1.6)
38
+ rubocop-performance (1.1.0)
39
+ rubocop (>= 0.67.0)
40
+ ruby-progressbar (1.10.0)
41
+ unicode-display_width (1.5.0)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ bundler (~> 2.0)
48
+ minitest (~> 5.0)
49
+ rake (~> 10.0)
50
+ rubocop
51
+ rubocop-performance
52
+ simple_parameter_store!
53
+
54
+ BUNDLED WITH
55
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Timo Schilling
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # SimpleParameterStore
2
+
3
+ `SimpleParameterStore` gives you an nice abstraction over the AWS SSM Parameter Store.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'simple_parameter_store'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install simple_parameter_store
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'simple_parameter_store'
25
+
26
+ parameters = SimpleParameterStore.new(
27
+ client: Aws::SSM::Client.new, # optional, default: `Aws::SSM::Client.new`, can be used to set custom args for the SSM client
28
+ prefix: "/#{ENV['ENVIRONMENT']}", # optional, default: `nil`, can be used to prefix all parameter names with `/production`
29
+ expires_after: 3600, # optional, default: `nil`, time in seconds after the store will be refreshed
30
+ decryp: true, # optional, default: `true`, enable/disable automatic parameter decryption
31
+ names: { # requires, hash with mapping of parameter names, the key will be used for the store index
32
+ foo: '/bar', # aliased the key `/bar` (if prefix is `nil`) under the `:foo` in the store
33
+ max: ['max', :to_i.to_proc], # the value can be an array with the key as first and a caster as second value,
34
+ key: ['private_key', OpenSSL::PKey::RSA.method(:new)] # the caster must be respond to `call` and return the converted value
35
+ }
36
+ )
37
+
38
+ parameters[:foo] # => `'bar'`
39
+ parameters[:max] # => `123`
40
+ parameters[:key].class # => OpenSSL::PKey::RSA
41
+
42
+ parameters.refresh # forces an store refresh
43
+ parameters.refresh_if_needed # refreshes the store is expired
44
+ ```
45
+
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+
50
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/COMPEON/simple_parameter_store.
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'simple_parameter_store'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SimpleParameterStore
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'simple_parameter_store/version'
4
+
5
+ class SimpleParameterStore
6
+ class SSMKeyError < KeyError; end
7
+
8
+ def initialize(names:, client: nil, prefix: nil, decrypt: true, expires_after: nil)
9
+ @client = client || Aws::SSM::Client.new
10
+ @prefix = prefix
11
+ @decrypt = decrypt
12
+ @expires_after = expires_after
13
+
14
+ @mappings = {}
15
+ @casters = {}
16
+ @cache = {}
17
+
18
+ prepaire(names)
19
+ refresh
20
+ end
21
+
22
+ attr_reader :client, :prefix, :decrypt, :expires_after, :expires_at
23
+
24
+ def refresh
25
+ fetch.parameters.each do |parameter|
26
+ key, = @mappings.rassoc(parameter.name)
27
+ caster = @casters.fetch(key)
28
+ value = caster.call(parameter.value)
29
+ @cache[key] = value
30
+ end
31
+
32
+ @expires_at = Time.now + expires_after if expires_after
33
+ end
34
+
35
+ def refresh_if_needed
36
+ refresh if expired?
37
+ end
38
+
39
+ def expired?
40
+ expires_after && expires_at < Time.now
41
+ end
42
+
43
+ def [](key)
44
+ refresh_if_needed
45
+ @cache.fetch(key)
46
+ end
47
+
48
+ private
49
+
50
+ def fetch
51
+ result = client.get_parameters(names: @mappings.values, with_decryption: decrypt)
52
+ raise SSMKeyError if result.invalid_parameters.any?
53
+
54
+ result
55
+ end
56
+
57
+ def prepaire(names)
58
+ names.each_pair do |key, (name, caster)|
59
+ @mappings[key] = "#{prefix}#{name}"
60
+ @casters[key] = caster || :itself.to_proc
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'simple_parameter_store/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'simple_parameter_store'
9
+ spec.version = SimpleParameterStore::VERSION
10
+ spec.authors = ['Timo Schilling']
11
+ spec.email = ['timo@schilling.io']
12
+
13
+ spec.summary = 'Simple abstraction of AWS SSM Parameter Store.'
14
+ spec.description = 'Simple abstraction of AWS SSM Parameter Store.'
15
+ spec.homepage = 'https://github.com/COMPEON/simple_parameter_store'
16
+ spec.license = 'MIT'
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_dependency 'aws-sdk-ssm'
28
+
29
+ spec.add_development_dependency 'bundler', '~> 2.0'
30
+ spec.add_development_dependency 'minitest', '~> 5.0'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rubocop'
33
+ spec.add_development_dependency 'rubocop-performance'
34
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_parameter_store
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Timo Schilling
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-ssm
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-performance
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Simple abstraction of AWS SSM Parameter Store.
98
+ email:
99
+ - timo@schilling.io
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".github/main.workflow"
105
+ - ".gitignore"
106
+ - ".rubocop.yml"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/simple_parameter_store.rb
115
+ - lib/simple_parameter_store/version.rb
116
+ - simple_parameter_store.gemspec
117
+ homepage: https://github.com/COMPEON/simple_parameter_store
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubygems_version: 3.0.3
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Simple abstraction of AWS SSM Parameter Store.
140
+ test_files: []