blinkist-config 1.1.0 → 1.2.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
  SHA1:
3
- metadata.gz: f124d3763ba77723dd15b742f34059417f04e669
4
- data.tar.gz: 9d83b0e2e91c7f4f8dee43f31d678e8ad29b7ae9
3
+ metadata.gz: e3ced4954f00dac9ba41bf8942eadd20ed04c355
4
+ data.tar.gz: 7dc2ca9ab278f071dec3417f8f0ca82ccc317e2c
5
5
  SHA512:
6
- metadata.gz: 357f0e51ee0a058243a548e0f2a5a150554b3d3d022146d96c4850e280f6065279b305f918263b9f7d04e5906dadc301956db83a798e623c4dac525ca6436aae
7
- data.tar.gz: 8c3352a6add14f838b3a10da3bacdf08304775e25a79304a1dbb1154e8de8b1703e2f457cc8d18cdc5cc9b9b1d22e864c18f71de8b48838d42ab5f44804d40bf
6
+ metadata.gz: d463681c830d3e57f99eec95bb6ed456ac304ea246db4926cb0c4765d469aa0e129f132edeab14346e15b2bf5d898fc1b3602441e46717ae6f2da9513216090e
7
+ data.tar.gz: f090fa2cb1c05855b9b5dc22bd544c0bcec5b509a8a8cd7f9f3d553c5ed20b269c58be1998f6c59458263981480469d5fc4b4b48f88e18473a6baf0a05ce9510
data/Gemfile CHANGED
@@ -3,8 +3,6 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in blinkist-config.gemspec
4
4
  gemspec
5
5
 
6
- gem "rubocop", "~> 0"
7
-
8
6
  group :test do
9
7
  gem "codeclimate-test-reporter", "~> 1.0.0"
10
8
  gem "simplecov"
data/README.md CHANGED
@@ -74,6 +74,35 @@ my_config_value = Blinkist::Config.get! "another/config", scope: "global"
74
74
  # With :env the scope will simply be ignored
75
75
  ```
76
76
 
77
+ ### Using AWS SSM
78
+
79
+ If you want to use EC2's key value store SSM, simply use our aws_ssm adapter. It'll automatically try to decrypt all keys.
80
+
81
+ The GEM expects the code to run in an AWS environment with properly set up IAM.
82
+
83
+ ```ruby
84
+ Blinkist::Config.env = ENV["RAILS_ENV"]
85
+ Blinkist::Config.app_name = "my_nice_app"
86
+ Blinkist::Config.adapter_type = ENV["SSM_AVAILABLE"] == "true" ? :aws_ssm : :env
87
+
88
+ my_config_value = Blinkist::Config.get! "some/folder/config"
89
+
90
+ # This is will try to get a parameter from SSM at "/application/my_nice_app/some/folder/config"
91
+
92
+ # You can also preload all parameters to avoid later calls to SSM
93
+ Blinkist::Config.preload
94
+ Blinkist::Config.preload scope: "global" # in case you need also another scope being preloaded
95
+ ```
96
+
97
+ ### Using SSM with a folder scope
98
+ ```ruby
99
+ # Here we setting a scope outside of the app
100
+
101
+ my_config_value = Blinkist::Config.get! "another/config", scope: "global"
102
+
103
+ # This will replace `my_nice_app` with `global` and try to resolve "/application/global/another/config"
104
+ ```
105
+
77
106
 
78
107
  ## Installation
79
108
 
data/Rakefile CHANGED
@@ -3,10 +3,10 @@ require "rspec/core/rake_task"
3
3
  require "rubocop/rake_task"
4
4
 
5
5
  RuboCop::RakeTask.new do |task|
6
- task.options = %w[-a]
6
+ task.options = %w(-a)
7
7
  end
8
8
 
9
9
  RSpec::Core::RakeTask.new(:spec)
10
10
 
11
11
  task(:default).clear
12
- task default: %i[rubocop spec]
12
+ task default: %i(rubocop spec)
@@ -15,11 +15,12 @@ Gem::Specification.new do |spec|
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.require_paths = %w[lib]
18
+ spec.require_paths = %w(lib)
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.12"
21
21
  spec.add_development_dependency "rake", "~> 12.0"
22
22
  spec.add_development_dependency "rspec", "~> 3.0"
23
23
 
24
24
  spec.add_runtime_dependency "diplomat", "~> 1"
25
+ spec.add_runtime_dependency "aws-sdk-ssm", "~> 1.3.0"
25
26
  end
@@ -9,6 +9,7 @@ require_relative "config/error_handlers/production_only_error_handler"
9
9
  require_relative "config/error_handlers"
10
10
  require_relative "config/adapters/env_adapter"
11
11
  require_relative "config/adapters/diplomat_adapter"
12
+ require_relative "config/adapters/aws_ssm_adapter"
12
13
  require_relative "config/adapters"
13
14
 
14
15
  module Blinkist
@@ -20,6 +21,10 @@ module Blinkist
20
21
  get!(key, default, scope: scope)
21
22
  end
22
23
 
24
+ def preload(scope: nil)
25
+ adapter.preload scope: scope
26
+ end
27
+
23
28
  extend Gem::Deprecate
24
29
  deprecate :get, "get!", 2017, 12
25
30
 
@@ -3,7 +3,8 @@ module Blinkist
3
3
  module Adapters
4
4
  BUILT_IN = {
5
5
  env: EnvAdapter,
6
- diplomat: DiplomatAdapter
6
+ diplomat: DiplomatAdapter,
7
+ aws_ssm: AwsSsmAdapter
7
8
  }.freeze
8
9
  end
9
10
  end
@@ -10,6 +10,10 @@ module Blinkist
10
10
  raise NotImplementedError
11
11
  end
12
12
 
13
+ def preload(**)
14
+ # nothing to do
15
+ end
16
+
13
17
  class << self
14
18
  def instance_for(type, env, app_name)
15
19
  Factory.new("Blinkist::Adapter.for", Adapters::BUILT_IN, env, app_name).call(type)
@@ -0,0 +1,56 @@
1
+ require_relative "adapter"
2
+ require "aws-sdk-ssm"
3
+
4
+ module Blinkist
5
+ class Config
6
+ class AwsSsmAdapter < Adapter
7
+ DEFAULT_PREFIX = "/application/".freeze
8
+
9
+ def initialize(env, app_name)
10
+ super env, app_name
11
+
12
+ @items_cache = {}
13
+ @client = Aws::SSM::Client.new
14
+ end
15
+
16
+ def get(key, default=nil, scope: nil)
17
+ prefix = prefix_for(scope)
18
+
19
+ query_ssm_parameter "#{prefix}/#{key}"
20
+ rescue Aws::SSM::Errors::ParameterNotFound
21
+ default
22
+ end
23
+
24
+ def preload(scope: nil)
25
+ query_all_ssm_parameters prefix_for(scope)
26
+ end
27
+
28
+ private
29
+
30
+ def prefix_for(scope)
31
+ if scope.nil?
32
+ DEFAULT_PREFIX + @app_name
33
+ else
34
+ DEFAULT_PREFIX + scope
35
+ end
36
+ end
37
+
38
+ def query_ssm_parameter(name)
39
+ @items_cache[name] ||= @client.get_parameter(
40
+ name: name,
41
+ with_decryption: true
42
+ ).parameter.value
43
+ end
44
+
45
+ def query_all_ssm_parameters(prefix)
46
+ @client.get_parameters_by_path(
47
+ path: prefix,
48
+ recursive: true,
49
+ with_decryption: true
50
+ ).parameters.map do |parameter|
51
+ @items_cache[parameter.name] = parameter.value
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,5 +1,5 @@
1
1
  module Blinkist
2
2
  class Config
3
- VERSION = "1.1.0".freeze
3
+ VERSION = "1.2.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blinkist-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Schleicher, Blinks Labs GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-22 00:00:00.000000000 Z
11
+ date: 2017-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aws-sdk-ssm
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.3.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.3.0
69
83
  description: This GEM allows you to keep your configuration class-based by calling
70
84
  Blinkist::Config.get!(...) instead of accessing the ENV directly. You can set up
71
85
  different types of adapters to connect to various configuration systems like your
@@ -91,6 +105,7 @@ files:
91
105
  - lib/blinkist/config.rb
92
106
  - lib/blinkist/config/adapters.rb
93
107
  - lib/blinkist/config/adapters/adapter.rb
108
+ - lib/blinkist/config/adapters/aws_ssm_adapter.rb
94
109
  - lib/blinkist/config/adapters/diplomat_adapter.rb
95
110
  - lib/blinkist/config/adapters/env_adapter.rb
96
111
  - lib/blinkist/config/error.rb