cfa 0.6.4 → 0.7.0
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/lib/cfa/augeas_parser.rb +94 -12
- data/lib/cfa/augeas_parser/keys_cache.rb +1 -0
- data/lib/cfa/augeas_parser/writer.rb +1 -0
- data/lib/cfa/matcher.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0256a5d406e5ed0a4bbedd2c59fe6ed3947b35286697301543285c8e588e1753
|
4
|
+
data.tar.gz: 0361b40d6ee2a3fc94a0f2218a2cec6c4c6c2c833942d62fe67513b65d776450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0b02d8195de9b6f72e347924253ad534b76de671f44f8c598f324ab1059473aa7f5039c0f1b16e5a2eb85651ed0fc51d162dd5c49cd4b0ff0efc3be6c5b66d3
|
7
|
+
data.tar.gz: d576b43dab99a7711f6012a4c270d53a409e5b7f2b9c7868dd9e31a87de6d616a0c4565e22970a1e481801b0572c8bbe1229b5f56d6f677d66419fa651da91df
|
data/lib/cfa/augeas_parser.rb
CHANGED
@@ -35,6 +35,66 @@ module CFA
|
|
35
35
|
class AugeasElement < Hash
|
36
36
|
end
|
37
37
|
|
38
|
+
# Error that is raised when augeas fail for some reason.
|
39
|
+
# Base class for more specialized exceptions.
|
40
|
+
class AugeasError < RuntimeError
|
41
|
+
end
|
42
|
+
|
43
|
+
# Error in augeas itself like broken lens
|
44
|
+
class AugeasInternalError < AugeasError
|
45
|
+
attr_reader :details
|
46
|
+
attr_reader :aug_message
|
47
|
+
|
48
|
+
def initialize(message, details)
|
49
|
+
@aug_message = message
|
50
|
+
@details = details
|
51
|
+
|
52
|
+
super("Augeas error: #{message}. Details: #{details}.")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Parsing error
|
57
|
+
class AugeasParsingError < AugeasError
|
58
|
+
attr_reader :aug_message
|
59
|
+
attr_reader :file
|
60
|
+
attr_reader :line
|
61
|
+
attr_reader :character
|
62
|
+
attr_reader :lens
|
63
|
+
attr_reader :file_content
|
64
|
+
|
65
|
+
def initialize(params)
|
66
|
+
@aug_message = params[:message]
|
67
|
+
@file = params[:file]
|
68
|
+
@line = params[:line]
|
69
|
+
@char = params[:char]
|
70
|
+
@lens = params[:lens]
|
71
|
+
@file_content = params[:file_content]
|
72
|
+
|
73
|
+
super("Augeas parsing error: #{@aug_message}" \
|
74
|
+
" at #{@file}:#{@line}:#{@char}, lens #{@lens}"
|
75
|
+
)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Serializing error
|
80
|
+
class AugeasSerializingError < AugeasError
|
81
|
+
attr_reader :aug_message
|
82
|
+
attr_reader :file
|
83
|
+
attr_reader :lens
|
84
|
+
attr_reader :aug_tree
|
85
|
+
|
86
|
+
def initialize(params)
|
87
|
+
@aug_message = params[:message]
|
88
|
+
@file = params[:file]
|
89
|
+
@lens = params[:lens]
|
90
|
+
@aug_tree = params[:aug_tree]
|
91
|
+
|
92
|
+
super("Augeas serializing error: #{@aug_message}" \
|
93
|
+
" for #{@file} with lens #{@lens}"
|
94
|
+
)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
38
98
|
# Represents list of same config options in augeas.
|
39
99
|
# For example comments are often stored in collections.
|
40
100
|
class AugeasCollection
|
@@ -168,6 +228,7 @@ module CFA
|
|
168
228
|
id = 1
|
169
229
|
loop do
|
170
230
|
return id.to_s unless ids.include?(id.to_s)
|
231
|
+
|
171
232
|
id += 1
|
172
233
|
end
|
173
234
|
end
|
@@ -180,6 +241,7 @@ module CFA
|
|
180
241
|
# @param [String, Matcher] matcher
|
181
242
|
def delete(matcher)
|
182
243
|
return if matcher.nil?
|
244
|
+
|
183
245
|
unless matcher.is_a?(CFA::Matcher)
|
184
246
|
matcher = CFA::Matcher.new(key: matcher)
|
185
247
|
end
|
@@ -236,6 +298,7 @@ module CFA
|
|
236
298
|
|
237
299
|
def ==(other)
|
238
300
|
return false if self.class != other.class
|
301
|
+
|
239
302
|
other_data = other.data # do not compute again
|
240
303
|
data.each_with_index do |entry, index|
|
241
304
|
other_entry = other_data[index]
|
@@ -329,7 +392,7 @@ module CFA
|
|
329
392
|
root = load_path = nil
|
330
393
|
Augeas.open(root, load_path, Augeas::NO_MODL_AUTOLOAD) do |aug|
|
331
394
|
aug.set("/input", raw_string)
|
332
|
-
report_error(aug,
|
395
|
+
report_error(aug, :parsing, file_name, raw_string) \
|
333
396
|
unless aug.text_store(@lens, "/input", "/store")
|
334
397
|
|
335
398
|
return AugeasReader.read(aug, "/store")
|
@@ -349,7 +412,7 @@ module CFA
|
|
349
412
|
AugeasWriter.new(aug).write("/store", data)
|
350
413
|
|
351
414
|
res = aug.text_retrieve(@lens, "/input", "/store", "/output")
|
352
|
-
report_error(aug,
|
415
|
+
report_error(aug, :serializing, file_name, data) unless res
|
353
416
|
|
354
417
|
return aug.get("/output")
|
355
418
|
end
|
@@ -364,19 +427,38 @@ module CFA
|
|
364
427
|
private
|
365
428
|
|
366
429
|
# @param aug [::Augeas]
|
367
|
-
# @param activity [
|
430
|
+
# @param activity [:parsing, :serializing] for better error messages
|
368
431
|
# @param file_name [String,nil] a file name
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
raise "Augeas error: #{error[:message]}. Details: #{error[:details]}."
|
374
|
-
end
|
432
|
+
# @param data [AugeasTree, String] used data so augeas tree for
|
433
|
+
# serializing or file content for parsing
|
434
|
+
def report_error(aug, activity, file_name, data = nil)
|
435
|
+
report_internal_error!(aug)
|
375
436
|
|
376
437
|
file_name ||= "(unknown file)"
|
377
|
-
|
378
|
-
|
379
|
-
|
438
|
+
args = aug_get_error(aug)
|
439
|
+
args[:file] = file_name
|
440
|
+
report_activity_error!(args, activity, data)
|
441
|
+
end
|
442
|
+
|
443
|
+
def report_internal_error!(aug)
|
444
|
+
error = aug.error
|
445
|
+
# zero is no error, so there's a problem in the lens
|
446
|
+
return if error[:code].zero?
|
447
|
+
|
448
|
+
raise AugeasInternalError.new(error[:message], error[:details])
|
449
|
+
end
|
450
|
+
|
451
|
+
def report_activity_error!(args, activity, data)
|
452
|
+
case activity
|
453
|
+
when :parsing
|
454
|
+
args[:file_content] = data
|
455
|
+
raise AugeasParsingError, args
|
456
|
+
when :serializing
|
457
|
+
args[:aug_tree] = data
|
458
|
+
raise AugeasSerializingError, args
|
459
|
+
else
|
460
|
+
raise ArgumentError, "invalid activity #{activity.inspect}"
|
461
|
+
end
|
380
462
|
end
|
381
463
|
|
382
464
|
def aug_get_error(aug)
|
data/lib/cfa/matcher.rb
CHANGED
@@ -43,6 +43,7 @@ module CFA
|
|
43
43
|
return false unless collection_match?(element, collection)
|
44
44
|
return false unless value_match?(element, value_matcher)
|
45
45
|
return false unless !block || yield(element[:key], element[:value])
|
46
|
+
|
46
47
|
return true
|
47
48
|
end
|
48
49
|
end
|
@@ -71,6 +72,7 @@ module CFA
|
|
71
72
|
when nil then true
|
72
73
|
when Regexp
|
73
74
|
return false unless element[:value].is_a?(String)
|
75
|
+
|
74
76
|
matcher =~ element[:value]
|
75
77
|
else
|
76
78
|
matcher == element[:value]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josef Reidinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-augeas
|