service_skeleton 0.0.0.34.g4f6fdb0 → 0.0.0.41.g9507cda
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/service_skeleton.rb +10 -8
- data/lib/service_skeleton/background_worker.rb +2 -0
- data/lib/service_skeleton/config.rb +21 -16
- data/lib/service_skeleton/config_variable.rb +21 -17
- data/lib/service_skeleton/config_variable/boolean.rb +21 -0
- data/lib/service_skeleton/config_variable/enum.rb +27 -0
- data/lib/service_skeleton/config_variable/float.rb +25 -0
- data/lib/service_skeleton/config_variable/integer.rb +25 -0
- data/lib/service_skeleton/config_variable/kv_list.rb +26 -0
- data/lib/service_skeleton/config_variable/path_list.rb +13 -0
- data/lib/service_skeleton/config_variable/string.rb +13 -0
- data/lib/service_skeleton/config_variable/url.rb +32 -0
- data/lib/service_skeleton/config_variables.rb +39 -77
- data/lib/service_skeleton/error.rb +2 -0
- data/lib/service_skeleton/filtering_logger.rb +2 -0
- data/lib/service_skeleton/logging_helpers.rb +2 -0
- data/lib/service_skeleton/metrics_methods.rb +2 -0
- data/lib/service_skeleton/signal_handler.rb +2 -0
- data/service_skeleton.gemspec +2 -0
- metadata +12 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4ef4c44c6af279c8870e58b4bf078424a30c87b6d979d2513fe093c15926287
|
4
|
+
data.tar.gz: 5a9d7d4fc51bae03eac369f6f902dabcfea925d3fd175b69e7888d4368fe87f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 353f92e555ba95c3e5776a0acb10119500671182a0efc082ff0d9e91a247f14209ff23dbc0f64cec73df445daba2435acac7104f18bef0e6cccd01a48e6b4954
|
7
|
+
data.tar.gz: c0c3341e8ab56f4cfed5809a94b6a9b8295e30b59a04977e1b45a24c1d64b3a5ad8f14927e0453145a4bcf93d94579b08d1e432bee49d0e8ac5352f88da6f3f9
|
data/lib/service_skeleton.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "service_skeleton/config"
|
2
4
|
require_relative "service_skeleton/config_variables"
|
3
5
|
require_relative "service_skeleton/logging_helpers"
|
@@ -184,22 +186,22 @@ class ServiceSkeleton
|
|
184
186
|
end
|
185
187
|
|
186
188
|
@registered_variables = [
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
189
|
+
{ name: :SERVICE_SKELETON_LOG_LEVEL, class: ConfigVariable::String, opts: { default: "INFO" } },
|
190
|
+
{ name: :SERVICE_SKELETON_LOG_ENABLE_TIMESTAMPS, class: ConfigVariable::Boolean, opts: { default: false } },
|
191
|
+
{ name: :SERVICE_SKELETON_LOG_FILE, class: ConfigVariable::String, opts: { default: nil } },
|
192
|
+
{ name: :SERVICE_SKELETON_LOG_MAX_FILE_SIZE, class: ConfigVariable::Integer, opts: { default: 1048576, range: 0..Float::INFINITY } },
|
193
|
+
{ name: :SERVICE_SKELETON_LOG_MAX_FILES, class: ConfigVariable::Integer, opts: { default: 3, range: 0..Float::INFINITY } },
|
194
|
+
{ name: :SERVICE_SKELETON_LOGSTASH_SERVER, class: ConfigVariable::String, opts: { default: nil } },
|
195
|
+
{ name: :SERVICE_SKELETON_METRICS_PORT, class: ConfigVariable::Integer, opts: { default: nil, range: 1..65535 } },
|
194
196
|
]
|
195
197
|
|
196
198
|
def self.inherited(subclass)
|
197
199
|
subclass.string(:"#{subclass.service_name.upcase}_LOG_LEVEL", default: "INFO")
|
198
|
-
subclass.string(:"#{subclass.service_name.upcase}_LOGSTASH_SERVER", default: "")
|
199
200
|
subclass.boolean(:"#{subclass.service_name.upcase}_LOG_ENABLE_TIMESTAMPS", default: false)
|
200
201
|
subclass.string(:"#{subclass.service_name.upcase}_LOG_FILE", default: nil)
|
201
202
|
subclass.integer(:"#{subclass.service_name.upcase}_LOG_MAX_FILE_SIZE", default: 1048576, range: 0..Float::INFINITY)
|
202
203
|
subclass.integer(:"#{subclass.service_name.upcase}_LOG_MAX_FILES", default: 3, range: 1..Float::INFINITY)
|
204
|
+
subclass.string(:"#{subclass.service_name.upcase}_LOGSTASH_SERVER", default: "")
|
203
205
|
subclass.integer(:"#{subclass.service_name.upcase}_METRICS_PORT", default: nil, range: 1..65535)
|
204
206
|
end
|
205
207
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "to_regexp"
|
2
4
|
|
3
5
|
require_relative "./filtering_logger"
|
@@ -11,8 +13,14 @@ class ServiceSkeleton
|
|
11
13
|
def initialize(env, svc)
|
12
14
|
@svc = svc
|
13
15
|
|
14
|
-
|
16
|
+
# Parsing registered variables will redact the environment, so we want
|
17
|
+
# to take a private unredacted copy before that happens
|
15
18
|
@env = env.to_hash.dup.freeze
|
19
|
+
|
20
|
+
parse_registered_variables(env)
|
21
|
+
|
22
|
+
# Sadly, we can't setup the logger until we know *how* to setup the
|
23
|
+
# logger, which requires parsing config variables
|
16
24
|
setup_logger
|
17
25
|
end
|
18
26
|
|
@@ -23,26 +31,23 @@ class ServiceSkeleton
|
|
23
31
|
private
|
24
32
|
|
25
33
|
def parse_registered_variables(env)
|
26
|
-
@svc.registered_variables.
|
27
|
-
|
34
|
+
(@svc.registered_variables || []).map do |var|
|
35
|
+
var[:class].new(var[:name], env, **var[:opts])
|
36
|
+
end.each do |var|
|
37
|
+
val = var.value
|
38
|
+
method_name = var.method_name(@svc.service_name).to_sym
|
28
39
|
|
29
|
-
define_singleton_method(
|
40
|
+
define_singleton_method(method_name) do
|
30
41
|
val
|
31
42
|
end
|
32
43
|
|
33
|
-
define_singleton_method(
|
34
|
-
val =
|
44
|
+
define_singleton_method(:"#{method_name}=") do |new_value|
|
45
|
+
val = new_value
|
35
46
|
end
|
36
|
-
|
37
|
-
if var.
|
38
|
-
|
39
|
-
|
40
|
-
"Attempted to sanitize sensitive variable #{var.name}, but was not passed the ENV object"
|
41
|
-
end
|
42
|
-
|
43
|
-
var.env_keys(env).each do |k|
|
44
|
-
env[k] = "*SENSITIVE*"
|
45
|
-
end
|
47
|
+
end.each do |var|
|
48
|
+
if var.redact!(env) && env.object_id != ENV.object_id
|
49
|
+
raise ServiceSkeleton::Error::CannotSanitizeEnvironmentError,
|
50
|
+
"Attempted to sanitize sensitive variable #{var.name}, but we're not operating on the process' environment"
|
46
51
|
end
|
47
52
|
end
|
48
53
|
end
|
@@ -1,35 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ServiceSkeleton
|
2
4
|
class ConfigVariable
|
3
|
-
attr_reader :name, :
|
5
|
+
attr_reader :name, :value
|
4
6
|
|
5
|
-
def initialize(name, **opts, &blk)
|
7
|
+
def initialize(name, env, **opts, &blk)
|
6
8
|
@name = name
|
7
9
|
@opts = opts
|
8
10
|
@blk = blk
|
9
|
-
end
|
10
11
|
|
11
|
-
|
12
|
-
name.to_s.gsub(/\A#{Regexp.quote(svc_name)}_/i, '').downcase
|
12
|
+
@value = pluck_value(env)
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
15
|
+
def method_name(svc_name)
|
16
|
+
@name.to_s.gsub(/\A#{Regexp.quote(svc_name)}_/i, '').downcase
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
if @opts[:
|
21
|
-
|
22
|
-
@blk.call(matches)
|
23
|
-
else
|
24
|
-
@blk.call(env[@name.to_s])
|
19
|
+
def redact!(env)
|
20
|
+
if @opts[:sensitive]
|
21
|
+
env[@name.to_s] = "*SENSITIVE*" if env.has_key?(@name.to_s)
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
private
|
26
|
+
|
27
|
+
def maybe_default(env)
|
28
|
+
if env.has_key?(@name.to_s)
|
29
|
+
yield
|
31
30
|
else
|
32
|
-
|
31
|
+
if @opts.has_key?(:default)
|
32
|
+
@opts[:default]
|
33
|
+
else
|
34
|
+
raise ServiceSkeleton::Error::InvalidEnvironmentError,
|
35
|
+
"Value for required environment variable #{@name} not specified"
|
36
|
+
end
|
33
37
|
end
|
34
38
|
end
|
35
39
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "service_skeleton/config_variable"
|
4
|
+
|
5
|
+
class ServiceSkeleton::ConfigVariable::Boolean < ServiceSkeleton::ConfigVariable
|
6
|
+
private
|
7
|
+
|
8
|
+
def pluck_value(env)
|
9
|
+
maybe_default(env) do
|
10
|
+
case env[@name.to_s]
|
11
|
+
when /\A(no|n|off|0|false)\z/i
|
12
|
+
false
|
13
|
+
when /\A(yes|y|on|1|true)\z/i
|
14
|
+
true
|
15
|
+
else
|
16
|
+
raise ServiceSkeleton::Error::InvalidEnvironmentError,
|
17
|
+
"Value #{env[@name.to_s].inspect} for environment variable #{@name} is not a valid boolean value"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "service_skeleton/config_variable"
|
4
|
+
|
5
|
+
class ServiceSkeleton::ConfigVariable::Enum < ServiceSkeleton::ConfigVariable
|
6
|
+
private
|
7
|
+
|
8
|
+
def pluck_value(env)
|
9
|
+
maybe_default(env) do
|
10
|
+
v = env[@name.to_s]
|
11
|
+
|
12
|
+
if @opts[:values].is_a?(Array)
|
13
|
+
unless @opts[:values].include?(v)
|
14
|
+
raise ServiceSkeleton::Error::InvalidEnvironmentError,
|
15
|
+
"Invalid value for #{@name}; must be one of #{@opts[:values].join(", ")}"
|
16
|
+
end
|
17
|
+
v
|
18
|
+
elsif @opts[:values].is_a?(Hash)
|
19
|
+
unless @opts[:values].keys.include?(v)
|
20
|
+
raise ServiceSkeleton::Error::InvalidEnvironmentError,
|
21
|
+
"Invalid value for #{@name}; must be one of #{@opts[:values].keys.join(", ")}"
|
22
|
+
end
|
23
|
+
@opts[:values][v]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "service_skeleton/config_variable"
|
4
|
+
|
5
|
+
class ServiceSkeleton::ConfigVariable::Float < ServiceSkeleton::ConfigVariable
|
6
|
+
private
|
7
|
+
|
8
|
+
def pluck_value(env)
|
9
|
+
maybe_default(env) do
|
10
|
+
value = env[@name.to_s]
|
11
|
+
|
12
|
+
if value =~ /\A-?\d+.?\d*\z/
|
13
|
+
value.to_f.tap do |f|
|
14
|
+
unless @opts[:range].include?(f)
|
15
|
+
raise ServiceSkeleton::Error::InvalidEnvironmentError,
|
16
|
+
"Value #{f} for environment variable #{@name} is out of the valid range (must be between #{@opts[:range].first} and #{@opts[:range].last} inclusive)"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
else
|
20
|
+
raise ServiceSkeleton::Error::InvalidEnvironmentError,
|
21
|
+
"Value #{value.inspect} for environment variable #{@name} is not a valid numeric value"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "service_skeleton/config_variable"
|
4
|
+
|
5
|
+
class ServiceSkeleton::ConfigVariable::Integer < ServiceSkeleton::ConfigVariable
|
6
|
+
private
|
7
|
+
|
8
|
+
def pluck_value(env)
|
9
|
+
maybe_default(env) do
|
10
|
+
value = env[@name.to_s]
|
11
|
+
|
12
|
+
if value =~ /\A-?\d+\z/
|
13
|
+
value.to_i.tap do |i|
|
14
|
+
unless @opts[:range].include?(i)
|
15
|
+
raise ServiceSkeleton::Error::InvalidEnvironmentError,
|
16
|
+
"Value #{i} for environment variable #{@name} is out of the valid range (must be between #{@opts[:range].first} and #{@opts[:range].last} inclusive)"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
else
|
20
|
+
raise ServiceSkeleton::Error::InvalidEnvironmentError,
|
21
|
+
"Value #{value.inspect} for environment variable #{@name} is not a valid integer value"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "service_skeleton/config_variable"
|
4
|
+
|
5
|
+
class ServiceSkeleton::ConfigVariable::KVList < ServiceSkeleton::ConfigVariable
|
6
|
+
def redact!(env)
|
7
|
+
env.keys.each { |k| env[k] = "*SENSITIVE*" if k =~ @opts[:key_pattern] }
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def pluck_value(env)
|
13
|
+
matches = env.select { |k, _| k.to_s =~ @opts[:key_pattern] }
|
14
|
+
|
15
|
+
if matches.empty?
|
16
|
+
if @opts.has_key?(:default)
|
17
|
+
@opts[:default]
|
18
|
+
else
|
19
|
+
raise ServiceSkeleton::Error::InvalidEnvironmentError,
|
20
|
+
"no keys for key-value list #{@name} specified"
|
21
|
+
end
|
22
|
+
else
|
23
|
+
matches.transform_keys { |k| @opts[:key_pattern].match(k.to_s)[1].to_sym }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "service_skeleton/config_variable"
|
4
|
+
|
5
|
+
class ServiceSkeleton::ConfigVariable::PathList < ServiceSkeleton::ConfigVariable
|
6
|
+
private
|
7
|
+
|
8
|
+
def pluck_value(env)
|
9
|
+
maybe_default(env) do
|
10
|
+
env[@name.to_s].split(":")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "service_skeleton/config_variable"
|
4
|
+
|
5
|
+
class ServiceSkeleton::ConfigVariable::String < ServiceSkeleton::ConfigVariable
|
6
|
+
private
|
7
|
+
|
8
|
+
def pluck_value(env)
|
9
|
+
maybe_default(env) do
|
10
|
+
env[@name.to_s]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "service_skeleton/config_variable"
|
4
|
+
|
5
|
+
class ServiceSkeleton::ConfigVariable::URL < ServiceSkeleton::ConfigVariable
|
6
|
+
def redact!(env)
|
7
|
+
if env.has_key?(@name.to_s)
|
8
|
+
super
|
9
|
+
uri = URI(env[@name.to_s])
|
10
|
+
if uri.password
|
11
|
+
uri.password = "*REDACTED*"
|
12
|
+
env[@name.to_s] = uri.to_s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def pluck_value(env)
|
20
|
+
maybe_default(env) do
|
21
|
+
begin
|
22
|
+
v = env[@name.to_s]
|
23
|
+
URI(v)
|
24
|
+
rescue URI::InvalidURIError
|
25
|
+
raise ServiceSkeleton::Error::InvalidEnvironmentError,
|
26
|
+
"Value for #{@name} (#{v}) does not appear to be a valid URL"
|
27
|
+
end
|
28
|
+
|
29
|
+
v
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "./error"
|
2
4
|
|
3
5
|
require "service_skeleton/config_variable"
|
@@ -6,107 +8,67 @@ class ServiceSkeleton
|
|
6
8
|
module ConfigVariables
|
7
9
|
attr_reader :registered_variables
|
8
10
|
|
9
|
-
UNDEFINED =
|
11
|
+
UNDEFINED = Module.new
|
10
12
|
private_constant :UNDEFINED
|
11
13
|
|
12
|
-
def register_variable(name, **opts
|
14
|
+
def register_variable(name, klass, **opts)
|
13
15
|
@registered_variables ||= []
|
14
16
|
|
15
|
-
|
17
|
+
if opts[:default] == UNDEFINED
|
18
|
+
opts.delete(:default)
|
19
|
+
end
|
20
|
+
|
21
|
+
@registered_variables << {
|
22
|
+
name: name,
|
23
|
+
class: klass,
|
24
|
+
opts: opts,
|
25
|
+
}
|
16
26
|
end
|
17
27
|
|
18
28
|
def string(var_name, default: UNDEFINED, sensitive: false)
|
19
|
-
register_variable(var_name, sensitive: sensitive)
|
20
|
-
maybe_default(value, default, var_name) do
|
21
|
-
value
|
22
|
-
end
|
23
|
-
end
|
29
|
+
register_variable(var_name, ConfigVariable::String, default: default, sensitive: sensitive)
|
24
30
|
end
|
25
31
|
|
26
32
|
def boolean(var_name, default: UNDEFINED, sensitive: false)
|
27
|
-
register_variable(var_name, sensitive: sensitive)
|
28
|
-
maybe_default(value, default, var_name) do
|
29
|
-
case value
|
30
|
-
when /\A(no|n|off|0|false)\z/i
|
31
|
-
false
|
32
|
-
when /\A(yes|y|on|1|true)\z/i
|
33
|
-
true
|
34
|
-
else
|
35
|
-
raise ServiceSkeleton::Error::InvalidEnvironmentError,
|
36
|
-
"Value #{value.inspect} for environment variable #{var_name} is not a valid boolean value"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
33
|
+
register_variable(var_name, ConfigVariable::Boolean, default: default, sensitive: sensitive)
|
40
34
|
end
|
41
35
|
|
42
36
|
def integer(var_name, default: UNDEFINED, sensitive: false, range: -Float::INFINITY..Float::INFINITY)
|
43
|
-
register_variable(var_name, sensitive: sensitive
|
44
|
-
maybe_default(value, default, var_name) do
|
45
|
-
if value =~ /\A-?\d+\z/
|
46
|
-
value.to_i.tap do |i|
|
47
|
-
unless range.include?(i)
|
48
|
-
raise ServiceSkeleton::Error::InvalidEnvironmentError,
|
49
|
-
"Value #{i} for environment variable #{var_name} is out of the valid range (must be between #{range.first} and #{range.last} inclusive)"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
else
|
53
|
-
raise ServiceSkeleton::Error::InvalidEnvironmentError,
|
54
|
-
"Value #{value.inspect} for environment variable #{var_name} is not a valid integer value"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
37
|
+
register_variable(var_name, ConfigVariable::Integer, default: default, sensitive: sensitive, range: range)
|
58
38
|
end
|
59
39
|
|
60
40
|
def float(var_name, default: UNDEFINED, sensitive: false, range: -Float::INFINITY..Float::INFINITY)
|
61
|
-
register_variable(var_name, sensitive: sensitive
|
62
|
-
maybe_default(value, default, var_name) do
|
63
|
-
if value =~ /\A-?\d+.?\d*\z/
|
64
|
-
value.to_f.tap do |i|
|
65
|
-
unless range.include?(i)
|
66
|
-
raise ServiceSkeleton::Error::InvalidEnvironmentError,
|
67
|
-
"Value #{i} for environment variable #{var_name} is out of the valid range (must be between #{range.first} and #{range.last} inclusive)"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
else
|
71
|
-
raise ServiceSkeleton::Error::InvalidEnvironmentError,
|
72
|
-
"Value #{value.inspect} for environment variable #{var_name} is not a valid numeric value"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
41
|
+
register_variable(var_name, ConfigVariable::Float, default: default, sensitive: sensitive, range: range)
|
76
42
|
end
|
77
43
|
|
78
44
|
def path_list(var_name, default: UNDEFINED, sensitive: false)
|
79
|
-
register_variable(var_name, sensitive: sensitive)
|
80
|
-
maybe_default(value, default, var_name) do
|
81
|
-
value.split(":")
|
82
|
-
end
|
83
|
-
end
|
45
|
+
register_variable(var_name, ConfigVariable::PathList, default: default, sensitive: sensitive)
|
84
46
|
end
|
85
47
|
|
86
|
-
def kv_list(var_name, default: UNDEFINED, sensitive: false, key_pattern:
|
87
|
-
key_pattern
|
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
|
94
|
-
end
|
48
|
+
def kv_list(var_name, default: UNDEFINED, sensitive: false, key_pattern: /\A#{var_name}_(.*)\z/)
|
49
|
+
register_variable(var_name, ConfigVariable::KVList, default: default, sensitive: sensitive, key_pattern: key_pattern)
|
95
50
|
end
|
96
51
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
if default == UNDEFINED
|
102
|
-
raise ServiceSkeleton::Error::InvalidEnvironmentError,
|
103
|
-
"Value for required environment variable #{var_name} not specified"
|
104
|
-
else
|
105
|
-
default
|
106
|
-
end
|
107
|
-
else
|
108
|
-
yield
|
52
|
+
def enum(var_name, values:, default: UNDEFINED, sensitive: false)
|
53
|
+
unless values.is_a?(Hash) || values.is_a?(Array)
|
54
|
+
raise ArgumentError,
|
55
|
+
"values option to enum must be a hash or array"
|
109
56
|
end
|
57
|
+
|
58
|
+
register_variable(var_name, ConfigVariable::Enum, default: default, sensitive: sensitive, values: values)
|
59
|
+
end
|
60
|
+
|
61
|
+
def url(var_name, default: UNDEFINED, sensitive: false)
|
62
|
+
register_variable(var_name, ConfigVariable::URL, default: default, sensitive: sensitive)
|
110
63
|
end
|
111
64
|
end
|
112
65
|
end
|
66
|
+
|
67
|
+
require_relative "config_variable/string"
|
68
|
+
require_relative "config_variable/boolean"
|
69
|
+
require_relative "config_variable/integer"
|
70
|
+
require_relative "config_variable/float"
|
71
|
+
require_relative "config_variable/path_list"
|
72
|
+
require_relative "config_variable/kv_list"
|
73
|
+
require_relative "config_variable/enum"
|
74
|
+
require_relative "config_variable/url"
|
data/service_skeleton.gemspec
CHANGED
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.
|
4
|
+
version: 0.0.0.41.g9507cda
|
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-05-
|
11
|
+
date: 2019-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: frankenstein
|
@@ -274,6 +274,14 @@ files:
|
|
274
274
|
- lib/service_skeleton/background_worker.rb
|
275
275
|
- lib/service_skeleton/config.rb
|
276
276
|
- lib/service_skeleton/config_variable.rb
|
277
|
+
- lib/service_skeleton/config_variable/boolean.rb
|
278
|
+
- lib/service_skeleton/config_variable/enum.rb
|
279
|
+
- lib/service_skeleton/config_variable/float.rb
|
280
|
+
- lib/service_skeleton/config_variable/integer.rb
|
281
|
+
- lib/service_skeleton/config_variable/kv_list.rb
|
282
|
+
- lib/service_skeleton/config_variable/path_list.rb
|
283
|
+
- lib/service_skeleton/config_variable/string.rb
|
284
|
+
- lib/service_skeleton/config_variable/url.rb
|
277
285
|
- lib/service_skeleton/config_variables.rb
|
278
286
|
- lib/service_skeleton/error.rb
|
279
287
|
- lib/service_skeleton/filtering_logger.rb
|
@@ -299,7 +307,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
299
307
|
- !ruby/object:Gem::Version
|
300
308
|
version: 1.3.1
|
301
309
|
requirements: []
|
302
|
-
|
310
|
+
rubyforge_project:
|
311
|
+
rubygems_version: 2.7.6
|
303
312
|
signing_key:
|
304
313
|
specification_version: 4
|
305
314
|
summary: The bare bones of a service
|