Class: Aspera::Cli::Plugins::Shares

Inherits:
BasicAuthPlugin show all
Defined in:
lib/aspera/cli/plugins/shares.rb

Constant Summary collapse

ACTIONS =
[ :repository,: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

Methods inherited from BasicAuthPlugin

#basic_auth_api

Methods inherited from Aspera::Cli::Plugin

#config, #entity_action, #entity_command, #format, #options, #transfer

Constructor Details

#initialize(env) ⇒ Shares

Returns a new instance of Shares.



7
8
9
10
# File 'lib/aspera/cli/plugins/shares.rb', line 7

def initialize(env)
  super(env)
  #self.options.parse_options!
end

Instance Method Details

#execute_actionObject



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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/aspera/cli/plugins/shares.rb', line 14

def execute_action
  command=self.options.get_next_command(ACTIONS)
  case command
  when :repository
    api_shares_node=basic_auth_api('node_api')
    command=self.options.get_next_command(Node::COMMON_ACTIONS)
    case command
    when *Node::COMMON_ACTIONS; Node.new(@agents.merge(skip_basic_auth_options: true,node_api: api_shares_node)).execute_action(command)
    else raise "INTERNAL ERROR, unknown command: [#{command}]"
    end
  when :admin
    api_shares_admin=basic_auth_api('api/v1')
    command=self.options.get_next_command([:user,:share])
    case command
    when :user
      command=self.options.get_next_command([:list,:id])
      case command
      when :list
        return {:type=>:object_list,:data=>api_shares_admin.read('data/users')[:data],:fields=>['username','email','directory_user','urn']}
      when :id
        res_id=self.options.get_next_argument('user id')
        command=self.options.get_next_command([:app_authorizations,:authorize_share])
        case command
        when :app_authorizations
          return {:type=>:single_object,:data=>api_shares_admin.read("data/users/#{res_id}/app_authorizations")[:data]}
        when :share
          share_name=self.options.get_next_argument('share name')
          all_shares=api_shares_admin.read('data/shares')[:data]
          share_id=all_shares.select{|s| s['name'].eql?(share_name)}.first['id']
          return {:type=>:single_object,:data=>api_shares_admin.create("data/shares/#{share_id}/user_permissions")[:data]}
        end
      end
    when :share
      command=self.options.get_next_command([:list,:name])
      all_shares=api_shares_admin.read('data/shares')[:data]
      case command
      when :list
        return {:type=>:object_list,:data=>all_shares,:fields=>['id','name','status','status_message']}
      when :name
        share_name=self.options.get_next_argument('share name')
        share_id=all_shares.select{|s| s['name'].eql?(share_name)}.first['id']
        raise "TODO"
      end
    end
  end
end