Class: Emasser::Poams

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

Overview

Remove one or more POA&M from a system

Endpoint:

/api/systems/{systemId}/poams - Remove one or many poa&m items in a system

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SubCommandBase

banner

Methods included from OutputConverters

#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)


278
279
280
# File 'lib/emasser/get.rb', line 278

def self.exit_on_failure?
  true
end

Instance Method Details

#addObject

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/emasser/post.rb', line 154

def add
  # Required fields
  body = EmassClient::PoamRequiredPost.new
  body.status = options[:status]
  body.vulnerability_description = options[:vulnerabilityDescription]
  body.source_ident_vuln = options[:sourceIdentVuln]
  body.poc_organization = options[:pocOrganization]
  body.resources = options[:resources]

  process_business_logic(body)

  # Add conditional fields
  body.poc_first_name = options[:pocFirstName] if options[:pocFirstName]
  body.poc_last_name = options[:pocLastName] if options[:pocLastName]
  body.poc_email = options[:pocEmail] if options[:pocEmail]
  body.poc_phone_number = options[:pocPhoneNumber] if options[:pocPhoneNumber]
  body.severity = options[:severity] if options[:severity]

  # Add optional fields
  body.external_uid = options[:externalUid] if options[:externalUid]
  body.control_acronyms = options[:controlAcronym] if options[:controlAcronym]
  body.cci = options[:cci] if options[:cci]
  body.security_checks = options[:securityChecks] if options[:securityChecks]
  body.raw_severity = options[:rawSeverity] if options[:rawSeverity]
  body.relevance_of_threat = options[:relevanceOfThreat] if options[:relevanceOfThreat]
  body.likelihood = options[:likelihood] if options[:likelihood]
  body.impact = options[:impact] if options[:impact]
  body.impact_description = options[:impactDescription] if options[:impactDescription]
  body.residual_risk_level = options[:residualRiskLevel] if options[:residualRiskLevel]
  body.recommendations = options[:recommendations] if options[:recommendations]
  body.mitigation = options[:mitigation] if options[:mitigation]

  body_array = Array.new(1, body)

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

#byPoamIdObject



317
318
319
320
321
322
323
# File 'lib/emasser/get.rb', line 317

def byPoamId
  result = EmassClient::POAMApi.new.get_system_poams_by_poam_id(options[:systemId], options[:poamId])
  puts to_output_hash(result).green
rescue EmassClient::ApiError => e
  puts 'Exception when calling POAMApi->get_system_poams_by_poam_id'.red
  puts to_output_hash(e)
end

#forSystemObject



296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/emasser/get.rb', line 296

def forSystem
  optional_options_keys = optional_options(@_initializer).keys
  optional_options = to_input_hash(optional_options_keys, options)

  begin
    result = EmassClient::POAMApi.new.get_system_poams(options[:systemId], optional_options)
    puts to_output_hash(result).green
  rescue EmassClient::ApiError => e
    puts 'Exception when calling POAMApi->get_system_poams'.red
    puts to_output_hash(e)
  end
end

#removeObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/emasser/delete.rb', line 57

def remove
  body = EmassClient::DeletePoam.new
  body.poam_id = options[:poamId]
  body_array = Array.new(1, body)

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

#updateObject

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/emasser/put.rb', line 313

def update
  # Required fields
  body = EmassClient::PoamRequiredPut.new
  body.poam_id = options[:poamId]
  body.status = options[:status]
  body.vulnerability_description = options[:vulnerabilityDescription]
  body.source_ident_vuln = options[:sourceIdentVuln]
  body.poc_organization = options[:pocOrganization]

  process_business_logic(body)

  # Add conditional fields
  body.poc_first_name = options[:pocFirstName] if options[:pocFirstName]
  body.poc_last_name = options[:pocLastName] if options[:pocLastName]
  body.poc_email = options[:pocEmail] if options[:pocEmail]
  body.poc_phone_number = options[:pocPhoneNumber] if options[:pocPhoneNumber]
  body.severity = options[:severity] if options[:severity]

  # Add optional fields
  body.external_uid = options[:externalUid] if options[:externalUid]
  body.control_acronym = options[:controlAcronym] if options[:controlAcronym]
  body.cci = options[:cci] if options[:cci]
  body.security_checks = options[:securityChecks] if options[:securityChecks]
  body.raw_severity = options[:rawSeverity] if options[:rawSeverity]
  body.relevance_of_threat = options[:relevanceOfThreat] if options[:relevanceOfThreat]
  body.likelihood = options[:likelihood] if options[:likelihood]
  body.impact = options[:impact] if options[:impact]
  body.impact_description = options[:impactDescription] if options[:impactDescription]
  body.residual_risk_level = options[:residualRiskLevel] if options[:residualRiskLevel]
  body.recommendations = options[:recommendations] if options[:recommendations]
  body.mitigation = options[:mitigation] if options[:mitigation]

  body_array = Array.new(1, body)

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