Class: Aspera::Cli::Plugins::Shares2
- Inherits:
-
BasicAuthPlugin
- Object
- Aspera::Cli::Plugin
- BasicAuthPlugin
- Aspera::Cli::Plugins::Shares2
- Defined in:
- lib/aspera/cli/plugins/shares2.rb
Constant Summary collapse
- ACTIONS =
[ :repository,:organization,:project,:team,:share,:appinfo,:userinfo,:admin]
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) ⇒ Shares2
constructor
A new instance of Shares2.
-
#process_entity_action(resource_sym, path_prefix) ⇒ Object
path_prefix is empty or ends with slash.
-
#set_resource_path_by_id_or_name(resource_path, resource_sym) ⇒ Object
path_prefix is either “” or “res/id/” adds : prefix+“res/id/” modify parameter string.
Methods inherited from BasicAuthPlugin
Methods inherited from Aspera::Cli::Plugin
#config, #entity_action, #entity_command, #format, #options, #transfer
Constructor Details
#initialize(env) ⇒ Shares2
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/aspera/cli/plugins/shares2.rb', line 8 def initialize(env) super(env) self..add_opt_simple(:organization,"organization") self..add_opt_simple(:project,"project") self..add_opt_simple(:share,"share") self.. return if env[:man_only] unless env[:man_only] # get parameters shares2_api_base_url=self..get_option(:url,:mandatory) shares2_username=self..get_option(:username,:mandatory) shares2_password=self..get_option(:password,:mandatory) # create object for REST calls to Shares2 @api_shares2_oauth=Rest.new({ :base_url => shares2_api_base_url, :auth => { :type => :oauth2, :base_url => shares2_api_base_url+'/oauth2', :grant => :header_userpass, :user_name => shares2_username, :user_pass => shares2_password }}) @api_node=Rest.new({ :base_url => shares2_api_base_url+'/node_api', :auth => { :type => :basic, :username => shares2_username, :password => shares2_password}}) end end |
Instance Method Details
#execute_action ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/aspera/cli/plugins/shares2.rb', line 89 def execute_action command=self..get_next_command(ACTIONS) case command when :repository command=self..get_next_command(Node::COMMON_ACTIONS) return Node.new(@agents.merge(skip_basic_auth_options: true, node_api: @api_node)).execute_action(command) when :appinfo node_info=@api_node.call({:operation=>'GET',:subpath=>'app',:headers=>{'Accept'=>'application/json','Content-Type'=>'application/json'}})[:data] return { :type=>:single_object ,:data => node_info } when :userinfo node_info=@api_node.call({:operation=>'GET',:subpath=>'current_user',:headers=>{'Accept'=>'application/json','Content-Type'=>'application/json'}})[:data] return { :type=>:single_object ,:data => node_info } when :organization,:project,:share,:team prefix='' set_resource_path_by_id_or_name(prefix,:organization) if [:project,:team,:share].include?(command) set_resource_path_by_id_or_name(prefix,:project) if [:share].include?(command) process_entity_action(command,prefix) when :admin command=self..get_next_command([:users,:groups,:nodes]) return self.entity_action(@api_shares2_oauth,"system/#{command}",nil,:id) end # command end |
#process_entity_action(resource_sym, path_prefix) ⇒ Object
path_prefix is empty or ends with slash
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/aspera/cli/plugins/shares2.rb', line 63 def process_entity_action(resource_sym,path_prefix) resource_path=path_prefix+resource_sym.to_s+'s' operations=[:list,:create,:delete] command=self..get_next_command(operations) case command when :create params=self..get_next_argument("creation data (json structure)") resp=@api_shares2_oauth.create(resource_path,params) return {:data=>resp[:data],:type => :other_struct} when :list default_fields=['id','name'] query=self..get_option(:query,:optional) args=query.nil? ? nil : {'json_query'=>query} Log.log.debug("#{args}".bg_red) return {:data=>@api_shares2_oauth.read(resource_path,args)[:data],:fields=>default_fields,:type=>:object_list} when :delete @api_shares2_oauth.delete(set_resource_path_by_id_or_name(path_prefix,resource_sym)) return Main.result_status('deleted') when :info return {:type=>:other_struct,:data=>@api_shares2_oauth.read(set_resource_path_by_id_or_name(path_prefix,resource_sym),args)[:data]} else raise :ERROR end end |
#set_resource_path_by_id_or_name(resource_path, resource_sym) ⇒ Object
path_prefix is either “” or “res/id/” adds : prefix+“res/id/” modify parameter string
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/aspera/cli/plugins/shares2.rb', line 44 def set_resource_path_by_id_or_name(resource_path,resource_sym) res_id=self..get_option(resource_sym,:mandatory) # lets get the class path resource_path<<resource_sym.to_s+'s' # is this an integer ? or a name if res_id.to_i.to_s != res_id all=@api_shares2_oauth.read(resource_path)[:data] one=all.select{|i|i['name'].start_with?(res_id)} Log.log.debug(one) raise CliBadArgument,"No matching name for #{res_id} in #{all}" if one.empty? raise CliBadArgument,"More than one match: #{one}" if one.length > 1 res_id=one.first['id'].to_s end Log.log.debug("res_id=#{res_id}") resource_path<<'/'+res_id+'/' return resource_path end |