Class: Aspera::Cli::Plugins::Cos
- Inherits:
-
Aspera::Cli::Plugin
- Object
- Aspera::Cli::Plugin
- Aspera::Cli::Plugins::Cos
- Defined in:
- lib/aspera/cli/plugins/cos.rb
Constant Summary collapse
- ACTIONS =
%i[node].freeze
Constants inherited from Aspera::Cli::Plugin
Aspera::Cli::Plugin::ALL_OPS, Aspera::Cli::Plugin::GLOBAL_OPS, Aspera::Cli::Plugin::INIT_PARAMS, Aspera::Cli::Plugin::INSTANCE_OPS, Aspera::Cli::Plugin::MAX_ITEMS, Aspera::Cli::Plugin::MAX_PAGES, Aspera::Cli::Plugin::REGEX_LOOKUP_ID_BY_FIELD
Instance Method Summary collapse
- #execute_action ⇒ Object
-
#initialize(**env) ⇒ Cos
constructor
A new instance of Cos.
Methods inherited from Aspera::Cli::Plugin
declare_generic_options, #do_bulk_operation, #entity_action, #entity_command, #init_params, #instance_identifier, #query_option, #query_read_delete, #value_create_modify
Constructor Details
#initialize(**env) ⇒ Cos
Returns a new instance of Cos.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/aspera/cli/plugins/cos.rb', line 12 def initialize(**env) super .declare(:bucket, 'Bucket name') .declare(:endpoint, 'Storage endpoint (URL)') .declare(:apikey, 'Storage API key') .declare(:crn, 'Resource instance id (CRN)') .declare(:service_credentials, 'IBM Cloud service credentials', types: Hash) .declare(:region, 'Storage region') .declare(:identity, "Authentication URL (#{Api::CosNode::IBM_CLOUD_TOKEN_URL})", default: Api::CosNode::IBM_CLOUD_TOKEN_URL) . end |
Instance Method Details
#execute_action ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/aspera/cli/plugins/cos.rb', line 26 def execute_action command = .get_next_command(ACTIONS) case command when :node # get service credentials, Hash, e.g. @json:@file:... service_credentials = .get_option(:service_credentials) cos_node_params = { auth_url: .get_option(:identity, mandatory: true), bucket: .get_option(:bucket, mandatory: true), endpoint: .get_option(:endpoint) } if service_credentials.nil? Aspera.assert(!cos_node_params[:endpoint].nil?, exception_class: Cli::BadArgument){'endpoint required when service credentials not provided'} cos_node_params[:api_key] = .get_option(:apikey, mandatory: true) cos_node_params[:instance_id] = .get_option(:crn, mandatory: true) else Aspera.assert(cos_node_params[:endpoint].nil?, exception_class: Cli::BadArgument){'endpoint not allowed when service credentials provided'} cos_node_params.merge!(Api::CosNode.parameters_from_svc_credentials(service_credentials, .get_option(:region, mandatory: true))) end api_node = Api::CosNode.new(**cos_node_params) node_plugin = Node.new(**init_params, api: api_node) command = .get_next_command(Node::COMMANDS_COS) return node_plugin.execute_action(command) end end |