abide_dev_utils 0.5.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abide_dev_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
- - Heston Snodgrass
7
+ - abide-team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-10 00:00:00.000000000 Z
11
+ date: 2021-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '6.19'
47
+ version: '6.23'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '6.19'
54
+ version: '6.23'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: jira-ruby
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,34 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 4.0.0.beta4
97
+ - !ruby/object:Gem::Dependency
98
+ name: google-cloud-storage
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.34'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.34'
111
+ - !ruby/object:Gem::Dependency
112
+ name: hashdiff
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.0'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: bundler
99
127
  requirement: !ruby/object:Gem::Requirement
@@ -276,9 +304,10 @@ dependencies:
276
304
  - - "~>"
277
305
  - !ruby/object:Gem::Version
278
306
  version: '1.8'
279
- description: Provides a CLI with helpful utilities for developing Abide
307
+ description: Provides a CLI with helpful utilities for developing compliance Puppet
308
+ code
280
309
  email:
281
- - hsnodgrass3@gmail.com
310
+ - abide-team@puppet.com
282
311
  executables:
283
312
  - abide
284
313
  extensions: []
@@ -290,6 +319,7 @@ files:
290
319
  - ".rubocop.yml"
291
320
  - ".rubocop_todo.yml"
292
321
  - CHANGELOG.md
322
+ - CODEOWNERS
293
323
  - Dockerfile
294
324
  - Gemfile
295
325
  - LICENSE.txt
@@ -300,6 +330,7 @@ files:
300
330
  - bin/console
301
331
  - bin/setup
302
332
  - exe/abide
333
+ - itests.rb
303
334
  - lib/abide_dev_utils.rb
304
335
  - lib/abide_dev_utils/cli.rb
305
336
  - lib/abide_dev_utils/cli/abstract.rb
@@ -313,31 +344,35 @@ files:
313
344
  - lib/abide_dev_utils/constants.rb
314
345
  - lib/abide_dev_utils/errors.rb
315
346
  - lib/abide_dev_utils/errors/base.rb
347
+ - lib/abide_dev_utils/errors/comply.rb
348
+ - lib/abide_dev_utils/errors/gcloud.rb
316
349
  - lib/abide_dev_utils/errors/general.rb
317
350
  - lib/abide_dev_utils/errors/jira.rb
318
351
  - lib/abide_dev_utils/errors/ppt.rb
319
352
  - lib/abide_dev_utils/errors/xccdf.rb
320
353
  - lib/abide_dev_utils/files.rb
354
+ - lib/abide_dev_utils/gcloud.rb
321
355
  - lib/abide_dev_utils/jira.rb
356
+ - lib/abide_dev_utils/mixins.rb
322
357
  - lib/abide_dev_utils/output.rb
323
358
  - lib/abide_dev_utils/ppt.rb
359
+ - lib/abide_dev_utils/ppt/api.rb
360
+ - lib/abide_dev_utils/ppt/class_utils.rb
324
361
  - lib/abide_dev_utils/ppt/coverage.rb
325
362
  - lib/abide_dev_utils/ppt/new_obj.rb
363
+ - lib/abide_dev_utils/ppt/score_module.rb
326
364
  - lib/abide_dev_utils/prompt.rb
327
365
  - lib/abide_dev_utils/resources/generic_spec.erb
328
- - lib/abide_dev_utils/utils/general.rb
329
366
  - lib/abide_dev_utils/validate.rb
330
367
  - lib/abide_dev_utils/version.rb
331
368
  - lib/abide_dev_utils/xccdf.rb
332
- - lib/abide_dev_utils/xccdf/cis.rb
333
- - lib/abide_dev_utils/xccdf/cis/hiera.rb
334
- homepage: https://github.com/hsnodgrass/abide_dev_utils
369
+ homepage: https://github.com/puppetlabs/abide_dev_utils
335
370
  licenses:
336
371
  - MIT
337
372
  metadata:
338
- homepage_uri: https://github.com/hsnodgrass/abide_dev_utils
339
- source_code_uri: https://github.com/hsnodgrass/abide_dev_utils
340
- changelog_uri: https://github.com/hsnodgrass/abide_dev_utils
373
+ homepage_uri: https://github.com/puppetlabs/abide_dev_utils
374
+ source_code_uri: https://github.com/puppetlabs/abide_dev_utils
375
+ changelog_uri: https://github.com/puppetlabs/abide_dev_utils
341
376
  post_install_message:
342
377
  rdoc_options: []
343
378
  require_paths:
@@ -346,7 +381,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
346
381
  requirements:
347
382
  - - ">="
348
383
  - !ruby/object:Gem::Version
349
- version: 2.5.0
384
+ version: 2.7.0
350
385
  required_rubygems_version: !ruby/object:Gem::Requirement
351
386
  requirements:
352
387
  - - ">="
@@ -356,5 +391,5 @@ requirements: []
356
391
  rubygems_version: 3.1.4
357
392
  signing_key:
358
393
  specification_version: 4
359
- summary: Helper utilities for developing Abide
394
+ summary: Helper utilities for developing compliance Puppet code
360
395
  test_files: []
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AbideDevUtils
4
- module Utils
5
- def self.deep_copy(hash_obj)
6
- Marshal.load(Marshal.dump(hash_obj))
7
- end
8
- end
9
- end
@@ -1,163 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'yaml'
4
- require 'nokogiri'
5
- require 'abide_dev_utils/errors'
6
-
7
- module AbideDevUtils
8
- module XCCDF
9
- module CIS
10
- # Creates a Hiera structure by parsing a CIS XCCDF benchmark
11
- # @!attribute [r] title
12
- # @!attribute [r] version
13
- # @!attribute [r] yaml_title
14
- class Hiera
15
- CONTROL_PREFIX = /^[\d.]+_/.freeze
16
- UNDERSCORED = /(\s|\(|\)|-|\.)/.freeze
17
- XPATHS = {
18
- benchmark: {
19
- all: 'xccdf:Benchmark',
20
- title: 'xccdf:Benchmark/xccdf:title',
21
- version: 'xccdf:Benchmark/xccdf:version'
22
- },
23
- profiles: {
24
- all: 'xccdf:Benchmark/xccdf:Profile',
25
- relative_title: './xccdf:title',
26
- relative_select: './xccdf:select'
27
- }
28
- }.freeze
29
- NEXT_GEN_WINDOWS = /(next_generation_windows_security)/.freeze
30
-
31
- attr_reader :title, :version
32
-
33
- # Creates a new Hiera object
34
- # @param xccdf_file [String] path to an XCCDF file
35
- # @param parent_key_prefix [String] a string to be prepended to the
36
- # top-level key in the Hiera structure. Useful for namespacing
37
- # the top-level key.
38
- def initialize(xccdf_file, parent_key_prefix: nil, num: false)
39
- @doc = parse(xccdf_file)
40
- @title = xpath(XPATHS[:benchmark][:title]).children.to_s
41
- @version = xpath(XPATHS[:benchmark][:version]).children.to_s
42
- @profiles = xpath(XPATHS[:profiles][:all])
43
- @parent_key = make_parent_key(@doc, parent_key_prefix)
44
- @hash = make_hash(@doc, num)
45
- end
46
-
47
- def yaml_title
48
- normalize_str(@title)
49
- end
50
-
51
- # Convert the Hiera object to a hash
52
- # @return [Hash]
53
- def to_h
54
- @hash
55
- end
56
-
57
- # Convert the Hiera object to a string
58
- # @return [String]
59
- def to_s
60
- @hash.inspect
61
- end
62
-
63
- # Convert the Hiera object to YAML string
64
- # @return [String] YAML-formatted string
65
- def to_yaml
66
- yh = @hash.transform_keys do |k|
67
- [@parent_key, k].join('::').strip
68
- end
69
- yh.to_yaml
70
- end
71
-
72
- # If a method gets called on the Hiera object which is not defined,
73
- # this sends that method call to hash, then doc, then super.
74
- def method_missing(method, *args, &block)
75
- return true if ['exist?', 'exists?'].include?(method.to_s)
76
-
77
- return @hash.send(method, *args, &block) if @hash.respond_to?(method)
78
-
79
- return @doc.send(method, *args, &block) if @doc.respond_to?(method)
80
-
81
- super(method, *args, &block)
82
- end
83
-
84
- # Checks the respond_to? of hash, doc, or super
85
- def respond_to_missing?(method_name, include_private = false)
86
- return true if ['exist?', 'exists?'].include?(method_name.to_s)
87
-
88
- @hash || @doc || super
89
- end
90
-
91
- private
92
-
93
- attr_accessor :doc, :hash, :parent_key, :profiles
94
-
95
- # Accepts a path to an xccdf xml file and returns a parsed Nokogiri object of the file
96
- # @param xccdf_file [String] path to an xccdf xml file
97
- # @return [Nokogiri::Node] A Nokogiri node object of the XML document
98
- def parse(xccdf_file)
99
- raise AbideDevUtils::Errors::FileNotFoundError, xccdf_file unless File.file?(xccdf_file)
100
-
101
- Nokogiri.XML(File.open(xccdf_file))
102
- end
103
-
104
- def make_hash(doc, num)
105
- hash = { 'title' => @title, 'version' => @version }
106
- profiles = doc.xpath('xccdf:Benchmark/xccdf:Profile')
107
- profiles.each do |p|
108
- title = normalize_profile_name(p.xpath('./xccdf:title').children.to_s)
109
- hash[title.to_s] = []
110
- selects = p.xpath('./xccdf:select')
111
- selects.each do |s|
112
- hash[title.to_s] << normalize_ctrl_name(s['idref'].to_s, num)
113
- end
114
- end
115
- hash
116
- end
117
-
118
- def normalize_str(str)
119
- nstr = str.downcase
120
- nstr.gsub!(/[^a-z0-9]$/, '')
121
- nstr.gsub!(/^[^a-z]/, '')
122
- nstr.gsub!(/^(l1_|l2_|ng_)/, '')
123
- nstr.delete!('(/|\\|\+)')
124
- nstr.gsub!(UNDERSCORED, '_')
125
- nstr.strip!
126
- nstr
127
- end
128
-
129
- def normalize_profile_name(prof)
130
- prof_name = normalize_str("profile_#{prof}")
131
- prof_name.gsub!(NEXT_GEN_WINDOWS, 'ngws')
132
- prof_name.strip!
133
- prof_name
134
- end
135
-
136
- def normalize_ctrl_name(ctrl, num)
137
- return num_normalize_ctrl(ctrl) if num
138
-
139
- name_normalize_ctrl(ctrl)
140
- end
141
-
142
- def name_normalize_ctrl(ctrl)
143
- new_ctrl = ctrl.split('benchmarks_rule_')[-1].gsub(CONTROL_PREFIX, '')
144
- normalize_str(new_ctrl)
145
- end
146
-
147
- def num_normalize_ctrl(ctrl)
148
- part = ctrl.split('benchmarks_rule_')[-1]
149
- numpart = CONTROL_PREFIX.match(part).to_s.chop.gsub(UNDERSCORED, '_')
150
- "c#{numpart}"
151
- end
152
-
153
- def make_parent_key(doc, prefix)
154
- doc_title = normalize_str(doc.xpath(XPATHS[:benchmark][:title]).children.to_s)
155
- return doc_title if prefix.nil?
156
-
157
- sepped_prefix = prefix.end_with?('::') ? prefix : "#{prefix}::"
158
- "#{sepped_prefix.chomp}#{doc_title}"
159
- end
160
- end
161
- end
162
- end
163
- end
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'abide_dev_utils/xccdf/cis/hiera'