aspera-cli 4.7.0 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +1267 -999
- data/bin/ascli +20 -1
- data/bin/asession +37 -34
- data/docs/test_env.conf +7 -3
- data/examples/aoc.rb +13 -12
- data/examples/dascli +23 -0
- data/examples/faspex4.rb +34 -29
- data/examples/{transfer.rb → node.rb} +31 -59
- data/examples/server.rb +93 -0
- data/lib/aspera/aoc.rb +153 -143
- data/lib/aspera/ascmd.rb +56 -45
- data/lib/aspera/ats_api.rb +9 -6
- data/lib/aspera/cli/basic_auth_plugin.rb +18 -16
- data/lib/aspera/cli/extended_value.rb +33 -30
- data/lib/aspera/cli/formater.rb +105 -111
- data/lib/aspera/cli/info.rb +3 -2
- data/lib/aspera/cli/listener/line_dump.rb +1 -0
- data/lib/aspera/cli/listener/logger.rb +1 -0
- data/lib/aspera/cli/listener/progress.rb +13 -12
- data/lib/aspera/cli/listener/progress_multi.rb +21 -20
- data/lib/aspera/cli/main.rb +110 -90
- data/lib/aspera/cli/manager.rb +99 -88
- data/lib/aspera/cli/plugin.rb +98 -39
- data/lib/aspera/cli/plugins/alee.rb +6 -5
- data/lib/aspera/cli/plugins/aoc.rb +581 -450
- data/lib/aspera/cli/plugins/ats.rb +84 -83
- data/lib/aspera/cli/plugins/bss.rb +30 -27
- data/lib/aspera/cli/plugins/config.rb +488 -397
- data/lib/aspera/cli/plugins/console.rb +17 -15
- data/lib/aspera/cli/plugins/cos.rb +26 -35
- data/lib/aspera/cli/plugins/faspex.rb +206 -172
- data/lib/aspera/cli/plugins/faspex5.rb +109 -74
- data/lib/aspera/cli/plugins/node.rb +379 -189
- data/lib/aspera/cli/plugins/orchestrator.rb +71 -65
- data/lib/aspera/cli/plugins/preview.rb +131 -122
- data/lib/aspera/cli/plugins/server.rb +50 -150
- data/lib/aspera/cli/plugins/shares.rb +61 -27
- data/lib/aspera/cli/plugins/sync.rb +15 -14
- data/lib/aspera/cli/transfer_agent.rb +75 -64
- data/lib/aspera/cli/version.rb +2 -1
- data/lib/aspera/colors.rb +29 -28
- data/lib/aspera/command_line_builder.rb +50 -43
- data/lib/aspera/cos_node.rb +64 -38
- data/lib/aspera/data_repository.rb +1 -0
- data/lib/aspera/environment.rb +33 -10
- data/lib/aspera/fasp/agent_base.rb +35 -30
- data/lib/aspera/fasp/agent_connect.rb +35 -30
- data/lib/aspera/fasp/agent_direct.rb +68 -60
- data/lib/aspera/fasp/agent_httpgw.rb +71 -64
- data/lib/aspera/fasp/agent_node.rb +24 -23
- data/lib/aspera/fasp/agent_trsdk.rb +19 -20
- data/lib/aspera/fasp/error.rb +2 -1
- data/lib/aspera/fasp/error_info.rb +79 -68
- data/lib/aspera/fasp/installation.rb +130 -126
- data/lib/aspera/fasp/listener.rb +1 -0
- data/lib/aspera/fasp/parameters.rb +71 -60
- data/lib/aspera/fasp/parameters.yaml +69 -17
- data/lib/aspera/fasp/resume_policy.rb +14 -11
- data/lib/aspera/fasp/transfer_spec.rb +6 -5
- data/lib/aspera/fasp/uri.rb +25 -24
- data/lib/aspera/faspex_gw.rb +83 -72
- data/lib/aspera/hash_ext.rb +23 -13
- data/lib/aspera/id_generator.rb +16 -13
- data/lib/aspera/keychain/encrypted_hash.rb +61 -46
- data/lib/aspera/keychain/macos_security.rb +26 -24
- data/lib/aspera/log.rb +35 -39
- data/lib/aspera/nagios.rb +36 -28
- data/lib/aspera/node.rb +19 -19
- data/lib/aspera/oauth.rb +120 -100
- data/lib/aspera/open_application.rb +25 -22
- data/lib/aspera/persistency_action_once.rb +9 -8
- data/lib/aspera/persistency_folder.rb +13 -9
- data/lib/aspera/preview/file_types.rb +261 -266
- data/lib/aspera/preview/generator.rb +74 -73
- data/lib/aspera/preview/image_error.png +0 -0
- data/lib/aspera/preview/options.rb +7 -6
- data/lib/aspera/preview/utils.rb +30 -33
- data/lib/aspera/preview/video_error.png +0 -0
- data/lib/aspera/proxy_auto_config.rb +27 -23
- data/lib/aspera/rest.rb +73 -74
- data/lib/aspera/rest_call_error.rb +1 -0
- data/lib/aspera/rest_error_analyzer.rb +23 -19
- data/lib/aspera/rest_errors_aspera.rb +43 -40
- data/lib/aspera/secret_hider.rb +74 -0
- data/lib/aspera/ssh.rb +13 -10
- data/lib/aspera/sync.rb +49 -47
- data/lib/aspera/temp_file_manager.rb +7 -5
- data/lib/aspera/timer_limiter.rb +9 -8
- data/lib/aspera/uri_reader.rb +17 -18
- data/lib/aspera/web_auth.rb +17 -15
- data.tar.gz.sig +5 -0
- metadata +119 -35
- metadata.gz.sig +0 -0
- data/bin/dascli +0 -13
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'aspera/cli/basic_auth_plugin'
|
3
4
|
require 'aspera/ascmd'
|
4
5
|
require 'aspera/fasp/transfer_spec'
|
@@ -13,226 +14,125 @@ module Aspera
|
|
13
14
|
class Server < BasicAuthPlugin
|
14
15
|
class LocalExecutor
|
15
16
|
def execute(cmd,_input=nil)
|
16
|
-
|
17
|
+
Log.log.debug("Executing: #{cmd}")
|
18
|
+
%x(#{cmd.join(' ')})
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
22
|
def initialize(env)
|
21
23
|
super(env)
|
22
|
-
options.add_opt_simple(:ssh_keys,'
|
23
|
-
options.add_opt_simple(:ssh_options,'
|
24
|
-
options.add_opt_simple(:cmd_prefix,'prefix to add for as cmd execution, e.g. sudo or /opt/aspera/bin ')
|
24
|
+
options.add_opt_simple(:ssh_keys,'SSH key path list (Array or single)')
|
25
|
+
options.add_opt_simple(:ssh_options,'SSH options (Hash)')
|
25
26
|
options.set_option(:ssh_keys,[])
|
26
27
|
options.set_option(:ssh_options,{})
|
27
28
|
options.parse_options!
|
28
29
|
end
|
29
30
|
|
30
|
-
def key_symb_to_str_single(source)
|
31
|
-
return source.each_with_object({}){|(k,v),memo| memo[k.to_s] = v; }
|
32
|
-
end
|
33
|
-
|
34
31
|
def key_symb_to_str_list(source)
|
35
|
-
return source.map
|
32
|
+
return source.map(&:stringify_keys)
|
36
33
|
end
|
37
34
|
|
38
|
-
|
39
|
-
# normal separator
|
40
|
-
r=/:\s*/
|
41
|
-
result=[]
|
42
|
-
text.split("\n").each do |line|
|
43
|
-
# console: missing space
|
44
|
-
line.gsub!(/(SessionDataCollector)/,'\1 ')
|
45
|
-
# orchestrator
|
46
|
-
line.gsub!(/ with pid:.*/,'')
|
47
|
-
line.gsub!(/ is /,': ')
|
48
|
-
items=line.split(r)
|
49
|
-
next unless items.length.eql?(2)
|
50
|
-
state={'process'=>items.first,'state'=>items.last}
|
51
|
-
# console
|
52
|
-
state['state'].gsub!(/\.+$/,'')
|
53
|
-
# console
|
54
|
-
state['process'].gsub!(/^.+::/,'')
|
55
|
-
# faspex
|
56
|
-
state['process'].gsub!(/^Faspex /,'')
|
57
|
-
# faspex
|
58
|
-
state['process'].gsub!(/ Background/,'')
|
59
|
-
state['process'].gsub!(/serving orchestrator on port /,'')
|
60
|
-
# console
|
61
|
-
r=/\s+/ if state['process'].eql?('Console')
|
62
|
-
# orchestrator
|
63
|
-
state['process'].gsub!(/^ -> /,'')
|
64
|
-
state['process'].gsub!(/ Process/,'')
|
65
|
-
result.push(state)
|
66
|
-
end
|
67
|
-
return result
|
68
|
-
end
|
69
|
-
|
70
|
-
ACTIONS=[:health,:nodeadmin,:userdata,:configurator,:ctl,:download,:upload,:browse,:delete,:rename].concat(Aspera::AsCmd::OPERATIONS)
|
35
|
+
ACTIONS = %i[health download upload browse delete rename].concat(Aspera::AsCmd::OPERATIONS).freeze
|
71
36
|
|
72
37
|
def execute_action
|
73
|
-
server_uri=URI.parse(options.get_option(:url
|
38
|
+
server_uri = URI.parse(options.get_option(:url,is_type: :mandatory))
|
74
39
|
Log.log.debug("URI : #{server_uri}, port=#{server_uri.port}, scheme:#{server_uri.scheme}")
|
75
|
-
server_transfer_spec={'remote_host'=>server_uri.hostname}
|
76
|
-
shell_executor=nil
|
40
|
+
server_transfer_spec = {'remote_host' => server_uri.hostname}
|
41
|
+
shell_executor = nil
|
77
42
|
case server_uri.scheme
|
78
43
|
when 'local'
|
79
|
-
shell_executor=LocalExecutor.new
|
44
|
+
shell_executor = LocalExecutor.new
|
80
45
|
when 'https'
|
81
46
|
raise 'ERROR: transfer spec with token required' unless transfer.option_transfer_spec['token'].is_a?(String)
|
82
|
-
server_transfer_spec
|
83
|
-
|
84
|
-
'wss_port' =>server_uri.port
|
85
|
-
})
|
47
|
+
server_transfer_spec['wss_enabled'] = true
|
48
|
+
server_transfer_spec['wss_port'] = server_uri.port
|
86
49
|
else # when 'ssh'
|
87
50
|
Log.log.error("Scheme #{server_uri.scheme} not supported. Assuming SSH.") if !server_uri.scheme.eql?('ssh')
|
88
|
-
if options.get_option(:username
|
51
|
+
if options.get_option(:username).nil?
|
89
52
|
options.set_option(:username,Aspera::Fasp::TransferSpec::ACCESS_KEY_TRANSFER_USER)
|
90
53
|
Log.log.info("Using default transfer user: #{Aspera::Fasp::TransferSpec::ACCESS_KEY_TRANSFER_USER}")
|
91
54
|
end
|
92
|
-
server_transfer_spec['remote_user']=options.get_option(:username
|
93
|
-
ssh_options=options.get_option(:ssh_options
|
55
|
+
server_transfer_spec['remote_user'] = options.get_option(:username,is_type: :mandatory)
|
56
|
+
ssh_options = options.get_option(:ssh_options)
|
94
57
|
raise 'expecting a Hash for ssh_options' unless ssh_options.is_a?(Hash)
|
58
|
+
ssh_options = ssh_options.symbolize_keys
|
95
59
|
if !server_uri.port.nil?
|
96
|
-
ssh_options[:port]=server_uri.port
|
97
|
-
server_transfer_spec['ssh_port']=server_uri.port
|
60
|
+
ssh_options[:port] = server_uri.port
|
61
|
+
server_transfer_spec['ssh_port'] = server_uri.port
|
98
62
|
end
|
99
|
-
cred_set=false
|
100
|
-
password=options.get_option(:password
|
63
|
+
cred_set = false
|
64
|
+
password = options.get_option(:password)
|
101
65
|
if !password.nil?
|
102
|
-
ssh_options[:password]=password
|
103
|
-
server_transfer_spec['remote_password']=password
|
104
|
-
cred_set=true
|
66
|
+
ssh_options[:password] = password
|
67
|
+
server_transfer_spec['remote_password'] = password
|
68
|
+
cred_set = true
|
105
69
|
end
|
106
|
-
ssh_keys=options.get_option(:ssh_keys
|
70
|
+
ssh_keys = options.get_option(:ssh_keys)
|
107
71
|
if !ssh_keys.nil?
|
108
72
|
raise 'expecting single value or array for ssh_keys' unless ssh_keys.is_a?(Array) || ssh_keys.is_a?(String)
|
109
|
-
ssh_keys=[ssh_keys] if ssh_keys.is_a?(String)
|
73
|
+
ssh_keys = [ssh_keys] if ssh_keys.is_a?(String)
|
110
74
|
ssh_keys.map!{|p|File.expand_path(p)}
|
111
75
|
Log.log.debug("ssh keys=#{ssh_keys}")
|
112
76
|
if !ssh_keys.empty?
|
113
|
-
ssh_options[:keys]=ssh_keys
|
114
|
-
server_transfer_spec['EX_ssh_key_paths']=ssh_keys
|
77
|
+
ssh_options[:keys] = ssh_keys
|
78
|
+
server_transfer_spec['EX_ssh_key_paths'] = ssh_keys
|
115
79
|
ssh_keys.each do |k|
|
116
80
|
Log.log.warn("no such key file: #{k}") unless File.exist?(k)
|
117
81
|
end
|
118
|
-
cred_set=true
|
82
|
+
cred_set = true
|
119
83
|
end
|
120
84
|
end
|
121
85
|
# if user provided transfer spec has a token, we will use by pass keys
|
122
|
-
cred_set=true if transfer.option_transfer_spec['token'].is_a?(String)
|
86
|
+
cred_set = true if transfer.option_transfer_spec['token'].is_a?(String)
|
123
87
|
raise 'either password, key , or transfer spec token must be provided' if !cred_set
|
124
|
-
shell_executor=Ssh.new(server_transfer_spec['remote_host'],server_transfer_spec['remote_user'],ssh_options)
|
88
|
+
shell_executor = Ssh.new(server_transfer_spec['remote_host'],server_transfer_spec['remote_user'],ssh_options)
|
125
89
|
end
|
126
90
|
|
127
91
|
# get command and set aliases
|
128
|
-
command=options.get_next_command(ACTIONS)
|
129
|
-
command
|
130
|
-
command
|
131
|
-
command
|
92
|
+
command = options.get_next_command(ACTIONS)
|
93
|
+
command = :ls if command.eql?(:browse)
|
94
|
+
command = :rm if command.eql?(:delete)
|
95
|
+
command = :mv if command.eql?(:rename)
|
132
96
|
case command
|
133
97
|
when :health
|
134
|
-
nagios=Nagios.new
|
135
|
-
command_nagios=options.get_next_command([
|
98
|
+
nagios = Nagios.new
|
99
|
+
command_nagios = options.get_next_command(%i[transfer])
|
136
100
|
case command_nagios
|
137
|
-
when :app_services
|
138
|
-
# will not work with aspshell, requires Linux/bash
|
139
|
-
procs=shell_executor.execute('ps -A -o comm').split("\n")
|
140
|
-
Log.log.debug("found: #{procs}")
|
141
|
-
['asperanoded','asperaredisd'].each do |name|
|
142
|
-
nagios.add_critical('general',"missing process #{name}") unless procs.include?(name)
|
143
|
-
end
|
144
|
-
nagios.add_ok('daemons','ok') if nagios.data.empty?
|
145
|
-
return nagios.result
|
146
101
|
when :transfer
|
147
102
|
file = Tempfile.new('transfer_test')
|
148
|
-
filepath=file.path
|
103
|
+
filepath = file.path
|
149
104
|
file.write('This is a test file for transfer test')
|
150
105
|
file.close
|
151
|
-
probe_ts=server_transfer_spec.merge({
|
106
|
+
probe_ts = server_transfer_spec.merge({
|
152
107
|
'direction' => 'send',
|
153
108
|
'cookie' => 'aspera.sync', # hide in console
|
154
109
|
'resume_policy' => 'none',
|
155
|
-
'paths' => [{'source'=>filepath,'destination'=>'.fasping'}]
|
110
|
+
'paths' => [{'source' => filepath,'destination' => '.fasping'}]
|
156
111
|
})
|
157
|
-
statuses=transfer.start(probe_ts,{src: :direct})
|
112
|
+
statuses = transfer.start(probe_ts,{src: :direct})
|
158
113
|
file.unlink
|
159
114
|
if TransferAgent.session_status(statuses).eql?(:success)
|
160
115
|
nagios.add_ok('transfer','ok')
|
161
116
|
else
|
162
117
|
nagios.add_critical('transfer',statuses.reject{|i|i.eql?(:success)}.first.to_s)
|
163
118
|
end
|
164
|
-
when :asctlstatus
|
165
|
-
realcmd='asctl'
|
166
|
-
prefix=options.get_option(:cmd_prefix,:optional)
|
167
|
-
realcmd="#{prefix}#{realcmd} all:status" unless prefix.nil?
|
168
|
-
result=shell_executor.execute(realcmd.split)
|
169
|
-
data=asctl_parse(result)
|
170
|
-
data.each do |i|
|
171
|
-
if i['state'].eql?('running')
|
172
|
-
nagios.add_ok(i['process'],i['state'])
|
173
|
-
else
|
174
|
-
nagios.add_critical(i['process'],i['state'])
|
175
|
-
end
|
176
|
-
end
|
177
119
|
else raise 'ERROR'
|
178
120
|
end
|
179
121
|
return nagios.result
|
180
|
-
when :nodeadmin,:userdata,:configurator,:ctl
|
181
|
-
realcmd='as'+command.to_s
|
182
|
-
prefix=options.get_option(:cmd_prefix,:optional)
|
183
|
-
if !prefix.nil?
|
184
|
-
realcmd="#{prefix}#{realcmd}"
|
185
|
-
end
|
186
|
-
args = options.get_next_argument("#{realcmd} arguments",:multiple)
|
187
|
-
result=shell_executor.execute(args.unshift(realcmd))
|
188
|
-
case command
|
189
|
-
when :ctl
|
190
|
-
return {type: :object_list,data: asctl_parse(result)}
|
191
|
-
when :configurator
|
192
|
-
lines=result.split("\n")
|
193
|
-
# not windows
|
194
|
-
Log.log.debug(%x(type asconfigurator))
|
195
|
-
result=lines
|
196
|
-
if lines.first.eql?('success')
|
197
|
-
lines.shift
|
198
|
-
result={}
|
199
|
-
lines.each do |line|
|
200
|
-
Log.log.debug(line.to_s)
|
201
|
-
data=line.split(',').map{|i|i.gsub(/^"/,'').gsub(/"$/,'')}.map{|i|case i;when 'AS_NULL' then nil;when 'true' then true;when 'false' then false;else i;end}
|
202
|
-
Log.log.debug(data.to_s)
|
203
|
-
section=data.shift
|
204
|
-
datapart=result[section]||={}
|
205
|
-
if section.eql?('user')
|
206
|
-
name=data.shift
|
207
|
-
datapart=datapart[name]||={}
|
208
|
-
end
|
209
|
-
datapart=datapart[data.shift]={}
|
210
|
-
datapart['default']=data.pop
|
211
|
-
datapart['value']=data.pop
|
212
|
-
end
|
213
|
-
return {type: :single_object,data: result,fields: ['section','name','value','default'],option_expand_last: true}
|
214
|
-
end
|
215
|
-
end
|
216
|
-
return Main.result_status(result)
|
217
122
|
when :upload
|
218
|
-
return Main.result_transfer(transfer.start(server_transfer_spec.merge('direction'=>Fasp::TransferSpec::DIRECTION_SEND),{src: :direct}))
|
123
|
+
return Main.result_transfer(transfer.start(server_transfer_spec.merge('direction' => Fasp::TransferSpec::DIRECTION_SEND),{src: :direct}))
|
219
124
|
when :download
|
220
|
-
return Main.result_transfer(transfer.start(server_transfer_spec.merge('direction'=>Fasp::TransferSpec::DIRECTION_RECEIVE),{src: :direct}))
|
125
|
+
return Main.result_transfer(transfer.start(server_transfer_spec.merge('direction' => Fasp::TransferSpec::DIRECTION_RECEIVE),{src: :direct}))
|
221
126
|
when *Aspera::AsCmd::OPERATIONS
|
222
|
-
args=options.get_next_argument('ascmd command arguments'
|
223
|
-
ascmd=Aspera::AsCmd.new(shell_executor)
|
127
|
+
args = options.get_next_argument('ascmd command arguments',expected: :multiple,mandatory: false)
|
128
|
+
ascmd = Aspera::AsCmd.new(shell_executor)
|
224
129
|
begin
|
225
|
-
result=ascmd.send(:execute_single,command,args)
|
130
|
+
result = ascmd.send(:execute_single,command,args)
|
226
131
|
case command
|
227
|
-
when :mkdir then
|
228
|
-
when :
|
229
|
-
when :
|
230
|
-
when :
|
231
|
-
when :ls then return {type: :object_list,data: key_symb_to_str_list(result),fields: ['zmode','zuid','zgid','size','mtime','name']}
|
232
|
-
when :info then return {type: :single_object,data: key_symb_to_str_single(result)}
|
233
|
-
when :df then return {type: :object_list,data: key_symb_to_str_list(result)}
|
234
|
-
when :du then return {type: :single_object,data: key_symb_to_str_single(result)}
|
235
|
-
when :md5sum then return {type: :single_object,data: key_symb_to_str_single(result)}
|
132
|
+
when :mkdir,:mv,:cp,:rm then return Main.result_success
|
133
|
+
when :ls then return {type: :object_list,data: key_symb_to_str_list(result),fields: %w[zmode zuid zgid size mtime name]}
|
134
|
+
when :df then return {type: :object_list,data: key_symb_to_str_list(result)}
|
135
|
+
when :du,:md5sum,:info then return {type: :single_object,data: result.stringify_keys}
|
236
136
|
end
|
237
137
|
rescue Aspera::AsCmd::Error => e
|
238
138
|
raise CliBadArgument,e.extended_message
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'aspera/cli/plugins/node'
|
3
4
|
|
4
5
|
module Aspera
|
@@ -7,7 +8,7 @@ module Aspera
|
|
7
8
|
class Shares < BasicAuthPlugin
|
8
9
|
class << self
|
9
10
|
def detect(base_url)
|
10
|
-
api=Rest.new({base_url: base_url})
|
11
|
+
api = Rest.new({base_url: base_url})
|
11
12
|
# Shares
|
12
13
|
begin
|
13
14
|
# shall fail: shares requires auth, but we check error message
|
@@ -25,50 +26,83 @@ module Aspera
|
|
25
26
|
# super(env)
|
26
27
|
# end
|
27
28
|
|
28
|
-
|
29
|
+
SAML_IMPORT_MANDATORY=%w[id name_id].freeze
|
30
|
+
SAML_IMPORT_ALLOWED=[SAML_IMPORT_MANDATORY,%w[email given_name surname]].flatten.freeze
|
31
|
+
|
32
|
+
ACTIONS = %i[health repository admin].freeze
|
29
33
|
|
30
34
|
def execute_action
|
31
|
-
command=options.get_next_command(ACTIONS)
|
35
|
+
command = options.get_next_command(ACTIONS)
|
32
36
|
case command
|
37
|
+
when :health
|
38
|
+
nagios = Nagios.new
|
39
|
+
begin
|
40
|
+
Rest.
|
41
|
+
new(base_url: options.get_option(:url,is_type: :mandatory)+'/node_api').
|
42
|
+
call(
|
43
|
+
operation: 'GET',
|
44
|
+
subpath: 'ping',
|
45
|
+
headers: {'content-type': 'application/json'},
|
46
|
+
return_error: true)
|
47
|
+
nagios.add_ok('shares api','accessible')
|
48
|
+
rescue StandardError => e
|
49
|
+
nagios.add_critical('node api',e.to_s)
|
50
|
+
end
|
51
|
+
return nagios.result
|
33
52
|
when :repository
|
34
|
-
api_shares_node=basic_auth_api('node_api')
|
35
|
-
command=options.get_next_command(Node::COMMON_ACTIONS)
|
53
|
+
api_shares_node = basic_auth_api('node_api')
|
54
|
+
command = options.get_next_command(Node::COMMON_ACTIONS)
|
36
55
|
case command
|
37
56
|
when *Node::COMMON_ACTIONS then Node.new(@agents.merge(skip_basic_auth_options: true,node_api: api_shares_node)).execute_action(command)
|
38
57
|
else raise "INTERNAL ERROR, unknown command: [#{command}]"
|
39
58
|
end
|
40
59
|
when :admin
|
41
|
-
api_shares_admin=basic_auth_api('api/v1')
|
42
|
-
command=options.get_next_command([
|
60
|
+
api_shares_admin = basic_auth_api('api/v1')
|
61
|
+
command = options.get_next_command(%i[user share])
|
43
62
|
case command
|
44
63
|
when :user
|
45
|
-
command=options.get_next_command([
|
64
|
+
command = options.get_next_command(%i[list app_authorizations share_permissions saml_import ldap_import])
|
65
|
+
user_id = instance_identifier if %i[app_authorizations share_permissions].include?(command)
|
46
66
|
case command
|
47
67
|
when :list
|
48
|
-
return {type: :object_list,data: api_shares_admin.read('data/users')[:data],fields: [
|
49
|
-
when :
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
68
|
+
return {type: :object_list,data: api_shares_admin.read('data/users')[:data],fields: %w[id username email directory_user urn]}
|
69
|
+
when :app_authorizations
|
70
|
+
return {type: :single_object,data: api_shares_admin.read("data/users/#{user_id}/app_authorizations")[:data]}
|
71
|
+
when :share_permissions
|
72
|
+
#share_name = options.get_next_argument('share name')
|
73
|
+
#all_shares = api_shares_admin.read('data/shares')[:data]
|
74
|
+
#share_id = all_shares.find{|s| s['name'].eql?(share_name)}['id']
|
75
|
+
return {type: :object_list,data: api_shares_admin.read("data/users/#{user_id}/share_permissions")[:data]}
|
76
|
+
when :saml_import
|
77
|
+
parameters = options.get_option(:value)
|
78
|
+
return do_bulk_operation(parameters,'created') do |user_params|
|
79
|
+
user_params=user_params.transform_keys{|k|k.gsub(/\s+/,'_').downcase}
|
80
|
+
raise 'expecting Hash' unless user_params.is_a?(Hash)
|
81
|
+
SAML_IMPORT_MANDATORY.each{|p|raise "missing mandatory field: #{p}" if user_params[p].nil?}
|
82
|
+
user_params.keys.each do |p|
|
83
|
+
raise "unsupported field: #{p}, use: #{SAML_IMPORT_ALLOWED.join(',')}" unless SAML_IMPORT_ALLOWED.include?(p)
|
84
|
+
end
|
85
|
+
api_shares_admin.create('data/saml_users/import',user_params)[:data]
|
86
|
+
end
|
87
|
+
when :ldap_import
|
88
|
+
parameters = options.get_option(:value)
|
89
|
+
return do_bulk_operation(parameters,'created') do |user_name|
|
90
|
+
raise 'expecting string (user name), have #{user_params.class}' unless user_params.is_a?(String)
|
91
|
+
api_shares_admin.create('data/ldap_users',{'user'=>user_name})[:data]
|
60
92
|
end
|
61
93
|
end
|
62
94
|
when :share
|
63
|
-
command=options.get_next_command([
|
64
|
-
|
95
|
+
command = options.get_next_command(%i[list user_permissions])
|
96
|
+
share_id = instance_identifier if %i[user_permissions].include?(command)
|
97
|
+
all_shares = api_shares_admin.read('data/shares')[:data]
|
65
98
|
case command
|
66
99
|
when :list
|
67
|
-
return {type: :object_list,data: all_shares,fields: [
|
68
|
-
when :
|
69
|
-
share_name=options.get_next_argument('share name')
|
70
|
-
share_id=all_shares.
|
71
|
-
raise "NOT IMPLEMENTED: #{share_name} #{share_id}"
|
100
|
+
return {type: :object_list,data: all_shares,fields: %w[id name status status_message]}
|
101
|
+
when :user_permissions
|
102
|
+
#share_name = options.get_next_argument('share name')
|
103
|
+
#share_id = all_shares.find{|s| s['name'].eql?(share_name)}['id']
|
104
|
+
#raise "NOT IMPLEMENTED: #{share_name} #{share_id}"
|
105
|
+
return {type: :object_list,data: api_shares_admin.read("data/shares/#{share_id}/user_permissions")[:data]}
|
72
106
|
end
|
73
107
|
end
|
74
108
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'English'
|
3
4
|
require 'aspera/cli/plugin'
|
4
5
|
require 'aspera/sync'
|
@@ -17,16 +18,16 @@ module Aspera
|
|
17
18
|
options.parse_options!
|
18
19
|
end
|
19
20
|
|
20
|
-
ACTIONS=[
|
21
|
+
ACTIONS = %i[start admin].freeze
|
21
22
|
|
22
23
|
def execute_action
|
23
|
-
command=options.get_next_command(ACTIONS)
|
24
|
+
command = options.get_next_command(ACTIONS)
|
24
25
|
case command
|
25
26
|
when :start
|
26
|
-
env_args=Aspera::Sync.new(options.get_option(:parameters
|
27
|
-
async_bin='async'
|
27
|
+
env_args = Aspera::Sync.new(options.get_option(:parameters,is_type: :mandatory)).compute_args
|
28
|
+
async_bin = 'async'
|
28
29
|
Log.log.debug("execute: #{env_args[:env].map{|k,v| "#{k}=\"#{v}\""}.join(' ')} \"#{async_bin}\" \"#{env_args[:args].join('" "')}\"")
|
29
|
-
res=system(env_args[:env],[async_bin,async_bin],*env_args[:args])
|
30
|
+
res = system(env_args[:env],[async_bin,async_bin],*env_args[:args])
|
30
31
|
Log.log.debug("result=#{res}")
|
31
32
|
case res
|
32
33
|
when true then return Main.result_success
|
@@ -35,22 +36,22 @@ module Aspera
|
|
35
36
|
else raise 'internal error: unspecified case'
|
36
37
|
end
|
37
38
|
when :admin
|
38
|
-
p=options.get_option(:parameters
|
39
|
-
n=options.get_option(:session_name
|
40
|
-
cmdline=['asyncadmin','--quiet']
|
41
|
-
session=n.nil? ? p['sessions'].first : p['sessions'].
|
42
|
-
cmdline.push('--name='+session['name'])
|
39
|
+
p = options.get_option(:parameters,is_type: :mandatory)
|
40
|
+
n = options.get_option(:session_name)
|
41
|
+
cmdline = ['asyncadmin','--quiet']
|
42
|
+
session = n.nil? ? p['sessions'].first : p['sessions'].find{|s|s['name'].eql?(n)}
|
43
|
+
cmdline.push('--name=' + session['name'])
|
43
44
|
if session.has_key?('local_db_dir')
|
44
|
-
cmdline.push('--local-db-dir='+session['local_db_dir'])
|
45
|
+
cmdline.push('--local-db-dir=' + session['local_db_dir'])
|
45
46
|
else
|
46
|
-
cmdline.push('--local-dir='+session['local_dir'])
|
47
|
+
cmdline.push('--local-dir=' + session['local_dir'])
|
47
48
|
end
|
48
|
-
command2=options.get_next_command([:status])
|
49
|
+
command2 = options.get_next_command([:status])
|
49
50
|
case command2
|
50
51
|
when :status
|
51
52
|
stdout, stderr, status = Open3.capture3(*cmdline)
|
52
53
|
Log.log.debug("status=#{status}, stderr=#{stderr}")
|
53
|
-
items=stdout.split("\n").each_with_object({}){|l,m|i=l.split(/: */);m[i.first.lstrip]=i.last.lstrip;}
|
54
|
+
items = stdout.split("\n").each_with_object({}){|l,m|i = l.split(/: */);m[i.first.lstrip] = i.last.lstrip;}
|
54
55
|
return {type: :single_object,data: items}
|
55
56
|
else raise 'error'
|
56
57
|
end # command
|