service_skeleton 0.0.0.25.gbf57918 → 0.0.0.28.gae2711b

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: 89afe58f5f8ce484ee0250284bae409b7d3a4f8f279747d1ee17e575befaa7df
4
- data.tar.gz: 2c6cc5ff9cf019be8e8c8258e5713c86090aa62dd2dddda7d10c22fece7a992d
3
+ metadata.gz: 260e10d209930607a4d11e9578f2e3d90b4489017e194b96206d9ccaf0402497
4
+ data.tar.gz: 4a02d856abb457d581917db95a913aeb8d645d582836000516153f7c367fd40d
5
5
  SHA512:
6
- metadata.gz: 7ab638d056ee90b752eb55fe4494fc2c395295413c651ad4e5f7b1b322e611ac02b02caf1c2b782c0518afb120708409ea92ec00f8d8258ef6116b12277e6885
7
- data.tar.gz: 73be99a6c35c5885e1e6edbac125ed0998f657421fa0b0a2dff019e468e47d14ae95d55ad6396cf81ddeb46867dea8e0f3b233bda13355d72c88333de90adb9d
6
+ metadata.gz: a4e08f970330214fc17c46c75c552ba6382fe6a6824d719032f5c5484ade8a8239a3769cf62869a81cc5faa0b9950601cad2db9895761815e3e7eaf31e78fcf7
7
+ data.tar.gz: e543e44d9b841fb86cf259610e0ef4265daff759efc9e44d7b482b9f150c307a5ccd1cf57c5d58f883ee98b73aaa0562267d88e5aa0cd96b6e763e37c393c4dd
@@ -24,17 +24,25 @@ class ServiceSkeleton
24
24
 
25
25
  def parse_registered_variables(env)
26
26
  @svc.registered_variables.each do |var|
27
- val = var.value(env[var.name.to_s])
27
+ val = var.value(env)
28
+
28
29
  define_singleton_method(var.method_name(@svc.service_name)) do
29
30
  val
30
31
  end
31
32
 
33
+ define_singleton_method(var.method_name(@svc.service_name) + "=") do |v|
34
+ val = v
35
+ end
36
+
32
37
  if var.sensitive?
33
38
  if env.object_id != ENV.object_id
34
39
  raise ServiceSkeleton::Error::CannotSanitizeEnvironmentError,
35
40
  "Attempted to sanitize sensitive variable #{var.name}, but was not passed the ENV object"
36
41
  end
37
- env[var.name.to_s] = "*SENSITIVE*"
42
+
43
+ var.env_keys(env).each do |k|
44
+ env[k] = "*SENSITIVE*"
45
+ end
38
46
  end
39
47
  end
40
48
  end
@@ -1,6 +1,6 @@
1
1
  class ServiceSkeleton
2
2
  class ConfigVariable
3
- attr_reader :name
3
+ attr_reader :name, :key_pattern
4
4
 
5
5
  def initialize(name, **opts, &blk)
6
6
  @name = name
@@ -16,8 +16,21 @@ class ServiceSkeleton
16
16
  !!@opts[:sensitive]
17
17
  end
18
18
 
19
- def value(raw_val)
20
- @blk.call(raw_val)
19
+ def value(env)
20
+ if @opts[:key_pattern]
21
+ matches = env.select { |k, _| @opts[:key_pattern] === k.to_s }
22
+ @blk.call(matches)
23
+ else
24
+ @blk.call(env[@name.to_s])
25
+ end
26
+ end
27
+
28
+ def env_keys(env)
29
+ if @opts[:key_pattern]
30
+ env.keys.select { |k| @opts[:key_pattern] === k.to_s }
31
+ else
32
+ env.keys.include?(@name.to_s) ? [@name.to_s] : []
33
+ end
21
34
  end
22
35
  end
23
36
  end
@@ -77,14 +77,27 @@ class ServiceSkeleton
77
77
 
78
78
  def path_list(var_name, default: UNDEFINED, sensitive: false)
79
79
  register_variable(var_name, sensitive: sensitive) do |value|
80
- value.split(":")
80
+ maybe_default(value, default, var_name) do
81
+ value.split(":")
82
+ end
83
+ end
84
+ end
85
+
86
+ def kv_list(var_name, default: UNDEFINED, sensitive: false, key_pattern: nil)
87
+ key_pattern ||= /\A#{var_name}_(.*)\z/
88
+ register_variable(var_name, sensitive: sensitive, key_pattern: key_pattern) do |matches|
89
+ maybe_default(matches, default, var_name) do
90
+ matches.transform_keys do |k|
91
+ key_pattern.match(k)[1].to_sym
92
+ end
93
+ end
81
94
  end
82
95
  end
83
96
 
84
97
  private
85
98
 
86
99
  def maybe_default(value, default, var_name)
87
- if value.nil?
100
+ if value.nil? || value == {}
88
101
  if default == UNDEFINED
89
102
  raise ServiceSkeleton::Error::InvalidEnvironmentError,
90
103
  "Value for required environment variable #{var_name} not specified"
@@ -129,7 +129,6 @@ class ServiceSkeleton
129
129
 
130
130
  @metrics.singleton_class.prepend(ServiceSkeleton::MetricsMethods)
131
131
  @metrics.service = self
132
-
133
132
  end
134
133
 
135
134
  def start_metrics_server
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
 
29
29
  s.files = `git ls-files -z`.split("\0").reject { |f| f =~ /^(G|spec|Rakefile)/ }
30
30
 
31
- s.required_ruby_version = ">= 2.3.0"
31
+ s.required_ruby_version = ">= 2.5.0"
32
32
 
33
33
  s.add_runtime_dependency "frankenstein", "~> 1.2"
34
34
  s.add_runtime_dependency "loggerstash", "~> 0.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: service_skeleton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.25.gbf57918
4
+ version: 0.0.0.28.gae2711b
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Palmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-05 00:00:00.000000000 Z
11
+ date: 2019-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: frankenstein
@@ -292,7 +292,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
292
292
  requirements:
293
293
  - - ">="
294
294
  - !ruby/object:Gem::Version
295
- version: 2.3.0
295
+ version: 2.5.0
296
296
  required_rubygems_version: !ruby/object:Gem::Requirement
297
297
  requirements:
298
298
  - - ">"