Class: PDK::Validate::YAML::YAMLSyntaxValidator
Constant Summary
collapse
- YAML_ALLOWLISTED_CLASSES =
[Symbol].freeze
Instance Attribute Summary
Attributes inherited from Validator
#context, #options, #prepared
Instance Method Summary
collapse
#before_validation, #invoke, #prepare_invoke!
#allow_empty_targets?, #fnmatch?, #ignore_dotfiles?, #invoke_style, #parse_targets, #pattern_ignore, #prepare_invoke!, #process_invalid, #process_skipped, #spinner, #valid_in_context?
Methods inherited from Validator
#initialize, #invoke, #prepare_invoke!, #spinner, #spinners_enabled?, #start_spinner, #stop_spinner, #valid_in_context?
Instance Method Details
#ignore_dotfiles ⇒ Object
9
10
11
|
# File 'lib/pdk/validate/yaml/yaml_syntax_validator.rb', line 9
def ignore_dotfiles
false
end
|
#name ⇒ Object
13
14
15
|
# File 'lib/pdk/validate/yaml/yaml_syntax_validator.rb', line 13
def name
'yaml-syntax'
end
|
#pattern ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/pdk/validate/yaml/yaml_syntax_validator.rb', line 17
def pattern
[
'**/*.yaml',
'**/*.yml'
].tap do |pat|
if context.is_a?(PDK::Context::ControlRepo)
pat.push(
'**/*.eyaml',
'**/*.eyml'
)
else
pat
end
end
end
|
#spinner_text ⇒ Object
33
34
35
|
# File 'lib/pdk/validate/yaml/yaml_syntax_validator.rb', line 33
def spinner_text
format('Checking YAML syntax (%{patterns}).', patterns: pattern.join(' '))
end
|
#validate_target(report, target) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/pdk/validate/yaml/yaml_syntax_validator.rb', line 37
def validate_target(report, target)
return 0 unless PDK::Util::Filesystem.file?(target)
unless PDK::Util::Filesystem.readable?(target)
report.add_event(
file: target,
source: name,
state: :failure,
severity: 'error',
message: 'Could not be read.'
)
return 1
end
begin
::YAML.safe_load(PDK::Util::Filesystem.read_file(target), permitted_classes: YAML_ALLOWLISTED_CLASSES, permitted_symbols: [], aliases: true)
report.add_event(
file: target,
source: name,
state: :passed,
severity: 'ok'
)
0
rescue Psych::SyntaxError => e
report.add_event(
file: target,
source: name,
state: :failure,
severity: 'error',
line: e.line,
column: e.column,
message: format('%{problem} %{context}', problem: e.problem, context: e.context)
)
1
rescue Psych::DisallowedClass => e
report.add_event(
file: target,
source: name,
state: :failure,
severity: 'error',
message: format('Unsupported class: %{message}', message: e.message)
)
1
end
end
|