process_settings 0.4.3 → 0.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84e9028401afcbed9bc2145c2a4bbc416ae4cebda00153c78f6296c5b0117356
|
4
|
+
data.tar.gz: 7dae4effa815df4e73c9403582e1d6b48ca931b5739c549f0ae93695d4a9e954
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa3fbb3c37f252497b2f43e91e50367096b7ea6d99ad7ef715f802cc606d9ecd75c195fc4695e16bb5e65b84058de8422e4ea6eaf309b569049299ddcd7ef8db
|
7
|
+
data.tar.gz: 577aa22b7573c09c012675b22df3fc304eb36726f76fa9c63af0c46b2d70e9f1c57617e9f2ff0f47f529b803e44ce5c9a2bef16babd9d22f457875494675bf09
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@ This gem provides dynamic settings for Ruby processes. The settings are stored i
|
|
3
3
|
Settings are managed in a git repo, in separate YAML files for each concern (for example, each micro-service). Each YAML file can be targeted based on matching context values (for example, `service_name`).
|
4
4
|
|
5
5
|
|
6
|
-
The context can be either static to the process (for example, `service_name` or `
|
6
|
+
The context can be either static to the process (for example, `service_name` or `data_center`) or dynamic (for example, the current web request `domain`).
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
To install this gem directly on your machine from rubygems, run the following:
|
@@ -37,7 +37,7 @@ The monitor should be initialized with static (unchanging) context for your proc
|
|
37
37
|
```
|
38
38
|
ProcessSettings::Monitor.static_context = {
|
39
39
|
"service_name" => "frontend",
|
40
|
-
"
|
40
|
+
"data_center" => "AWS-US-EAST-1"
|
41
41
|
}
|
42
42
|
```
|
43
43
|
The `static_context` is important because it is used to pre-filter settings for the process.
|
@@ -143,18 +143,18 @@ To `target` on context values, provide a hash of key-value pairs. All keys must
|
|
143
143
|
```
|
144
144
|
target:
|
145
145
|
service_name: frontend
|
146
|
-
|
146
|
+
data_center: AWS-US-EAST-1
|
147
147
|
```
|
148
|
-
This will be applied in any process that has `service_name == "frontend"` AND is running in `
|
148
|
+
This will be applied in any process that has `service_name == "frontend"` AND is running in `data_center == "AWS-US-EAST-1"`.
|
149
149
|
|
150
150
|
### Multiple Values Are OR'd
|
151
151
|
Values may be set to an array, in which case the key matches if _any_ of the values matches. For example, consider this target hash:
|
152
152
|
```
|
153
153
|
target:
|
154
154
|
service_name: [frontend, auth]
|
155
|
-
|
155
|
+
data_center: AWS-US-EAST-1
|
156
156
|
```
|
157
|
-
This will be applied in any process that has (`service_name == "frontend"` OR `service_name == "auth"`) AND `
|
157
|
+
This will be applied in any process that has (`service_name == "frontend"` OR `service_name == "auth"`) AND `data_center == "AWS-US-EAST-1"`.
|
158
158
|
|
159
159
|
### Precedence
|
160
160
|
The settings YAML files are always combined in alphabetical order by file path. Later settings take precedence over the earlier ones.
|
@@ -62,14 +62,14 @@ flat_services_yml_json_doc.each do |service, nodes|
|
|
62
62
|
if (changed = node_targeted_process_settings_old != node_targeted_process_settings_new)
|
63
63
|
node_old = node_targeted_process_settings_old.map do |node_targeted_process_setting|
|
64
64
|
{
|
65
|
-
'target'
|
66
|
-
"
|
65
|
+
'target' => node_targeted_process_setting.target,
|
66
|
+
"process_settings" => node_targeted_process_setting.process_settings
|
67
67
|
}
|
68
68
|
end
|
69
69
|
node_new = node_targeted_process_settings_new.map do |node_targeted_process_setting|
|
70
70
|
{
|
71
|
-
'target'
|
72
|
-
"
|
71
|
+
'target' => node_targeted_process_setting.target,
|
72
|
+
"process_settings" => node_targeted_process_setting.process_settings
|
73
73
|
}
|
74
74
|
end
|
75
75
|
|
@@ -81,7 +81,7 @@ module ProcessSettings
|
|
81
81
|
result = statically_targeted_settings.reduce(:not_found) do |latest_result, target_and_settings|
|
82
82
|
# find last value from matching targets
|
83
83
|
if target_and_settings.target.target_key_matches?(full_context)
|
84
|
-
if (value = target_and_settings.
|
84
|
+
if (value = target_and_settings.process_settings.json_doc.mine(*path, not_found_value: :not_found)) != :not_found
|
85
85
|
latest_result = value
|
86
86
|
end
|
87
87
|
end
|
@@ -6,7 +6,7 @@ require_relative 'settings'
|
|
6
6
|
module ProcessSettings
|
7
7
|
# This class encapsulates a single YAML file with target and process_settings.
|
8
8
|
class TargetAndSettings
|
9
|
-
attr_reader :filename, :target, :
|
9
|
+
attr_reader :filename, :target, :process_settings
|
10
10
|
|
11
11
|
def initialize(filename, target, settings)
|
12
12
|
@filename = filename
|
@@ -15,7 +15,7 @@ module ProcessSettings
|
|
15
15
|
@target = target
|
16
16
|
|
17
17
|
settings.is_a?(Settings) or raise ArgumentError, "settings must be a ProcessSettings; got #{settings.inspect}"
|
18
|
-
@
|
18
|
+
@process_settings = settings
|
19
19
|
end
|
20
20
|
|
21
21
|
def ==(rhs)
|
@@ -29,7 +29,7 @@ module ProcessSettings
|
|
29
29
|
def to_json_doc
|
30
30
|
{
|
31
31
|
"target" => @target.json_doc,
|
32
|
-
"settings" => @
|
32
|
+
"settings" => @process_settings.json_doc
|
33
33
|
}
|
34
34
|
end
|
35
35
|
|
@@ -37,9 +37,9 @@ module ProcessSettings
|
|
37
37
|
def from_json_docs(filename, target_json_doc, settings_json_doc)
|
38
38
|
target_json_doc = Target.new(target_json_doc)
|
39
39
|
|
40
|
-
|
40
|
+
process_settings = Settings.new(settings_json_doc)
|
41
41
|
|
42
|
-
new(filename, target_json_doc,
|
42
|
+
new(filename, target_json_doc, process_settings)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -49,7 +49,7 @@ module ProcessSettings
|
|
49
49
|
if new_target == @target
|
50
50
|
self
|
51
51
|
else
|
52
|
-
self.class.new(@filename, new_target, @
|
52
|
+
self.class.new(@filename, new_target, @process_settings)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../monitor'
|
4
|
+
require_relative '../hash_with_hash_path'
|
5
|
+
|
6
|
+
module ProcessSettings
|
7
|
+
module Testing
|
8
|
+
# This class implements the Monitor#targeted_value interface but is stubbed to use a simple hash in tests
|
9
|
+
class MonitorStub
|
10
|
+
def initialize(settings_hash)
|
11
|
+
@settings_hash = HashWithHashPath[settings_hash]
|
12
|
+
end
|
13
|
+
|
14
|
+
def targeted_value(*path, dynamic_context:, required: true)
|
15
|
+
result = @settings_hash.mine(*path, not_found_value: :not_found)
|
16
|
+
|
17
|
+
if result == :not_found
|
18
|
+
if required
|
19
|
+
raise SettingsPathNotFound, "no settings found for path #{path.inspect}"
|
20
|
+
else
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
else
|
24
|
+
result
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: process_settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Invoca
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- lib/process_settings/target.rb
|
79
79
|
- lib/process_settings/target_and_settings.rb
|
80
80
|
- lib/process_settings/targeted_settings.rb
|
81
|
+
- lib/process_settings/testing/monitor_stub.rb
|
81
82
|
- lib/process_settings/util.rb
|
82
83
|
- lib/process_settings/version.rb
|
83
84
|
homepage: https://rubygems.org/gems/process_settings
|