legion-settings 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +16 -0
- data/.rubocop.yml +41 -9
- data/CHANGELOG.md +13 -1
- data/CLAUDE.md +115 -0
- data/Gemfile +2 -0
- data/LICENSE +1 -1
- data/README.md +42 -21
- data/legion-settings.gemspec +11 -11
- data/lib/legion/settings/loader.rb +34 -28
- data/lib/legion/settings/os.rb +3 -6
- data/lib/legion/settings/schema.rb +202 -0
- data/lib/legion/settings/validation_error.rb +25 -0
- data/lib/legion/settings/version.rb +3 -1
- data/lib/legion/settings.rb +105 -2
- metadata +18 -26
- data/.github/workflows/sourcehawk-scan.yml +0 -20
- data/CODE_OF_CONDUCT.md +0 -75
- data/CONTRIBUTING.md +0 -55
- data/INDIVIDUAL_CONTRIBUTOR_LICENSE.md +0 -30
- data/NOTICE.txt +0 -9
- data/SECURITY.md +0 -9
- data/attribution.txt +0 -1
- data/lib/legion/settings/validators/legion.rb +0 -29
- data/sourcehawk.yml +0 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7e6bfc5465268327a07174136c9b4cc7eb8793345bc43b61bbefbf99fdf2406a
|
|
4
|
+
data.tar.gz: 9e6b1384a02334a6aecbe50474f184bfb7996d16efe36d9b80744a4feb6171bc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c8d084a1a0b75578ada3bb4f765bf7948ed9f9969e03717d10bf357d82895d1717b7e634e5f7ce8385bc3f1f4734e7e8e0d00a24ad4596a04f72f950c1ec84ec
|
|
7
|
+
data.tar.gz: 6f2ed8e7febb6d6a9f9e36b3d86a5522230f7254bf46aaa4e966c9d60b91f71f80a8a2e46de9510f77bedbda53d759426d087c71fdecbb15c2ef2c1efdb08298
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [main]
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
ci:
|
|
9
|
+
uses: LegionIO/.github/.github/workflows/ci.yml@main
|
|
10
|
+
|
|
11
|
+
release:
|
|
12
|
+
needs: ci
|
|
13
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
14
|
+
uses: LegionIO/.github/.github/workflows/release.yml@main
|
|
15
|
+
secrets:
|
|
16
|
+
rubygems-api-key: ${{ secrets.RUBYGEMS_API_KEY }}
|
data/.rubocop.yml
CHANGED
|
@@ -1,18 +1,50 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 3.4
|
|
3
|
+
NewCops: enable
|
|
4
|
+
SuggestExtensions: false
|
|
5
|
+
|
|
1
6
|
Layout/LineLength:
|
|
2
|
-
Max:
|
|
7
|
+
Max: 160
|
|
8
|
+
|
|
9
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
|
10
|
+
EnforcedStyle: space
|
|
11
|
+
|
|
12
|
+
Layout/HashAlignment:
|
|
13
|
+
EnforcedHashRocketStyle: table
|
|
14
|
+
EnforcedColonStyle: table
|
|
15
|
+
|
|
3
16
|
Metrics/MethodLength:
|
|
4
|
-
Max:
|
|
17
|
+
Max: 50
|
|
18
|
+
|
|
5
19
|
Metrics/ClassLength:
|
|
6
20
|
Max: 1500
|
|
21
|
+
|
|
22
|
+
Metrics/ModuleLength:
|
|
23
|
+
Max: 1500
|
|
24
|
+
|
|
7
25
|
Metrics/BlockLength:
|
|
8
|
-
Max:
|
|
26
|
+
Max: 40
|
|
27
|
+
Exclude:
|
|
28
|
+
- 'spec/**/*'
|
|
29
|
+
|
|
30
|
+
Metrics/AbcSize:
|
|
31
|
+
Max: 60
|
|
32
|
+
|
|
33
|
+
Metrics/CyclomaticComplexity:
|
|
34
|
+
Max: 15
|
|
35
|
+
|
|
36
|
+
Metrics/PerceivedComplexity:
|
|
37
|
+
Max: 17
|
|
38
|
+
|
|
9
39
|
Style/Documentation:
|
|
10
40
|
Enabled: false
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
41
|
+
|
|
42
|
+
Style/SymbolArray:
|
|
43
|
+
Enabled: true
|
|
44
|
+
|
|
15
45
|
Style/FrozenStringLiteralComment:
|
|
46
|
+
Enabled: true
|
|
47
|
+
EnforcedStyle: always
|
|
48
|
+
|
|
49
|
+
Naming/FileName:
|
|
16
50
|
Enabled: false
|
|
17
|
-
Gemspec/RequiredRubyVersion:
|
|
18
|
-
Enabled: false
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
# Legion::Settings Changelog
|
|
2
2
|
|
|
3
|
+
## [1.2.2] - 2026-03-16
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- `role` key in default settings with `profile` and `extensions` fields for extension profile filtering
|
|
7
|
+
|
|
8
|
+
## v1.2.1
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- `dev_mode?` method — returns true when `LEGION_DEV=true` env var or `Settings[:dev]` is set
|
|
12
|
+
- Dev mode soft validation: `validate!` warns instead of raising when dev mode is active
|
|
13
|
+
- Warning output via `Legion::Logging.warn` (falls back to `$stderr` if logging unavailable)
|
|
14
|
+
|
|
3
15
|
## v1.2.0
|
|
4
|
-
Moving from BitBucket to GitHub
|
|
16
|
+
Moving from BitBucket to GitHub. All git history is reset from this point on
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# legion-settings: Configuration Management for LegionIO
|
|
2
|
+
|
|
3
|
+
**Repository Level 3 Documentation**
|
|
4
|
+
- **Parent**: `/Users/miverso2/rubymine/legion/CLAUDE.md`
|
|
5
|
+
|
|
6
|
+
## Purpose
|
|
7
|
+
|
|
8
|
+
Hash-like configuration store for the LegionIO framework. Loads settings from JSON files, directories, and environment variables. Provides a unified `Legion::Settings[:key]` accessor used by all other Legion gems. Includes schema-based validation with type inference, enum constraints, and cross-module checks.
|
|
9
|
+
|
|
10
|
+
**GitHub**: https://github.com/LegionIO/legion-settings
|
|
11
|
+
**License**: Apache-2.0
|
|
12
|
+
|
|
13
|
+
## Architecture
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
Legion::Settings (singleton module)
|
|
17
|
+
├── .load(config_dir:, config_file:, config_dirs:) # Initialize loader
|
|
18
|
+
├── .[](:key) # Hash-like accessor (auto-loads if needed)
|
|
19
|
+
├── .set_prop(key, value) # Set a value
|
|
20
|
+
├── .merge_settings(key, hash) # Merge module defaults + register schema
|
|
21
|
+
├── .define_schema(key, overrides) # Add enum/required constraints
|
|
22
|
+
├── .add_cross_validation(&block) # Register cross-module validation
|
|
23
|
+
├── .validate! # Run all validations, raise on errors
|
|
24
|
+
├── .schema # Access Schema instance
|
|
25
|
+
├── .errors # Access collected errors
|
|
26
|
+
│
|
|
27
|
+
├── Loader # Core: loads env vars, files, directories, merges settings
|
|
28
|
+
│ ├── .load_env # Load environment variables (LEGION_API_PORT)
|
|
29
|
+
│ ├── .load_file # Load single JSON file
|
|
30
|
+
│ ├── .load_directory # Load all JSON files from directory
|
|
31
|
+
│ ├── .load_module_settings # Merge with module priority
|
|
32
|
+
│ └── .load_module_default # Merge with default priority
|
|
33
|
+
│
|
|
34
|
+
├── Schema # Type inference, validation, unknown key detection
|
|
35
|
+
│ ├── .register # Infer types from defaults
|
|
36
|
+
│ ├── .define_override # Add enum/required/type constraints
|
|
37
|
+
│ ├── .validate_module # Validate values against schema
|
|
38
|
+
│ └── .detect_unknown_keys # Find typos via Levenshtein distance
|
|
39
|
+
│
|
|
40
|
+
├── ValidationError # Collects all errors, raises once with formatted message
|
|
41
|
+
├── OS # OS detection helpers
|
|
42
|
+
└── CORE_MODULES # [:transport, :cache, :crypt, :data, :logging, :client]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Key Design Patterns
|
|
46
|
+
|
|
47
|
+
- **Auto-Load on Access**: `Legion::Settings[:key]` auto-loads if not initialized
|
|
48
|
+
- **Directory-Based Config**: Loads all `.json` files from config directories (default paths: `/etc/legionio`, `~/legionio`, `./settings`)
|
|
49
|
+
- **Module Merging**: Each Legion module registers its defaults via `merge_settings` during startup
|
|
50
|
+
- **Schema Inference**: Types are inferred from default values — no manual schema definitions needed
|
|
51
|
+
- **Two-Pass Validation**: Per-module on merge (catches type mismatches immediately) + cross-module on `validate!` (catches dependency conflicts)
|
|
52
|
+
- **Self-Service Registration**: LEX modules register schemas alongside defaults via `merge_settings` — no core changes needed
|
|
53
|
+
- **Fail-Fast**: `validate!` collects all errors and raises `ValidationError` once with a formatted message
|
|
54
|
+
- **Lazy Logging**: Falls back to `::Logger.new($stdout)` if `Legion::Logging` isn't loaded yet
|
|
55
|
+
|
|
56
|
+
## Dependencies
|
|
57
|
+
|
|
58
|
+
| Gem | Purpose |
|
|
59
|
+
|-----|---------|
|
|
60
|
+
| `legion-json` (>= 1.2) | JSON file parsing |
|
|
61
|
+
|
|
62
|
+
## File Map
|
|
63
|
+
|
|
64
|
+
| Path | Purpose |
|
|
65
|
+
|------|---------|
|
|
66
|
+
| `lib/legion/settings.rb` | Module entry, singleton accessors, schema integration, validation orchestration |
|
|
67
|
+
| `lib/legion/settings/loader.rb` | Config loading from env/files/directories, deep merge, indifferent access |
|
|
68
|
+
| `lib/legion/settings/schema.rb` | Type inference, validation logic, unknown key detection (Levenshtein) |
|
|
69
|
+
| `lib/legion/settings/validation_error.rb` | Error collection and formatted reporting |
|
|
70
|
+
| `lib/legion/settings/os.rb` | OS detection helpers |
|
|
71
|
+
| `lib/legion/settings/version.rb` | VERSION constant |
|
|
72
|
+
| `spec/legion/settings_spec.rb` | Core settings module tests |
|
|
73
|
+
| `spec/legion/settings_module_spec.rb` | Module-level accessor and merge tests |
|
|
74
|
+
| `spec/legion/loader_spec.rb` | Loader: env/file/directory loading tests |
|
|
75
|
+
| `spec/legion/settings/schema_spec.rb` | Schema validation tests |
|
|
76
|
+
| `spec/legion/settings/validation_error_spec.rb` | Error formatting tests |
|
|
77
|
+
| `spec/legion/settings/integration_spec.rb` | End-to-end validation tests |
|
|
78
|
+
| `spec/legion/settings/role_defaults_spec.rb` | Role profile default settings tests |
|
|
79
|
+
|
|
80
|
+
## Role in LegionIO
|
|
81
|
+
|
|
82
|
+
**Core configuration gem** - every other Legion gem reads its configuration from `Legion::Settings`. Settings are organized by module key:
|
|
83
|
+
|
|
84
|
+
```ruby
|
|
85
|
+
Legion::Settings[:transport] # legion-transport config
|
|
86
|
+
Legion::Settings[:cache] # legion-cache config
|
|
87
|
+
Legion::Settings[:crypt] # legion-crypt config
|
|
88
|
+
Legion::Settings[:data] # legion-data config
|
|
89
|
+
Legion::Settings[:client] # Node identity (name, hostname, ready state)
|
|
90
|
+
Legion::Settings[:role] # Extension profile filtering (profile, extensions)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Validation Usage
|
|
94
|
+
|
|
95
|
+
```ruby
|
|
96
|
+
# Modules register defaults (schema inferred automatically)
|
|
97
|
+
Legion::Settings.merge_settings('transport', { host: 'localhost', port: 5672 })
|
|
98
|
+
|
|
99
|
+
# Optional: add constraints beyond type inference
|
|
100
|
+
Legion::Settings.define_schema('cache', { driver: { enum: %w[dalli redis] } })
|
|
101
|
+
|
|
102
|
+
# Optional: cross-module validation
|
|
103
|
+
Legion::Settings.add_cross_validation do |settings, errors|
|
|
104
|
+
if settings[:crypt][:cluster_secret].nil? && settings[:transport][:connected]
|
|
105
|
+
errors << { module: :crypt, path: 'crypt.cluster_secret', message: 'required when transport is connected' }
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Validate all at once (raises ValidationError with all collected errors)
|
|
110
|
+
Legion::Settings.validate!
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
**Maintained By**: Matthew Iverson (@Esity)
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright 2021
|
|
189
|
+
Copyright 2021 Esity
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
data/README.md
CHANGED
|
@@ -1,36 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
=====
|
|
1
|
+
# legion-settings
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
Configuration management module for the [LegionIO](https://github.com/LegionIO/LegionIO) framework. Loads settings from JSON files, directories, and environment variables. Provides a unified `Legion::Settings[:key]` accessor used by all other Legion gems.
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
------------------------------------------------
|
|
5
|
+
## Installation
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
```bash
|
|
8
|
+
gem install legion-settings
|
|
9
|
+
```
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
* Ruby 2.4+
|
|
11
|
+
Or add to your Gemfile:
|
|
13
12
|
|
|
13
|
+
```ruby
|
|
14
|
+
gem 'legion-settings'
|
|
15
|
+
```
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
------------------------
|
|
17
|
+
## Usage
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
```ruby
|
|
20
|
+
require 'legion/settings'
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
Legion::Settings.load(config_dir: './') # loads all .json files in the directory
|
|
23
|
+
|
|
24
|
+
Legion::Settings[:client][:hostname]
|
|
25
|
+
Legion::Settings[:transport][:connection][:host]
|
|
22
26
|
```
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
require 'legion-settings'
|
|
26
|
-
Legion::Settings.load(config_dir: './') # will automatically load json files it has access to inside this dir
|
|
28
|
+
### Config Paths (checked in order)
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
1. `/etc/legionio/`
|
|
31
|
+
2. `~/legionio/`
|
|
32
|
+
3. `./settings/`
|
|
33
|
+
|
|
34
|
+
Each Legion module registers its own defaults via `merge_settings` during startup.
|
|
35
|
+
|
|
36
|
+
### Schema Validation
|
|
37
|
+
|
|
38
|
+
Types are inferred automatically from default values. Optional constraints can be added:
|
|
30
39
|
|
|
40
|
+
```ruby
|
|
41
|
+
Legion::Settings.merge_settings('mymodule', { host: 'localhost', port: 8080 })
|
|
42
|
+
Legion::Settings.define_schema('mymodule', { port: { required: true } })
|
|
43
|
+
Legion::Settings.validate! # raises ValidationError if any settings are invalid
|
|
44
|
+
|
|
45
|
+
# In development, warn instead of raising:
|
|
46
|
+
# Set LEGION_DEV=true or Legion::Settings.set_prop(:dev, true)
|
|
47
|
+
# validate! will warn to $stderr (or Legion::Logging) instead of raising
|
|
31
48
|
```
|
|
32
49
|
|
|
33
|
-
|
|
34
|
-
|
|
50
|
+
## Requirements
|
|
51
|
+
|
|
52
|
+
- Ruby >= 3.4
|
|
53
|
+
- `legion-json`
|
|
54
|
+
|
|
55
|
+
## License
|
|
35
56
|
|
|
36
|
-
|
|
57
|
+
Apache-2.0
|
data/legion-settings.gemspec
CHANGED
|
@@ -6,24 +6,24 @@ Gem::Specification.new do |spec|
|
|
|
6
6
|
spec.name = 'legion-settings'
|
|
7
7
|
spec.version = Legion::Settings::VERSION
|
|
8
8
|
spec.authors = ['Esity']
|
|
9
|
-
spec.email =
|
|
9
|
+
spec.email = ['matthewdiverson@gmail.com']
|
|
10
10
|
|
|
11
11
|
spec.summary = 'Legion::Settings'
|
|
12
12
|
spec.description = 'A gem written to handle LegionIO Settings in a consistent way across extensions'
|
|
13
|
-
spec.homepage = 'https://github.com/
|
|
13
|
+
spec.homepage = 'https://github.com/LegionIO/legion-settings'
|
|
14
14
|
spec.license = 'Apache-2.0'
|
|
15
15
|
spec.require_paths = ['lib']
|
|
16
|
-
spec.required_ruby_version = '>=
|
|
16
|
+
spec.required_ruby_version = '>= 3.4'
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
|
-
spec.
|
|
19
|
-
spec.extra_rdoc_files = %w[README.md LICENSE CHANGELOG.md]
|
|
18
|
+
spec.extra_rdoc_files = %w[README.md LICENSE CHANGELOG.md]
|
|
20
19
|
spec.metadata = {
|
|
21
|
-
'bug_tracker_uri'
|
|
22
|
-
'changelog_uri'
|
|
23
|
-
'documentation_uri'
|
|
24
|
-
'homepage_uri'
|
|
25
|
-
'source_code_uri'
|
|
26
|
-
'wiki_uri'
|
|
20
|
+
'bug_tracker_uri' => 'https://github.com/LegionIO/legion-settings/issues',
|
|
21
|
+
'changelog_uri' => 'https://github.com/LegionIO/legion-settings/blob/main/CHANGELOG.md',
|
|
22
|
+
'documentation_uri' => 'https://github.com/LegionIO/legion-settings',
|
|
23
|
+
'homepage_uri' => 'https://github.com/LegionIO/LegionIO',
|
|
24
|
+
'source_code_uri' => 'https://github.com/LegionIO/legion-settings',
|
|
25
|
+
'wiki_uri' => 'https://github.com/LegionIO/legion-settings/wiki',
|
|
26
|
+
'rubygems_mfa_required' => 'true'
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
spec.add_dependency 'legion-json', '>= 1.2'
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'socket'
|
|
2
4
|
require 'legion/settings/os'
|
|
3
5
|
|
|
@@ -20,37 +22,38 @@ module Legion
|
|
|
20
22
|
def client_defaults
|
|
21
23
|
{
|
|
22
24
|
hostname: system_hostname,
|
|
23
|
-
address:
|
|
24
|
-
name:
|
|
25
|
-
ready:
|
|
25
|
+
address: system_address,
|
|
26
|
+
name: "#{::Socket.gethostname.tr('.', '_')}.#{::Process.pid}",
|
|
27
|
+
ready: false
|
|
26
28
|
}
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
def default_settings
|
|
30
32
|
{
|
|
31
|
-
client:
|
|
32
|
-
cluster:
|
|
33
|
-
crypt:
|
|
34
|
-
cluster_secret:
|
|
33
|
+
client: client_defaults,
|
|
34
|
+
cluster: { public_keys: {} },
|
|
35
|
+
crypt: {
|
|
36
|
+
cluster_secret: nil,
|
|
35
37
|
cluster_secret_timeout: 5,
|
|
36
|
-
vault:
|
|
38
|
+
vault: { connected: false }
|
|
37
39
|
},
|
|
38
|
-
cache:
|
|
39
|
-
extensions:
|
|
40
|
-
reload:
|
|
41
|
-
reloading:
|
|
42
|
-
auto_install_missing_lex:
|
|
40
|
+
cache: { enabled: true, connected: false, driver: 'dalli' },
|
|
41
|
+
extensions: {},
|
|
42
|
+
reload: false,
|
|
43
|
+
reloading: false,
|
|
44
|
+
auto_install_missing_lex: true,
|
|
43
45
|
default_extension_settings: {
|
|
44
46
|
logger: { level: 'info', trace: false, extended: false }
|
|
45
47
|
},
|
|
46
|
-
logging:
|
|
47
|
-
level:
|
|
48
|
-
location:
|
|
49
|
-
trace:
|
|
48
|
+
logging: {
|
|
49
|
+
level: 'info',
|
|
50
|
+
location: 'stdout',
|
|
51
|
+
trace: true,
|
|
50
52
|
backtrace_logging: true
|
|
51
53
|
},
|
|
52
|
-
transport:
|
|
53
|
-
data:
|
|
54
|
+
transport: { connected: false },
|
|
55
|
+
data: { connected: false },
|
|
56
|
+
role: { profile: nil, extensions: [] }
|
|
54
57
|
}
|
|
55
58
|
end
|
|
56
59
|
|
|
@@ -66,6 +69,11 @@ module Legion
|
|
|
66
69
|
to_hash[key]
|
|
67
70
|
end
|
|
68
71
|
|
|
72
|
+
def []=(key, value)
|
|
73
|
+
@settings[key] = value
|
|
74
|
+
@indifferent_access = false
|
|
75
|
+
end
|
|
76
|
+
|
|
69
77
|
def hexdigest
|
|
70
78
|
if @hexdigest && @indifferent_access
|
|
71
79
|
@hexdigest
|
|
@@ -147,8 +155,9 @@ module Legion
|
|
|
147
155
|
end
|
|
148
156
|
|
|
149
157
|
def validate
|
|
150
|
-
|
|
151
|
-
|
|
158
|
+
Legion::Settings.validate!
|
|
159
|
+
rescue Legion::Settings::ValidationError
|
|
160
|
+
# errors are already collected in @errors
|
|
152
161
|
end
|
|
153
162
|
|
|
154
163
|
private
|
|
@@ -191,11 +200,12 @@ module Legion
|
|
|
191
200
|
end
|
|
192
201
|
|
|
193
202
|
def read_config_file(file)
|
|
194
|
-
contents =
|
|
203
|
+
contents = File.read(file).dup
|
|
195
204
|
if contents.respond_to?(:force_encoding)
|
|
196
205
|
encoding = ::Encoding::ASCII_8BIT
|
|
197
206
|
contents = contents.force_encoding(encoding)
|
|
198
|
-
|
|
207
|
+
bom = (+"\xEF\xBB\xBF").force_encoding(encoding)
|
|
208
|
+
contents.sub!(bom, '')
|
|
199
209
|
else
|
|
200
210
|
contents.sub!(/^\357\273\277/, '')
|
|
201
211
|
end
|
|
@@ -216,7 +226,6 @@ module Legion
|
|
|
216
226
|
merged
|
|
217
227
|
end
|
|
218
228
|
|
|
219
|
-
# rubocop:disable Metrics/AbcSize
|
|
220
229
|
def deep_diff(hash_one, hash_two)
|
|
221
230
|
keys = hash_one.keys.concat(hash_two.keys).uniq
|
|
222
231
|
keys.each_with_object({}) do |key, diff|
|
|
@@ -229,15 +238,12 @@ module Legion
|
|
|
229
238
|
end
|
|
230
239
|
end
|
|
231
240
|
end
|
|
232
|
-
# rubocop:enable Metrics/AbcSize
|
|
233
241
|
|
|
234
242
|
def create_loaded_tempfile!
|
|
235
243
|
dir = ENV['LEGION_LOADED_TEMPFILE_DIR'] || Dir.tmpdir
|
|
236
244
|
file_name = "legion_#{legion_service_name}_loaded_files"
|
|
237
245
|
path = File.join(dir, file_name)
|
|
238
|
-
File.
|
|
239
|
-
file.write(@loaded_files.join(':'))
|
|
240
|
-
end
|
|
246
|
+
File.write(path, @loaded_files.join(':'))
|
|
241
247
|
path
|
|
242
248
|
end
|
|
243
249
|
|
data/lib/legion/settings/os.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Legion
|
|
2
4
|
module Settings
|
|
3
5
|
module OS
|
|
@@ -14,15 +16,10 @@ module Legion
|
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
def self.linux?
|
|
17
|
-
OS.unix?
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def self.jruby?
|
|
21
|
-
RUBY_ENGINE == 'jruby'
|
|
19
|
+
OS.unix? && !OS.mac?
|
|
22
20
|
end
|
|
23
21
|
|
|
24
22
|
def os
|
|
25
|
-
return 'jruby' if jruby?
|
|
26
23
|
return 'windows' if windows?
|
|
27
24
|
return 'mac' if mac?
|
|
28
25
|
return 'unix' if unix?
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Settings
|
|
5
|
+
class Schema
|
|
6
|
+
def initialize
|
|
7
|
+
@schemas = {}
|
|
8
|
+
@registered = []
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def register(mod_name, defaults)
|
|
12
|
+
mod_name = mod_name.to_sym
|
|
13
|
+
@registered << mod_name unless @registered.include?(mod_name)
|
|
14
|
+
@schemas[mod_name] ||= {}
|
|
15
|
+
infer_types(defaults, @schemas[mod_name])
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def define_override(mod_name, overrides)
|
|
19
|
+
mod_name = mod_name.to_sym
|
|
20
|
+
@schemas[mod_name] ||= {}
|
|
21
|
+
apply_overrides(overrides, @schemas[mod_name])
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def constraint(mod_name, key_path)
|
|
25
|
+
node = @schemas[mod_name.to_sym]
|
|
26
|
+
key_path.each do |key|
|
|
27
|
+
return nil unless node.is_a?(Hash) && node.key?(key)
|
|
28
|
+
|
|
29
|
+
node = node[key]
|
|
30
|
+
end
|
|
31
|
+
node
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def registered_modules
|
|
35
|
+
@registered.dup
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def schema_for(mod_name)
|
|
39
|
+
@schemas[mod_name.to_sym]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def validate_module(mod_name, values)
|
|
43
|
+
mod_name = mod_name.to_sym
|
|
44
|
+
mod_schema = @schemas[mod_name]
|
|
45
|
+
return [] if mod_schema.nil?
|
|
46
|
+
|
|
47
|
+
errors = []
|
|
48
|
+
validate_node(mod_schema, values, mod_name, '', errors)
|
|
49
|
+
errors
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
TYPE_NAMES = { string: 'String', integer: 'Integer', float: 'Float', boolean: 'Boolean',
|
|
53
|
+
array: 'Array', hash: 'Hash' }.freeze
|
|
54
|
+
|
|
55
|
+
def detect_unknown_keys(settings, known_defaults: [])
|
|
56
|
+
warnings = []
|
|
57
|
+
all_known = @registered + known_defaults
|
|
58
|
+
|
|
59
|
+
settings.each_key do |key|
|
|
60
|
+
next if all_known.include?(key)
|
|
61
|
+
|
|
62
|
+
suggestion = find_similar(key, all_known)
|
|
63
|
+
msg = "top-level key :#{key} is not registered by any module"
|
|
64
|
+
msg += " (did you mean :#{suggestion}?)" if suggestion
|
|
65
|
+
warnings << { module: :unknown_key, path: key.to_s, message: msg }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
check_first_level_keys(settings, warnings)
|
|
69
|
+
warnings
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
private
|
|
73
|
+
|
|
74
|
+
def infer_types(defaults, target)
|
|
75
|
+
defaults.each do |key, value|
|
|
76
|
+
target[key] ||= {}
|
|
77
|
+
if value.is_a?(Hash) && !value.empty?
|
|
78
|
+
infer_types(value, target[key])
|
|
79
|
+
else
|
|
80
|
+
target[key][:type] = infer_type(value)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def infer_type(value)
|
|
86
|
+
case value
|
|
87
|
+
when String then :string
|
|
88
|
+
when Integer then :integer
|
|
89
|
+
when Float then :float
|
|
90
|
+
when true, false then :boolean
|
|
91
|
+
when Array then :array
|
|
92
|
+
when Hash then :hash
|
|
93
|
+
else :any
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def apply_overrides(overrides, target)
|
|
98
|
+
overrides.each do |key, value|
|
|
99
|
+
target[key] ||= {}
|
|
100
|
+
if value.is_a?(Hash) && !value.key?(:type) && !value.key?(:required) && !value.key?(:enum)
|
|
101
|
+
apply_overrides(value, target[key])
|
|
102
|
+
else
|
|
103
|
+
target[key].merge!(value)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def validate_node(schema_node, value_node, mod_name, path_prefix, errors)
|
|
109
|
+
schema_node.each do |key, constraint|
|
|
110
|
+
current_path = path_prefix.empty? ? key.to_s : "#{path_prefix}.#{key}"
|
|
111
|
+
value = value_node.is_a?(Hash) ? value_node[key] : nil
|
|
112
|
+
|
|
113
|
+
if constraint.is_a?(Hash) && constraint.key?(:type)
|
|
114
|
+
validate_leaf(constraint, value, mod_name, current_path, errors)
|
|
115
|
+
elsif constraint.is_a?(Hash)
|
|
116
|
+
validate_node(constraint, value, mod_name, current_path, errors) if value.is_a?(Hash)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def validate_leaf(constraint, value, mod_name, path, errors)
|
|
122
|
+
if value.nil?
|
|
123
|
+
errors << { module: mod_name, path: path, message: 'is required but was nil' } if constraint[:required]
|
|
124
|
+
return
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
validate_type(constraint, value, mod_name, path, errors)
|
|
128
|
+
validate_enum(constraint, value, mod_name, path, errors)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def validate_type(constraint, value, mod_name, path, errors)
|
|
132
|
+
expected = constraint[:type]
|
|
133
|
+
return if expected == :any
|
|
134
|
+
|
|
135
|
+
valid = case expected
|
|
136
|
+
when :string then value.is_a?(String)
|
|
137
|
+
when :integer then value.is_a?(Integer)
|
|
138
|
+
when :float then value.is_a?(Float) || value.is_a?(Integer)
|
|
139
|
+
when :boolean then value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
|
140
|
+
when :array then value.is_a?(Array)
|
|
141
|
+
when :hash then value.is_a?(Hash)
|
|
142
|
+
else true
|
|
143
|
+
end
|
|
144
|
+
return if valid
|
|
145
|
+
|
|
146
|
+
type_name = TYPE_NAMES.fetch(expected, expected.to_s)
|
|
147
|
+
errors << { module: mod_name, path: path, message: "expected #{type_name}, got #{value.class} (#{value.inspect})" }
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def validate_enum(constraint, value, mod_name, path, errors)
|
|
151
|
+
return unless constraint[:enum]
|
|
152
|
+
return if constraint[:enum].include?(value)
|
|
153
|
+
|
|
154
|
+
errors << { module: mod_name, path: path, message: "expected one of #{constraint[:enum].inspect}, got #{value.inspect}" }
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def check_first_level_keys(settings, warnings)
|
|
158
|
+
@schemas.each do |mod_name, mod_schema|
|
|
159
|
+
values = settings[mod_name]
|
|
160
|
+
next unless values.is_a?(Hash)
|
|
161
|
+
|
|
162
|
+
known_keys = mod_schema.keys
|
|
163
|
+
values.each_key do |key|
|
|
164
|
+
next if known_keys.include?(key)
|
|
165
|
+
|
|
166
|
+
suggestion = find_similar(key, known_keys)
|
|
167
|
+
msg = "unknown key :#{key}"
|
|
168
|
+
msg += " (did you mean :#{suggestion}?)" if suggestion
|
|
169
|
+
warnings << { module: mod_name, path: "#{mod_name}.#{key}", message: msg }
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def find_similar(key, candidates)
|
|
175
|
+
key_str = key.to_s
|
|
176
|
+
candidates.map(&:to_s).select { |c| levenshtein(key_str, c) <= 2 }
|
|
177
|
+
.min_by { |c| levenshtein(key_str, c) }
|
|
178
|
+
&.to_sym
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def levenshtein(str_a, str_b)
|
|
182
|
+
m = str_a.length
|
|
183
|
+
n = str_b.length
|
|
184
|
+
return m if n.zero?
|
|
185
|
+
return n if m.zero?
|
|
186
|
+
|
|
187
|
+
matrix = Array.new(m + 1) { |i| i }
|
|
188
|
+
(1..n).each do |j|
|
|
189
|
+
prev = matrix[0]
|
|
190
|
+
matrix[0] = j
|
|
191
|
+
(1..m).each do |i|
|
|
192
|
+
cost = str_a[i - 1] == str_b[j - 1] ? 0 : 1
|
|
193
|
+
temp = matrix[i]
|
|
194
|
+
matrix[i] = [matrix[i] + 1, matrix[i - 1] + 1, prev + cost].min
|
|
195
|
+
prev = temp
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
matrix[m]
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Settings
|
|
5
|
+
class ValidationError < StandardError
|
|
6
|
+
attr_reader :errors
|
|
7
|
+
|
|
8
|
+
def initialize(errors)
|
|
9
|
+
@errors = errors
|
|
10
|
+
super(format_message)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def format_message
|
|
16
|
+
count = @errors.length
|
|
17
|
+
label = count == 1 ? 'error' : 'errors'
|
|
18
|
+
lines = @errors.map do |err|
|
|
19
|
+
" [#{err[:module]}] #{err[:path]}: #{err[:message]}"
|
|
20
|
+
end
|
|
21
|
+
"#{count} configuration #{label} detected:\n\n#{lines.join("\n")}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/legion/settings.rb
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'legion/json'
|
|
2
4
|
require 'legion/settings/version'
|
|
3
5
|
require 'legion/json/parse_error'
|
|
4
6
|
require 'legion/settings/loader'
|
|
7
|
+
require 'legion/settings/schema'
|
|
8
|
+
require 'legion/settings/validation_error'
|
|
5
9
|
|
|
6
10
|
module Legion
|
|
7
11
|
module Settings
|
|
12
|
+
CORE_MODULES = %i[transport cache crypt data logging client].freeze
|
|
13
|
+
|
|
8
14
|
class << self
|
|
9
15
|
attr_accessor :loader
|
|
10
16
|
|
|
@@ -28,7 +34,6 @@ module Legion
|
|
|
28
34
|
@loader = load if @loader.nil?
|
|
29
35
|
@loader[key]
|
|
30
36
|
rescue NoMethodError, TypeError
|
|
31
|
-
logger.fatal 'rescue inside [](key)'
|
|
32
37
|
nil
|
|
33
38
|
end
|
|
34
39
|
|
|
@@ -42,6 +47,45 @@ module Legion
|
|
|
42
47
|
thing = {}
|
|
43
48
|
thing[key.to_sym] = hash
|
|
44
49
|
@loader.load_module_settings(thing)
|
|
50
|
+
schema.register(key.to_sym, hash)
|
|
51
|
+
validate_module_on_merge(key.to_sym)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def define_schema(key, overrides)
|
|
55
|
+
schema.define_override(key.to_sym, overrides)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def add_cross_validation(&block)
|
|
59
|
+
cross_validations << block
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def dev_mode?
|
|
63
|
+
return true if ENV['LEGION_DEV'] == 'true'
|
|
64
|
+
|
|
65
|
+
Legion::Settings[:dev] ? true : false
|
|
66
|
+
rescue StandardError
|
|
67
|
+
false
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def validate!
|
|
71
|
+
@loader = load if @loader.nil?
|
|
72
|
+
revalidate_all_modules
|
|
73
|
+
run_cross_validations
|
|
74
|
+
detect_unknown_keys
|
|
75
|
+
return if errors.empty?
|
|
76
|
+
|
|
77
|
+
raise ValidationError, errors unless dev_mode?
|
|
78
|
+
|
|
79
|
+
warn_validation_errors(errors)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def schema
|
|
83
|
+
@schema ||= Schema.new
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def errors
|
|
87
|
+
@loader = load if @loader.nil?
|
|
88
|
+
@loader.errors
|
|
45
89
|
end
|
|
46
90
|
|
|
47
91
|
def logger
|
|
@@ -49,9 +93,68 @@ module Legion
|
|
|
49
93
|
::Legion::Logging
|
|
50
94
|
else
|
|
51
95
|
require 'logger'
|
|
52
|
-
::Logger.new($stdout)
|
|
96
|
+
l = ::Logger.new($stdout)
|
|
97
|
+
l.formatter = proc do |severity, datetime, _progname, msg|
|
|
98
|
+
"[#{datetime.strftime('%Y-%m-%d %H:%M:%S %z')}] #{severity} #{msg}\n"
|
|
99
|
+
end
|
|
100
|
+
l
|
|
53
101
|
end
|
|
54
102
|
end
|
|
103
|
+
|
|
104
|
+
private
|
|
105
|
+
|
|
106
|
+
def cross_validations
|
|
107
|
+
@cross_validations ||= []
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def warn_validation_errors(errs)
|
|
111
|
+
count = errs.length
|
|
112
|
+
label = count == 1 ? 'error' : 'errors'
|
|
113
|
+
message = "Legion::Settings dev mode: #{count} configuration #{label} detected (not raising):\n"
|
|
114
|
+
message += errs.map { |e| " [#{e[:module]}] #{e[:path]}: #{e[:message]}" }.join("\n")
|
|
115
|
+
if ::Legion.const_defined?('Logging')
|
|
116
|
+
::Legion::Logging.warn(message)
|
|
117
|
+
else
|
|
118
|
+
warn(message)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def validate_module_on_merge(mod_name)
|
|
123
|
+
values = @loader[mod_name]
|
|
124
|
+
return unless values.is_a?(Hash)
|
|
125
|
+
|
|
126
|
+
module_errors = schema.validate_module(mod_name, values)
|
|
127
|
+
@loader.errors.concat(module_errors)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def revalidate_all_modules
|
|
131
|
+
schema.registered_modules.each do |mod_name|
|
|
132
|
+
values = @loader[mod_name]
|
|
133
|
+
next unless values.is_a?(Hash)
|
|
134
|
+
|
|
135
|
+
module_errors = schema.validate_module(mod_name, values)
|
|
136
|
+
@loader.errors.concat(module_errors)
|
|
137
|
+
end
|
|
138
|
+
@loader.errors.uniq!
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def run_cross_validations
|
|
142
|
+
settings_hash = @loader.to_hash
|
|
143
|
+
cross_validations.each do |block|
|
|
144
|
+
block.call(settings_hash, @loader.errors)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def detect_unknown_keys
|
|
149
|
+
default_keys = @loader.default_settings.keys
|
|
150
|
+
registered = schema.registered_modules
|
|
151
|
+
known_defaults = default_keys - registered
|
|
152
|
+
|
|
153
|
+
warnings = schema.detect_unknown_keys(@loader.to_hash, known_defaults: known_defaults)
|
|
154
|
+
warnings.each do |w|
|
|
155
|
+
@loader.errors << w
|
|
156
|
+
end
|
|
157
|
+
end
|
|
55
158
|
end
|
|
56
159
|
end
|
|
57
160
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: legion-settings
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Esity
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: legion-json
|
|
@@ -28,46 +27,40 @@ description: A gem written to handle LegionIO Settings in a consistent way acros
|
|
|
28
27
|
extensions
|
|
29
28
|
email:
|
|
30
29
|
- matthewdiverson@gmail.com
|
|
31
|
-
- ruby@optum.com
|
|
32
30
|
executables: []
|
|
33
31
|
extensions: []
|
|
34
32
|
extra_rdoc_files:
|
|
35
|
-
- README.md
|
|
36
|
-
- LICENSE
|
|
37
33
|
- CHANGELOG.md
|
|
34
|
+
- LICENSE
|
|
35
|
+
- README.md
|
|
38
36
|
files:
|
|
39
|
-
- ".github/workflows/
|
|
37
|
+
- ".github/workflows/ci.yml"
|
|
40
38
|
- ".gitignore"
|
|
41
39
|
- ".rubocop.yml"
|
|
42
40
|
- CHANGELOG.md
|
|
43
|
-
-
|
|
44
|
-
- CONTRIBUTING.md
|
|
41
|
+
- CLAUDE.md
|
|
45
42
|
- Gemfile
|
|
46
|
-
- INDIVIDUAL_CONTRIBUTOR_LICENSE.md
|
|
47
43
|
- LICENSE
|
|
48
|
-
- NOTICE.txt
|
|
49
44
|
- README.md
|
|
50
|
-
- SECURITY.md
|
|
51
|
-
- attribution.txt
|
|
52
45
|
- legion-settings.gemspec
|
|
53
46
|
- lib/legion/settings.rb
|
|
54
47
|
- lib/legion/settings/loader.rb
|
|
55
48
|
- lib/legion/settings/os.rb
|
|
56
|
-
- lib/legion/settings/
|
|
49
|
+
- lib/legion/settings/schema.rb
|
|
50
|
+
- lib/legion/settings/validation_error.rb
|
|
57
51
|
- lib/legion/settings/version.rb
|
|
58
52
|
- sonar-project.properties
|
|
59
|
-
|
|
60
|
-
homepage: https://github.com/Optum/legion-settings
|
|
53
|
+
homepage: https://github.com/LegionIO/legion-settings
|
|
61
54
|
licenses:
|
|
62
55
|
- Apache-2.0
|
|
63
56
|
metadata:
|
|
64
|
-
bug_tracker_uri: https://github.com/
|
|
65
|
-
changelog_uri: https://github.com/
|
|
66
|
-
documentation_uri: https://github.com/
|
|
67
|
-
homepage_uri: https://github.com/
|
|
68
|
-
source_code_uri: https://github.com/
|
|
69
|
-
wiki_uri: https://github.com/
|
|
70
|
-
|
|
57
|
+
bug_tracker_uri: https://github.com/LegionIO/legion-settings/issues
|
|
58
|
+
changelog_uri: https://github.com/LegionIO/legion-settings/blob/main/CHANGELOG.md
|
|
59
|
+
documentation_uri: https://github.com/LegionIO/legion-settings
|
|
60
|
+
homepage_uri: https://github.com/LegionIO/LegionIO
|
|
61
|
+
source_code_uri: https://github.com/LegionIO/legion-settings
|
|
62
|
+
wiki_uri: https://github.com/LegionIO/legion-settings/wiki
|
|
63
|
+
rubygems_mfa_required: 'true'
|
|
71
64
|
rdoc_options: []
|
|
72
65
|
require_paths:
|
|
73
66
|
- lib
|
|
@@ -75,15 +68,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
75
68
|
requirements:
|
|
76
69
|
- - ">="
|
|
77
70
|
- !ruby/object:Gem::Version
|
|
78
|
-
version: '
|
|
71
|
+
version: '3.4'
|
|
79
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
73
|
requirements:
|
|
81
74
|
- - ">="
|
|
82
75
|
- !ruby/object:Gem::Version
|
|
83
76
|
version: '0'
|
|
84
77
|
requirements: []
|
|
85
|
-
rubygems_version: 3.
|
|
86
|
-
signing_key:
|
|
78
|
+
rubygems_version: 3.6.9
|
|
87
79
|
specification_version: 4
|
|
88
80
|
summary: Legion::Settings
|
|
89
81
|
test_files: []
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
name: Sourcehawk Scan
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
branches:
|
|
5
|
-
- main
|
|
6
|
-
- master
|
|
7
|
-
pull_request:
|
|
8
|
-
branches:
|
|
9
|
-
- main
|
|
10
|
-
- master
|
|
11
|
-
jobs:
|
|
12
|
-
build:
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
steps:
|
|
15
|
-
- uses: actions/checkout@v2
|
|
16
|
-
- name: Sourcehawk Scan
|
|
17
|
-
uses: optum/sourcehawk-scan-github-action@main
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
data/CODE_OF_CONDUCT.md
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
|
2
|
-
|
|
3
|
-
## Our Pledge
|
|
4
|
-
|
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
-
orientation.
|
|
11
|
-
|
|
12
|
-
## Our Standards
|
|
13
|
-
|
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
|
15
|
-
include:
|
|
16
|
-
|
|
17
|
-
* Using welcoming and inclusive language
|
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
|
19
|
-
* Gracefully accepting constructive criticism
|
|
20
|
-
* Focusing on what is best for the community
|
|
21
|
-
* Showing empathy towards other community members
|
|
22
|
-
|
|
23
|
-
Examples of unacceptable behavior by participants include:
|
|
24
|
-
|
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
-
advances
|
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
-
* Public or private harassment
|
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
|
30
|
-
address, without explicit permission
|
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
-
professional setting
|
|
33
|
-
|
|
34
|
-
## Our Responsibilities
|
|
35
|
-
|
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
-
response to any instances of unacceptable behavior.
|
|
39
|
-
|
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
-
threatening, offensive, or harmful.
|
|
45
|
-
|
|
46
|
-
## Scope
|
|
47
|
-
|
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
-
when an individual is representing the project or its community. Examples of
|
|
50
|
-
representing a project or community include using an official project email
|
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
|
53
|
-
further defined and clarified by project maintainers.
|
|
54
|
-
|
|
55
|
-
## Enforcement
|
|
56
|
-
|
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
-
reported by contacting the project team at [opensource@optum.com][email]. All
|
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
|
63
|
-
|
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
-
members of the project's leadership.
|
|
67
|
-
|
|
68
|
-
## Attribution
|
|
69
|
-
|
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
-
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
-
|
|
73
|
-
[homepage]: http://contributor-covenant.org
|
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|
|
75
|
-
[email]: mailto:opensource@optum.com
|
data/CONTRIBUTING.md
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# Contribution Guidelines
|
|
2
|
-
|
|
3
|
-
Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms. Please also review our [Contributor License Agreement ("CLA")](INDIVIDUAL_CONTRIBUTOR_LICENSE.md) prior to submitting changes to the project. You will need to attest to this agreement following the instructions in the [Paperwork for Pull Requests](#paperwork-for-pull-requests) section below.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# How to Contribute
|
|
8
|
-
|
|
9
|
-
Now that we have the disclaimer out of the way, let's get into how you can be a part of our project. There are many different ways to contribute.
|
|
10
|
-
|
|
11
|
-
## Issues
|
|
12
|
-
|
|
13
|
-
We track our work using Issues in GitHub. Feel free to open up your own issue to point out areas for improvement or to suggest your own new experiment. If you are comfortable with signing the waiver linked above and contributing code or documentation, grab your own issue and start working.
|
|
14
|
-
|
|
15
|
-
## Coding Standards
|
|
16
|
-
|
|
17
|
-
We have some general guidelines towards contributing to this project.
|
|
18
|
-
Please run RSpec and Rubocop while developing code for LegionIO
|
|
19
|
-
|
|
20
|
-
### Languages
|
|
21
|
-
|
|
22
|
-
*Ruby*
|
|
23
|
-
|
|
24
|
-
## Pull Requests
|
|
25
|
-
|
|
26
|
-
If you've gotten as far as reading this section, then thank you for your suggestions.
|
|
27
|
-
|
|
28
|
-
## Paperwork for Pull Requests
|
|
29
|
-
|
|
30
|
-
* Please read this guide and make sure you agree with our [Contributor License Agreement ("CLA")](INDIVIDUAL_CONTRIBUTOR_LICENSE.md).
|
|
31
|
-
* Make sure git knows your name and email address:
|
|
32
|
-
```
|
|
33
|
-
$ git config user.name "J. Random User"
|
|
34
|
-
$ git config user.email "j.random.user@example.com"
|
|
35
|
-
```
|
|
36
|
-
>The name and email address must be valid as we cannot accept anonymous contributions.
|
|
37
|
-
* Write good commit messages.
|
|
38
|
-
> Concise commit messages that describe your changes help us better understand your contributions.
|
|
39
|
-
* The first time you open a pull request in this repository, you will see a comment on your PR with a link that will allow you to sign our Contributor License Agreement (CLA) if necessary.
|
|
40
|
-
> The link will take you to a page that allows you to view our CLA. You will need to click the `Sign in with GitHub to agree button` and authorize the cla-assistant application to access the email addresses associated with your GitHub account. Agreeing to the CLA is also considered to be an attestation that you either wrote or have the rights to contribute the code. All committers to the PR branch will be required to sign the CLA, but you will only need to sign once. This CLA applies to all repositories in the Optum org.
|
|
41
|
-
|
|
42
|
-
## General Guidelines
|
|
43
|
-
|
|
44
|
-
Ensure your pull request (PR) adheres to the following guidelines:
|
|
45
|
-
|
|
46
|
-
* Try to make the name concise and descriptive.
|
|
47
|
-
* Give a good description of the change being made. Since this is very subjective, see the [Updating Your Pull Request (PR)](#updating-your-pull-request-pr) section below for further details.
|
|
48
|
-
* Every pull request should be associated with one or more issues. If no issue exists yet, please create your own.
|
|
49
|
-
* Make sure that all applicable issues are mentioned somewhere in the PR description. This can be done by typing # to bring up a list of issues.
|
|
50
|
-
|
|
51
|
-
### Updating Your Pull Request (PR)
|
|
52
|
-
|
|
53
|
-
A lot of times, making a PR adhere to the standards above can be difficult. If the maintainers notice anything that we'd like changed, we'll ask you to edit your PR before we merge it. This applies to both the content documented in the PR and the changed contained within the branch being merged. There's no need to open a new PR. Just edit the existing one.
|
|
54
|
-
|
|
55
|
-
[email]: mailto:opensource@optum.com
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# Individual Contributor License Agreement ("Agreement") V2.0
|
|
2
|
-
|
|
3
|
-
Thank you for your interest in this Optum project (the "PROJECT"). In order to clarify the intellectual property license granted with Contributions from any person or entity, the PROJECT must have a Contributor License Agreement ("CLA") on file that has been signed by each Contributor, indicating agreement to the license terms below. This license is for your protection as a Contributor as well as the protection of the PROJECT and its users; it does not change your rights to use your own Contributions for any other purpose.
|
|
4
|
-
|
|
5
|
-
You accept and agree to the following terms and conditions for Your present and future Contributions submitted to the PROJECT. In return, the PROJECT shall not use Your Contributions in a way that is inconsistent with stated project goals in effect at the time of the Contribution. Except for the license granted herein to the PROJECT and recipients of software distributed by the PROJECT, You reserve all right, title, and interest in and to Your Contributions.
|
|
6
|
-
1. Definitions.
|
|
7
|
-
|
|
8
|
-
"You" (or "Your") shall mean the copyright owner or legal entity authorized by the copyright owner that is making this Agreement with the PROJECT. For legal entities, the entity making a Contribution and all other entities that control, are controlled by, or are under common control with that entity are considered to be a single Contributor. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
9
|
-
|
|
10
|
-
"Contribution" shall mean any original work of authorship, including any modifications or additions to an existing work, that is intentionally submitted by You to the PROJECT for inclusion in, or documentation of, any of the products owned or managed by the PROJECT (the "Work"). For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the PROJECT or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the PROJECT for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by You as "Not a Contribution."
|
|
11
|
-
|
|
12
|
-
2. Grant of Copyright License.
|
|
13
|
-
|
|
14
|
-
Subject to the terms and conditions of this Agreement, You hereby grant to the PROJECT and to recipients of software distributed by the PROJECT a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions and such derivative works.
|
|
15
|
-
|
|
16
|
-
3. Grant of Patent License.
|
|
17
|
-
|
|
18
|
-
Subject to the terms and conditions of this Agreement, You hereby grant to the PROJECT and to recipients of software distributed by the PROJECT a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by You that are necessarily infringed by Your Contribution(s) alone or by combination of Your Contribution(s) with the Work to which such Contribution(s) was submitted. If any entity institutes patent litigation against You or any other entity (including a cross-claim or counterclaim in a lawsuit) alleging that your Contribution, or the Work to which you have contributed, constitutes direct or contributory patent infringement, then any patent licenses granted to that entity under this Agreement for that Contribution or Work shall terminate as of the date such litigation is filed.
|
|
19
|
-
|
|
20
|
-
4. Representations.
|
|
21
|
-
|
|
22
|
-
(a) You represent that you are legally entitled to grant the above license. If your employer(s) has rights to intellectual property that you create that includes your Contributions, you represent that you have received permission to make Contributions on behalf of that employer, that your employer has waived such rights for your Contributions to the PROJECT, or that your employer has executed a separate Corporate CLA with the PROJECT.
|
|
23
|
-
|
|
24
|
-
(b) You represent that each of Your Contributions is Your original creation (see section 6 for submissions on behalf of others). You represent that Your Contribution submissions include complete details of any third-party license or other restriction (including, but not limited to, related patents and trademarks) of which you are personally aware and which are associated with any part of Your Contributions.
|
|
25
|
-
|
|
26
|
-
5. You are not expected to provide support for Your Contributions, except to the extent You desire to provide support. You may provide support for free, for a fee, or not at all. Unless required by applicable law or agreed to in writing, You provide Your Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
|
|
27
|
-
|
|
28
|
-
6. Should You wish to submit work that is not Your original creation, You may submit it to the PROJECT separately from any Contribution, identifying the complete details of its source and of any license or other restriction (including, but not limited to, related patents, trademarks, and license agreements) of which you are personally aware, and conspicuously marking the work as "Submitted on behalf of a third-party: [named here]".
|
|
29
|
-
|
|
30
|
-
7. You agree to notify the PROJECT of any facts or circumstances of which you become aware that would make these representations inaccurate in any respect.
|
data/NOTICE.txt
DELETED
data/SECURITY.md
DELETED
data/attribution.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Add attributions here.
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
module Legion
|
|
2
|
-
module Settings
|
|
3
|
-
module Validators
|
|
4
|
-
module Legion
|
|
5
|
-
def validate_legion_spawn(legion)
|
|
6
|
-
spawn = legion[:spawn]
|
|
7
|
-
if is_a_hash?(spawn)
|
|
8
|
-
if is_an_integer?(spawn[:limit])
|
|
9
|
-
(spawn[:limit]).positive? ||
|
|
10
|
-
invalid(legion, 'legion spawn limit must be greater than 0')
|
|
11
|
-
else
|
|
12
|
-
invalid(legion, 'legion spawn limit must be an integer')
|
|
13
|
-
end
|
|
14
|
-
else
|
|
15
|
-
invalid(legion, 'legion spawn must be a hash')
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def validate_legion(legion)
|
|
20
|
-
if is_a_hash?(legion)
|
|
21
|
-
validate_legion_spawn(legion)
|
|
22
|
-
else
|
|
23
|
-
invalid(legion, 'legion must be a hash')
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
data/sourcehawk.yml
DELETED