aspera-cli 4.7.0 → 4.8.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 +1 -0
- data/README.md +844 -861
- data/bin/ascli +20 -1
- data/bin/asession +37 -34
- data/docs/test_env.conf +11 -3
- data/examples/aoc.rb +13 -12
- data/examples/dascli +26 -0
- data/examples/faspex4.rb +34 -29
- data/examples/transfer.rb +30 -29
- data/lib/aspera/aoc.rb +151 -143
- data/lib/aspera/ascmd.rb +56 -45
- data/lib/aspera/ats_api.rb +6 -5
- data/lib/aspera/cli/basic_auth_plugin.rb +18 -16
- data/lib/aspera/cli/extended_value.rb +32 -30
- data/lib/aspera/cli/formater.rb +103 -111
- data/lib/aspera/cli/info.rb +2 -1
- 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 +106 -89
- data/lib/aspera/cli/manager.rb +96 -85
- data/lib/aspera/cli/plugin.rb +50 -32
- data/lib/aspera/cli/plugins/alee.rb +6 -5
- data/lib/aspera/cli/plugins/aoc.rb +521 -426
- 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 +483 -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 +201 -168
- data/lib/aspera/cli/plugins/faspex5.rb +109 -74
- data/lib/aspera/cli/plugins/node.rb +378 -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 +94 -93
- data/lib/aspera/cli/plugins/shares.rb +42 -28
- data/lib/aspera/cli/plugins/sync.rb +15 -14
- data/lib/aspera/cli/transfer_agent.rb +56 -52
- 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 +18 -8
- data/lib/aspera/fasp/agent_base.rb +26 -23
- 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 +122 -114
- data/lib/aspera/fasp/listener.rb +1 -0
- data/lib/aspera/fasp/parameters.rb +44 -41
- 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 +10 -12
- data/lib/aspera/id_generator.rb +8 -7
- data/lib/aspera/keychain/encrypted_hash.rb +60 -45
- data/lib/aspera/keychain/macos_security.rb +26 -24
- data/lib/aspera/log.rb +34 -38
- data/lib/aspera/nagios.rb +14 -13
- data/lib/aspera/node.rb +19 -19
- data/lib/aspera/oauth.rb +121 -101
- data/lib/aspera/open_application.rb +6 -5
- data/lib/aspera/persistency_action_once.rb +9 -8
- data/lib/aspera/persistency_folder.rb +10 -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 +25 -23
- data/lib/aspera/rest.rb +73 -74
- data/lib/aspera/rest_call_error.rb +1 -0
- data/lib/aspera/rest_error_analyzer.rb +11 -9
- data/lib/aspera/rest_errors_aspera.rb +5 -4
- data/lib/aspera/secret_hider.rb +68 -0
- data/lib/aspera/ssh.rb +12 -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 +11 -14
- data/lib/aspera/web_auth.rb +17 -15
- data.tar.gz.sig +0 -0
- metadata +117 -34
- metadata.gz.sig +2 -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,7 +14,8 @@ 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
|
|
@@ -37,17 +39,17 @@ module Aspera
|
|
37
39
|
|
38
40
|
def asctl_parse(text)
|
39
41
|
# normal separator
|
40
|
-
r
|
41
|
-
result=[]
|
42
|
+
r = /:\s*/
|
43
|
+
result = []
|
42
44
|
text.split("\n").each do |line|
|
43
45
|
# console: missing space
|
44
46
|
line.gsub!(/(SessionDataCollector)/,'\1 ')
|
45
47
|
# orchestrator
|
46
48
|
line.gsub!(/ with pid:.*/,'')
|
47
49
|
line.gsub!(/ is /,': ')
|
48
|
-
items=line.split(r)
|
50
|
+
items = line.split(r)
|
49
51
|
next unless items.length.eql?(2)
|
50
|
-
state={'process'=>items.first,'state'=>items.last}
|
52
|
+
state = {'process' => items.first,'state' => items.last}
|
51
53
|
# console
|
52
54
|
state['state'].gsub!(/\.+$/,'')
|
53
55
|
# console
|
@@ -58,7 +60,7 @@ module Aspera
|
|
58
60
|
state['process'].gsub!(/ Background/,'')
|
59
61
|
state['process'].gsub!(/serving orchestrator on port /,'')
|
60
62
|
# console
|
61
|
-
r
|
63
|
+
r = /\s+/ if state['process'].eql?('Console')
|
62
64
|
# orchestrator
|
63
65
|
state['process'].gsub!(/^ -> /,'')
|
64
66
|
state['process'].gsub!(/ Process/,'')
|
@@ -67,94 +69,120 @@ module Aspera
|
|
67
69
|
return result
|
68
70
|
end
|
69
71
|
|
70
|
-
|
72
|
+
def asconfigurator_parse(result)
|
73
|
+
lines = result.split("\n")
|
74
|
+
# not windows
|
75
|
+
Log.log.debug(%x(type asconfigurator))
|
76
|
+
status=lines.shift
|
77
|
+
case status
|
78
|
+
when 'success'
|
79
|
+
result = []
|
80
|
+
lines.each do |line|
|
81
|
+
Log.log.debug(line.to_s)
|
82
|
+
# normalize values
|
83
|
+
data = line.
|
84
|
+
gsub(/^"/,'').
|
85
|
+
gsub(/,""$/,',"AS_EMPTY"').
|
86
|
+
gsub(/"$/,'').
|
87
|
+
split('","').
|
88
|
+
map{|i|case i;when 'AS_NULL' then nil;when 'AS_EMPTY' then '';when 'true' then true;when 'false' then false;else i;end}
|
89
|
+
data.insert(1,'') if data.length.eql?(4)
|
90
|
+
titles=%w[level section parameter value default]
|
91
|
+
result.push(titles.each_with_object({}){|t,o|o[t]=data.shift})
|
92
|
+
end
|
93
|
+
return result
|
94
|
+
when 'failure'
|
95
|
+
raise lines.join("\n")
|
96
|
+
else raise "Unexpected: #{status}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
ACTIONS = %i[health nodeadmin userdata configurator ctl download upload browse delete rename].concat(Aspera::AsCmd::OPERATIONS).freeze
|
71
101
|
|
72
102
|
def execute_action
|
73
|
-
server_uri=URI.parse(options.get_option(:url
|
103
|
+
server_uri = URI.parse(options.get_option(:url,is_type: :mandatory))
|
74
104
|
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
|
105
|
+
server_transfer_spec = {'remote_host' => server_uri.hostname}
|
106
|
+
shell_executor = nil
|
77
107
|
case server_uri.scheme
|
78
108
|
when 'local'
|
79
|
-
shell_executor=LocalExecutor.new
|
109
|
+
shell_executor = LocalExecutor.new
|
80
110
|
when 'https'
|
81
111
|
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
|
-
})
|
112
|
+
server_transfer_spec['wss_enabled'] = true
|
113
|
+
server_transfer_spec['wss_port'] = server_uri.port
|
86
114
|
else # when 'ssh'
|
87
115
|
Log.log.error("Scheme #{server_uri.scheme} not supported. Assuming SSH.") if !server_uri.scheme.eql?('ssh')
|
88
|
-
if options.get_option(:username
|
116
|
+
if options.get_option(:username).nil?
|
89
117
|
options.set_option(:username,Aspera::Fasp::TransferSpec::ACCESS_KEY_TRANSFER_USER)
|
90
118
|
Log.log.info("Using default transfer user: #{Aspera::Fasp::TransferSpec::ACCESS_KEY_TRANSFER_USER}")
|
91
119
|
end
|
92
|
-
server_transfer_spec['remote_user']=options.get_option(:username
|
93
|
-
ssh_options=options.get_option(:ssh_options
|
120
|
+
server_transfer_spec['remote_user'] = options.get_option(:username,is_type: :mandatory)
|
121
|
+
ssh_options = options.get_option(:ssh_options)
|
94
122
|
raise 'expecting a Hash for ssh_options' unless ssh_options.is_a?(Hash)
|
95
123
|
if !server_uri.port.nil?
|
96
|
-
ssh_options[:port]=server_uri.port
|
97
|
-
server_transfer_spec['ssh_port']=server_uri.port
|
124
|
+
ssh_options[:port] = server_uri.port
|
125
|
+
server_transfer_spec['ssh_port'] = server_uri.port
|
98
126
|
end
|
99
|
-
cred_set=false
|
100
|
-
password=options.get_option(:password
|
127
|
+
cred_set = false
|
128
|
+
password = options.get_option(:password)
|
101
129
|
if !password.nil?
|
102
|
-
ssh_options[:password]=password
|
103
|
-
server_transfer_spec['remote_password']=password
|
104
|
-
cred_set=true
|
130
|
+
ssh_options[:password] = password
|
131
|
+
server_transfer_spec['remote_password'] = password
|
132
|
+
cred_set = true
|
105
133
|
end
|
106
|
-
ssh_keys=options.get_option(:ssh_keys
|
134
|
+
ssh_keys = options.get_option(:ssh_keys)
|
107
135
|
if !ssh_keys.nil?
|
108
136
|
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)
|
137
|
+
ssh_keys = [ssh_keys] if ssh_keys.is_a?(String)
|
110
138
|
ssh_keys.map!{|p|File.expand_path(p)}
|
111
139
|
Log.log.debug("ssh keys=#{ssh_keys}")
|
112
140
|
if !ssh_keys.empty?
|
113
|
-
ssh_options[:keys]=ssh_keys
|
114
|
-
server_transfer_spec['EX_ssh_key_paths']=ssh_keys
|
141
|
+
ssh_options[:keys] = ssh_keys
|
142
|
+
server_transfer_spec['EX_ssh_key_paths'] = ssh_keys
|
115
143
|
ssh_keys.each do |k|
|
116
144
|
Log.log.warn("no such key file: #{k}") unless File.exist?(k)
|
117
145
|
end
|
118
|
-
cred_set=true
|
146
|
+
cred_set = true
|
119
147
|
end
|
120
148
|
end
|
121
149
|
# 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)
|
150
|
+
cred_set = true if transfer.option_transfer_spec['token'].is_a?(String)
|
123
151
|
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)
|
152
|
+
shell_executor = Ssh.new(server_transfer_spec['remote_host'],server_transfer_spec['remote_user'],ssh_options)
|
125
153
|
end
|
126
154
|
|
127
155
|
# get command and set aliases
|
128
|
-
command=options.get_next_command(ACTIONS)
|
129
|
-
command
|
130
|
-
command
|
131
|
-
command
|
156
|
+
command = options.get_next_command(ACTIONS)
|
157
|
+
command = :ls if command.eql?(:browse)
|
158
|
+
command = :rm if command.eql?(:delete)
|
159
|
+
command = :mv if command.eql?(:rename)
|
132
160
|
case command
|
133
161
|
when :health
|
134
|
-
nagios=Nagios.new
|
135
|
-
command_nagios=options.get_next_command([
|
162
|
+
nagios = Nagios.new
|
163
|
+
command_nagios = options.get_next_command(%i[app_services transfer asctlstatus])
|
136
164
|
case command_nagios
|
137
165
|
when :app_services
|
138
166
|
# will not work with aspshell, requires Linux/bash
|
139
|
-
procs=shell_executor.execute('ps -A -o comm').split("\n")
|
167
|
+
procs = shell_executor.execute('ps -A -o comm').split("\n")
|
140
168
|
Log.log.debug("found: #{procs}")
|
141
|
-
[
|
169
|
+
%w[asperanoded asperaredisd].each do |name|
|
142
170
|
nagios.add_critical('general',"missing process #{name}") unless procs.include?(name)
|
143
171
|
end
|
144
172
|
nagios.add_ok('daemons','ok') if nagios.data.empty?
|
145
173
|
return nagios.result
|
146
174
|
when :transfer
|
147
175
|
file = Tempfile.new('transfer_test')
|
148
|
-
filepath=file.path
|
176
|
+
filepath = file.path
|
149
177
|
file.write('This is a test file for transfer test')
|
150
178
|
file.close
|
151
|
-
probe_ts=server_transfer_spec.merge({
|
179
|
+
probe_ts = server_transfer_spec.merge({
|
152
180
|
'direction' => 'send',
|
153
181
|
'cookie' => 'aspera.sync', # hide in console
|
154
182
|
'resume_policy' => 'none',
|
155
|
-
'paths' => [{'source'=>filepath,'destination'=>'.fasping'}]
|
183
|
+
'paths' => [{'source' => filepath,'destination' => '.fasping'}]
|
156
184
|
})
|
157
|
-
statuses=transfer.start(probe_ts,{src: :direct})
|
185
|
+
statuses = transfer.start(probe_ts,{src: :direct})
|
158
186
|
file.unlink
|
159
187
|
if TransferAgent.session_status(statuses).eql?(:success)
|
160
188
|
nagios.add_ok('transfer','ok')
|
@@ -162,11 +190,11 @@ module Aspera
|
|
162
190
|
nagios.add_critical('transfer',statuses.reject{|i|i.eql?(:success)}.first.to_s)
|
163
191
|
end
|
164
192
|
when :asctlstatus
|
165
|
-
realcmd='asctl'
|
166
|
-
prefix=options.get_option(:cmd_prefix
|
167
|
-
realcmd="#{prefix}#{realcmd} all:status" unless prefix.nil?
|
168
|
-
result=shell_executor.execute(realcmd.split)
|
169
|
-
data=asctl_parse(result)
|
193
|
+
realcmd = 'asctl'
|
194
|
+
prefix = options.get_option(:cmd_prefix)
|
195
|
+
realcmd = "#{prefix}#{realcmd} all:status" unless prefix.nil?
|
196
|
+
result = shell_executor.execute(realcmd.split)
|
197
|
+
data = asctl_parse(result)
|
170
198
|
data.each do |i|
|
171
199
|
if i['state'].eql?('running')
|
172
200
|
nagios.add_ok(i['process'],i['state'])
|
@@ -178,61 +206,34 @@ module Aspera
|
|
178
206
|
end
|
179
207
|
return nagios.result
|
180
208
|
when :nodeadmin,:userdata,:configurator,:ctl
|
181
|
-
realcmd=
|
182
|
-
prefix=options.get_option(:cmd_prefix
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
result=shell_executor.execute(args.unshift(realcmd))
|
209
|
+
realcmd = "as#{command}"
|
210
|
+
prefix = options.get_option(:cmd_prefix)
|
211
|
+
realcmd = "#{prefix}#{realcmd}" unless prefix.nil?
|
212
|
+
args = options.get_next_argument("#{realcmd} arguments",expected: :multiple)
|
213
|
+
args.unshift('-x') if command.eql?(:configurator)
|
214
|
+
result = shell_executor.execute(args.unshift(realcmd))
|
188
215
|
case command
|
189
216
|
when :ctl
|
190
217
|
return {type: :object_list,data: asctl_parse(result)}
|
191
218
|
when :configurator
|
192
|
-
|
193
|
-
#
|
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
|
219
|
+
result=asconfigurator_parse(result)
|
220
|
+
return {type: :object_list,data: result} # ,option_expand_last: true
|
215
221
|
end
|
216
222
|
return Main.result_status(result)
|
217
223
|
when :upload
|
218
|
-
return Main.result_transfer(transfer.start(server_transfer_spec.merge('direction'=>Fasp::TransferSpec::DIRECTION_SEND),{src: :direct}))
|
224
|
+
return Main.result_transfer(transfer.start(server_transfer_spec.merge('direction' => Fasp::TransferSpec::DIRECTION_SEND),{src: :direct}))
|
219
225
|
when :download
|
220
|
-
return Main.result_transfer(transfer.start(server_transfer_spec.merge('direction'=>Fasp::TransferSpec::DIRECTION_RECEIVE),{src: :direct}))
|
226
|
+
return Main.result_transfer(transfer.start(server_transfer_spec.merge('direction' => Fasp::TransferSpec::DIRECTION_RECEIVE),{src: :direct}))
|
221
227
|
when *Aspera::AsCmd::OPERATIONS
|
222
|
-
args=options.get_next_argument('ascmd command arguments'
|
223
|
-
ascmd=Aspera::AsCmd.new(shell_executor)
|
228
|
+
args = options.get_next_argument('ascmd command arguments',expected: :multiple,mandatory: false)
|
229
|
+
ascmd = Aspera::AsCmd.new(shell_executor)
|
224
230
|
begin
|
225
|
-
result=ascmd.send(:execute_single,command,args)
|
231
|
+
result = ascmd.send(:execute_single,command,args)
|
226
232
|
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)}
|
233
|
+
when :mkdir,:mv,:cp,:rm then return Main.result_success
|
234
|
+
when :ls then return {type: :object_list,data: key_symb_to_str_list(result),fields: %w[zmode zuid zgid size mtime name]}
|
235
|
+
when :df then return {type: :object_list,data: key_symb_to_str_list(result)}
|
236
|
+
when :du,:md5sum,:info then return {type: :single_object,data: key_symb_to_str_single(result)}
|
236
237
|
end
|
237
238
|
rescue Aspera::AsCmd::Error => e
|
238
239
|
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,63 @@ module Aspera
|
|
25
26
|
# super(env)
|
26
27
|
# end
|
27
28
|
|
28
|
-
ACTIONS=[
|
29
|
+
ACTIONS = %i[health repository admin].freeze
|
29
30
|
|
30
31
|
def execute_action
|
31
|
-
command=options.get_next_command(ACTIONS)
|
32
|
+
command = options.get_next_command(ACTIONS)
|
32
33
|
case command
|
34
|
+
when :health
|
35
|
+
nagios = Nagios.new
|
36
|
+
begin
|
37
|
+
Rest.
|
38
|
+
new(base_url: options.get_option(:url,is_type: :mandatory)+'/node_api').
|
39
|
+
call(
|
40
|
+
operation: 'GET',
|
41
|
+
subpath: 'ping',
|
42
|
+
headers: {'content-type': 'application/json'},
|
43
|
+
return_error: true)
|
44
|
+
nagios.add_ok('shares api','accessible')
|
45
|
+
rescue StandardError => e
|
46
|
+
nagios.add_critical('node api',e.to_s)
|
47
|
+
end
|
48
|
+
return nagios.result
|
33
49
|
when :repository
|
34
|
-
api_shares_node=basic_auth_api('node_api')
|
35
|
-
command=options.get_next_command(Node::COMMON_ACTIONS)
|
50
|
+
api_shares_node = basic_auth_api('node_api')
|
51
|
+
command = options.get_next_command(Node::COMMON_ACTIONS)
|
36
52
|
case command
|
37
53
|
when *Node::COMMON_ACTIONS then Node.new(@agents.merge(skip_basic_auth_options: true,node_api: api_shares_node)).execute_action(command)
|
38
54
|
else raise "INTERNAL ERROR, unknown command: [#{command}]"
|
39
55
|
end
|
40
56
|
when :admin
|
41
|
-
api_shares_admin=basic_auth_api('api/v1')
|
42
|
-
command=options.get_next_command([
|
57
|
+
api_shares_admin = basic_auth_api('api/v1')
|
58
|
+
command = options.get_next_command(%i[user share])
|
43
59
|
case command
|
44
60
|
when :user
|
45
|
-
command=options.get_next_command([
|
61
|
+
command = options.get_next_command(%i[list app_authorizations share_permissions])
|
62
|
+
user_id = instance_identifier if %i[app_authorizations share_permissions].include?(command)
|
46
63
|
case command
|
47
64
|
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
|
-
share_name=options.get_next_argument('share name')
|
57
|
-
all_shares=api_shares_admin.read('data/shares')[:data]
|
58
|
-
share_id=all_shares.select{|s| s['name'].eql?(share_name)}.first['id']
|
59
|
-
return {type: :single_object,data: api_shares_admin.create("data/shares/#{share_id}/user_permissions")[:data]}
|
60
|
-
end
|
65
|
+
return {type: :object_list,data: api_shares_admin.read('data/users')[:data],fields: %w[id username email directory_user urn]}
|
66
|
+
when :app_authorizations
|
67
|
+
return {type: :single_object,data: api_shares_admin.read("data/users/#{user_id}/app_authorizations")[:data]}
|
68
|
+
when :share_permissions
|
69
|
+
#share_name = options.get_next_argument('share name')
|
70
|
+
#all_shares = api_shares_admin.read('data/shares')[:data]
|
71
|
+
#share_id = all_shares.find{|s| s['name'].eql?(share_name)}['id']
|
72
|
+
return {type: :object_list,data: api_shares_admin.read("data/users/#{user_id}/share_permissions")[:data]}
|
61
73
|
end
|
62
74
|
when :share
|
63
|
-
command=options.get_next_command([
|
64
|
-
|
75
|
+
command = options.get_next_command(%i[list user_permissions])
|
76
|
+
share_id = instance_identifier if %i[user_permissions].include?(command)
|
77
|
+
all_shares = api_shares_admin.read('data/shares')[:data]
|
65
78
|
case command
|
66
79
|
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}"
|
80
|
+
return {type: :object_list,data: all_shares,fields: %w[id name status status_message]}
|
81
|
+
when :user_permissions
|
82
|
+
#share_name = options.get_next_argument('share name')
|
83
|
+
#share_id = all_shares.find{|s| s['name'].eql?(share_name)}['id']
|
84
|
+
#raise "NOT IMPLEMENTED: #{share_name} #{share_id}"
|
85
|
+
return {type: :object_list,data: api_shares_admin.read("data/shares/#{share_id}/user_permissions")[:data]}
|
72
86
|
end
|
73
87
|
end
|
74
88
|
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
|