Class: Emasser::Artifacts
- Inherits:
-
SubCommandBase
- Object
- Thor
- SubCommandBase
- Emasser::Artifacts
- Defined in:
- lib/emasser/get.rb,
lib/emasser/put.rb,
lib/emasser/post.rb,
lib/emasser/delete.rb
Overview
Remove one or many artifacts in a system
Endpoint:
/api/systems/{systemId}/artifacts - Delete one or more artifacts (files) from a system
Class Method Summary collapse
Instance Method Summary collapse
-
#export ⇒ Object
NOTE: compress is a required parameter, however Thor does not allow a boolean type to be required because it automatically creates a –no-compress option, which is confusing in the help output: [–compress], [–no-compress] # BOOLEAN - true or false.
- #forSystem ⇒ Object
- #remove ⇒ Object
-
#update ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
- #upload ⇒ Object
Methods inherited from SubCommandBase
Methods included from OutputConverters
Methods included from InputConverters
Methods included from OptionsParser
#optional_options, #required_options
Class Method Details
.exit_on_failure? ⇒ Boolean
392 393 394 |
# File 'lib/emasser/get.rb', line 392 def self.exit_on_failure? true end |
Instance Method Details
#export ⇒ Object
NOTE: compress is a required parameter, however Thor does not allow a boolean type to be required because it automatically creates a –no-compress option, which is confusing in the help output:
[--compress], [--no-compress] # BOOLEAN - true or false.
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/emasser/get.rb', line 431 def export = (@_initializer).keys = to_input_hash(, ) .merge!(Emasser::GET_ARTIFACTS_RETURN_TYPE) result = EmassClient::ArtifactsExportApi.new.get_system_artifacts_export( [:systemId], [:filename], ) if [:compress] p result.green else begin puts JSON.pretty_generate(JSON.parse(result)).green rescue StandardError puts result.red end end rescue EmassClient::ApiError => e puts 'Exception when calling ArtifactsApi->get_system_artifacts_export'.red puts to_output_hash(e) end |
#forSystem ⇒ Object
406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/emasser/get.rb', line 406 def forSystem = (@_initializer).keys = to_input_hash(, ) begin # Get one or many artifacts in a system result = EmassClient::ArtifactsApi.new.get_system_artifacts([:systemId], ) puts to_output_hash(result).green rescue EmassClient::ApiError => e puts 'Exception when calling ArtifactsApi->get_system_artifacts'.red puts to_output_hash(e) end end |
#remove ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/emasser/delete.rb', line 120 def remove body_array = [] [:files].each do |file| obj = {} obj[:filename] = file body_array << obj end result = EmassClient::ArtifactsApi.new.delete_artifact(body_array, [:systemId]) puts to_output_hash(result).green rescue EmassClient::ApiError => e puts 'Exception when calling ArtifactsApi->delete_artifact'.red puts to_output_hash(e) end |
#update ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'lib/emasser/put.rb', line 541 def update body = EmassClient::ArtifactsRequestPutBody.new body.filename = [:filename] body.type = [:type] body.category = [:category] body.is_template = [:isTemplate] # Optional fields body.description = [:description] if [:description] body.ref_page_number = [:refPageNumber] if [:refPageNumber] body.ccis = [:ccis] if [:ccis] body.controls = [:controls] if [:controls] body.artifact_expiration_date = [:artifactExpirationDate] if [:artifactExpirationDate] body.last_reviewed_date = [:lastReviewedDate] if [:lastReviewedDate] body_array = Array.new(1, body) begin result = EmassClient::ArtifactsApi.new.update_artifact_by_system_id(body_array, [:systemId]) puts to_output_hash(result).green rescue EmassClient::ApiError => e puts 'Exception when calling ArtifactsApi->update_artifact_by_system_id'.red puts to_output_hash(e) end end |
#upload ⇒ Object
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/emasser/post.rb', line 375 def upload = (@_initializer).keys = to_input_hash(, ) # Remove the isTemplate as we can't use the required = true. .delete(:is_template) opts = {} opts[:form_params] = tempfile = Tempfile.create(['artifacts', '.zip']) Zip::OutputStream.open(tempfile.path) do |z| [:files].each do |file| # Add file name to the archive: Don't use the full path z.put_next_entry(File.basename(file)) # Add the file to the archive z.print File.read(file) end end begin result = EmassClient::ArtifactsApi .new .add_artifacts_by_system_id([:isTemplate], [:type], [:category], tempfile, [:systemId], opts) puts to_output_hash(result).green rescue EmassClient::ApiError => e puts 'Exception when calling ArtifactsApi->add_artifacts_by_system_id'.red puts to_output_hash(e) ensure # Delete the temp file unless File.exist? tempfile tempfile.close FileUtils.remove_file(tempfile, true) end end end |