Module: AbideDevUtils::Ppt
- Defined in:
- lib/abide_dev_utils/ppt.rb,
lib/abide_dev_utils/ppt/api.rb,
lib/abide_dev_utils/ppt/hiera.rb,
lib/abide_dev_utils/ppt/new_obj.rb,
lib/abide_dev_utils/ppt/strings.rb,
lib/abide_dev_utils/ppt/code_gen.rb,
lib/abide_dev_utils/ppt/class_utils.rb,
lib/abide_dev_utils/ppt/facter_utils.rb,
lib/abide_dev_utils/ppt/score_module.rb,
lib/abide_dev_utils/ppt/puppet_module.rb,
lib/abide_dev_utils/ppt/code_gen/generate.rb,
lib/abide_dev_utils/ppt/code_gen/resource.rb,
lib/abide_dev_utils/ppt/code_introspection.rb,
lib/abide_dev_utils/ppt/code_gen/data_types.rb,
lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb,
lib/abide_dev_utils/ppt/code_gen/resource_types/class.rb,
lib/abide_dev_utils/ppt/code_gen/resource_types/strings.rb,
lib/abide_dev_utils/ppt/code_gen/resource_types/manifest.rb,
lib/abide_dev_utils/ppt/code_gen/resource_types/parameter.rb
Defined Under Namespace
Modules: ClassUtils, CodeGen, CodeIntrospection, FacterUtils, Hiera
Classes: ApiClient, NewObjectBuilder, PuppetModule, ScoreModule, Strings, YardObjectWrapper
Class Method Summary
collapse
-
.add_cis_comment(path, xccdf, number_format: false) ⇒ Object
-
.add_cis_comment_to_all(path, xccdf, number_format: false) ⇒ Object
-
.add_cis_comment_to_single(path, xccdf, number_format: false) ⇒ Object
-
.audit_class_names(dir, **kwargs) ⇒ Object
-
.build_new_object(type, name, opts) ⇒ Object
-
.cis_recommendation_comment(puppet_file, xccdf, number_format) ⇒ Object
-
.fix_class_names_class_rename(dir, **kwargs) ⇒ Object
-
.fix_class_names_file_rename(dir, **kwargs) ⇒ Object
-
.rename_puppet_class(from, to, **kwargs) ⇒ Object
Renames a Puppet class by renaming the class declaration and class file.
-
.score_module(module_path, outfile: nil, quiet: false, checks: ['all'], **_) ⇒ Object
-
.write_cis_comment_to_file(path, comment) ⇒ Object
Class Method Details
82
83
84
85
86
87
88
89
90
|
# File 'lib/abide_dev_utils/ppt.rb', line 82
def self.(path, xccdf, number_format: false)
require 'abide_dev_utils/xccdf'
parsed_xccdf = AbideDevUtils::XCCDF::Benchmark.new(xccdf)
return (path, parsed_xccdf, number_format: number_format) if File.directory?(path)
return (path, parsed_xccdf, number_format: number_format) if File.file?(path)
raise AbideDevUtils::Errors::FileNotFoundError, path
end
|
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/abide_dev_utils/ppt.rb', line 103
def self.(path, xccdf, number_format: false)
= {}
Dir[File.join(path, '*.pp')].each do |puppet_file|
= (puppet_file, xccdf, number_format)
[puppet_file] = unless .nil?
end
.each do |key, value|
(key, value)
end
AbideDevUtils::Output.simple('Successfully added comments.')
end
|
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/abide_dev_utils/ppt.rb', line 92
def self.(path, xccdf, number_format: false)
(
path,
(
path,
xccdf,
number_format
)
)
end
|
.audit_class_names(dir, **kwargs) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/abide_dev_utils/ppt.rb', line 33
def self.audit_class_names(dir, **kwargs)
mismatched = ClassUtils.find_all_mismatched_class_declarations(dir)
outfile = kwargs.key?(:file) ? File.open(kwargs[:file], 'a') : nil
quiet = kwargs.fetch(:quiet, false)
mismatched.each do |class_file|
AbideDevUtils::Output.simple("Mismatched class name in file #{class_file}") unless quiet
outfile << "MISMATCHED_CLASS_NAME: #{class_file}\n" unless outfile.nil?
end
outfile&.close
AbideDevUtils::Output.simple("Found #{mismatched.length} mismatched classes in #{dir}.") unless quiet
ensure
outfile&.close
end
|
.build_new_object(type, name, opts) ⇒ Object
72
73
74
75
76
77
78
79
80
|
# File 'lib/abide_dev_utils/ppt.rb', line 72
def self.build_new_object(type, name, opts)
require 'abide_dev_utils/ppt/new_obj'
AbideDevUtils::Ppt::NewObjectBuilder.new(
type,
name,
opts: opts,
vars: opts.fetch(:vars, '').split(',').map { |i| i.split('=') }.to_h ).build
end
|
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/abide_dev_utils/ppt.rb', line 136
def self.(puppet_file, xccdf, number_format)
_, control = xccdf.find_cis_recommendation(
File.basename(puppet_file, '.pp'),
number_format: number_format
)
if control.nil?
AbideDevUtils::Output.simple("Could not find recommendation text for #{puppet_file}...")
return nil
end
control_title = xccdf.resolve_control_reference(control).xpath('./xccdf:title').text
"# #{control_title}"
end
|
.fix_class_names_class_rename(dir, **kwargs) ⇒ Object
.fix_class_names_file_rename(dir, **kwargs) ⇒ Object
.rename_puppet_class(from, to, **kwargs) ⇒ Object
Renames a Puppet class by renaming the class declaration and class file
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/abide_dev_utils/ppt.rb', line 19
def self.rename_puppet_class(from, to, **kwargs)
from_path = ClassUtils.path_from_class_name(from)
to_path = ClassUtils.path_from_class_name(to)
file_path = kwargs.fetch(:declaration_in_to_file, false) ? to_path : from_path
raise ClassFileNotFoundError, "Path:#{file_path}" if !File.file?(file_path) && kwargs.fetch(:validate_path, true)
rename_puppet_class_declaration(from, to, file_path, **kwargs)
AbideDevUtils::Output.simple("Renamed #{from} to #{to} at #{file_path}.")
return unless kwargs.fetch(:declaration_only, false)
rename_class_file(from_path, to_path, **kwargs)
AbideDevUtils::Output.simple("Renamed file #{from_path} to #{to_path}.")
end
|
.score_module(module_path, outfile: nil, quiet: false, checks: ['all'], **_) ⇒ Object
149
150
151
152
153
154
|
# File 'lib/abide_dev_utils/ppt.rb', line 149
def self.score_module(module_path, outfile: nil, quiet: false, checks: ['all'], **_)
AbideDevUtils::Output.simple 'This command is not currently implemented'
end
|
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/abide_dev_utils/ppt.rb', line 115
def self.(path, )
require 'tempfile'
tempfile = Tempfile.new
begin
File.open(tempfile, 'w') do |nf|
nf.write("#{}\n")
File.foreach(path) do |line|
nf.write(line) unless line == "#{}\n"
end
end
File.rename(path, "#{path}.old")
tempfile.close
File.rename(tempfile.path, path)
File.delete("#{path}.old")
AbideDevUtils::Output.simple("Added CIS recomendation comment to #{path}...")
ensure
tempfile.close
tempfile.unlink
end
end
|