Class: Chelsea::IQClient
- Inherits:
-
Object
- Object
- Chelsea::IQClient
- Defined in:
- lib/chelsea/iq_client.rb
Overview
IQ audit operations
Constant Summary collapse
- DEFAULT_OPTIONS =
rubocop:disable Metrics/ClassLength
{ public_application_id: 'testapp', server_url: 'http://localhost:8070', username: 'admin', auth_token: 'admin123', internal_application_id: '', stage: 'build' }.freeze
- COLOR_FAILURE =
colors to use when printing message
31
- COLOR_WARNING =
want yellow, but doesn’t appear to print
33
- COLOR_NONE =
32
- POLICY_ACTION_FAILURE =
Known policy actions
'Failure'
- POLICY_ACTION_WARNING =
'Warning'
- POLICY_ACTION_NONE =
'None'
Instance Method Summary collapse
-
#initialize(options: DEFAULT_OPTIONS) ⇒ IQClient
constructor
A new instance of IQClient.
- #poll_status(url) ⇒ Object
-
#post_sbom(sbom) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #status_url(res) ⇒ Object
Constructor Details
#initialize(options: DEFAULT_OPTIONS) ⇒ IQClient
Returns a new instance of IQClient.
38 39 40 41 42 |
# File 'lib/chelsea/iq_client.rb', line 38 def initialize(options: DEFAULT_OPTIONS) @options = @pastel = Pastel.new @spinner = Chelsea::Spinner.new end |
Instance Method Details
#poll_status(url) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/chelsea/iq_client.rb', line 67 def poll_status(url) spin = @spinner.spin_msg 'Polling Nexus IQ Server for results' loop do res = _poll_iq_server(url) if res.code == 200 spin.success('...done.') return _handle_response(res) end rescue StandardError sleep(1) end end |
#post_sbom(sbom) ⇒ Object
rubocop:disable Metrics/MethodLength
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/chelsea/iq_client.rb', line 44 def post_sbom(sbom) # rubocop:disable Metrics/MethodLength spin = @spinner.spin_msg 'Submitting sbom to Nexus IQ Server' @internal_application_id = _get_internal_application_id resource = RestClient::Resource.new( _api_url, user: @options[:username], password: @options[:auth_token] ) res = resource.post sbom.to_s, _headers.merge(content_type: 'application/xml') if res.code == 202 spin.success('...done.') status_url(res) else spin.stop('...request failed.') nil end end |
#status_url(res) ⇒ Object
62 63 64 65 |
# File 'lib/chelsea/iq_client.rb', line 62 def status_url(res) res = JSON.parse(res.body) res['statusUrl'] end |