legion-settings 1.3.5 → 1.3.6
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/CHANGELOG.md +5 -0
- data/CLAUDE.md +14 -2
- data/README.md +1 -1
- data/lib/legion/settings/loader.rb +21 -9
- data/lib/legion/settings/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 226a1ae2303f64b96fc48bd42101545a9d06b73aefab19278f27007c406c39d2
|
|
4
|
+
data.tar.gz: 4cbf2414166794436869ed44646f86c2860e7bdad4a07feebbd2536fe0e15276
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0b719320bd415ffbf14d68c5a43122dddf8182a0cfddca05915ba8f36490ede658abcb74fa499f320711a20fb5ec67d4f108c17fa4a1b35ee6a51dac801d0402
|
|
7
|
+
data.tar.gz: 88220500e2cc7a8542ce32b26c94b8ccf143d6b90d7ef0054a32f8d4507d175534dd8ac4ddae724ac8cfaa1fb4e88ac099200ca7d028fe4e258fe945398d939a
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Legion::Settings Changelog
|
|
2
2
|
|
|
3
|
+
## [1.3.6] - 2026-03-20
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- Guard all `Legion::Logging` calls in loader with `defined?` check to prevent `NameError` when legion-logging is not loaded (fixes CI for downstream gems like legion-transport)
|
|
7
|
+
|
|
3
8
|
## [1.3.5] - 2026-03-19
|
|
4
9
|
|
|
5
10
|
### Added
|
data/CLAUDE.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
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
9
|
|
|
10
10
|
**GitHub**: https://github.com/LegionIO/legion-settings
|
|
11
|
-
**Version**: 1.3.
|
|
11
|
+
**Version**: 1.3.5
|
|
12
12
|
**License**: Apache-2.0
|
|
13
13
|
|
|
14
14
|
## Architecture
|
|
@@ -27,11 +27,19 @@ Legion::Settings (singleton module)
|
|
|
27
27
|
│
|
|
28
28
|
├── Loader # Core: loads env vars, files, directories, merges settings
|
|
29
29
|
│ ├── .load_env # Load environment variables (LEGION_API_PORT)
|
|
30
|
+
│ ├── .load_dns_bootstrap # DNS-based corporate config discovery (baseline defaults)
|
|
30
31
|
│ ├── .load_file # Load single JSON file
|
|
31
32
|
│ ├── .load_directory # Load all JSON files from directory
|
|
32
33
|
│ ├── .load_module_settings # Merge with module priority
|
|
33
34
|
│ └── .load_module_default # Merge with default priority
|
|
34
35
|
│
|
|
36
|
+
├── DnsBootstrap # DNS-based corporate config auto-discovery
|
|
37
|
+
│ ├── .resolve? # Check if legion-bootstrap.<domain> resolves
|
|
38
|
+
│ ├── .fetch # HTTPS GET /legion/bootstrap.json
|
|
39
|
+
│ ├── .write_cache # Atomic write to ~/.legionio/settings/_dns_bootstrap.json
|
|
40
|
+
│ ├── .read_cache # Read + strip metadata, delete if corrupted
|
|
41
|
+
│ └── .cache_exists? # Check for cached config
|
|
42
|
+
│
|
|
35
43
|
├── Schema # Type inference, validation, unknown key detection
|
|
36
44
|
│ ├── .register # Infer types from defaults
|
|
37
45
|
│ ├── .define_override # Add enum/required/type constraints
|
|
@@ -46,7 +54,9 @@ Legion::Settings (singleton module)
|
|
|
46
54
|
### Key Design Patterns
|
|
47
55
|
|
|
48
56
|
- **Auto-Load on Access**: `Legion::Settings[:key]` auto-loads if not initialized
|
|
57
|
+
- **DNS Bootstrap Discovery**: On load, resolves `legion-bootstrap.<search-domain>` to fetch corporate baseline config. First boot blocks; subsequent boots use cache + async refresh. Disabled via `LEGION_DNS_BOOTSTRAP=false`
|
|
49
58
|
- **Directory-Based Config**: Loads all `.json` files from config directories (default paths: `/etc/legionio`, `~/legionio`, `./settings`)
|
|
59
|
+
- **Load Priority** (lowest to highest): hardcoded defaults < DNS bootstrap < local JSON files < CLI flags < secret resolution
|
|
50
60
|
- **Module Merging**: Each Legion module registers its defaults via `merge_settings` during startup
|
|
51
61
|
- **Schema Inference**: Types are inferred from default values — no manual schema definitions needed
|
|
52
62
|
- **Two-Pass Validation**: Per-module on merge (catches type mismatches immediately) + cross-module on `validate!` (catches dependency conflicts)
|
|
@@ -70,13 +80,15 @@ Legion::Settings (singleton module)
|
|
|
70
80
|
| `lib/legion/settings/validation_error.rb` | Error collection and formatted reporting |
|
|
71
81
|
| `lib/legion/settings/os.rb` | OS detection helpers |
|
|
72
82
|
| `lib/legion/settings/resolver.rb` | Secret resolution: `vault://` and `env://` URI references, fallback chains |
|
|
83
|
+
| `lib/legion/settings/dns_bootstrap.rb` | DNS-based corporate config discovery, caching, background refresh |
|
|
73
84
|
| `lib/legion/settings/version.rb` | VERSION constant |
|
|
74
85
|
| `spec/legion/settings_spec.rb` | Core settings module tests |
|
|
75
86
|
| `spec/legion/settings_module_spec.rb` | Module-level accessor and merge tests |
|
|
76
87
|
| `spec/legion/loader_spec.rb` | Loader: env/file/directory loading tests |
|
|
77
88
|
| `spec/legion/settings/schema_spec.rb` | Schema validation tests |
|
|
78
89
|
| `spec/legion/settings/validation_error_spec.rb` | Error formatting tests |
|
|
79
|
-
| `spec/legion/settings/integration_spec.rb` | End-to-end validation tests |
|
|
90
|
+
| `spec/legion/settings/integration_spec.rb` | End-to-end validation + DNS bootstrap override tests |
|
|
91
|
+
| `spec/legion/settings/dns_bootstrap_spec.rb` | DnsBootstrap class tests (resolve, fetch, cache) |
|
|
80
92
|
| `spec/legion/settings/role_defaults_spec.rb` | Role profile default settings tests |
|
|
81
93
|
| `spec/legion/settings/resolver_spec.rb` | Secret resolver tests (env://, vault://, lease://, fallback chains) |
|
|
82
94
|
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
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.
|
|
4
4
|
|
|
5
|
-
**Version**: 1.3.
|
|
5
|
+
**Version**: 1.3.5
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -162,7 +162,7 @@ module Legion
|
|
|
162
162
|
end
|
|
163
163
|
|
|
164
164
|
def load_file(file)
|
|
165
|
-
|
|
165
|
+
log_debug("Trying to load file #{file}")
|
|
166
166
|
if File.file?(file) && File.readable?(file)
|
|
167
167
|
begin
|
|
168
168
|
contents = read_config_file(file)
|
|
@@ -173,11 +173,11 @@ module Legion
|
|
|
173
173
|
# @indifferent_access = false
|
|
174
174
|
@loaded_files << file
|
|
175
175
|
rescue Legion::JSON::ParseError => e
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
log_error("config file must be valid json: #{file}")
|
|
177
|
+
log_error(" parse error: #{e.message}")
|
|
178
178
|
end
|
|
179
179
|
else
|
|
180
|
-
|
|
180
|
+
log_warn("Config file does not exist or is not readable file:#{file}")
|
|
181
181
|
end
|
|
182
182
|
end
|
|
183
183
|
|
|
@@ -199,7 +199,7 @@ module Legion
|
|
|
199
199
|
@settings[:client][:subscriptions].uniq!
|
|
200
200
|
@indifferent_access = false
|
|
201
201
|
else
|
|
202
|
-
|
|
202
|
+
log_warn('unable to apply legion client overrides, reason: client subscriptions is not an array')
|
|
203
203
|
end
|
|
204
204
|
end
|
|
205
205
|
|
|
@@ -226,7 +226,7 @@ module Legion
|
|
|
226
226
|
end
|
|
227
227
|
|
|
228
228
|
def load_dns_first_boot(bootstrap)
|
|
229
|
-
|
|
229
|
+
log_debug("DNS bootstrap: first boot, fetching from #{bootstrap.url}")
|
|
230
230
|
config = bootstrap.fetch
|
|
231
231
|
bootstrap.write_cache(config) if config
|
|
232
232
|
config
|
|
@@ -285,7 +285,7 @@ module Legion
|
|
|
285
285
|
|
|
286
286
|
@settings[:api] ||= {}
|
|
287
287
|
@settings[:api][:port] = ENV['LEGION_API_PORT'].to_i
|
|
288
|
-
|
|
288
|
+
log_warn("using api port environment variable, api: #{@settings[:api]}")
|
|
289
289
|
@indifferent_access = false
|
|
290
290
|
end
|
|
291
291
|
|
|
@@ -355,18 +355,30 @@ module Legion
|
|
|
355
355
|
'unknown'
|
|
356
356
|
end
|
|
357
357
|
|
|
358
|
+
def log_debug(message)
|
|
359
|
+
Legion::Logging.debug(message) if defined?(Legion::Logging)
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
def log_warn(message)
|
|
363
|
+
defined?(Legion::Logging) ? Legion::Logging.warn(message) : warn(message)
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
def log_error(message)
|
|
367
|
+
defined?(Legion::Logging) ? Legion::Logging.error(message) : warn(message)
|
|
368
|
+
end
|
|
369
|
+
|
|
358
370
|
def warning(message, data = {})
|
|
359
371
|
@warnings << {
|
|
360
372
|
message: message
|
|
361
373
|
}.merge(data)
|
|
362
|
-
|
|
374
|
+
log_warn(message)
|
|
363
375
|
end
|
|
364
376
|
|
|
365
377
|
def load_error(message, data = {})
|
|
366
378
|
@errors << {
|
|
367
379
|
message: message
|
|
368
380
|
}.merge(data)
|
|
369
|
-
|
|
381
|
+
log_error(message)
|
|
370
382
|
raise(Error, message)
|
|
371
383
|
end
|
|
372
384
|
|