abide_dev_utils 0.5.2 → 0.6.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/abide_dev_utils.gemspec +2 -1
- data/lib/abide_dev_utils/cli/comply.rb +22 -20
- data/lib/abide_dev_utils/cli/puppet.rb +118 -11
- data/lib/abide_dev_utils/comply.rb +410 -99
- data/lib/abide_dev_utils/errors/comply.rb +13 -0
- data/lib/abide_dev_utils/errors/gcloud.rb +27 -0
- data/lib/abide_dev_utils/errors/ppt.rb +12 -0
- data/lib/abide_dev_utils/errors.rb +2 -0
- data/lib/abide_dev_utils/gcloud.rb +21 -0
- data/lib/abide_dev_utils/mixins.rb +16 -0
- data/lib/abide_dev_utils/ppt/class_utils.rb +184 -0
- data/lib/abide_dev_utils/ppt/coverage.rb +2 -3
- data/lib/abide_dev_utils/ppt.rb +135 -49
- data/lib/abide_dev_utils/version.rb +1 -1
- data/lib/abide_dev_utils/xccdf/cis/hiera.rb +67 -64
- data/lib/abide_dev_utils/xccdf/utils.rb +85 -0
- data/lib/abide_dev_utils/xccdf.rb +5 -0
- data/lib/abide_dev_utils.rb +1 -0
- metadata +24 -5
- data/lib/abide_dev_utils/utils/general.rb +0 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cf0d6affedd8f13f06af7f1f0db11666b9df2707d87a7685a4bd39ecd3e1519d
|
|
4
|
+
data.tar.gz: 0f20af443ff1e13f9e854daa5e7cf5ec45213dfe9a2f0390c250dac92a8cc8d3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '097e88fb6b19170c2b727fd8873fa3dbb766ace25a7538ab8cfbd0a35083cb11654b58fb7f45ee7130d7c4f4cb48b8b241de4849b0cb406de8f7eb62cf09ce68'
|
|
7
|
+
data.tar.gz: 4c0bc197da434b0ee25c9854b4b2af98a6ad9600733b734f9be21022ce312d7e8f0aea4f27c2217c3f56f7d2df26fedfe228f80b60fcd04da4ec08877a86bc54
|
data/abide_dev_utils.gemspec
CHANGED
|
@@ -34,10 +34,11 @@ Gem::Specification.new do |spec|
|
|
|
34
34
|
# Prod dependencies
|
|
35
35
|
spec.add_dependency 'nokogiri', '~> 1.11'
|
|
36
36
|
spec.add_dependency 'cmdparse', '~> 3.0'
|
|
37
|
-
spec.add_dependency 'puppet', '>= 6.
|
|
37
|
+
spec.add_dependency 'puppet', '>= 6.23'
|
|
38
38
|
spec.add_dependency 'jira-ruby', '~> 2.1'
|
|
39
39
|
spec.add_dependency 'ruby-progressbar', '~> 1.11'
|
|
40
40
|
spec.add_dependency 'selenium-webdriver', '~> 4.0.0.beta4'
|
|
41
|
+
spec.add_dependency 'google-cloud-storage', '~> 1.34'
|
|
41
42
|
|
|
42
43
|
# Dev dependencies
|
|
43
44
|
spec.add_development_dependency 'bundler'
|
|
@@ -28,6 +28,10 @@ module Abide
|
|
|
28
28
|
LONGCMD
|
|
29
29
|
CMD_COMPLY_URL = 'The URL (including https://) of Puppet Comply'
|
|
30
30
|
CMD_COMPLY_PASSWORD = 'The password for Puppet Comply'
|
|
31
|
+
OPT_TIMEOUT_DESC = <<~EOTO
|
|
32
|
+
The number of seconds you would like requests to wait before timing out. Defaults
|
|
33
|
+
to 10 seconds.
|
|
34
|
+
EOTO
|
|
31
35
|
OPT_STATUS_DESC = <<~EODESC
|
|
32
36
|
A comma-separated list of check statuses to ONLY include in the report.
|
|
33
37
|
Valid statuses are: pass, fail, error, notapplicable, notchecked, unknown, informational
|
|
@@ -50,19 +54,26 @@ module Abide
|
|
|
50
54
|
options.on('-u [USERNAME]', '--username [USERNAME]', 'The username for Comply (defaults to comply)') do |u|
|
|
51
55
|
@data[:username] = u
|
|
52
56
|
end
|
|
53
|
-
options.on('-
|
|
54
|
-
|
|
55
|
-
status_array&.map! { |i| i == 'notchecked' ? 'not checked' : i }
|
|
56
|
-
@data[:status] = status_array
|
|
57
|
+
options.on('-t [SECONDS]', '--timeout [SECONDS]', OPT_TIMEOUT_DESC) do |t|
|
|
58
|
+
@data[:timeout] = t
|
|
57
59
|
end
|
|
58
|
-
options.on('-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
options.on('-s x,y,z', '--status x,y,x',
|
|
61
|
+
%w[pass fail error notapplicable notchecked unknown informational],
|
|
62
|
+
Array,
|
|
63
|
+
OPT_STATUS_DESC) do |s|
|
|
64
|
+
s&.map! { |i| i == 'notchecked' ? 'not checked' : i }
|
|
65
|
+
@data[:status] = s
|
|
61
66
|
end
|
|
62
|
-
options.on('
|
|
63
|
-
|
|
64
|
-
@data[:ignore] = ignore_array
|
|
67
|
+
options.on('--only x,y,z', Array, OPT_ONLY_NODES) do |o|
|
|
68
|
+
@data[:onlylist] = o
|
|
65
69
|
end
|
|
70
|
+
options.on('--ignore x,y,z', Array, OPT_IGNORE_NODES) do |i|
|
|
71
|
+
@data[:ignorelist] = i
|
|
72
|
+
end
|
|
73
|
+
# options.on('-R', '--[no-]regression-test', OPT_REGRESSION_TEST) do |r|
|
|
74
|
+
# @data[:regression] = r
|
|
75
|
+
# end
|
|
76
|
+
# options.on('--')
|
|
66
77
|
end
|
|
67
78
|
|
|
68
79
|
def help_arguments
|
|
@@ -79,16 +90,7 @@ module Abide
|
|
|
79
90
|
conf = config_section('comply')
|
|
80
91
|
comply_url = conf.fetch(:url) if comply_url.nil?
|
|
81
92
|
comply_password = comply_password.nil? ? conf.fetch(:password, Abide::CLI::PROMPT.password) : comply_password
|
|
82
|
-
|
|
83
|
-
status = @data.fetch(:status, nil).nil? ? conf.fetch(:status, nil) : @data[:status]
|
|
84
|
-
ignorelist = @data.fetch(:ignore, nil).nil? ? conf.fetch(:ignore, nil) : @data[:ignore]
|
|
85
|
-
onlylist = @data.fetch(:only, nil).nil? ? conf.fetch(:only, nil) : @data[:only]
|
|
86
|
-
report = AbideDevUtils::Comply.scan_report(comply_url,
|
|
87
|
-
comply_password,
|
|
88
|
-
username: username,
|
|
89
|
-
status: status,
|
|
90
|
-
ignorelist: ignorelist,
|
|
91
|
-
onlylist: onlylist)
|
|
93
|
+
report = AbideDevUtils::Comply.build_report(comply_url, comply_password, conf, **@data)
|
|
92
94
|
outfile = @data.fetch(:file, nil).nil? ? conf.fetch(:report_path, 'comply_scan_report.yaml') : @data[:file]
|
|
93
95
|
Abide::CLI::OUTPUT.yaml(report, file: outfile)
|
|
94
96
|
end
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'abide_dev_utils/cli/abstract'
|
|
4
|
+
require 'abide_dev_utils/output'
|
|
5
|
+
require 'abide_dev_utils/ppt'
|
|
4
6
|
|
|
5
7
|
module Abide
|
|
6
8
|
module CLI
|
|
@@ -12,6 +14,10 @@ module Abide
|
|
|
12
14
|
super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: true)
|
|
13
15
|
add_command(PuppetCoverageCommand.new)
|
|
14
16
|
add_command(PuppetNewCommand.new)
|
|
17
|
+
add_command(PuppetRenameCommand.new)
|
|
18
|
+
add_command(PuppetFixClassNamesCommand.new)
|
|
19
|
+
add_command(PuppetAuditClassNamesCommand.new)
|
|
20
|
+
add_command(PuppetAddCISCommentCommand.new)
|
|
15
21
|
end
|
|
16
22
|
end
|
|
17
23
|
|
|
@@ -38,12 +44,12 @@ module Abide
|
|
|
38
44
|
end
|
|
39
45
|
|
|
40
46
|
def execute(class_dir, hiera_file)
|
|
41
|
-
require 'abide_dev_utils/ppt'
|
|
47
|
+
require 'abide_dev_utils/ppt/coverage'
|
|
42
48
|
Abide::CLI::VALIDATE.directory(class_dir)
|
|
43
49
|
Abide::CLI::VALIDATE.file(hiera_file)
|
|
44
|
-
coverage = AbideDevUtils::Ppt
|
|
50
|
+
coverage = AbideDevUtils::Ppt.generate_coverage_report(class_dir, hiera_file, @data[:profile])
|
|
45
51
|
coverage.each do |k, v|
|
|
46
|
-
next if
|
|
52
|
+
next if k.match?(/classes|benchmark/)
|
|
47
53
|
|
|
48
54
|
Abide::CLI::OUTPUT.simple("#{k} coverage: #{v[:coverage]}%")
|
|
49
55
|
end
|
|
@@ -100,14 +106,115 @@ module Abide
|
|
|
100
106
|
end
|
|
101
107
|
|
|
102
108
|
def execute(type, name)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
AbideDevUtils::Ppt.build_new_object(type, name, @data)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
class PuppetRenameCommand < AbideCommand
|
|
114
|
+
CMD_NAME = 'rename'
|
|
115
|
+
CMD_SHORT = 'Renames a Puppet class'
|
|
116
|
+
CMD_LONG = 'Renames a Puppet class. It does this by renaming the file and also the class name in the file. This command can also move class files based on the new class name.'
|
|
117
|
+
CMD_FROM_ARG = 'The current full class name'
|
|
118
|
+
CMD_TO_ARG = 'The new full class name'
|
|
119
|
+
def initialize
|
|
120
|
+
super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: false)
|
|
121
|
+
argument_desc(FROM: CMD_FROM_ARG, TO: CMD_TO_ARG)
|
|
122
|
+
options.on(
|
|
123
|
+
'-d',
|
|
124
|
+
'--declaration-only',
|
|
125
|
+
'Will not rename the class file, only the class declaration in the file'
|
|
126
|
+
) { @data[:declaration_only] = true }
|
|
127
|
+
options.on(
|
|
128
|
+
'-t',
|
|
129
|
+
'--declaration-in-to-file',
|
|
130
|
+
'Use the path derived from the TO class name as the existing file path when renaming class declaration'
|
|
131
|
+
) { @data[:declaration_in_to_file] = true }
|
|
132
|
+
options.on(
|
|
133
|
+
'-f',
|
|
134
|
+
'--force',
|
|
135
|
+
'Forces file move operations'
|
|
136
|
+
) { @data[:force] = true }
|
|
137
|
+
options.on(
|
|
138
|
+
'-v',
|
|
139
|
+
'--verbose',
|
|
140
|
+
'Sets verbose mode on file operations'
|
|
141
|
+
) { @data[:verbose] = true }
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def execute(from, to)
|
|
145
|
+
AbideDevUtils::Ppt.rename_puppet_class(from, to, **@data)
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
class PuppetFixClassNamesCommand < AbideCommand
|
|
150
|
+
CMD_NAME = 'fix-class-names'
|
|
151
|
+
CMD_SHORT = 'Fixes Puppet class names that are mismatched'
|
|
152
|
+
CMD_LONG = 'Fixes Puppet class names that are mismatched'
|
|
153
|
+
CMD_MODE_ARG = '"file" or "class". If "file", the file names will be changed to match their class declarations. If "class", the class declarations will be changed to match the file names.'
|
|
154
|
+
CMD_DIR_ARG = 'The directory containing the Puppet class files'
|
|
155
|
+
def initialize
|
|
156
|
+
super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: false)
|
|
157
|
+
argument_desc(MODE: CMD_MODE_ARG, DIR: CMD_DIR_ARG)
|
|
158
|
+
options.on(
|
|
159
|
+
'-f',
|
|
160
|
+
'--force',
|
|
161
|
+
'Forces file move operations'
|
|
162
|
+
) { @data[:force] = true }
|
|
163
|
+
options.on(
|
|
164
|
+
'-v',
|
|
165
|
+
'--verbose',
|
|
166
|
+
'Sets verbose mode on file operations'
|
|
167
|
+
) { @data[:verbose] = true }
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def execute(mode, dir)
|
|
171
|
+
case mode
|
|
172
|
+
when /^f.*/
|
|
173
|
+
AbideDevUtils::Ppt.fix_class_names_file_rename(dir, **@data)
|
|
174
|
+
when /^c.*/
|
|
175
|
+
AbideDevUtils::Ppt.fix_class_names_class_rename(dir, **@data)
|
|
176
|
+
else
|
|
177
|
+
raise ::ArgumentError, "Invalid mode. Mode:#{mode}"
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
class PuppetAuditClassNamesCommand < AbideCommand
|
|
183
|
+
CMD_NAME = 'audit-class-names'
|
|
184
|
+
CMD_SHORT = 'Finds Puppet classes in a directory that have names that do not match their path'
|
|
185
|
+
CMD_LONG = 'Finds Puppet classes in a directory that have names that do not match their path. This is helpful because class names that do not match their path structure break Puppet autoloading.'
|
|
186
|
+
CMD_DIR_ARG = 'The directory containing the Puppet class files'
|
|
187
|
+
def initialize
|
|
188
|
+
super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: false)
|
|
189
|
+
argument_desc(DIR: CMD_DIR_ARG)
|
|
190
|
+
options.on('-o [FILE]', '--out-file [FILE]', 'Save results to a file') { |f| @data[:file] = f }
|
|
191
|
+
options.on('-q', '--quiet', 'Do not print results to console') { @data[:quiet] = true }
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def execute(dir)
|
|
195
|
+
if @data.fetch(:quiet, false) && !@data.key?(:file)
|
|
196
|
+
AbideDevUtils::Output.simple('ERROR: Specifying --quiet without --out-file is useless.', stream: $stderr)
|
|
197
|
+
exit 1
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
AbideDevUtils::Ppt.audit_class_names(dir, **@data)
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
class PuppetAddCISCommentCommand < AbideCommand
|
|
205
|
+
CMD_NAME = 'add-cis-comment'
|
|
206
|
+
CMD_SHORT = 'Adds the CIS recommendation name to the top of a .pp file'
|
|
207
|
+
CMD_LONG = 'Adds the CIS recommendation name to the top of a .pp file. Finds CIS recommendation by pattern-matching the class name against XCCDF recommendations.'
|
|
208
|
+
CMD_PATH_ARG = 'Path to a .pp file or to a directory containing .pp files'
|
|
209
|
+
CMD_XCCDF_ARG = 'Path to XCCDF file to source recommendation names from'
|
|
210
|
+
def initialize
|
|
211
|
+
super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: false)
|
|
212
|
+
argument_desc(PATH: CMD_PATH_ARG, XCCDF: CMD_XCCDF_ARG)
|
|
213
|
+
options.on('-N', '--number-format', 'Matches based on number-formatted control class names') { @data[:number_format] = true }
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def execute(path, xccdf)
|
|
217
|
+
AbideDevUtils::Ppt.add_cis_comment(path, xccdf, number_format: @data.fetch(:number_format, false))
|
|
111
218
|
end
|
|
112
219
|
end
|
|
113
220
|
end
|