zfs_mgmt 0.9.0 → 0.9.1
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/Gemfile +1 -0
- data/Gemfile.lock +10 -1
- data/README.md +1 -1
- data/lib/zfs_mgmt/config.rb +46 -121
- data/lib/zfs_mgmt/version.rb +1 -1
- data/zfs_mgmt.gemspec +1 -0
- metadata +15 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7f749dcb4793693a2431f9ce155410b7e1e13881d058cbc0f523d6fbd9266972
|
|
4
|
+
data.tar.gz: e634a5cb121db940f4cfeef64654bef91d0f9255ebecf250cfff0e2386fd09c7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0acd6349727e7694779bd1d0a0f1f125359b50f450399ae6902e861b7f96737f025ea93f0af8c5fbeba78b498dc1543eb5828ef6f3e2a075a10d306e0f6a1bc3
|
|
7
|
+
data.tar.gz: 62fe25c5e62a9d6097513b3b892f1830552058bdb6440c8fd541661a9b745d8425ee0d742bc7958359c4f677cb26e50b5ad8b64b724163c916b0a7402ef2fe8d
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
zfs_mgmt (0.9.
|
|
4
|
+
zfs_mgmt (0.9.1)
|
|
5
5
|
deep_merge
|
|
6
6
|
easy_talk
|
|
7
7
|
filesize (~> 0.2)
|
|
8
|
+
json_schemer (~> 2.0)
|
|
8
9
|
pstore
|
|
9
10
|
text-table (~> 1.2)
|
|
10
11
|
thor (~> 1.0)
|
|
@@ -43,6 +44,7 @@ GEM
|
|
|
43
44
|
js_regex (~> 3.0)
|
|
44
45
|
sorbet-runtime (~> 0.5)
|
|
45
46
|
filesize (0.2.0)
|
|
47
|
+
hana (1.3.7)
|
|
46
48
|
i18n (1.15.2)
|
|
47
49
|
concurrent-ruby (~> 1.0)
|
|
48
50
|
js_regex (3.15.0)
|
|
@@ -50,6 +52,11 @@ GEM
|
|
|
50
52
|
regexp_parser (~> 2.11)
|
|
51
53
|
regexp_property_values (~> 1.0)
|
|
52
54
|
json (3.2.0)
|
|
55
|
+
json_schemer (2.5.0)
|
|
56
|
+
bigdecimal
|
|
57
|
+
hana (~> 1.3)
|
|
58
|
+
regexp_parser (~> 2.0)
|
|
59
|
+
simpleidn (~> 0.2)
|
|
53
60
|
language_server-protocol (3.17.0.6)
|
|
54
61
|
logger (1.7.0)
|
|
55
62
|
minitest (6.1.0)
|
|
@@ -88,6 +95,7 @@ GEM
|
|
|
88
95
|
simplecov_json_formatter (~> 0.1)
|
|
89
96
|
simplecov-html (0.13.2)
|
|
90
97
|
simplecov_json_formatter (0.1.4)
|
|
98
|
+
simpleidn (0.3.0)
|
|
91
99
|
sorbet-runtime (0.6.13724)
|
|
92
100
|
text-table (1.2.4)
|
|
93
101
|
thor (1.5.0)
|
|
@@ -107,6 +115,7 @@ DEPENDENCIES
|
|
|
107
115
|
easy_talk
|
|
108
116
|
filesize
|
|
109
117
|
json
|
|
118
|
+
json_schemer
|
|
110
119
|
pstore
|
|
111
120
|
rake (>= 12.3.3)
|
|
112
121
|
rspec (~> 3.0)
|
data/README.md
CHANGED
|
@@ -218,7 +218,7 @@ The schema file is also bundled inside the `zfs_mgmt` gem so tools like `taplo`
|
|
|
218
218
|
|
|
219
219
|
### Validation
|
|
220
220
|
|
|
221
|
-
Validate one or more TOML configuration files (or all `*.toml` files in the active configuration directory) with `zfsmgr config validate`:
|
|
221
|
+
Validate one or more TOML configuration files (or all `*.toml` files in the active configuration directory) against both TOML syntax and the JSON Schema (`schema/config.schema.json`, rejecting unknown keys and type/value mismatches) with `zfsmgr config validate`:
|
|
222
222
|
|
|
223
223
|
$ zfsmgr config validate /etc/zfsmgr/50-puppet.toml
|
|
224
224
|
$ zfsmgr config validate --all
|
data/lib/zfs_mgmt/config.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
require 'easy_talk'
|
|
3
|
+
require 'json_schemer'
|
|
3
4
|
require 'tomlrb'
|
|
4
5
|
require 'deep_merge/core'
|
|
5
6
|
require 'json'
|
|
@@ -33,15 +34,11 @@ module ZfsMgmt
|
|
|
33
34
|
description: 'Per-dataset ZFS configuration keyed by dataset name'
|
|
34
35
|
end
|
|
35
36
|
|
|
36
|
-
validate :
|
|
37
|
-
validate :validate_overrides
|
|
38
|
-
validate :validate_ssh_config
|
|
39
|
-
validate :validate_mbuffer
|
|
40
|
-
validate :validate_mbuffer_size
|
|
41
|
-
validate :validate_zfs_entries
|
|
37
|
+
validate :validate_with_json_schemer
|
|
42
38
|
|
|
43
39
|
def initialize(attributes = {})
|
|
44
40
|
@raw_zfs = {}
|
|
41
|
+
@raw_attributes = normalize_raw_attributes(attributes || {})
|
|
45
42
|
raw_attrs = (attributes || {}).each_with_object({}) { |(k, v), h| h[k.to_s] = v }
|
|
46
43
|
|
|
47
44
|
raw_attrs.each_key do |k|
|
|
@@ -337,8 +334,51 @@ module ZfsMgmt
|
|
|
337
334
|
{ path: path, valid: false, error: e.message }
|
|
338
335
|
end
|
|
339
336
|
|
|
337
|
+
def self.json_schemer
|
|
338
|
+
@json_schemer ||= JSONSchemer.schema(config_json_schema, regexp_resolver: 'ecma')
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
def self.validate_schema(data)
|
|
342
|
+
json_schemer.validate(data).map { |err| err['error'] || JSONSchemer::Errors.pretty(err) }
|
|
343
|
+
end
|
|
344
|
+
|
|
340
345
|
private
|
|
341
346
|
|
|
347
|
+
def normalize_raw_attributes(value)
|
|
348
|
+
case value
|
|
349
|
+
when Hash
|
|
350
|
+
value.each_with_object({}) { |(k, v), h| h[k.to_s] = normalize_raw_attributes(v) }
|
|
351
|
+
when Array
|
|
352
|
+
value.map { |v| normalize_raw_attributes(v) }
|
|
353
|
+
when ZfsMgmt::Zfs
|
|
354
|
+
extract_raw_from_model(value)
|
|
355
|
+
else
|
|
356
|
+
value
|
|
357
|
+
end
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
def validate_with_json_schemer
|
|
361
|
+
unless @raw_attributes.is_a?(Hash)
|
|
362
|
+
errors.add(:base, 'expected top-level table')
|
|
363
|
+
return
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
self.class.json_schemer.validate(@raw_attributes).each do |err|
|
|
367
|
+
pointer = err['data_pointer'].to_s
|
|
368
|
+
segments = pointer.sub(/\A\//, '').split('/').map { |s| s.gsub('~1', '/').gsub('~0', '~') }
|
|
369
|
+
top_key = segments.first
|
|
370
|
+
message = err['error'] || JSONSchemer::Errors.pretty(err)
|
|
371
|
+
|
|
372
|
+
if top_key == 'zfs' && segments[1]
|
|
373
|
+
errors.add(:zfs, "#{segments[1]}: #{message}")
|
|
374
|
+
elsif TOP_LEVEL_KEYS.include?(top_key)
|
|
375
|
+
errors.add(top_key.to_sym, message)
|
|
376
|
+
else
|
|
377
|
+
errors.add(:base, message)
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
end
|
|
381
|
+
|
|
342
382
|
def zfs_hash_layers_for(dataset_name, key)
|
|
343
383
|
layers = []
|
|
344
384
|
dataset_ancestors(dataset_name).each do |ancestor|
|
|
@@ -416,120 +456,5 @@ module ZfsMgmt
|
|
|
416
456
|
raw['source'] = model.source_base if model.source_base
|
|
417
457
|
raw
|
|
418
458
|
end
|
|
419
|
-
|
|
420
|
-
def validate_excludes
|
|
421
|
-
unless excludes.is_a?(Array) && excludes.all? { |item| item.is_a?(String) }
|
|
422
|
-
errors.add(:excludes, 'must be an array of strings')
|
|
423
|
-
end
|
|
424
|
-
end
|
|
425
|
-
|
|
426
|
-
def validate_overrides
|
|
427
|
-
validate_top_level_hash(:overrides, overrides, 'hash of property=value pairs')
|
|
428
|
-
end
|
|
429
|
-
|
|
430
|
-
def validate_ssh_config
|
|
431
|
-
validate_top_level_hash(:ssh_config, ssh_config, 'hash of option=value pairs', table_hint: 'use [ssh_config], not [[ssh_config]]')
|
|
432
|
-
end
|
|
433
|
-
|
|
434
|
-
def validate_mbuffer
|
|
435
|
-
return if mbuffer.nil? || mbuffer == true || mbuffer == false
|
|
436
|
-
|
|
437
|
-
errors.add(:mbuffer, 'must be a boolean')
|
|
438
|
-
end
|
|
439
|
-
|
|
440
|
-
def validate_mbuffer_size
|
|
441
|
-
return if mbuffer_size.nil? || mbuffer_size.is_a?(String)
|
|
442
|
-
|
|
443
|
-
errors.add(:mbuffer_size, 'must be a string')
|
|
444
|
-
end
|
|
445
|
-
|
|
446
|
-
def validate_top_level_hash(attr, value, expected_desc, table_hint: nil)
|
|
447
|
-
if value.is_a?(Array) && table_hint
|
|
448
|
-
errors.add(attr, "must be a #{expected_desc} (#{table_hint})")
|
|
449
|
-
return
|
|
450
|
-
end
|
|
451
|
-
|
|
452
|
-
unless value.is_a?(Hash)
|
|
453
|
-
errors.add(attr, "must be a #{expected_desc}")
|
|
454
|
-
return
|
|
455
|
-
end
|
|
456
|
-
|
|
457
|
-
value.each do |k, v|
|
|
458
|
-
unless k.is_a?(String) && v.is_a?(String)
|
|
459
|
-
errors.add(attr, "#{k}: property and value must be strings")
|
|
460
|
-
end
|
|
461
|
-
end
|
|
462
|
-
end
|
|
463
|
-
|
|
464
|
-
def validate_zfs_entries
|
|
465
|
-
unless zfs.is_a?(Hash)
|
|
466
|
-
errors.add(:zfs, 'must be a hash keyed by dataset name')
|
|
467
|
-
return
|
|
468
|
-
end
|
|
469
|
-
|
|
470
|
-
zfs.each do |dataset_name, zfs_obj|
|
|
471
|
-
unless zfs_obj.is_a?(ZfsMgmt::Zfs)
|
|
472
|
-
if zfs_obj.is_a?(Array)
|
|
473
|
-
errors.add(:zfs, "#{dataset_name}: must be a Zfs configuration table (use [zfs.\"#{dataset_name}\"], not [[zfs.\"#{dataset_name}\"]])")
|
|
474
|
-
else
|
|
475
|
-
errors.add(:zfs, "#{dataset_name}: must be a Zfs configuration table")
|
|
476
|
-
end
|
|
477
|
-
next
|
|
478
|
-
end
|
|
479
|
-
raw_entry = @raw_zfs[dataset_name]
|
|
480
|
-
if raw_entry
|
|
481
|
-
if raw_entry.key?('destination')
|
|
482
|
-
raw_dest = raw_entry['destination']
|
|
483
|
-
valid_dest = raw_dest.is_a?(String) || (raw_dest.is_a?(Array) && raw_dest.all? { |item| item.is_a?(String) })
|
|
484
|
-
unless valid_dest
|
|
485
|
-
errors.add(:zfs, "#{dataset_name}: destination must be a string or an array of strings")
|
|
486
|
-
end
|
|
487
|
-
end
|
|
488
|
-
if raw_entry.key?('source') && !raw_entry['source'].is_a?(String)
|
|
489
|
-
errors.add(:zfs, "#{dataset_name}: source must be a string")
|
|
490
|
-
end
|
|
491
|
-
if raw_entry.key?('excludes')
|
|
492
|
-
raw_excl = raw_entry['excludes']
|
|
493
|
-
unless raw_excl.is_a?(Array) && raw_excl.all? { |item| item.is_a?(String) }
|
|
494
|
-
errors.add(:zfs, "#{dataset_name}: excludes must be an array of strings")
|
|
495
|
-
end
|
|
496
|
-
end
|
|
497
|
-
if raw_entry.key?('overrides')
|
|
498
|
-
validate_per_zfs_hash(dataset_name, 'overrides', raw_entry['overrides'], 'table of property=value pairs', 'hash of property=value pairs')
|
|
499
|
-
end
|
|
500
|
-
if raw_entry.key?('ssh_config')
|
|
501
|
-
validate_per_zfs_hash(dataset_name, 'ssh_config', raw_entry['ssh_config'], 'table of option=value pairs', 'hash of option=value pairs')
|
|
502
|
-
end
|
|
503
|
-
if raw_entry.key?('mbuffer')
|
|
504
|
-
raw_mbuffer = raw_entry['mbuffer']
|
|
505
|
-
unless raw_mbuffer == true || raw_mbuffer == false
|
|
506
|
-
errors.add(:zfs, "#{dataset_name}: mbuffer must be a boolean")
|
|
507
|
-
end
|
|
508
|
-
end
|
|
509
|
-
if raw_entry.key?('mbuffer_size')
|
|
510
|
-
unless raw_entry['mbuffer_size'].is_a?(String)
|
|
511
|
-
errors.add(:zfs, "#{dataset_name}: mbuffer_size must be a string")
|
|
512
|
-
end
|
|
513
|
-
end
|
|
514
|
-
end
|
|
515
|
-
unless zfs_obj.valid?
|
|
516
|
-
errors.add(:zfs, "#{dataset_name}: #{zfs_obj.errors.full_messages.join(', ')}")
|
|
517
|
-
end
|
|
518
|
-
end
|
|
519
|
-
end
|
|
520
|
-
|
|
521
|
-
def validate_per_zfs_hash(dataset_name, key, raw_val, table_desc, hash_desc)
|
|
522
|
-
if raw_val.is_a?(Array)
|
|
523
|
-
errors.add(:zfs, "#{dataset_name}: #{key} must be a #{table_desc} (use [zfs.\"#{dataset_name}\".#{key}], not [[zfs.\"#{dataset_name}\".#{key}]])")
|
|
524
|
-
elsif !raw_val.is_a?(Hash)
|
|
525
|
-
errors.add(:zfs, "#{dataset_name}: #{key} must be a #{hash_desc}")
|
|
526
|
-
else
|
|
527
|
-
raw_val.each do |k, v|
|
|
528
|
-
unless k.is_a?(String) && v.is_a?(String)
|
|
529
|
-
errors.add(:zfs, "#{dataset_name}: #{key}.#{k}: property and value must be strings")
|
|
530
|
-
end
|
|
531
|
-
end
|
|
532
|
-
end
|
|
533
|
-
end
|
|
534
459
|
end
|
|
535
460
|
end
|
data/lib/zfs_mgmt/version.rb
CHANGED
data/zfs_mgmt.gemspec
CHANGED
|
@@ -48,6 +48,7 @@ Gem::Specification.new do |spec|
|
|
|
48
48
|
spec.add_runtime_dependency "filesize", "~> 0.2"
|
|
49
49
|
spec.add_runtime_dependency "pstore"
|
|
50
50
|
spec.add_runtime_dependency "easy_talk"
|
|
51
|
+
spec.add_runtime_dependency "json_schemer", "~> 2.0"
|
|
51
52
|
spec.add_runtime_dependency "tomlrb"
|
|
52
53
|
spec.add_runtime_dependency "deep_merge"
|
|
53
54
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zfs_mgmt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.
|
|
4
|
+
version: 0.9.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aran Cox
|
|
@@ -135,6 +135,20 @@ dependencies:
|
|
|
135
135
|
- - ">="
|
|
136
136
|
- !ruby/object:Gem::Version
|
|
137
137
|
version: '0'
|
|
138
|
+
- !ruby/object:Gem::Dependency
|
|
139
|
+
name: json_schemer
|
|
140
|
+
requirement: !ruby/object:Gem::Requirement
|
|
141
|
+
requirements:
|
|
142
|
+
- - "~>"
|
|
143
|
+
- !ruby/object:Gem::Version
|
|
144
|
+
version: '2.0'
|
|
145
|
+
type: :runtime
|
|
146
|
+
prerelease: false
|
|
147
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
148
|
+
requirements:
|
|
149
|
+
- - "~>"
|
|
150
|
+
- !ruby/object:Gem::Version
|
|
151
|
+
version: '2.0'
|
|
138
152
|
- !ruby/object:Gem::Dependency
|
|
139
153
|
name: tomlrb
|
|
140
154
|
requirement: !ruby/object:Gem::Requirement
|