emasser 3.4.0 → 3.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +8 -8
  3. data/.env-example +12 -12
  4. data/.github/release-drafter.yml +15 -15
  5. data/.github/workflows/codeql-analysis.yml +70 -70
  6. data/.github/workflows/draft-release.yml +15 -15
  7. data/.github/workflows/gh-pages.yml +32 -32
  8. data/.github/workflows/push-to-docker-mail.yml +28 -28
  9. data/.github/workflows/push-to-docker.yml +35 -35
  10. data/.github/workflows/release.yml +42 -42
  11. data/.github/workflows/rubocop.yml +23 -23
  12. data/.github/workflows/test-cli.yml +72 -72
  13. data/.gitignore +19 -19
  14. data/.mergify.yml +25 -25
  15. data/.rubocop.yml +80 -80
  16. data/.rubocop_todo.yml +27 -27
  17. data/CHANGELOG.md +16 -16
  18. data/Dockerfile +44 -44
  19. data/Gemfile +8 -8
  20. data/Gemfile.lock +104 -104
  21. data/LICENSE.md +15 -15
  22. data/README.md +178 -178
  23. data/Rakefile +18 -18
  24. data/_config.yml +1 -1
  25. data/docs/features.md +1436 -1436
  26. data/docs/redoc/index.html +1230 -1230
  27. data/emasser.gemspec +44 -44
  28. data/exe/emasser +5 -5
  29. data/lib/emasser/cli.rb +37 -37
  30. data/lib/emasser/configuration.rb +49 -49
  31. data/lib/emasser/constants.rb +26 -26
  32. data/lib/emasser/delete.rb +148 -148
  33. data/lib/emasser/errors.rb +14 -14
  34. data/lib/emasser/get.rb +949 -949
  35. data/lib/emasser/help/approvalCac_post_mapper.md +20 -20
  36. data/lib/emasser/help/approvalPac_post_mapper.md +20 -20
  37. data/lib/emasser/help/artifacts_del_mapper.md +9 -9
  38. data/lib/emasser/help/artifacts_post_mapper.md +59 -59
  39. data/lib/emasser/help/artifacts_put_mapper.md +34 -34
  40. data/lib/emasser/help/cloudresource_post_mapper.md +62 -62
  41. data/lib/emasser/help/cmmc_get_mapper.md +4 -4
  42. data/lib/emasser/help/container_post_mapper.md +44 -44
  43. data/lib/emasser/help/controls_put_mapper.md +74 -74
  44. data/lib/emasser/help/milestone_del_mapper.md +11 -11
  45. data/lib/emasser/help/milestone_post_mapper.md +14 -14
  46. data/lib/emasser/help/milestone_put_mapper.md +23 -23
  47. data/lib/emasser/help/poam_del_mapper.md +5 -5
  48. data/lib/emasser/help/poam_post_mapper.md +93 -93
  49. data/lib/emasser/help/poam_put_mapper.md +107 -107
  50. data/lib/emasser/help/staticcode_clear_mapper.md +16 -16
  51. data/lib/emasser/help/staticcode_post_mapper.md +21 -21
  52. data/lib/emasser/help/testresults_post_mapper.md +21 -21
  53. data/lib/emasser/help.rb +11 -11
  54. data/lib/emasser/input_converters.rb +21 -21
  55. data/lib/emasser/options_parser.rb +20 -20
  56. data/lib/emasser/output_converters.rb +111 -111
  57. data/lib/emasser/post.rb +830 -802
  58. data/lib/emasser/put.rb +588 -588
  59. data/lib/emasser/version.rb +5 -5
  60. data/lib/emasser.rb +19 -19
  61. metadata +8 -8
data/emasser.gemspec CHANGED
@@ -1,44 +1,44 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/emasser/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'emasser'
7
- spec.version = Emasser::VERSION
8
- spec.authors = ['Amndeep Singh Mann', 'George Dias', 'Kyle Fagan', 'Robert Clark', 'Aaron Lippold']
9
- spec.email = ['saf@groups.mitre.org']
10
- spec.licenses = ['Apache-2.0']
11
-
12
- spec.summary = 'Provide an automated capability for invoving eMASS API endpoints'
13
- spec.description = 'emasser can be used as a gem or used from the command line (CL) to access eMASS endpoints via their API.'
14
- spec.homepage = 'https://saf.mitre.org'
15
- spec.required_ruby_version = Gem::Requirement.new('~> 2.5')
16
-
17
- # Specify which files should be added to the gem when it is released.
18
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(emass_client|test|spec|features)/}) }
21
- end
22
- spec.bindir = 'exe'
23
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
- # References: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-rubygems-registry
25
- spec.metadata = { "github_repo" => "ssh://github.com/mitre/emasser" }
26
-
27
- spec.add_runtime_dependency 'activesupport', '~> 6.1.4'
28
- spec.add_runtime_dependency 'colorize', '~> 0.8.1'
29
- spec.add_runtime_dependency 'dotenv', '~> 2.7.6'
30
- spec.add_runtime_dependency 'rubyzip', '~> 2.3.2'
31
- spec.add_runtime_dependency 'thor', '~> 1.1.0'
32
- spec.add_runtime_dependency 'emass_client', '~> 3.0'
33
-
34
- spec.add_development_dependency 'bundler', '~> 2.3'
35
- spec.add_development_dependency 'bundler-audit', '~> 0.7'
36
- spec.add_development_dependency 'byebug', '~> 11.1.3'
37
- spec.add_development_dependency 'rspec', '~> 3.10.0'
38
- spec.add_development_dependency 'yaml', '~> 0.2.0'
39
- spec.add_development_dependency 'rake', '~> 13.0'
40
- spec.add_development_dependency 'rubocop', '~> 1.7'
41
- spec.add_development_dependency 'rubocop-minitest', '~> 0.10'
42
- spec.add_development_dependency 'rubocop-performance', '~> 1.11'
43
- spec.add_development_dependency 'rubocop-rake', '~> 0.5'
44
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/emasser/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'emasser'
7
+ spec.version = Emasser::VERSION
8
+ spec.authors = ['Amndeep Singh Mann', 'George Dias', 'Kyle Fagan', 'Robert Clark', 'Aaron Lippold']
9
+ spec.email = ['saf@groups.mitre.org']
10
+ spec.licenses = ['Apache-2.0']
11
+
12
+ spec.summary = 'Provide an automated capability for invoving eMASS API endpoints'
13
+ spec.description = 'The emasser can be used as a gem or used from the command line (CL) to access eMASS endpoints via their API.'
14
+ spec.homepage = 'https://saf.mitre.org'
15
+ spec.required_ruby_version = Gem::Requirement.new('~> 2.5')
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(emass_client|test|spec|features)/}) }
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ # References: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-rubygems-registry
25
+ spec.metadata = { "github_repo" => "ssh://github.com/mitre/emasser" }
26
+
27
+ spec.add_runtime_dependency 'activesupport', '~> 6.1.4'
28
+ spec.add_runtime_dependency 'colorize', '~> 0.8.1'
29
+ spec.add_runtime_dependency 'dotenv', '~> 2.7.6'
30
+ spec.add_runtime_dependency 'rubyzip', '~> 2.3.2'
31
+ spec.add_runtime_dependency 'thor', '~> 1.1.0'
32
+ spec.add_runtime_dependency 'emass_client', '~> 3.0'
33
+
34
+ spec.add_development_dependency 'bundler', '~> 2.3'
35
+ spec.add_development_dependency 'bundler-audit', '~> 0.7'
36
+ spec.add_development_dependency 'byebug', '~> 11.1.3'
37
+ spec.add_development_dependency 'rspec', '~> 3.10.0'
38
+ spec.add_development_dependency 'yaml', '~> 0.2.0'
39
+ spec.add_development_dependency 'rake', '~> 13.0'
40
+ spec.add_development_dependency 'rubocop', '~> 1.7'
41
+ spec.add_development_dependency 'rubocop-minitest', '~> 0.10'
42
+ spec.add_development_dependency 'rubocop-performance', '~> 1.11'
43
+ spec.add_development_dependency 'rubocop-rake', '~> 0.5'
44
+ end
data/exe/emasser CHANGED
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'dotenv/load'
5
- require 'emasser'
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'dotenv/load'
5
+ require 'emasser'
data/lib/emasser/cli.rb CHANGED
@@ -1,37 +1,37 @@
1
- # frozen_string_literal: true
2
-
3
- module Emasser
4
- class CLI < Thor
5
- package_name 'Emasser'
6
-
7
- if ARGV[0].to_s.include? 'get'
8
- require 'emasser/get'
9
- register(Emasser::Get, 'get', 'get [RESOURCE]', 'Gets a resource')
10
- elsif ARGV[0].to_s.include? 'post'
11
- require 'emasser/post'
12
- register(Emasser::Post, 'post', 'post [RESOURCE]', 'Posts resources')
13
- elsif ARGV[0].to_s.include? 'put'
14
- require 'emasser/put'
15
- register(Emasser::Put, 'put', 'put [RESOURCE]', 'Puts resources')
16
- elsif ARGV[0].to_s.include? 'del'
17
- require 'emasser/delete'
18
- register(Emasser::Delete, 'delete', 'delete [RESOURCE]', 'Deletes resources')
19
- elsif (ARGV[0].to_s.include? '-v') || (ARGV[0].to_s.include? '-V')
20
- puts "emasser version: #{Emasser::VERSION}".green
21
- exit
22
- elsif ARGV[0].to_s.include? 'hello'
23
- user_name = ENV.fetch('USERNAME', 'rookie')
24
- puts "Hello #{user_name} - enjoy using emasser version #{Emasser::VERSION}!".cyan
25
- exit
26
- end
27
-
28
- def help
29
- puts 'Emasser commands:'.yellow
30
- puts ' emasser [get, put, post, delete, -v, or -V]'.yellow
31
- end
32
-
33
- def self.exit_on_failure?
34
- true
35
- end
36
- end
37
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Emasser
4
+ class CLI < Thor
5
+ package_name 'Emasser'
6
+
7
+ if ARGV[0].to_s.include? 'get'
8
+ require 'emasser/get'
9
+ register(Emasser::Get, 'get', 'get [RESOURCE]', 'Gets a resource')
10
+ elsif ARGV[0].to_s.include? 'post'
11
+ require 'emasser/post'
12
+ register(Emasser::Post, 'post', 'post [RESOURCE]', 'Posts resources')
13
+ elsif ARGV[0].to_s.include? 'put'
14
+ require 'emasser/put'
15
+ register(Emasser::Put, 'put', 'put [RESOURCE]', 'Puts resources')
16
+ elsif ARGV[0].to_s.include? 'del'
17
+ require 'emasser/delete'
18
+ register(Emasser::Delete, 'delete', 'delete [RESOURCE]', 'Deletes resources')
19
+ elsif (ARGV[0].to_s.include? '-v') || (ARGV[0].to_s.include? '-V')
20
+ puts "emasser version: #{Emasser::VERSION}".green
21
+ exit
22
+ elsif ARGV[0].to_s.include? 'hello'
23
+ user_name = ENV.fetch('USERNAME', 'rookie')
24
+ puts "Hello #{user_name} - enjoy using emasser version #{Emasser::VERSION}!".cyan
25
+ exit
26
+ end
27
+
28
+ def help
29
+ puts 'Emasser commands:'.yellow
30
+ puts ' emasser [get, put, post, delete, -v, or -V]'.yellow
31
+ end
32
+
33
+ def self.exit_on_failure?
34
+ true
35
+ end
36
+ end
37
+ end
@@ -1,49 +1,49 @@
1
- # frozen_string_literal: true
2
-
3
- module Emasser
4
- require 'emasser/errors'
5
-
6
- class Configuration
7
- # rubocop: disable Style/RaiseArgs
8
- def self.raise_unless_present(env)
9
- ENV.fetch(env) { raise Emasser::ConfigurationMissingError.new(env) }
10
- rescue Emasser::ConfigurationMissingError => e
11
- if (ARGV[0].to_s.include? '-v') || (ARGV[0].to_s.include? '-V')
12
- puts "emasser version: #{Emasser::VERSION}".green
13
- else
14
- puts "\n", e.message.red
15
- puts 'Create a .env file containing required variables, place it in the root directory where the emasser command is executed'.yellow
16
- puts 'Required environment variables are:'.yellow
17
- puts ' export EMASSER_API_KEY_API_KEY=<API key>'.green
18
- puts ' export EMASSER_API_KEY_USER_UID=<unique identifier of the eMASS user EMASSER_API_KEY_API_KEY belongs to>'.green
19
- puts ' export EMASSER_HOST=<FQDN of the eMASS server>'.green
20
- puts ' export EMASSER_KEY_FILE_PATH=<path to your emass key in PEM format>'.green
21
- puts ' export EMASSER_CERT_FILE_PATH=<path to your emass certficate in PEM format>'.green
22
- puts ' export EMASSER_KEY_PASSWORD=<password for the key given in EMASSER_KEY_FILE_PATH>'.green, "\n"
23
- puts 'See emasser environment variables requirements in emasser CLI Features for more information (https://mitre.github.io/emasser/docs/features.html).', "\n"
24
- end
25
- exit
26
- end
27
- # rubocop: enable Style/RaiseArgs
28
-
29
- # rubocop: disable Style/TernaryParentheses, Style/IfWithBooleanLiteralBranches
30
- EmassClient.configure do |config|
31
- # Required env variables
32
- config.api_key['api-key'] = raise_unless_present('EMASSER_API_KEY_API_KEY')
33
- config.api_key['user-uid'] = raise_unless_present('EMASSER_API_KEY_USER_UID')
34
- config.scheme = 'https'
35
- config.base_path = '/'
36
- config.server_index = nil
37
- config.host = raise_unless_present('EMASSER_HOST')
38
- config.key_file = raise_unless_present('EMASSER_KEY_FILE_PATH')
39
- config.cert_file = raise_unless_present('EMASSER_CERT_FILE_PATH')
40
- config.key_password = raise_unless_present('EMASSER_KEY_PASSWORD')
41
- # Optional env variables
42
- config.client_side_validation = (ENV.fetch('EMASSER_CLIENT_SIDE_VALIDATION', 'true').eql? 'true') ? true : false
43
- config.verify_ssl = (ENV.fetch('EMASSER_VERIFY_SSL', 'true').eql? 'true') ? true : false
44
- config.verify_ssl_host = (ENV.fetch('EMASSER_VERIFY_SSL_HOST', 'true').eql? 'true') ? true : false
45
- config.debugging = (ENV.fetch('EMASSER_DEBUGGING', 'false') == 'false') ? false : true
46
- end
47
- # rubocop: enable Style/TernaryParentheses, Style/IfWithBooleanLiteralBranches
48
- end
49
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Emasser
4
+ require 'emasser/errors'
5
+
6
+ class Configuration
7
+ # rubocop: disable Style/RaiseArgs
8
+ def self.raise_unless_present(env)
9
+ ENV.fetch(env) { raise Emasser::ConfigurationMissingError.new(env) }
10
+ rescue Emasser::ConfigurationMissingError => e
11
+ if (ARGV[0].to_s.include? '-v') || (ARGV[0].to_s.include? '-V')
12
+ puts "emasser version: #{Emasser::VERSION}".green
13
+ else
14
+ puts "\n", e.message.red
15
+ puts 'Create a .env file containing required variables, place it in the root directory where the emasser command is executed'.yellow
16
+ puts 'Required environment variables are:'.yellow
17
+ puts ' export EMASSER_API_KEY_API_KEY=<API key>'.green
18
+ puts ' export EMASSER_API_KEY_USER_UID=<unique identifier of the eMASS user EMASSER_API_KEY_API_KEY belongs to>'.green
19
+ puts ' export EMASSER_HOST=<FQDN of the eMASS server>'.green
20
+ puts ' export EMASSER_KEY_FILE_PATH=<path to your emass key in PEM format>'.green
21
+ puts ' export EMASSER_CERT_FILE_PATH=<path to your emass certficate in PEM format>'.green
22
+ puts ' export EMASSER_KEY_PASSWORD=<password for the key given in EMASSER_KEY_FILE_PATH>'.green, "\n"
23
+ puts 'See emasser environment variables requirements in emasser CLI Features for more information (https://mitre.github.io/emasser/docs/features.html).', "\n"
24
+ end
25
+ exit
26
+ end
27
+ # rubocop: enable Style/RaiseArgs
28
+
29
+ # rubocop: disable Style/TernaryParentheses, Style/IfWithBooleanLiteralBranches
30
+ EmassClient.configure do |config|
31
+ # Required env variables
32
+ config.api_key['api-key'] = raise_unless_present('EMASSER_API_KEY_API_KEY')
33
+ config.api_key['user-uid'] = raise_unless_present('EMASSER_API_KEY_USER_UID')
34
+ config.scheme = 'https'
35
+ config.base_path = '/'
36
+ config.server_index = nil
37
+ config.host = raise_unless_present('EMASSER_HOST')
38
+ config.key_file = raise_unless_present('EMASSER_KEY_FILE_PATH')
39
+ config.cert_file = raise_unless_present('EMASSER_CERT_FILE_PATH')
40
+ config.key_password = raise_unless_present('EMASSER_KEY_PASSWORD')
41
+ # Optional env variables
42
+ config.client_side_validation = (ENV.fetch('EMASSER_CLIENT_SIDE_VALIDATION', 'true').eql? 'true') ? true : false
43
+ config.verify_ssl = (ENV.fetch('EMASSER_VERIFY_SSL', 'true').eql? 'true') ? true : false
44
+ config.verify_ssl_host = (ENV.fetch('EMASSER_VERIFY_SSL_HOST', 'true').eql? 'true') ? true : false
45
+ config.debugging = (ENV.fetch('EMASSER_DEBUGGING', 'false') == 'false') ? false : true
46
+ end
47
+ # rubocop: enable Style/TernaryParentheses, Style/IfWithBooleanLiteralBranches
48
+ end
49
+ end
@@ -1,26 +1,26 @@
1
- # frozen_string_literal: true
2
-
3
- module Emasser
4
- GET_SYSTEM_ID_QUERY_PARAMS = {
5
- include_package: false,
6
- include_ditpr_metrics: false,
7
- include_decommissioned: false,
8
- debug_return_type: 'SystemResponse' # This is used by swagger client only to format output
9
- }.freeze
10
-
11
- GET_SYSTEM_RETURN_TYPE = {
12
- debug_return_type: 'SystemResponse'
13
- }.freeze
14
-
15
- GET_ARTIFACTS_RETURN_TYPE = {
16
- debug_return_type: 'String'
17
- }.freeze
18
-
19
- GET_WORKFLOWINSTANCES_RETURN_TYPE = {
20
- debug_return_type: 'Object'
21
- }.freeze
22
-
23
- DEL_MILESTONES_RETURN_TYPE = {
24
- debug_return_type: 'Object'
25
- }.freeze
26
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Emasser
4
+ GET_SYSTEM_ID_QUERY_PARAMS = {
5
+ include_package: false,
6
+ include_ditpr_metrics: false,
7
+ include_decommissioned: false,
8
+ debug_return_type: 'SystemResponse' # This is used by swagger client only to format output
9
+ }.freeze
10
+
11
+ GET_SYSTEM_RETURN_TYPE = {
12
+ debug_return_type: 'SystemResponse'
13
+ }.freeze
14
+
15
+ GET_ARTIFACTS_RETURN_TYPE = {
16
+ debug_return_type: 'String'
17
+ }.freeze
18
+
19
+ GET_WORKFLOWINSTANCES_RETURN_TYPE = {
20
+ debug_return_type: 'Object'
21
+ }.freeze
22
+
23
+ DEL_MILESTONES_RETURN_TYPE = {
24
+ debug_return_type: 'Object'
25
+ }.freeze
26
+ end
@@ -1,148 +1,148 @@
1
- # frozen_string_literal: true
2
-
3
- # Hack class that properly formats the CLI help
4
- class SubCommandBase < Thor
5
- # include OptionsParser
6
- # include InputConverters
7
- include OutputConverters
8
-
9
- # We do not control the method declaration for the banner
10
-
11
- # rubocop:disable Style/OptionalBooleanParameter
12
- def self.banner(command, _namespace = nil, subcommand = false)
13
- # Use the $thor_runner (declared by the Thor CLI framework)
14
- # to properly format the help text of sub-sub-commands.
15
-
16
- # rubocop:disable Style/GlobalVars
17
- if ancestors[0].to_s.include? '::Del'
18
- "#{basename} #{command.formatted_usage(self, $thor_runner, subcommand)}"
19
- else
20
- "#{basename} delete #{command.formatted_usage(self, $thor_runner, subcommand)}"
21
- end
22
- # rubocop:enable Style/GlobalVars
23
- end
24
- # rubocop:enable Style/OptionalBooleanParameter
25
- end
26
-
27
- # Override thor's long_desc identation behavior
28
- class Thor
29
- module Shell
30
- class Basic
31
- def print_wrapped(message, _options = {})
32
- message = "\n#{message}\n" unless message[0] == "\n"
33
- stdout.puts message
34
- end
35
- end
36
- end
37
- end
38
-
39
- module Emasser
40
- # Remove one or more POA&M from a system
41
- #
42
- # Endpoint:
43
- # /api/systems/{systemId}/poams - Remove one or many poa&m items in a system
44
- class Poams < SubCommandBase
45
- def self.exit_on_failure?
46
- true
47
- end
48
-
49
- # Delete a POAM -----------------------------------------------------------
50
- desc 'remove', 'Delete one or many POA&M items in a system'
51
- long_desc Help.text(:poam_del_mapper)
52
-
53
- # Required parameters/fields
54
- option :systemId, type: :numeric, required: true, desc: 'A numeric value representing the system identification'
55
- option :poamId, type: :numeric, required: true, desc: 'A numeric value representing the poam identification'
56
-
57
- def remove
58
- body = EmassClient::PoamGet.new
59
- body.poam_id = options[:poamId]
60
- body_array = Array.new(1, body)
61
-
62
- result = EmassClient::POAMApi.new.delete_poam(options[:systemId], body_array)
63
- puts to_output_hash(result).green
64
- rescue EmassClient::ApiError => e
65
- puts 'Exception when calling POAMApi->delete_poam'.red
66
- puts to_output_hash(e)
67
- end
68
- end
69
-
70
- # Remove one or more Milestones from a system for a POA
71
- #
72
- # Endpoint:
73
- # /api/systems/{systemId}/poam/{poamId}/milestones - Remove milestones in a system for one or many poa&m items
74
- class Milestones < SubCommandBase
75
- def self.exit_on_failure?
76
- true
77
- end
78
-
79
- desc 'remove', 'Delete one or many POA&M MILSTONES in a system'
80
- long_desc Help.text(:milestone_del_mapper)
81
-
82
- # Required parameters/fields
83
- option :systemId, type: :numeric, required: true,
84
- desc: 'A numeric value representing the system identification'
85
- option :poamId, type: :numeric, required: true,
86
- desc: 'A numeric value representing the poam identification'
87
- option :milestoneId, type: :numeric, required: true,
88
- desc: 'A numeric value representing the milestone identification'
89
-
90
- def remove
91
- body = EmassClient::MilestonesGet.new
92
- body.milestone_id = options[:milestoneId]
93
- body_array = Array.new(1, body)
94
-
95
- # Getting an empty return when utilizing the default return type - using 'Object' as return type
96
- opts = Emasser::DEL_MILESTONES_RETURN_TYPE
97
-
98
- result = EmassClient::MilestonesApi.new.delete_milestone(options[:systemId], options[:poamId], body_array, opts)
99
- puts to_output_hash(result).green
100
- rescue EmassClient::ApiError => e
101
- puts 'Exception when calling MilestonesApi->delete_milestone'.red
102
- puts to_output_hash(e).yellow
103
- end
104
- end
105
-
106
- # Remove one or many artifacts in a system
107
- #
108
- # Endpoint:
109
- # /api/systems/{systemId}/artifacts - Delete one or more artifacts (files) from a system
110
- class Artifacts < SubCommandBase
111
- def self.exit_on_failure?
112
- true
113
- end
114
-
115
- desc 'remove', 'Delete one or many artifacts in a system'
116
- long_desc Help.text(:artifact_del_mapper)
117
-
118
- # Required parameters/fields
119
- option :systemId, type: :numeric, required: true, desc: 'A numeric value representing the system identification'
120
- option :files, type: :array, required: true, desc: 'Artifact file(s) to remove from the given system'
121
-
122
- def remove
123
- body_array = []
124
- options[:files].each do |file|
125
- obj = {}
126
- obj[:filename] = file
127
- body_array << obj
128
- end
129
-
130
- result = EmassClient::ArtifactsApi.new.delete_artifact(options[:systemId], body_array)
131
- puts to_output_hash(result).green
132
- rescue EmassClient::ApiError => e
133
- puts 'Exception when calling ArtifactsApi->delete_artifact'.red
134
- puts to_output_hash(e)
135
- end
136
- end
137
-
138
- class Delete < SubCommandBase
139
- desc 'poams', 'Delete Plan of Action and Milestones (POA&M) items for a system'
140
- subcommand 'poams', Poams
141
-
142
- desc 'milestones', 'Delete Milestones from a Plan of Action ffrom a system'
143
- subcommand 'milestones', Milestones
144
-
145
- desc 'artifacts', 'Delete system Artifacts'
146
- subcommand 'artifacts', Artifacts
147
- end
148
- end
1
+ # frozen_string_literal: true
2
+
3
+ # Hack class that properly formats the CLI help
4
+ class SubCommandBase < Thor
5
+ # include OptionsParser
6
+ # include InputConverters
7
+ include OutputConverters
8
+
9
+ # We do not control the method declaration for the banner
10
+
11
+ # rubocop:disable Style/OptionalBooleanParameter
12
+ def self.banner(command, _namespace = nil, subcommand = false)
13
+ # Use the $thor_runner (declared by the Thor CLI framework)
14
+ # to properly format the help text of sub-sub-commands.
15
+
16
+ # rubocop:disable Style/GlobalVars
17
+ if ancestors[0].to_s.include? '::Del'
18
+ "#{basename} #{command.formatted_usage(self, $thor_runner, subcommand)}"
19
+ else
20
+ "#{basename} delete #{command.formatted_usage(self, $thor_runner, subcommand)}"
21
+ end
22
+ # rubocop:enable Style/GlobalVars
23
+ end
24
+ # rubocop:enable Style/OptionalBooleanParameter
25
+ end
26
+
27
+ # Override thor's long_desc identation behavior
28
+ class Thor
29
+ module Shell
30
+ class Basic
31
+ def print_wrapped(message, _options = {})
32
+ message = "\n#{message}\n" unless message[0] == "\n"
33
+ stdout.puts message
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ module Emasser
40
+ # Remove one or more POA&M from a system
41
+ #
42
+ # Endpoint:
43
+ # /api/systems/{systemId}/poams - Remove one or many poa&m items in a system
44
+ class Poams < SubCommandBase
45
+ def self.exit_on_failure?
46
+ true
47
+ end
48
+
49
+ # Delete a POAM -----------------------------------------------------------
50
+ desc 'remove', 'Delete one or many POA&M items in a system'
51
+ long_desc Help.text(:poam_del_mapper)
52
+
53
+ # Required parameters/fields
54
+ option :systemId, type: :numeric, required: true, desc: 'A numeric value representing the system identification'
55
+ option :poamId, type: :numeric, required: true, desc: 'A numeric value representing the poam identification'
56
+
57
+ def remove
58
+ body = EmassClient::PoamGet.new
59
+ body.poam_id = options[:poamId]
60
+ body_array = Array.new(1, body)
61
+
62
+ result = EmassClient::POAMApi.new.delete_poam(options[:systemId], body_array)
63
+ puts to_output_hash(result).green
64
+ rescue EmassClient::ApiError => e
65
+ puts 'Exception when calling POAMApi->delete_poam'.red
66
+ puts to_output_hash(e)
67
+ end
68
+ end
69
+
70
+ # Remove one or more Milestones from a system for a POA
71
+ #
72
+ # Endpoint:
73
+ # /api/systems/{systemId}/poam/{poamId}/milestones - Remove milestones in a system for one or many poa&m items
74
+ class Milestones < SubCommandBase
75
+ def self.exit_on_failure?
76
+ true
77
+ end
78
+
79
+ desc 'remove', 'Delete one or many POA&M MILSTONES in a system'
80
+ long_desc Help.text(:milestone_del_mapper)
81
+
82
+ # Required parameters/fields
83
+ option :systemId, type: :numeric, required: true,
84
+ desc: 'A numeric value representing the system identification'
85
+ option :poamId, type: :numeric, required: true,
86
+ desc: 'A numeric value representing the poam identification'
87
+ option :milestoneId, type: :numeric, required: true,
88
+ desc: 'A numeric value representing the milestone identification'
89
+
90
+ def remove
91
+ body = EmassClient::MilestonesGet.new
92
+ body.milestone_id = options[:milestoneId]
93
+ body_array = Array.new(1, body)
94
+
95
+ # Getting an empty return when utilizing the default return type - using 'Object' as return type
96
+ opts = Emasser::DEL_MILESTONES_RETURN_TYPE
97
+
98
+ result = EmassClient::MilestonesApi.new.delete_milestone(options[:systemId], options[:poamId], body_array, opts)
99
+ puts to_output_hash(result).green
100
+ rescue EmassClient::ApiError => e
101
+ puts 'Exception when calling MilestonesApi->delete_milestone'.red
102
+ puts to_output_hash(e).yellow
103
+ end
104
+ end
105
+
106
+ # Remove one or many artifacts in a system
107
+ #
108
+ # Endpoint:
109
+ # /api/systems/{systemId}/artifacts - Delete one or more artifacts (files) from a system
110
+ class Artifacts < SubCommandBase
111
+ def self.exit_on_failure?
112
+ true
113
+ end
114
+
115
+ desc 'remove', 'Delete one or many artifacts in a system'
116
+ long_desc Help.text(:artifact_del_mapper)
117
+
118
+ # Required parameters/fields
119
+ option :systemId, type: :numeric, required: true, desc: 'A numeric value representing the system identification'
120
+ option :files, type: :array, required: true, desc: 'Artifact file(s) to remove from the given system'
121
+
122
+ def remove
123
+ body_array = []
124
+ options[:files].each do |file|
125
+ obj = {}
126
+ obj[:filename] = file
127
+ body_array << obj
128
+ end
129
+
130
+ result = EmassClient::ArtifactsApi.new.delete_artifact(options[:systemId], body_array)
131
+ puts to_output_hash(result).green
132
+ rescue EmassClient::ApiError => e
133
+ puts 'Exception when calling ArtifactsApi->delete_artifact'.red
134
+ puts to_output_hash(e)
135
+ end
136
+ end
137
+
138
+ class Delete < SubCommandBase
139
+ desc 'poams', 'Delete Plan of Action and Milestones (POA&M) items for a system'
140
+ subcommand 'poams', Poams
141
+
142
+ desc 'milestones', 'Delete Milestones from a Plan of Action ffrom a system'
143
+ subcommand 'milestones', Milestones
144
+
145
+ desc 'artifacts', 'Delete system Artifacts'
146
+ subcommand 'artifacts', Artifacts
147
+ end
148
+ end
@@ -1,14 +1,14 @@
1
- # frozen_string_literal: true
2
-
3
- module Emasser
4
- class Error < StandardError; end
5
-
6
- class ConfigurationMissingError < Error
7
- attr_reader :config
8
-
9
- def initialize(config = 'an option', message = 'No configuration was provided for variable:')
10
- @config = config
11
- super("#{message} #{@config}")
12
- end
13
- end
14
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Emasser
4
+ class Error < StandardError; end
5
+
6
+ class ConfigurationMissingError < Error
7
+ attr_reader :config
8
+
9
+ def initialize(config = 'an option', message = 'No configuration was provided for variable:')
10
+ @config = config
11
+ super("#{message} #{@config}")
12
+ end
13
+ end
14
+ end