abide_dev_utils 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +1 -0
  3. data/.gitignore +0 -0
  4. data/.rspec +0 -0
  5. data/.rubocop.yml +0 -0
  6. data/.rubocop_todo.yml +0 -0
  7. data/CHANGELOG.md +0 -0
  8. data/Dockerfile +23 -0
  9. data/Gemfile +0 -0
  10. data/LICENSE.txt +0 -0
  11. data/README.md +9 -0
  12. data/Rakefile +0 -0
  13. data/abide_dev_utils.gemspec +1 -0
  14. data/lib/abide_dev_utils.rb +0 -0
  15. data/lib/abide_dev_utils/cli.rb +0 -0
  16. data/lib/abide_dev_utils/cli/abstract.rb +0 -0
  17. data/lib/abide_dev_utils/cli/jira.rb +0 -0
  18. data/lib/abide_dev_utils/cli/puppet.rb +0 -0
  19. data/lib/abide_dev_utils/cli/test.rb +1 -1
  20. data/lib/abide_dev_utils/cli/xccdf.rb +1 -0
  21. data/lib/abide_dev_utils/config.rb +0 -0
  22. data/lib/abide_dev_utils/constants.rb +0 -0
  23. data/lib/abide_dev_utils/errors.rb +0 -0
  24. data/lib/abide_dev_utils/errors/base.rb +0 -0
  25. data/lib/abide_dev_utils/errors/general.rb +0 -0
  26. data/lib/abide_dev_utils/errors/jira.rb +0 -0
  27. data/lib/abide_dev_utils/errors/ppt.rb +0 -0
  28. data/lib/abide_dev_utils/errors/xccdf.rb +4 -0
  29. data/lib/abide_dev_utils/files.rb +0 -0
  30. data/lib/abide_dev_utils/jira.rb +0 -0
  31. data/lib/abide_dev_utils/output.rb +0 -0
  32. data/lib/abide_dev_utils/ppt.rb +0 -0
  33. data/lib/abide_dev_utils/ppt/coverage.rb +0 -0
  34. data/lib/abide_dev_utils/ppt/new_obj.rb +3 -3
  35. data/lib/abide_dev_utils/prompt.rb +0 -0
  36. data/lib/abide_dev_utils/resources/generic_spec.erb +0 -0
  37. data/lib/abide_dev_utils/utils/general.rb +0 -0
  38. data/lib/abide_dev_utils/validate.rb +0 -0
  39. data/lib/abide_dev_utils/version.rb +1 -1
  40. data/lib/abide_dev_utils/xccdf.rb +1 -1
  41. data/lib/abide_dev_utils/xccdf/cis.rb +0 -0
  42. data/lib/abide_dev_utils/xccdf/cis/hiera.rb +21 -6
  43. metadata +22 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4ee71223292cc98028db5407eaef69cb2a0a150de9552b4d51d3b1ee17197bf
4
- data.tar.gz: 3f56a0ad99e2ae3ccc8478210f7bb1961c4500267bedc1d42612c1947ee7c3fb
3
+ metadata.gz: 9e53d77f476f80d886ab35e07bbfcf897f117d24be9fdf6cc3c31fc50b3d40e7
4
+ data.tar.gz: 1fc189884a7c351da992f6ad6e915cc0321c290c67b5e10ae3e35fb0bbc26d79
5
5
  SHA512:
6
- metadata.gz: 821d519b152ffc0a246939050b2b6117b5f3986fdf094d6333cfef8617b06c1572517a93b96f76039368c860715a4ef7ef39c78c039581369c4e61b484bce0c0
7
- data.tar.gz: 6010ad3359da0de05b352e48210f3e4ddbd95b30e942598c6e6cfa77c175a1041ab87491d2a2afa15490a12fc197c549ab5d58dbb4bfc816e569afe5ac66dd9e
6
+ metadata.gz: 2dedd8ca47872aa859852f51172233ffefca9420004804d750969c0b7558caa10caba812570538c5e4989c021c2a6409620502f7459dfcd5027f9c7afafbb6fe
7
+ data.tar.gz: fe3b5f70661297672e171fce5f452c06a9042f2e101918caaf65be0527c5e401e22169bdfde0d1649b1d8ea6ce85c04262c7147c4fd8f0514d81e0bfdb2e860e
data/.dockerignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
data/.rubocop.yml CHANGED
File without changes
data/.rubocop_todo.yml CHANGED
File without changes
data/CHANGELOG.md CHANGED
File without changes
data/Dockerfile ADDED
@@ -0,0 +1,23 @@
1
+ FROM ruby:2.7.3-alpine
2
+
3
+ ARG version
4
+
5
+ RUN mkdir /extvol && \
6
+ apk update && \
7
+ apk add git build-base
8
+
9
+ VOLUME /extvol
10
+
11
+ WORKDIR /usr/src/app
12
+
13
+ RUN mkdir -p ./lib/abide_dev_utils/
14
+ COPY Gemfile abide_dev_utils.gemspec ./
15
+ COPY lib/abide_dev_utils/version.rb lib/abide_dev_utils
16
+ RUN bundle install
17
+
18
+ COPY . .
19
+
20
+ RUN bundle exec rake build && \
21
+ gem install pkg/abide_dev_utils-${version}.gem
22
+
23
+ ENTRYPOINT [ "abide" ]
data/Gemfile CHANGED
File without changes
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
@@ -231,6 +231,15 @@ NOTE: When converting XCCDF files to Hiera, control names are sanitized. This me
231
231
  * `--out-file`, `-o` - A path to a file where you would like to save the generated Hiera
232
232
  * `--parent-key-prefix`, `-p` - Allows you to append a prefix to all top-level Hiera keys
233
233
 
234
+ ## Docker
235
+
236
+ A Dockerfile has been provided in this repo for convenience since Ruby environments can be painful to deal with. To abide_dev_utils with Docker:
237
+
238
+ * Build the Dockerfile: `docker build . -t abide_dev_utils --build-arg version=<semver>`
239
+ * Run the commands using the container: `docker run -it abide_dev_utils --help`
240
+ * The container declares a volume for external resources such as files. To use the volume, add the following flag to your `docker run` commands: `-v /path/to/my/files:/extvol`
241
+ * When using the volume, all paths should be absolute based on the root directory `/extvol`
242
+
234
243
  ## Development
235
244
 
236
245
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/Rakefile CHANGED
File without changes
@@ -41,6 +41,7 @@ Gem::Specification.new do |spec|
41
41
  # Dev dependencies
42
42
  spec.add_development_dependency 'bundler'
43
43
  spec.add_development_dependency 'rake'
44
+ spec.add_development_dependency 'console'
44
45
  spec.add_development_dependency 'github_changelog_generator'
45
46
  spec.add_development_dependency 'gem-release'
46
47
  spec.add_development_dependency 'rspec', '~> 3.10'
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -35,10 +35,10 @@ module Abide
35
35
  @litmus_im = [CMD_LIT_BASE, "'litmus:install_module'"]
36
36
  @litmus_ap = [CMD_LIT_BASE, "'litmus:acceptance:parallel'"]
37
37
  @litmus_td = [CMD_LIT_BASE, "'litmus:tear_down'"]
38
- validate_env_and_opts
39
38
  end
40
39
 
41
40
  def execute(suite)
41
+ validate_env_and_opts
42
42
  case suite.downcase
43
43
  when /^a[A-Za-z]*/
44
44
  run_command(@validate)
@@ -28,6 +28,7 @@ module Abide
28
28
  options.on('-b [TYPE]', '--benchmark-type [TYPE]', 'XCCDF Benchmark type') { |b| @data[:type] = b }
29
29
  options.on('-o [FILE]', '--out-file [FILE]', 'Path to save file') { |f| @data[:file] = f }
30
30
  options.on('-p [PREFIX]', '--parent-key-prefix [PREFIX]', 'A prefix to append to the parent key') { |p| @data[:parent_key_prefix] = p }
31
+ options.on('-N', '--number-fmt', 'Format Hiera control names based off of control number instead of name.') { |s| @data[:num] = true }
31
32
  end
32
33
 
33
34
  def execute(xccdf_file)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -8,5 +8,9 @@ module AbideDevUtils
8
8
  class XPathSearchError < GenericError
9
9
  @default = 'XPath seach failed to find anything at:'
10
10
  end
11
+
12
+ class StrategyInvalidError < GenericError
13
+ @default = 'Invalid strategy selected. Should be either \'name\' or \'num\''
14
+ end
11
15
  end
12
16
  end
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -22,9 +22,10 @@ module AbideDevUtils
22
22
  @vars = vars
23
23
  class_vars
24
24
  validate_class_vars
25
+ @tmpl_data = template_data(@opts.fetch(:tmpl_name, @obj_type))
25
26
  end
26
27
 
27
- attr_reader :obj_type, :obj_name, :root_dir, :tmpl_dir, :obj_path, :vars
28
+ attr_reader :obj_type, :obj_name, :root_dir, :tmpl_dir, :obj_path, :vars, :tmpl_data
28
29
 
29
30
  def build
30
31
  force = @opts.fetch(:force, false)
@@ -85,7 +86,6 @@ module AbideDevUtils
85
86
  else
86
87
  "#{@root_dir}/#{@opts.fetch(:tmpl_dir, 'object_templates')}"
87
88
  end
88
- @tmpl_data = template_data(@opts.fetch(:tmpl_name, @obj_type))
89
89
  @obj_path = new_obj_path
90
90
  @spec_tmpl = @opts.fetch(:spec_template, File.expand_path(File.join(__dir__, '../resources/generic_spec.erb')))
91
91
  end
@@ -129,7 +129,7 @@ module AbideDevUtils
129
129
  data[:pfx] = data[:fname].match?(OBJ_PREFIX) ? data[:fname].match(OBJ_PREFIX)[1] : 'c-'
130
130
  data[:spec_base] = PREFIX_TEST_PATH[data[:pfx]]
131
131
  data[:obj_name] = normalize_obj_name(data.dup)
132
- data[:spec_name] = "#{data[:obj_name].slice(/([^\s]+)(?:#{Regexp.quote(data[:ext])})/, 1)}_spec.rb"
132
+ data[:spec_name] = "#{@obj_name.split('::')[-1]}_spec.rb"
133
133
  data[:spec_path] = spec_path(data[:spec_base], data[:spec_name])
134
134
  data
135
135
  end
File without changes
File without changes
File without changes
File without changes
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AbideDevUtils
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -15,7 +15,7 @@ module AbideDevUtils
15
15
  type = opts.fetch(:type, 'cis')
16
16
  case type.downcase
17
17
  when 'cis'
18
- AbideDevUtils::XCCDF::CIS::Hiera.new(xccdf_file, parent_key_prefix: opts[:parent_key_prefix])
18
+ AbideDevUtils::XCCDF::CIS::Hiera.new(xccdf_file, parent_key_prefix: opts[:parent_key_prefix], strategy: opts[:strategy])
19
19
  else
20
20
  AbideDevUtils::Output.simple("XCCDF type #{type} is unsupported!")
21
21
  end
File without changes
@@ -35,13 +35,13 @@ module AbideDevUtils
35
35
  # @param parent_key_prefix [String] a string to be prepended to the
36
36
  # top-level key in the Hiera structure. Useful for namespacing
37
37
  # the top-level key.
38
- def initialize(xccdf_file, parent_key_prefix: nil)
38
+ def initialize(xccdf_file, parent_key_prefix: nil, num: false)
39
39
  @doc = parse(xccdf_file)
40
40
  @title = xpath(XPATHS[:benchmark][:title]).children.to_s
41
41
  @version = xpath(XPATHS[:benchmark][:version]).children.to_s
42
42
  @profiles = xpath(XPATHS[:profiles][:all])
43
43
  @parent_key = make_parent_key(@doc, parent_key_prefix)
44
- @hash = make_hash(@doc, @parent_key)
44
+ @hash = make_hash(@doc, @parent_key, num)
45
45
  end
46
46
 
47
47
  def yaml_title
@@ -92,13 +92,16 @@ module AbideDevUtils
92
92
 
93
93
  attr_accessor :doc, :hash, :parent_key, :profiles
94
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
95
98
  def parse(xccdf_file)
96
99
  raise AbideDevUtils::Errors::FileNotFoundError, xccdf_file unless File.file?(xccdf_file)
97
100
 
98
101
  Nokogiri.XML(File.open(xccdf_file))
99
102
  end
100
103
 
101
- def make_hash(doc, parent_key)
104
+ def make_hash(doc, parent_key, num)
102
105
  hash = { parent_key.to_sym => { title: @title, version: @version } }
103
106
  profiles = doc.xpath('xccdf:Benchmark/xccdf:Profile')
104
107
  profiles.each do |p|
@@ -106,7 +109,7 @@ module AbideDevUtils
106
109
  hash[parent_key.to_sym][title.to_sym] = []
107
110
  selects = p.xpath('./xccdf:select')
108
111
  selects.each do |s|
109
- hash[parent_key.to_sym][title.to_sym] << normalize_ctrl_name(s['idref'].to_s)
112
+ hash[parent_key.to_sym][title.to_sym] << normalize_ctrl_name(s['idref'].to_s, num)
110
113
  end
111
114
  end
112
115
  hash
@@ -128,11 +131,23 @@ module AbideDevUtils
128
131
  prof_name
129
132
  end
130
133
 
131
- def normalize_ctrl_name(ctrl)
132
- new_ctrl = ctrl.split('_rule_')[-1].gsub(CONTROL_PREFIX, '')
134
+ def normalize_ctrl_name(ctrl, num)
135
+ return num_normalize_ctrl(ctrl) if num
136
+
137
+ name_normalize_ctrl(ctrl)
138
+ end
139
+
140
+ def name_normalize_ctrl(ctrl)
141
+ new_ctrl = ctrl.split('benchmarks_rule_')[-1].gsub(CONTROL_PREFIX, '')
133
142
  normalize_str(new_ctrl)
134
143
  end
135
144
 
145
+ def num_normalize_ctrl(ctrl)
146
+ part = ctrl.split('benchmarks_rule_')[-1]
147
+ numpart = CONTROL_PREFIX.match(part).to_s.chop.gsub(UNDERSCORED, '_')
148
+ "c#{numpart}"
149
+ end
150
+
136
151
  def make_parent_key(doc, prefix)
137
152
  doc_title = normalize_str(doc.xpath(XPATHS[:benchmark][:title]).children.to_s)
138
153
  return doc_title if prefix.nil?
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Heston Snodgrass
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-01 00:00:00.000000000 Z
11
+ date: 2021-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: console
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: github_changelog_generator
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -242,11 +256,13 @@ executables:
242
256
  extensions: []
243
257
  extra_rdoc_files: []
244
258
  files:
259
+ - ".dockerignore"
245
260
  - ".gitignore"
246
261
  - ".rspec"
247
262
  - ".rubocop.yml"
248
263
  - ".rubocop_todo.yml"
249
264
  - CHANGELOG.md
265
+ - Dockerfile
250
266
  - Gemfile
251
267
  - LICENSE.txt
252
268
  - README.md
@@ -292,7 +308,7 @@ metadata:
292
308
  homepage_uri: https://github.com/hsnodgrass/abide_dev_utils
293
309
  source_code_uri: https://github.com/hsnodgrass/abide_dev_utils
294
310
  changelog_uri: https://github.com/hsnodgrass/abide_dev_utils
295
- post_install_message:
311
+ post_install_message:
296
312
  rdoc_options: []
297
313
  require_paths:
298
314
  - lib
@@ -307,8 +323,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
307
323
  - !ruby/object:Gem::Version
308
324
  version: '0'
309
325
  requirements: []
310
- rubygems_version: 3.0.9
311
- signing_key:
326
+ rubygems_version: 3.1.2
327
+ signing_key:
312
328
  specification_version: 4
313
329
  summary: Helper utilities for developing Abide
314
330
  test_files: []