Class: Aspera::Cli::Plugins::Faspio
- Defined in:
- lib/aspera/cli/plugins/faspio.rb
Constant Summary collapse
- ACTIONS =
%i[health bridges].freeze
Constants inherited from Base
Base::ALL_OPS, Base::GLOBAL_OPS, Base::INSTANCE_OPS, Base::MAX_ITEMS, Base::MAX_PAGES, Base::REGEX_LOOKUP_ID_BY_FIELD
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #execute_action ⇒ Object
-
#initialize(**_) ⇒ Faspio
constructor
A new instance of Faspio.
-
#wizard(wizard, app_url) ⇒ Hash
:preset_value, :test_args.
Methods inherited from BasicAuth
#basic_auth_api, #basic_auth_params, declare_options
Methods inherited from Base
#add_manual_header, #config, declare_options, #do_bulk_operation, #entity_execute, #formatter, #instance_identifier, #list_entities_limit_offset_total_count, #lookup_entity_by_field, #options, #persistency, #query_read_delete, #transfer, #value_create_modify
Constructor Details
#initialize(**_) ⇒ Faspio
Returns a new instance of Faspio.
43 44 45 46 47 48 49 50 |
# File 'lib/aspera/cli/plugins/faspio.rb', line 43 def initialize(**_) super .declare(:auth, 'OAuth type of authentication', values: %i[jwt basic]) .declare(:client_id, 'OAuth client identifier') .declare(:private_key, 'OAuth JWT RSA private key PEM value (prefix file path with @file:)') .declare(:passphrase, 'OAuth JWT RSA private key passphrase') . end |
Class Method Details
.application_name ⇒ Object
12 13 14 |
# File 'lib/aspera/cli/plugins/faspio.rb', line 12 def application_name 'faspio Gateway' end |
.detect(base_url) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/aspera/cli/plugins/faspio.rb', line 16 def detect(base_url) api = Rest.new(base_url: base_url) ping_result = api.call(operation: 'GET', subpath: 'ping', headers: {'Accept' => Rest::MIME_JSON}) server_type = ping_result[:http]['Server'] return unless ping_result[:data].is_a?(Hash) && ping_result[:data].empty? return unless server_type.is_a?(String) && server_type.include?('faspio') return { version: server_type.gsub(%r{^.*/}, ''), url: base_url } end |
Instance Method Details
#execute_action ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/aspera/cli/plugins/faspio.rb', line 52 def execute_action base_url = .get_option(:url, mandatory: true) api = case .get_option(:auth, mandatory: true) when :basic basic_auth_api when :jwt app_client_id = .get_option(:client_id, mandatory: true) Rest.new( base_url: base_url, auth: { type: :oauth2, grant_method: :jwt, base_url: "#{base_url}/auth", client_id: app_client_id, use_query: true, payload: { iss: app_client_id, # issuer sub: app_client_id # subject }, private_key_obj: OpenSSL::PKey::RSA.new(.get_option(:private_key, mandatory: true), .get_option(:passphrase)), headers: {typ: 'JWT'} } ) end command = .get_next_command(ACTIONS) case command when :health nagios = Nagios.new begin result = api.read('ping') if result.is_a?(Hash) && result.empty? nagios.add_ok('api', 'answered ok') else nagios.add_critical('api', 'not expected answer') end rescue StandardError => e nagios.add_critical('api', e.to_s) end return nagios.result when :bridges return entity_execute(api: api, entity: 'bridges') end end |
#wizard(wizard, app_url) ⇒ Hash
Returns :preset_value, :test_args.
32 33 34 35 36 37 38 39 |
# File 'lib/aspera/cli/plugins/faspio.rb', line 32 def wizard(wizard, app_url) return { preset_value: { url: app_url }, test_args: 'info' } end |