Class: Emasser::Container

Inherits:
SubCommandBase show all
Defined in:
lib/emasser/post.rb,
lib/emasser/delete.rb

Overview

The Container Scan Results endpoint provides the ability to remove containers and their scan results in the assets module for a system.

Endpoint:

/api/systems/{systemId}/container-scan-results

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SubCommandBase

banner

Methods included from OutputConverters

#change_to_datetime, #to_output_hash

Methods included from InputConverters

#to_input_hash

Methods included from OptionsParser

#optional_options, #required_options

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


968
969
970
# File 'lib/emasser/post.rb', line 968

def self.exit_on_failure?
  true
end

Instance Method Details

#addObject

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
# File 'lib/emasser/post.rb', line 1004

def add
  # Required fields
  body = {}
  body[:containerId] = options[:containerId]
  body[:containerName] = options[:containerName]
  body[:time] = options[:time]
  # Optional fields
  body[:namespace] = options[:namespace] if options[:namespace]
  body[:podIp] = options[:podIp] if options[:podIp]
  body[:podName] = options[:podName] if options[:podName]

  # Tags - Optional field
  tags = {}
  tags[:test] = options[:test] if options[:test]

  # Benchmarks - Required field
  benchmarks = {}
  benchmarks[:benchmark] = options[:benchmark]
  # Benchmarks - Optional fields
  benchmarks[:isBaseline] = options[:isBaseline] if options[:isBaseline]
  benchmarks[:version] = options[:version] if options[:version]
  benchmarks[:release] = options[:release] if options[:release]

  # Benchmarks.Results - Required fields
  benchmarks_results = {}
  benchmarks_results[:lastSeen] = options[:lastSeen]
  benchmarks_results[:ruleId] = options[:ruleId]
  benchmarks_results[:status] = options[:status]
  # Benchmarks.Results - Optional field
  benchmarks_results[:message] = options[:message] if options[:message]

  # Add Benchmark results to an array and add array to benchmarks object
  benchmarks_results_array = Array.new(1, benchmarks_results)
  benchmarks[:results] = benchmarks_results_array

  # Add benchmarks object to an array
  benchmarks_array = Array.new(1, benchmarks)
  # Add tags and benchmark ojects to body object
  body[:tags] = tags if tags.any?
  body[:benchmarks] = benchmarks_array

  # Build the body array
  body_array = Array.new(1, body)

  # Call the API
  begin
    result = EmassClient::ContainerScanResultsApi
             .new.add_container_sans_by_system_id(options[:systemId], body_array)
    puts to_output_hash(result).green
  rescue EmassClient::ApiError => e
    puts 'Exception when calling ContainerScanResultsApi->add_container_sans_by_system_id'.red
    puts to_output_hash(e)
  end
end

#removeObject



243
244
245
246
247
248
249
250
251
252
253
# File 'lib/emasser/delete.rb', line 243

def remove
  body = EmassClient::ContainerResourcesDeleteBodyInner.new
  body.container_id = options[:containerId]
  body_array = Array.new(1, body)

  result = EmassClient::ContainerScanResultsApi.new.delete_container_sans(options[:systemId], body_array)
  puts to_output_hash(result).green
rescue EmassClient::ApiError => e
  puts 'Exception when calling ContainerScanResultsApi->delete_container_sans'.red
  puts to_output_hash(e)
end