cloud-config 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +7 -2
- data/examples/001_parameter_store.rb +3 -2
- data/examples/002_parameter_store_with_cache.rb +9 -4
- data/examples/003_parameter_store_with_preload.rb +7 -4
- data/examples/004_handling_configuration_changes.rb +2 -0
- data/examples/005_parameter_store_encrypted_key.rb +40 -0
- data/lib/cloud-config/providers/aws_parameter_store.rb +16 -3
- data/lib/cloud-config/providers/in_memory.rb +2 -2
- data/lib/cloud-config/providers/yaml_file.rb +5 -4
- data/lib/cloud-config/version.rb +1 -1
- data/lib/cloud-config.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f4463471bbbffc8cdfcda8361581f051804c106523c0fa86838f5e62de59a6e
|
4
|
+
data.tar.gz: 8c31a0844247d7e210e219099170f8bda4212fca7e2e61ab323872a8d68f8ed7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75a640f3415c4ae1b66e1d9260f1e02c77b5d4a692ef1de609ef3fbef5afcd6e858120a74ca15ef3a8a77259cce702bf856d60c1bac3d549cad1c32f24f2343e
|
7
|
+
data.tar.gz: 9e033c6fa3481c798ff064666f419478a5ff150e05cce1fe0bd6a44a235601b7a28f54fc7e37fa95bed89ddb38a2fb97b9e4587f1375a2531084cfbd55aad9e3
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [Released]
|
4
|
+
|
5
|
+
## [0.2.1] - 2023-05-21
|
6
|
+
|
7
|
+
Enhancements:
|
8
|
+
|
9
|
+
- Allow options to be passed when fetching configuration from the provider
|
10
|
+
|
11
|
+
|
3
12
|
## [0.2.0] - 2023-05-20
|
4
13
|
|
5
14
|
Bug fixes:
|
@@ -11,7 +20,6 @@ Enhancements:
|
|
11
20
|
- Reset cache for single key
|
12
21
|
- Lookup providers by configuration key
|
13
22
|
|
14
|
-
## [Released]
|
15
23
|
|
16
24
|
## [0.1.0] - 2023-05-17
|
17
25
|
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ A library to modernise the way applications fetch configuration. Typically an ap
|
|
4
4
|
|
5
5
|
A modern approach stores configuration remotely, often using key/value databases. Storing configurations in a single database, separately from the codebase reduces infrastructure dependency. Configuration updates can automatically sync with any application, without requiring redeployments. Security risk is greatly reduced, since configurations can be securely stored. Another goal with this approach is creating an environmentless codebase. The application no longer needs to know which environment it's running in, since all the configuration is handled by the infrastucture.
|
6
6
|
|
7
|
-
Another common problem is password rotation. A typical application will need to be restarted or even redeployed when the configuration settings change
|
7
|
+
Another common problem is password rotation. A typical application will need to be restarted or even redeployed when the configuration settings change. CloudConfig can handle this elegantly, improving application uptime and resilience.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -75,6 +75,11 @@ CloudConfig.configure do
|
|
75
75
|
provider :in_memory do
|
76
76
|
setting :key1, cache: 60 # 60 seconds
|
77
77
|
end
|
78
|
+
|
79
|
+
# If the datastore has configurable options
|
80
|
+
provider :aws_parameter_store do
|
81
|
+
setting :key1, with_decryption: true
|
82
|
+
end
|
78
83
|
end
|
79
84
|
```
|
80
85
|
|
@@ -109,7 +114,7 @@ class CustomProvider
|
|
109
114
|
def initialize(params = {}); end
|
110
115
|
|
111
116
|
# Define `get` for fetching keys from the remote datastore
|
112
|
-
def get(key); end
|
117
|
+
def get(key, opts = {}); end
|
113
118
|
|
114
119
|
# Define `set` for storing keys in the remote datastore
|
115
120
|
def set(key, value); end
|
@@ -14,12 +14,13 @@ end
|
|
14
14
|
require 'benchmark'
|
15
15
|
require 'cloud-config/providers/aws_parameter_store'
|
16
16
|
|
17
|
+
# @note: Make sure the `parameter_store_example` key is set in the parameter store
|
17
18
|
CloudConfig.configure do
|
18
19
|
provider :aws_parameter_store do
|
19
20
|
setting :parameter_store_example
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
puts 'Fetching key parameter_store_example'
|
24
|
+
puts 'Fetching key: parameter_store_example'
|
24
25
|
value = CloudConfig.get(:parameter_store_example)
|
25
|
-
puts "Fetched value #{value}"
|
26
|
+
puts "Fetched value: #{value}"
|
@@ -15,6 +15,7 @@ require 'benchmark'
|
|
15
15
|
require 'cloud-config/cache/in_memory'
|
16
16
|
require 'cloud-config/providers/aws_parameter_store'
|
17
17
|
|
18
|
+
# @note: Make sure the `parameter_store_example` key is set in the parameter store
|
18
19
|
CloudConfig.configure do
|
19
20
|
cache_client CloudConfig::Cache::InMemory.new
|
20
21
|
|
@@ -25,16 +26,20 @@ end
|
|
25
26
|
|
26
27
|
value = nil
|
27
28
|
|
28
|
-
puts 'Fetching key parameter_store_example'
|
29
|
+
puts 'Fetching key; parameter_store_example'
|
29
30
|
time = Benchmark.measure { value = CloudConfig.get(:parameter_store_example) }
|
30
|
-
puts "Fetched value #{value} in #{time.real.round(5)} seconds"
|
31
|
+
puts "Fetched value: #{value} in #{time.real.round(5)} seconds"
|
32
|
+
|
33
|
+
puts
|
31
34
|
|
32
|
-
puts 'Fetching key parameter_store_example (cached)'
|
35
|
+
puts 'Fetching key: parameter_store_example (cached)'
|
33
36
|
time = Benchmark.measure { value = CloudConfig.get(:parameter_store_example) }
|
34
|
-
puts "Fetched value #{value} in #{time.real.round(5)} seconds"
|
37
|
+
puts "Fetched value: #{value} in #{time.real.round(5)} seconds"
|
35
38
|
|
36
39
|
sleep 5
|
37
40
|
|
41
|
+
puts
|
42
|
+
|
38
43
|
puts 'Fetching key parameter_store_example'
|
39
44
|
time = Benchmark.measure { value = CloudConfig.get(:parameter_store_example) }
|
40
45
|
puts "Fetched value #{value} in #{time.real.round(5)} seconds"
|
@@ -15,6 +15,7 @@ require 'benchmark'
|
|
15
15
|
require 'cloud-config/cache/in_memory'
|
16
16
|
require 'cloud-config/providers/aws_parameter_store'
|
17
17
|
|
18
|
+
# @note: Make sure the `parameter_store_example` key is set in the parameter store
|
18
19
|
CloudConfig.configure do
|
19
20
|
cache_client CloudConfig::Cache::InMemory.new
|
20
21
|
|
@@ -27,12 +28,14 @@ CloudConfig.preload
|
|
27
28
|
|
28
29
|
value = nil
|
29
30
|
|
30
|
-
puts 'Fetching key parameter_store_example (cached)'
|
31
|
+
puts 'Fetching key: parameter_store_example (cached)'
|
31
32
|
time = Benchmark.measure { value = CloudConfig.get(:parameter_store_example) }
|
32
|
-
puts "Fetched value #{value} in #{time.real.round(5)} seconds"
|
33
|
+
puts "Fetched value: #{value} in #{time.real.round(5)} seconds"
|
33
34
|
|
34
35
|
sleep 5
|
35
36
|
|
36
|
-
puts
|
37
|
+
puts
|
38
|
+
|
39
|
+
puts 'Fetching key: parameter_store_example'
|
37
40
|
time = Benchmark.measure { value = CloudConfig.get(:parameter_store_example) }
|
38
|
-
puts "Fetched value #{value} in #{time.real.round(5)} seconds"
|
41
|
+
puts "Fetched value: #{value} in #{time.real.round(5)} seconds"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/inline'
|
4
|
+
|
5
|
+
gemfile do
|
6
|
+
source 'https://rubygems.org'
|
7
|
+
|
8
|
+
gem 'nokogiri'
|
9
|
+
gem 'aws-sdk-ssm'
|
10
|
+
|
11
|
+
gem 'cloud-config', path: '..'
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'benchmark'
|
15
|
+
require 'cloud-config/providers/aws_parameter_store'
|
16
|
+
|
17
|
+
# @note: Make sure the `encrypted_key` key is set in the parameter store
|
18
|
+
CloudConfig.configure do
|
19
|
+
provider :aws_parameter_store do
|
20
|
+
setting :encrypted_key
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
puts 'Fetching key: encrypted_key'
|
25
|
+
value = CloudConfig.get(:encrypted_key)
|
26
|
+
puts "Fetched value: #{value}"
|
27
|
+
|
28
|
+
puts
|
29
|
+
|
30
|
+
CloudConfig.reset!
|
31
|
+
|
32
|
+
CloudConfig.configure do
|
33
|
+
provider :aws_parameter_store do
|
34
|
+
setting :encrypted_key, with_decryption: true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
puts 'Fetching key: encrypted_key (decrypt)'
|
39
|
+
value = CloudConfig.get(:encrypted_key)
|
40
|
+
puts "Fetched value: #{value}"
|
@@ -13,18 +13,31 @@ module CloudConfig
|
|
13
13
|
# @return [Aws::SSM::Client]
|
14
14
|
attr_reader :client
|
15
15
|
|
16
|
+
# @!attribute [r] Whether parameters need to be decrypted
|
17
|
+
# @return [Boolean]
|
18
|
+
attr_reader :with_decryption
|
19
|
+
|
16
20
|
# Create a new instance of {AwsParameterStore}.
|
17
|
-
|
21
|
+
#
|
22
|
+
# @param [Hash] opts Parameter store options
|
23
|
+
# @option opts [Boolean] :with_decryption Whether all keys need to be decrypted
|
24
|
+
def initialize(opts = {})
|
18
25
|
@client = Aws::SSM::Client.new
|
26
|
+
|
27
|
+
@with_decryption = opts.fetch(:with_decryption, false)
|
19
28
|
end
|
20
29
|
|
21
30
|
# Fetch the value of the key
|
22
31
|
#
|
23
32
|
# @param key [String,Symbol] Key to fetch
|
33
|
+
# @param [Hash] opts for fetching the key
|
34
|
+
# @option opts [Boolean] :with_decryption Whether the key needs decrypting
|
24
35
|
#
|
25
36
|
# @return [String] Value of the key
|
26
|
-
def get(key)
|
27
|
-
|
37
|
+
def get(key, opts = {})
|
38
|
+
decrypt = opts.fetch(:with_decryption) { with_decryption }
|
39
|
+
|
40
|
+
client.get_parameter(name: key, with_decryption: decrypt).parameter.value
|
28
41
|
end
|
29
42
|
|
30
43
|
# Set the value of the key
|
@@ -14,7 +14,7 @@ module CloudConfig
|
|
14
14
|
attr_reader :settings
|
15
15
|
|
16
16
|
# Create an instance of {InMemory}
|
17
|
-
def initialize(
|
17
|
+
def initialize(_opts = {})
|
18
18
|
@settings = {}
|
19
19
|
end
|
20
20
|
|
@@ -23,7 +23,7 @@ module CloudConfig
|
|
23
23
|
# @param key [String,Symbol] Key to fetch
|
24
24
|
#
|
25
25
|
# @return [Object] Value of the key
|
26
|
-
def get(key)
|
26
|
+
def get(key, _opts = {})
|
27
27
|
settings[key]
|
28
28
|
end
|
29
29
|
|
@@ -15,9 +15,10 @@ module CloudConfig
|
|
15
15
|
|
16
16
|
# Create an instance of {YamlFile}
|
17
17
|
#
|
18
|
-
# @
|
19
|
-
|
20
|
-
|
18
|
+
# @param [Hash] opts Yaml file options
|
19
|
+
# @option opts [String] :filename Name of the YAML file
|
20
|
+
def initialize(opts = {})
|
21
|
+
@contents = YAML.load_file(opts[:filename]) || {}
|
21
22
|
end
|
22
23
|
|
23
24
|
# Fetch the value of the key
|
@@ -25,7 +26,7 @@ module CloudConfig
|
|
25
26
|
# @param key [String,Symbol] Key to fetch
|
26
27
|
#
|
27
28
|
# @return [Object] Value of the key
|
28
|
-
def get(key)
|
29
|
+
def get(key, _opts = {})
|
29
30
|
contents[key]
|
30
31
|
end
|
31
32
|
|
data/lib/cloud-config/version.rb
CHANGED
data/lib/cloud-config.rb
CHANGED
@@ -90,7 +90,7 @@ module CloudConfig
|
|
90
90
|
# @return [Object] Value of the key
|
91
91
|
def load_key(provider_config, key, reset_cache: false)
|
92
92
|
with_cache(key, reset_cache:, expire_in: provider_config.settings[key][:cache]) do
|
93
|
-
provider_config.provider.get(key)
|
93
|
+
provider_config.provider.get(key, provider_config.settings[key])
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hypernova2002
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parallel
|
@@ -231,6 +231,7 @@ files:
|
|
231
231
|
- examples/002_parameter_store_with_cache.rb
|
232
232
|
- examples/003_parameter_store_with_preload.rb
|
233
233
|
- examples/004_handling_configuration_changes.rb
|
234
|
+
- examples/005_parameter_store_encrypted_key.rb
|
234
235
|
- lib/cloud-config.rb
|
235
236
|
- lib/cloud-config/cache.rb
|
236
237
|
- lib/cloud-config/cache/in_memory.rb
|