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 =
[:node]
Constants inherited from Aspera::Cli::Plugin
Aspera::Cli::Plugin::ALL_OPS, Aspera::Cli::Plugin::GLOBAL_OPS, Aspera::Cli::Plugin::INSTANCE_OPS
Instance Method Summary collapse
- #execute_action ⇒ Object
-
#initialize(env) ⇒ Cos
constructor
A new instance of Cos.
Methods inherited from Aspera::Cli::Plugin
#config, #entity_action, #entity_command, #format, #options, #transfer
Constructor Details
#initialize(env) ⇒ Cos
Returns a new instance of Cos.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/aspera/cli/plugins/cos.rb', line 9 def initialize(env) super(env) @service_creds=nil self..add_opt_simple(:bucket,'IBM Cloud Object storage bucket') self..add_opt_simple(:endpoint,'storage endpoint url') self..add_opt_simple(:apikey,'storage API key') self..add_opt_simple(:crn,'ressource instance id') #self.options.add_opt_simple(:oauth,'Oauth url') self..add_opt_simple(:service_credentials,'IBM Cloud service credentials (Hash)') self..add_opt_simple(:region,'IBM Cloud Object storage region') end |
Instance Method Details
#execute_action ⇒ Object
23 24 25 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 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/aspera/cli/plugins/cos.rb', line 23 def execute_action command=self..get_next_command(ACTIONS) case command when :node bucket_name=self..get_option(:bucket,:mandatory) # get service credentials, Hash, e.g. @json:@file:... service_credentials=self..get_option(:service_credentials,:optional) storage_endpoint=self..get_option(:endpoint,:optional) raise "one of: endpoint or service_credentials is required" if service_credentials.nil? and storage_endpoint.nil? raise "endpoint and service_credentials are mutually exclusive" unless service_credentials.nil? or storage_endpoint.nil? if service_credentials.nil? service_api_key = self..get_option(:apikey,:mandatory) instance_id = self..get_option(:crn,:mandatory) else # check necessary contents raise CliBadArgument,'service_credentials must be a Hash' unless service_credentials.is_a?(Hash) ['apikey','resource_instance_id','endpoints'].each do |field| raise CliBadArgument,"service_credentials must have a field: #{field}" unless service_credentials.has_key?(field) end Aspera::Log.dump('service_credentials',service_credentials) # get options bucket_region=self..get_option(:region,:mandatory) # get API key from service credentials service_api_key=service_credentials['apikey'] instance_id=service_credentials['resource_instance_id'] # read endpoints from service provided in service credentials endpoints=Aspera::Rest.new({:base_url=>service_credentials['endpoints']}).read('')[:data] Aspera::Log.dump('endpoints',endpoints) storage_endpoint=endpoints.dig('service-endpoints','regional',bucket_region,'public',bucket_region) raise "no such region: #{bucket_region}" if storage_endpoint.nil? storage_endpoint='https://'+storage_endpoint end api_node=CosNode.new(bucket_name,storage_endpoint,instance_id,service_api_key) #command=self.options.get_next_command(Node::ACTIONS) #command=self.options.get_next_command(Node::COMMON_ACTIONS) command=self..get_next_command([:upload,:download,:info,:access_key,:api_details]) node_plugin=Node.new(@agents.merge(skip_basic_auth_options: true, node_api: api_node, add_request_param: api_node.add_ts)) return node_plugin.execute_action(command) end end |