legion-settings 0.1.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +53 -137
- data/.gitignore +0 -1
- data/.rubocop.yml +4 -5
- data/CHANGELOG.md +4 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +72 -0
- data/legion-settings.gemspec +8 -12
- data/lib/legion/settings.rb +11 -1
- data/lib/legion/settings/loader.rb +37 -38
- data/lib/legion/settings/rules.rb +3 -81
- data/lib/legion/settings/validator.rb +0 -17
- data/lib/legion/settings/validators/legion.rb +0 -8
- data/lib/legion/settings/version.rb +1 -1
- data/sonar-project.properties +12 -0
- metadata +59 -31
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bac4b40b52e35751f9b72eb5bb806c7a83702f887f0e817ca11505d72f32a008
|
4
|
+
data.tar.gz: e9e01f6af6b63cfb2860c64d6f8a80d80c70a9647f94a7c6365091a716dadca9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dbafcc1e2994fe5bc1f3a915765388b47f8cabf7575a63a92130c149be6aa0fe2d767f586e110878ac0595260ad77293720dc7eb8b1c906e90c37d482b1395d
|
7
|
+
data.tar.gz: a3fc8d52a94daf8e430489299435eb2ba5c974d14fd99cd92ec8577561325ae8a1aa10322baa1c7d1e052fcbaad9386b784aa6c09ba5b758e2813a8bf95abadf
|
data/.circleci/config.yml
CHANGED
@@ -1,167 +1,83 @@
|
|
1
|
-
version: 2.1
|
1
|
+
version: 2.1
|
2
|
+
orbs:
|
3
|
+
ruby: circleci/ruby@0.2.1
|
4
|
+
sonarcloud: sonarsource/sonarcloud@1.0.1
|
5
|
+
|
2
6
|
jobs:
|
3
7
|
"rubocop":
|
4
8
|
docker:
|
5
|
-
- image: circleci/ruby:2.
|
9
|
+
- image: circleci/ruby:2.7-node
|
6
10
|
steps:
|
7
11
|
- checkout
|
8
|
-
-
|
12
|
+
- ruby/load-cache
|
13
|
+
- ruby/install-deps
|
9
14
|
- run:
|
10
15
|
name: Run Rubocop
|
11
|
-
command: rubocop
|
12
|
-
-
|
13
|
-
|
14
|
-
"ruby-two-zero":
|
15
|
-
docker:
|
16
|
-
- image: circleci/ruby:2.0
|
17
|
-
steps:
|
18
|
-
- checkout
|
19
|
-
- run:
|
20
|
-
name: Bundle Install
|
21
|
-
command: bundle install
|
22
|
-
- run:
|
23
|
-
name: Run RSpec
|
24
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
25
|
-
when: always
|
26
|
-
- store_test_results:
|
27
|
-
path: test-results
|
28
|
-
"ruby-two-one":
|
29
|
-
docker:
|
30
|
-
- image: circleci/ruby:2.1
|
31
|
-
steps:
|
32
|
-
- checkout
|
33
|
-
- run:
|
34
|
-
name: Bundle Install
|
35
|
-
command: bundle install
|
36
|
-
- run:
|
37
|
-
name: Run RSpec
|
38
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
39
|
-
when: always
|
40
|
-
- store_test_results:
|
41
|
-
path: test-results
|
42
|
-
"ruby-two-two":
|
43
|
-
docker:
|
44
|
-
- image: circleci/ruby:2.2
|
45
|
-
steps:
|
46
|
-
- checkout
|
47
|
-
- run:
|
48
|
-
name: Bundle Install
|
49
|
-
command: bundle install
|
50
|
-
- run:
|
51
|
-
name: Run RSpec
|
52
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
53
|
-
when: always
|
54
|
-
- store_test_results:
|
55
|
-
path: test-results
|
56
|
-
|
57
|
-
"ruby-two-three":
|
58
|
-
docker:
|
59
|
-
- image: circleci/ruby:2.3
|
60
|
-
steps:
|
61
|
-
- checkout
|
62
|
-
- run:
|
63
|
-
name: Bundle Install
|
64
|
-
command: bundle install
|
65
|
-
- run:
|
66
|
-
name: Run RSpec
|
67
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
68
|
-
when: always
|
69
|
-
- store_test_results:
|
70
|
-
path: test-results
|
71
|
-
|
72
|
-
"ruby-two-four":
|
16
|
+
command: bundle exec rubocop
|
17
|
+
- ruby/save-cache
|
18
|
+
"ruby-two-five":
|
73
19
|
docker:
|
74
|
-
- image: circleci/ruby:2.
|
20
|
+
- image: circleci/ruby:2.5
|
75
21
|
steps:
|
76
22
|
- checkout
|
23
|
+
- ruby/load-cache
|
77
24
|
- run:
|
78
|
-
name:
|
79
|
-
command:
|
80
|
-
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
- store_test_results:
|
85
|
-
path: test-results
|
86
|
-
"ruby-two-five":
|
25
|
+
name: update bundler
|
26
|
+
command: gem update bundler
|
27
|
+
- ruby/install-deps
|
28
|
+
- ruby/run-tests
|
29
|
+
- ruby/save-cache
|
30
|
+
"ruby-two-six":
|
87
31
|
docker:
|
88
|
-
- image: circleci/ruby:2.
|
32
|
+
- image: circleci/ruby:2.6
|
89
33
|
steps:
|
90
34
|
- checkout
|
91
|
-
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
path: test-results
|
100
|
-
"ruby-two-six":
|
35
|
+
- ruby/load-cache
|
36
|
+
- run:
|
37
|
+
name: update bundler
|
38
|
+
command: gem update bundler
|
39
|
+
- ruby/install-deps
|
40
|
+
- ruby/run-tests
|
41
|
+
- ruby/save-cache
|
42
|
+
"ruby-two-seven":
|
101
43
|
docker:
|
102
|
-
- image: circleci/ruby:2.
|
44
|
+
- image: circleci/ruby:2.7
|
45
|
+
- image: memcached:1.5-alpine
|
103
46
|
steps:
|
104
47
|
- checkout
|
105
|
-
-
|
106
|
-
|
107
|
-
|
108
|
-
-
|
109
|
-
|
110
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
111
|
-
when: always
|
112
|
-
- store_test_results:
|
113
|
-
path: test-results
|
114
|
-
"jruby-nine-two":
|
48
|
+
- ruby/load-cache
|
49
|
+
- ruby/install-deps
|
50
|
+
- ruby/run-tests
|
51
|
+
- ruby/save-cache
|
52
|
+
"sonarcloud":
|
115
53
|
docker:
|
116
|
-
- image: circleci/
|
54
|
+
- image: circleci/ruby:2.7
|
117
55
|
steps:
|
118
56
|
- checkout
|
57
|
+
- ruby/load-cache
|
58
|
+
- ruby/install-deps
|
59
|
+
- ruby/run-tests
|
119
60
|
- run:
|
120
|
-
name:
|
121
|
-
command: bundle
|
122
|
-
-
|
123
|
-
|
124
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
125
|
-
when: always
|
126
|
-
- store_test_results:
|
127
|
-
path: test-results
|
61
|
+
name: Run Rubocop
|
62
|
+
command: bundle exec rubocop --format=json --out=rubocop-result.json
|
63
|
+
- sonarcloud/scan
|
64
|
+
- ruby/save-cache
|
128
65
|
|
129
66
|
workflows:
|
130
67
|
version: 2
|
131
|
-
|
68
|
+
rubocop-rspec:
|
132
69
|
jobs:
|
133
70
|
- rubocop
|
134
|
-
# - ruby-two-two:
|
135
|
-
# requires:
|
136
|
-
# - ruby-two-four
|
137
|
-
# filters:
|
138
|
-
# branches:
|
139
|
-
# only: /\bdevelop\b|\bmaster\b/
|
140
|
-
- ruby-two-three:
|
141
|
-
requires:
|
142
|
-
- ruby-two-four
|
143
|
-
filters:
|
144
|
-
branches:
|
145
|
-
only: /\bdevelop\b|\bmaster\b/
|
146
|
-
- ruby-two-four:
|
147
|
-
requires:
|
148
|
-
- rubocop
|
149
71
|
- ruby-two-five:
|
150
72
|
requires:
|
151
|
-
-
|
152
|
-
filters:
|
153
|
-
branches:
|
154
|
-
only: /\bdevelop\b|\bmaster\b/
|
73
|
+
- rubocop
|
155
74
|
- ruby-two-six:
|
156
75
|
requires:
|
157
|
-
- ruby-two-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
# - ruby-two-four
|
166
|
-
# - ruby-two-five
|
167
|
-
# - ruby-two-six
|
76
|
+
- ruby-two-five
|
77
|
+
- ruby-two-seven:
|
78
|
+
requires:
|
79
|
+
- ruby-two-five
|
80
|
+
- sonarcloud:
|
81
|
+
requires:
|
82
|
+
- ruby-two-seven
|
83
|
+
- ruby-two-six
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
Layout/LineLength:
|
2
2
|
Max: 120
|
3
3
|
Metrics/MethodLength:
|
4
4
|
Max: 30
|
@@ -10,15 +10,14 @@ Layout/SpaceAroundEqualsInParameterDefault:
|
|
10
10
|
EnforcedStyle: space
|
11
11
|
Style/SymbolArray:
|
12
12
|
Enabled: true
|
13
|
-
Layout/
|
13
|
+
Layout/HashAlignment:
|
14
14
|
EnforcedHashRocketStyle: table
|
15
15
|
EnforcedColonStyle: table
|
16
|
-
Style/HashSyntax:
|
17
|
-
EnforcedStyle: ruby19_no_mixed_keys
|
18
16
|
Style/Documentation:
|
19
17
|
Enabled: false
|
20
18
|
AllCops:
|
21
|
-
TargetRubyVersion: 2.
|
19
|
+
TargetRubyVersion: 2.5
|
20
|
+
NewCops: enable
|
22
21
|
Style/FrozenStringLiteralComment:
|
23
22
|
Enabled: false
|
24
23
|
Naming/FileName:
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
legion-settings (1.1.1)
|
5
|
+
legion-json
|
6
|
+
legion-logging
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.1)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
docile (1.3.2)
|
14
|
+
legion-json (1.1.0)
|
15
|
+
multi_json
|
16
|
+
legion-logging (1.1.0)
|
17
|
+
rainbow (~> 3)
|
18
|
+
multi_json (1.15.0)
|
19
|
+
parallel (1.19.2)
|
20
|
+
parser (2.7.1.4)
|
21
|
+
ast (~> 2.4.1)
|
22
|
+
rainbow (3.0.0)
|
23
|
+
rake (13.0.1)
|
24
|
+
regexp_parser (1.7.1)
|
25
|
+
rexml (3.2.4)
|
26
|
+
rspec (3.9.0)
|
27
|
+
rspec-core (~> 3.9.0)
|
28
|
+
rspec-expectations (~> 3.9.0)
|
29
|
+
rspec-mocks (~> 3.9.0)
|
30
|
+
rspec-core (3.9.2)
|
31
|
+
rspec-support (~> 3.9.3)
|
32
|
+
rspec-expectations (3.9.2)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.9.0)
|
35
|
+
rspec-mocks (3.9.1)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.9.0)
|
38
|
+
rspec-support (3.9.3)
|
39
|
+
rspec_junit_formatter (0.4.1)
|
40
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
41
|
+
rubocop (0.88.0)
|
42
|
+
parallel (~> 1.10)
|
43
|
+
parser (>= 2.7.1.1)
|
44
|
+
rainbow (>= 2.2.2, < 4.0)
|
45
|
+
regexp_parser (>= 1.7)
|
46
|
+
rexml
|
47
|
+
rubocop-ast (>= 0.1.0, < 1.0)
|
48
|
+
ruby-progressbar (~> 1.7)
|
49
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
50
|
+
rubocop-ast (0.2.0)
|
51
|
+
parser (>= 2.7.0.1)
|
52
|
+
ruby-progressbar (1.10.1)
|
53
|
+
simplecov (0.18.5)
|
54
|
+
docile (~> 1.1)
|
55
|
+
simplecov-html (~> 0.11)
|
56
|
+
simplecov-html (0.12.2)
|
57
|
+
unicode-display_width (1.7.0)
|
58
|
+
|
59
|
+
PLATFORMS
|
60
|
+
ruby
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
bundler
|
64
|
+
legion-settings!
|
65
|
+
rake
|
66
|
+
rspec
|
67
|
+
rspec_junit_formatter
|
68
|
+
rubocop
|
69
|
+
simplecov
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
2.1.4
|
data/legion-settings.gemspec
CHANGED
@@ -16,19 +16,15 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
17
|
f.match(%r{^(test|spec|features)/})
|
18
18
|
end
|
19
|
-
spec.bindir = 'exe'
|
20
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
20
|
spec.require_paths = ['lib']
|
22
21
|
|
23
|
-
spec.add_development_dependency 'bundler'
|
24
|
-
|
25
|
-
spec.add_development_dependency '
|
26
|
-
spec.add_development_dependency '
|
27
|
-
spec.add_development_dependency '
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
spec.add_dependency('legion-json', '~> 0.1')
|
32
|
-
end
|
33
|
-
spec.add_dependency 'legion-logging', '~> 0.1'
|
22
|
+
spec.add_development_dependency 'bundler'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'rspec'
|
25
|
+
spec.add_development_dependency 'rspec_junit_formatter'
|
26
|
+
spec.add_development_dependency 'rubocop'
|
27
|
+
spec.add_development_dependency 'simplecov'
|
28
|
+
spec.add_dependency 'legion-json'
|
29
|
+
spec.add_dependency 'legion-logging'
|
34
30
|
end
|
data/lib/legion/settings.rb
CHANGED
@@ -7,6 +7,7 @@ module Legion
|
|
7
7
|
module Settings
|
8
8
|
class << self
|
9
9
|
attr_accessor :loader
|
10
|
+
|
10
11
|
def load(options = {})
|
11
12
|
@loader = Legion::Settings::Loader.new
|
12
13
|
@loader.load_env
|
@@ -26,13 +27,22 @@ module Legion
|
|
26
27
|
Legion::Logging.info('Legion::Settings was not loading, auto loading now!') if @loader.nil?
|
27
28
|
@loader = load if @loader.nil?
|
28
29
|
@loader[key]
|
30
|
+
rescue NoMethodError, TypeError
|
31
|
+
Legion::Logging.fatal 'rescue inside [](key)'
|
32
|
+
nil
|
29
33
|
end
|
30
34
|
|
31
35
|
def set_prop(key, value)
|
32
|
-
Legion::Logging.info('Legion::Settings was not loading, auto loading now!') if @loader.nil?
|
33
36
|
@loader = load if @loader.nil?
|
34
37
|
@loader[key] = value
|
35
38
|
end
|
39
|
+
|
40
|
+
def merge_settings(key, hash)
|
41
|
+
@loader = load if @loader.nil?
|
42
|
+
thing = {}
|
43
|
+
thing[key.to_sym] = hash
|
44
|
+
@loader.load_module_settings(thing)
|
45
|
+
end
|
36
46
|
end
|
37
47
|
end
|
38
48
|
end
|
@@ -1,13 +1,10 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
1
3
|
module Legion
|
2
4
|
module Settings
|
3
|
-
# This is the main settings class, needs refactor
|
4
5
|
class Loader
|
5
|
-
# This is the standard error
|
6
6
|
class Error < RuntimeError; end
|
7
|
-
|
8
|
-
attr_reader :warnings
|
9
|
-
attr_reader :errors
|
10
|
-
attr_reader :loaded_files
|
7
|
+
attr_reader :warnings, :errors, :loaded_files, :settings
|
11
8
|
|
12
9
|
def initialize
|
13
10
|
@warnings = []
|
@@ -20,43 +17,36 @@ module Legion
|
|
20
17
|
|
21
18
|
def client_defaults
|
22
19
|
{
|
23
|
-
|
24
|
-
address:
|
20
|
+
hostname: system_hostname,
|
21
|
+
address: system_address,
|
22
|
+
name: "#{::Socket.gethostname.gsub('.', '_')}.#{::Process.pid}",
|
23
|
+
ready: false
|
25
24
|
}
|
26
25
|
end
|
27
26
|
|
28
|
-
def default_settings
|
29
|
-
|
30
|
-
client:
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
def default_settings
|
28
|
+
{
|
29
|
+
client: client_defaults,
|
30
|
+
cluster: { public_keys: {} },
|
31
|
+
crypt: {
|
32
|
+
cluster_secret: nil,
|
33
|
+
cluster_secret_timeout: 5,
|
34
|
+
vault: { connected: false }
|
35
|
+
},
|
36
|
+
cache: { enabled: true, connected: false, driver: 'dalli' },
|
37
|
+
extensions: {},
|
38
|
+
default_extension_settings: {
|
39
|
+
logger: { level: 'info', trace: false, extended: false }
|
36
40
|
},
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
}
|
41
|
+
logging: {
|
42
|
+
level: 'info',
|
43
|
+
location: 'stdout',
|
44
|
+
trace: true,
|
45
|
+
backtrace_logging: true
|
43
46
|
},
|
44
|
-
|
45
|
-
|
46
|
-
user: 'legion',
|
47
|
-
password: 'legion',
|
48
|
-
max_connections: 20,
|
49
|
-
database: 'legion',
|
50
|
-
host: '127.0.0.1',
|
51
|
-
debug: false
|
52
|
-
},
|
53
|
-
models: {},
|
54
|
-
connection: {},
|
55
|
-
migrations: { continue_on_fail: false }
|
56
|
-
}
|
47
|
+
transport: { connected: false },
|
48
|
+
data: { connected: false }
|
57
49
|
}
|
58
|
-
default[:client] = client_defaults if %w[client rspec].include?(legion_service_name)
|
59
|
-
default
|
60
50
|
end
|
61
51
|
|
62
52
|
def self.create_category_methods
|
@@ -103,6 +93,16 @@ module Legion
|
|
103
93
|
load_api_env
|
104
94
|
end
|
105
95
|
|
96
|
+
def load_module_settings(config)
|
97
|
+
@settings = deep_merge(config, @settings)
|
98
|
+
end
|
99
|
+
|
100
|
+
def load_module_default(config)
|
101
|
+
merged = deep_merge(@settings, config)
|
102
|
+
deep_diff(@settings, merged) unless @loaded_files.empty?
|
103
|
+
@settings = merged
|
104
|
+
end
|
105
|
+
|
106
106
|
def load_file(file) # rubocop:disable Metrics/AbcSize
|
107
107
|
Legion::Logging.debug("Trying to load file #{file}")
|
108
108
|
if File.file?(file) && File.readable?(file)
|
@@ -124,7 +124,6 @@ module Legion
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def load_directory(directory)
|
127
|
-
warning('loading config files from directory', directory: directory)
|
128
127
|
path = directory.gsub(/\\(?=\S)/, '/')
|
129
128
|
if File.readable?(path) && File.executable?(path)
|
130
129
|
Dir.glob(File.join(path, '**{,/*/**}/*.json')).uniq.each do |file|
|
@@ -1,120 +1,62 @@
|
|
1
1
|
module Legion
|
2
2
|
module Settings
|
3
3
|
module Rules
|
4
|
-
# Check that a value is a hash.
|
5
|
-
#
|
6
|
-
# @param value [Object] to check.
|
7
|
-
# @return [TrueClass, FalseClass]
|
8
4
|
def must_be_a_hash(value)
|
9
5
|
value.is_a?(Hash)
|
10
6
|
end
|
11
7
|
alias is_a_hash? must_be_a_hash
|
12
8
|
|
13
|
-
# Check that a value is a hash, if set (not nil).
|
14
|
-
#
|
15
|
-
# @param value [Object] to check.
|
16
|
-
# @return [TrueClass, FalseClass]
|
17
9
|
def must_be_a_hash_if_set(value)
|
18
10
|
value.nil? ? true : must_be_a_hash(value)
|
19
11
|
end
|
20
12
|
|
21
|
-
# Check that a value is an array.
|
22
|
-
#
|
23
|
-
# @param value [Object] to check.
|
24
|
-
# @return [TrueClass, FalseClass]
|
25
13
|
def must_be_an_array(value)
|
26
14
|
value.is_a?(Array)
|
27
15
|
end
|
28
16
|
alias is_an_array? must_be_an_array
|
29
17
|
|
30
|
-
# Check that a value is an array, if set (not nil).
|
31
|
-
#
|
32
|
-
# @param value [Object] to check.
|
33
|
-
# @return [TrueClass, FalseClass]
|
34
18
|
def must_be_an_array_if_set(value)
|
35
19
|
value.nil? ? true : must_be_an_array(value)
|
36
20
|
end
|
37
21
|
|
38
|
-
# Check that a value is a string.
|
39
|
-
#
|
40
|
-
# @param value [Object] to check.
|
41
|
-
# @return [TrueClass, FalseClass]
|
42
22
|
def must_be_a_string(value)
|
43
23
|
value.is_a?(String)
|
44
24
|
end
|
45
25
|
alias is_a_string? must_be_a_string
|
46
26
|
|
47
|
-
# Check that a value is a string, if set (not nil).
|
48
|
-
#
|
49
|
-
# @param value [Object] to check.
|
50
|
-
# @return [TrueClass, FalseClass]
|
51
27
|
def must_be_a_string_if_set(value)
|
52
28
|
value.nil? ? true : must_be_a_string(value)
|
53
29
|
end
|
54
30
|
|
55
|
-
# Check that a value is an integer.
|
56
|
-
#
|
57
|
-
# @param value [Object] to check.
|
58
|
-
# @return [TrueClass, FalseClass]
|
59
31
|
def must_be_an_integer(value)
|
60
32
|
value.is_a?(Integer)
|
61
33
|
end
|
62
34
|
alias is_an_integer? must_be_an_integer
|
63
35
|
|
64
|
-
# Check that a value is an integer, if set (not nil).
|
65
|
-
#
|
66
|
-
# @param value [Object] to check.
|
67
|
-
# @return [TrueClass, FalseClass]
|
68
36
|
def must_be_an_integer_if_set(value)
|
69
37
|
value.nil? ? true : must_be_an_integer(value)
|
70
38
|
end
|
71
39
|
|
72
|
-
# Check that a value is numeric.
|
73
|
-
#
|
74
|
-
# @param value [Object] to check.
|
75
|
-
# @return [TrueClass, FalseClass]
|
76
40
|
def must_be_a_numeric(value)
|
77
41
|
value.is_a?(Numeric)
|
78
42
|
end
|
79
43
|
|
80
|
-
# Check that a value is numeric, if set (not nil).
|
81
|
-
#
|
82
|
-
# @param value [Object] to check.
|
83
|
-
# @return [TrueClass, FalseClass]
|
84
44
|
def must_be_a_numeric_if_set(value)
|
85
45
|
value.nil? ? true : must_be_a_numeric(value)
|
86
46
|
end
|
87
47
|
|
88
|
-
# Check that a value matches a regular expression.
|
89
|
-
#
|
90
|
-
# @param regex [Regexp] pattern to compare with value.
|
91
|
-
# @param value [Object] to check if matches pattern.
|
92
|
-
# @return [TrueClass, FalseClass]
|
93
48
|
def must_match_regex(regex, value)
|
94
49
|
(value =~ regex).zero?
|
95
50
|
end
|
96
51
|
|
97
|
-
# Check if a value is boolean.
|
98
|
-
#
|
99
|
-
# @param value [Object] to check.
|
100
|
-
# @return [TrueClass, FalseClass]
|
101
52
|
def must_be_boolean(value)
|
102
53
|
!value.nil?
|
103
54
|
end
|
104
55
|
|
105
|
-
# Check if a value is boolean, if set (no nil).
|
106
|
-
#
|
107
|
-
# @param value [Object] to check.
|
108
|
-
# @return [TrueClass, FalseClass]
|
109
56
|
def must_be_boolean_if_set(value)
|
110
57
|
value.nil? ? true : must_be_boolean(value)
|
111
58
|
end
|
112
59
|
|
113
|
-
# Check that value items are all strings and not empty.
|
114
|
-
#
|
115
|
-
# @param value [Array] with items to check.
|
116
|
-
# @param regex [Regexp] to validate string items with.
|
117
|
-
# @return [TrueClass, FalseClass]
|
118
60
|
def items_must_be_strings(value, regex = nil)
|
119
61
|
value.all? do |item|
|
120
62
|
item.is_a?(String) && !item.empty? &&
|
@@ -122,46 +64,26 @@ module Legion
|
|
122
64
|
end
|
123
65
|
end
|
124
66
|
|
125
|
-
# Check if either of the values are set (not nil).
|
126
|
-
#
|
127
|
-
# @param values [Array<Object>] to check if not nil.
|
128
|
-
# @return [TrueClass, FalseClass]
|
129
67
|
def either_are_set?(*values)
|
130
68
|
values.any? do |value|
|
131
69
|
!value.nil?
|
132
70
|
end
|
133
71
|
end
|
134
72
|
|
135
|
-
# Check if values are valid times (can be parsed).
|
136
|
-
#
|
137
|
-
# @param values [Array<Object>] to check if valid time.
|
138
|
-
# @return [TrueClass, FalseClass]
|
139
73
|
def must_be_time(*values)
|
140
74
|
values.all? do |value|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
false
|
145
|
-
end
|
75
|
+
Time.parse(value)
|
76
|
+
rescue StandardError
|
77
|
+
false
|
146
78
|
end
|
147
79
|
end
|
148
80
|
|
149
|
-
# Check if values are allowed.
|
150
|
-
#
|
151
|
-
# @param allowed [Array<Object>] allowed values.
|
152
|
-
# @param values [Array<Object>] to check if allowed.
|
153
|
-
# @return [TrueClass, FalseClass]
|
154
81
|
def must_be_either(allowed, *values)
|
155
82
|
values.flatten.all? do |value|
|
156
83
|
allowed.include?(value)
|
157
84
|
end
|
158
85
|
end
|
159
86
|
|
160
|
-
# Check if values are allowed, if set (not nil).
|
161
|
-
#
|
162
|
-
# @param allowed [Array<Object>] allowed values.
|
163
|
-
# @param values [Array<Object>] to check if allowed.
|
164
|
-
# @return [TrueClass, FalseClass]
|
165
87
|
def must_be_either_if_set(allowed, *values)
|
166
88
|
values[0].nil? ? true : must_be_either(allowed, values)
|
167
89
|
end
|
@@ -8,19 +8,12 @@ module Legion
|
|
8
8
|
include Rules
|
9
9
|
include Validators
|
10
10
|
|
11
|
-
# @!attribute [r] failures
|
12
|
-
# @return [Array] validation failures.
|
13
11
|
attr_reader :failures
|
14
12
|
|
15
13
|
def initialize
|
16
14
|
@failures = []
|
17
15
|
end
|
18
16
|
|
19
|
-
# Run the validator.
|
20
|
-
#
|
21
|
-
# @param settings [Hash] legion settings to validate.
|
22
|
-
# @param service [String] legion service to validate for.
|
23
|
-
# @return [Array] validation failures.
|
24
17
|
def run(settings, service = nil)
|
25
18
|
validate_legion(settings[:legion])
|
26
19
|
validate_transport(settings[:transport])
|
@@ -46,10 +39,6 @@ module Legion
|
|
46
39
|
|
47
40
|
private
|
48
41
|
|
49
|
-
# Validate setting categories: checks, filters, mutators, and
|
50
|
-
# handlers.
|
51
|
-
#
|
52
|
-
# @param settings [Hash] legion settings to validate.
|
53
42
|
def validate_categories(settings)
|
54
43
|
CATEGORIES.each do |category|
|
55
44
|
if is_a_hash?(settings[category])
|
@@ -63,12 +52,6 @@ module Legion
|
|
63
52
|
end
|
64
53
|
end
|
65
54
|
|
66
|
-
# Record an invalid object with a message.
|
67
|
-
#
|
68
|
-
# @param object [Object] invalid object.
|
69
|
-
# @param message [String] message explaining why the object is
|
70
|
-
# invalid.
|
71
|
-
# @return [Array] current validation failures.
|
72
55
|
def invalid(object, message)
|
73
56
|
@failures << {
|
74
57
|
object: object,
|
@@ -2,10 +2,6 @@ module Legion
|
|
2
2
|
module Settings
|
3
3
|
module Validators
|
4
4
|
module Legion
|
5
|
-
# Validate Legion spawn.
|
6
|
-
# Validates: limit
|
7
|
-
#
|
8
|
-
# @param legion [Hash] legion definition.
|
9
5
|
def validate_legion_spawn(legion)
|
10
6
|
spawn = legion[:spawn]
|
11
7
|
if is_a_hash?(spawn)
|
@@ -20,10 +16,6 @@ module Legion
|
|
20
16
|
end
|
21
17
|
end
|
22
18
|
|
23
|
-
# Validate a Legion definition.
|
24
|
-
# Validates: spawn
|
25
|
-
#
|
26
|
-
# @param legion [Hash] legion definition.
|
27
19
|
def validate_legion(legion)
|
28
20
|
if is_a_hash?(legion)
|
29
21
|
validate_legion_spawn(legion)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
sonar.projectKey=legion-io_legion-settings
|
2
|
+
sonar.organization=legion-io
|
3
|
+
sonar.projectName=Legion::Settings
|
4
|
+
sonar.sources=.
|
5
|
+
sonar.exclusions=vendor/**
|
6
|
+
sonar.coverage.exclusions=spec/**
|
7
|
+
sonar.ruby.coverage.reportPath=coverage/.resultset.json
|
8
|
+
sonar.ruby.file.suffixes=rb,ruby
|
9
|
+
sonar.ruby.coverage.framework=RSpec
|
10
|
+
sonar.ruby.rubocopConfig=.rubocop.yml
|
11
|
+
sonar.ruby.rubocop.reportPath=rubocop-result.json
|
12
|
+
sonar.ruby.rubocop.filePath=.
|
metadata
CHANGED
@@ -1,99 +1,127 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: legion-settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esity
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec_junit_formatter
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
60
88
|
- !ruby/object:Gem::Version
|
61
89
|
version: '0'
|
62
90
|
type: :development
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
|
-
- - "
|
94
|
+
- - ">="
|
67
95
|
- !ruby/object:Gem::Version
|
68
96
|
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: legion-json
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
|
-
- - "
|
101
|
+
- - ">="
|
74
102
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0
|
103
|
+
version: '0'
|
76
104
|
type: :runtime
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
|
-
- - "
|
108
|
+
- - ">="
|
81
109
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0
|
110
|
+
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: legion-logging
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
|
-
- - "
|
115
|
+
- - ">="
|
88
116
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0
|
117
|
+
version: '0'
|
90
118
|
type: :runtime
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
93
121
|
requirements:
|
94
|
-
- - "
|
122
|
+
- - ">="
|
95
123
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0
|
124
|
+
version: '0'
|
97
125
|
description: Based on Sensu's implementation of settings
|
98
126
|
email:
|
99
127
|
- matthewdiverson@gmail.com
|
@@ -106,11 +134,10 @@ files:
|
|
106
134
|
- ".rubocop.yml"
|
107
135
|
- CHANGELOG.md
|
108
136
|
- Gemfile
|
137
|
+
- Gemfile.lock
|
109
138
|
- LICENSE.txt
|
110
139
|
- README.md
|
111
140
|
- Rakefile
|
112
|
-
- bin/console
|
113
|
-
- bin/setup
|
114
141
|
- bitbucket-pipelines.yml
|
115
142
|
- legion-settings.gemspec
|
116
143
|
- lib/legion/settings.rb
|
@@ -121,11 +148,12 @@ files:
|
|
121
148
|
- lib/legion/settings/validators.rb
|
122
149
|
- lib/legion/settings/validators/legion.rb
|
123
150
|
- lib/legion/settings/version.rb
|
151
|
+
- sonar-project.properties
|
124
152
|
homepage: https://bitbucket.org/whonodes/legion-settings
|
125
153
|
licenses:
|
126
154
|
- MIT
|
127
155
|
metadata: {}
|
128
|
-
post_install_message:
|
156
|
+
post_install_message:
|
129
157
|
rdoc_options: []
|
130
158
|
require_paths:
|
131
159
|
- lib
|
@@ -140,8 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
168
|
- !ruby/object:Gem::Version
|
141
169
|
version: '0'
|
142
170
|
requirements: []
|
143
|
-
rubygems_version: 3.
|
144
|
-
signing_key:
|
171
|
+
rubygems_version: 3.1.2
|
172
|
+
signing_key:
|
145
173
|
specification_version: 4
|
146
174
|
summary: Used to load the json settings files
|
147
175
|
test_files: []
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'legion/settings'
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require 'irb'
|
14
|
-
IRB.start(__FILE__)
|