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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '03743386fed00b094d759cb20a53d25d807492fd98097564d140aa0cacfecce0'
4
- data.tar.gz: be8082a88120f30f2754f79194a818c7640fd5f104c0c57dc07cd84d8bbc460f
3
+ metadata.gz: cf0d6affedd8f13f06af7f1f0db11666b9df2707d87a7685a4bd39ecd3e1519d
4
+ data.tar.gz: 0f20af443ff1e13f9e854daa5e7cf5ec45213dfe9a2f0390c250dac92a8cc8d3
5
5
  SHA512:
6
- metadata.gz: 1bcd5add724cc85cc95915d778a6320de028b351ea19920b712efe228a4e01efdb36bb2840f5b566f5cf8a3d9ebe90236138fdd0bc0d83e90fbe1f4a0cf67763
7
- data.tar.gz: 91f71049317153abafaa32fd9bacdfbfa26b1ba2145ddd902238f6cbc8e31417540eee0812b67ecdb5b5b0c500f1b0ce02ee43b028c37ffb3d87753c75e1729e
6
+ metadata.gz: '097e88fb6b19170c2b727fd8873fa3dbb766ace25a7538ab8cfbd0a35083cb11654b58fb7f45ee7130d7c4f4cb48b8b241de4849b0cb406de8f7eb62cf09ce68'
7
+ data.tar.gz: 4c0bc197da434b0ee25c9854b4b2af98a6ad9600733b734f9be21022ce312d7e8f0aea4f27c2217c3f56f7d2df26fedfe228f80b60fcd04da4ec08877a86bc54
@@ -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.19'
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('-s [STATUS]', '--status [STATUS]', OPT_STATUS_DESC) do |s|
54
- status_array = s.nil? ? nil : s.split(',').map(&:downcase)
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('-O [CERTNAME]', '--only [CERTNAME]', OPT_ONLY_NODES) do |o|
59
- only_array = o.nil? ? nil : s.split(',').map(&:downcase)
60
- @data[:only] = only_array
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('-I [CERTNAME]', '--ignore [CERTNAME]', OPT_IGNORE_NODES) do |i|
63
- ignore_array = i.nil? ? nil : i.split(',').map(&:downcase)
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
- username = @data.fetch(:username, nil).nil? ? conf.fetch(:username, 'comply') : @data[:username]
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::CoverageReport.generate(class_dir, hiera_file, @data[:profile])
50
+ coverage = AbideDevUtils::Ppt.generate_coverage_report(class_dir, hiera_file, @data[:profile])
45
51
  coverage.each do |k, v|
46
- next if ['classes', 'benchmark'].include?(k)
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
- require 'abide_dev_utils/ppt/new_obj'
104
- builder = AbideDevUtils::Ppt::NewObjectBuilder.new(
105
- type,
106
- name,
107
- opts: @data,
108
- vars: @data.fetch(:vars, '').split(',').map { |i| i.split('=') }.to_h # makes the str a hash
109
- )
110
- builder.build
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