aspera-cli 4.0.0 → 4.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +843 -304
- data/bin/dascli +13 -0
- data/docs/Makefile +4 -4
- data/docs/README.erb.md +805 -172
- data/docs/test_env.conf +22 -3
- data/examples/aoc.rb +14 -3
- data/examples/faspex4.rb +89 -0
- data/lib/aspera/aoc.rb +87 -108
- data/lib/aspera/cli/formater.rb +2 -0
- data/lib/aspera/cli/main.rb +89 -49
- data/lib/aspera/cli/plugin.rb +9 -4
- data/lib/aspera/cli/plugins/alee.rb +1 -1
- data/lib/aspera/cli/plugins/aoc.rb +188 -173
- data/lib/aspera/cli/plugins/ats.rb +2 -2
- data/lib/aspera/cli/plugins/config.rb +218 -145
- data/lib/aspera/cli/plugins/console.rb +2 -2
- data/lib/aspera/cli/plugins/faspex.rb +114 -61
- data/lib/aspera/cli/plugins/faspex5.rb +85 -43
- data/lib/aspera/cli/plugins/node.rb +3 -3
- data/lib/aspera/cli/plugins/preview.rb +59 -45
- data/lib/aspera/cli/plugins/server.rb +23 -8
- data/lib/aspera/cli/transfer_agent.rb +77 -49
- data/lib/aspera/cli/version.rb +1 -1
- data/lib/aspera/command_line_builder.rb +49 -31
- data/lib/aspera/cos_node.rb +33 -28
- data/lib/aspera/environment.rb +2 -2
- data/lib/aspera/fasp/connect.rb +28 -21
- data/lib/aspera/fasp/http_gw.rb +140 -28
- data/lib/aspera/fasp/installation.rb +93 -46
- data/lib/aspera/fasp/local.rb +88 -45
- data/lib/aspera/fasp/manager.rb +15 -0
- data/lib/aspera/fasp/node.rb +4 -4
- data/lib/aspera/fasp/parameters.rb +59 -101
- data/lib/aspera/fasp/parameters.yaml +531 -0
- data/lib/aspera/fasp/resume_policy.rb +13 -12
- data/lib/aspera/fasp/uri.rb +1 -1
- data/lib/aspera/log.rb +1 -1
- data/lib/aspera/node.rb +61 -1
- data/lib/aspera/oauth.rb +49 -46
- data/lib/aspera/persistency_folder.rb +9 -4
- data/lib/aspera/preview/file_types.rb +53 -21
- data/lib/aspera/preview/generator.rb +3 -3
- data/lib/aspera/rest.rb +29 -18
- data/lib/aspera/secrets.rb +20 -0
- data/lib/aspera/sync.rb +40 -35
- data/lib/aspera/temp_file_manager.rb +19 -0
- data/lib/aspera/web_auth.rb +105 -0
- metadata +54 -20
- data/docs/transfer_spec.html +0 -99
@@ -14,13 +14,13 @@ module Aspera
|
|
14
14
|
self.options.parse_options!
|
15
15
|
end
|
16
16
|
|
17
|
-
ACTIONS=[:transfer,:
|
17
|
+
ACTIONS=[:transfer,:health]
|
18
18
|
|
19
19
|
def execute_action
|
20
20
|
api_console=basic_auth_api('api')
|
21
21
|
command=self.options.get_next_command(ACTIONS)
|
22
22
|
case command
|
23
|
-
when :
|
23
|
+
when :health
|
24
24
|
nagios=Nagios.new
|
25
25
|
begin
|
26
26
|
api_console.read('ssh_keys')
|
@@ -9,6 +9,7 @@ require 'aspera/fasp/uri'
|
|
9
9
|
require 'aspera/nagios'
|
10
10
|
require 'xmlsimple'
|
11
11
|
require 'json'
|
12
|
+
require 'cgi'
|
12
13
|
|
13
14
|
module Aspera
|
14
15
|
module Cli
|
@@ -17,7 +18,17 @@ module Aspera
|
|
17
18
|
KEY_NODE='node'
|
18
19
|
KEY_PATH='path'
|
19
20
|
VAL_ALL='ALL'
|
20
|
-
|
21
|
+
# added field in result that identifies the package
|
22
|
+
PACKAGE_MATCH_FIELD='package_id'
|
23
|
+
# list of supported atoms
|
24
|
+
ATOM_MAILBOXES=[:inbox, :archive, :sent]
|
25
|
+
# number is added by CLI
|
26
|
+
MAX_ITEMS='max'
|
27
|
+
MAX_PAGES='pmax'
|
28
|
+
ATOM_PARAMS=['page', 'count', 'startIndex', MAX_ITEMS, MAX_PAGES]
|
29
|
+
PUB_LINK_EXTERNAL_MATCH='external_deliveries/'
|
30
|
+
private_constant :KEY_NODE,:KEY_PATH,:VAL_ALL,:PACKAGE_MATCH_FIELD,:ATOM_MAILBOXES,:PUB_LINK_EXTERNAL_MATCH
|
31
|
+
|
21
32
|
def initialize(env)
|
22
33
|
@api_v3=nil
|
23
34
|
@api_v4=nil
|
@@ -26,7 +37,8 @@ module Aspera
|
|
26
37
|
self.options.add_opt_simple(:delivery_info,'package delivery information (extended value)')
|
27
38
|
self.options.add_opt_simple(:source_name,'create package from remote source (by name)')
|
28
39
|
self.options.add_opt_simple(:storage,'Faspex local storage definition')
|
29
|
-
self.options.
|
40
|
+
self.options.add_opt_simple(:recipient,'use if recipient is a dropbox (with *)')
|
41
|
+
self.options.add_opt_list(:box,ATOM_MAILBOXES,'package box')
|
30
42
|
self.options.set_option(:box,:inbox)
|
31
43
|
self.options.parse_options!
|
32
44
|
end
|
@@ -52,7 +64,7 @@ module Aspera
|
|
52
64
|
|
53
65
|
# get faspe: URI from entry in xml, and fix problems..
|
54
66
|
def self.get_fasp_uri_from_entry(entry)
|
55
|
-
raise CliBadArgument, 'package
|
67
|
+
raise CliBadArgument, 'package has no link (deleted?)' unless entry.has_key?('link')
|
56
68
|
result=entry['link'].select{|e| e['rel'].eql?('package')}.first['href']
|
57
69
|
# tags in the end of URL is not well % encoded... there are "=" that should be %3D
|
58
70
|
# TODO: enter ticket to Faspex ?
|
@@ -72,7 +84,7 @@ module Aspera
|
|
72
84
|
def self.get_source_id(source_list,source_name)
|
73
85
|
source_ids=source_list.select { |i| i['name'].eql?(source_name) }
|
74
86
|
if source_ids.empty?
|
75
|
-
raise CliError
|
87
|
+
raise CliError,%Q{No such Faspex source "#{source_name}" in [#{source_list.map{|i| %Q{"#{i['name']}"}}.join(', ')}]}
|
76
88
|
end
|
77
89
|
return source_ids.first['id']
|
78
90
|
end
|
@@ -101,22 +113,57 @@ module Aspera
|
|
101
113
|
return @api_v4
|
102
114
|
end
|
103
115
|
|
104
|
-
|
105
|
-
|
106
|
-
# we match recv command on atom feed on this field
|
107
|
-
PACKAGE_MATCH_FIELD='package_id'
|
108
|
-
|
116
|
+
# query supports : {"startIndex":10,"count":1,"page":109}
|
109
117
|
def mailbox_all_entries
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
118
|
+
recipient_name=self.options.get_option(:recipient,:optional) || self.options.get_option(:username,:mandatory)
|
119
|
+
# mailbox is in ATOM_MAILBOXES
|
120
|
+
mailbox=self.options.get_option(:box,:mandatory)
|
121
|
+
# parameters
|
122
|
+
mailbox_query=self.options.get_option(:query,:optional)
|
123
|
+
max_items=nil
|
124
|
+
max_pages=nil
|
125
|
+
result=[]
|
126
|
+
if !mailbox_query.nil?
|
127
|
+
raise "query: must be Hash or nil" unless mailbox_query.is_a?(Hash)
|
128
|
+
raise "query: supported params: #{ATOM_PARAMS}" unless (mailbox_query.keys-ATOM_PARAMS).empty?
|
129
|
+
raise "query: startIndex and page are exclusive" if mailbox_query.has_key?('startIndex') and mailbox_query.has_key?('page')
|
130
|
+
max_items=mailbox_query[MAX_ITEMS]
|
131
|
+
mailbox_query.delete(MAX_ITEMS)
|
132
|
+
max_pages=mailbox_query[MAX_PAGES]
|
133
|
+
mailbox_query.delete(MAX_PAGES)
|
134
|
+
end
|
135
|
+
loop do
|
136
|
+
atom_xml=api_v3.call({operation: 'GET',subpath: "#{mailbox}.atom",headers: {'Accept'=>'application/xml'},url_params: mailbox_query})[:http].body
|
137
|
+
box_data=XmlSimple.xml_in(atom_xml, {'ForceArray' => true})
|
138
|
+
Log.dump(:box_data,box_data)
|
139
|
+
items=box_data.has_key?('entry') ? box_data['entry'] : []
|
140
|
+
Log.log.debug("new items: #{items.count}")
|
141
|
+
# it is the end if page is empty
|
142
|
+
break if items.empty?
|
143
|
+
items.each do |package|
|
144
|
+
package[PACKAGE_MATCH_FIELD]=case mailbox
|
145
|
+
when :inbox,:archive
|
146
|
+
recipient=package['to'].select{|i|i['name'].first.eql?(recipient_name)}.first
|
147
|
+
recipient.nil? ? nil : recipient['recipient_delivery_id'].first
|
148
|
+
else # :sent
|
149
|
+
package['delivery_id'].first
|
150
|
+
end
|
151
|
+
# keep only those for the specified recipient
|
152
|
+
result.push(package) unless package[PACKAGE_MATCH_FIELD].nil?
|
153
|
+
end
|
154
|
+
Log.log.debug("total items: #{result.count}")
|
155
|
+
# reach the limit ?
|
156
|
+
break if !max_items.nil? and result.count > max_items
|
157
|
+
link=box_data['link'].select{|i|i['rel'].eql?('next')}.first
|
158
|
+
Log.log.debug("link: #{link}")
|
159
|
+
# no next link
|
160
|
+
break if link.nil?
|
161
|
+
# replace parameters with the ones from next link
|
162
|
+
params=CGI.parse(URI.parse(link['href']).query)
|
163
|
+
mailbox_query=params.keys.inject({}){|m,i|;m[i]=params[i].first;m}
|
164
|
+
Log.log.debug("query: #{mailbox_query}")
|
165
|
+
break if !max_pages.nil? and mailbox_query['page'].to_i > max_pages
|
117
166
|
end
|
118
|
-
# remove dropbox packages
|
119
|
-
result.select!{|p|p['metadata'].first['field'].select{|j|j['name'].eql?('_dropbox_name')}.empty? rescue false}
|
120
167
|
return result
|
121
168
|
end
|
122
169
|
|
@@ -152,10 +199,12 @@ module Aspera
|
|
152
199
|
return pkgdatares.first
|
153
200
|
end
|
154
201
|
|
202
|
+
ACTIONS=[ :health,:package, :source, :me, :dropbox, :v4, :address_book, :login_methods ]
|
203
|
+
|
155
204
|
def execute_action
|
156
205
|
command=self.options.get_next_command(ACTIONS)
|
157
206
|
case command
|
158
|
-
when :
|
207
|
+
when :health
|
159
208
|
nagios=Nagios.new
|
160
209
|
begin
|
161
210
|
api_v3.read('me')
|
@@ -201,52 +250,59 @@ module Aspera
|
|
201
250
|
#Log.dump('transfer_spec',transfer_spec)
|
202
251
|
return Main.result_transfer(self.transfer.start(transfer_spec,{:src=>:node_gen3}))
|
203
252
|
when :recv
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
253
|
+
link_url=self.options.get_option(:link,:optional)
|
254
|
+
# list of faspex ID/URI to download
|
255
|
+
pkg_id_uri=nil
|
256
|
+
skip_ids_data=[]
|
257
|
+
skip_ids_persistency=nil
|
258
|
+
case link_url
|
259
|
+
when nil # usual case: no link
|
260
|
+
if self.options.get_option(:once_only,:mandatory)
|
261
|
+
skip_ids_persistency=PersistencyActionOnce.new(
|
262
|
+
manager: @agents[:persistency],
|
263
|
+
data: skip_ids_data,
|
264
|
+
ids: ['faspex_recv',self.options.get_option(:url,:mandatory),self.options.get_option(:username,:mandatory),self.options.get_option(:box,:mandatory).to_s])
|
265
|
+
end
|
266
|
+
# get command line parameters
|
267
|
+
delivid=self.options.get_option(:id,:mandatory)
|
268
|
+
if delivid.eql?(VAL_ALL)
|
269
|
+
pkg_id_uri=mailbox_all_entries.map{|i|{:id=>i[PACKAGE_MATCH_FIELD],:uri=>self.class.get_fasp_uri_from_entry(i)}}
|
270
|
+
# TODO : remove ids from skip not present in inbox
|
271
|
+
# skip_ids_data.select!{|id|pkg_id_uri.select{|p|p[:id].eql?(id)}}
|
272
|
+
pkg_id_uri.select!{|i|!skip_ids_data.include?(i[:id])}
|
273
|
+
else
|
274
|
+
recipient=options.get_option(:recipient,:optional)
|
275
|
+
if !recipient.nil? and recipient.start_with?('*')
|
276
|
+
raise "Dropbox and Workgroup packages should use link option with faspe:"
|
277
|
+
end
|
278
|
+
# TODO: delivery id is the right one if package was receive by workgroup
|
279
|
+
endpoint=case self.options.get_option(:box,:mandatory)
|
280
|
+
when :inbox,:archive;'received'
|
281
|
+
when :sent; 'sent'
|
282
|
+
end
|
283
|
+
entry_xml=api_v3.call({:operation=>'GET',:subpath=>"#{endpoint}/#{delivid}",:headers=>{'Accept'=>'application/xml'}})[:http].body
|
284
|
+
package_entry=XmlSimple.xml_in(entry_xml, {'ForceArray' => true})
|
285
|
+
pkg_id_uri=[{:id=>delivid,:uri=>self.class.get_fasp_uri_from_entry(package_entry)}]
|
286
|
+
end
|
287
|
+
when /^faspe:/
|
288
|
+
pkg_id_uri=[{:id=>'package',:uri=>link_url}]
|
289
|
+
else
|
290
|
+
link_data=self.class.get_link_data(link_url)
|
291
|
+
if !link_data[:subpath].start_with?(PUB_LINK_EXTERNAL_MATCH)
|
292
|
+
raise CliBadArgument,"Pub link is #{link_data[:subpath]}. Expecting #{PUB_LINK_EXTERNAL_MATCH}"
|
209
293
|
end
|
210
|
-
# Note: unauthenticated API
|
294
|
+
# Note: unauthenticated API (autorization is in url params)
|
211
295
|
api_public_link=Rest.new({:base_url=>link_data[:base_url]})
|
212
296
|
pkgdatares=api_public_link.call({:operation=>'GET',:subpath=>link_data[:subpath],:url_params=>{:passcode=>link_data[:query]['passcode']},:headers=>{'Accept'=>'application/xml'}})
|
213
297
|
if !pkgdatares[:http].body.start_with?('<?xml ')
|
214
|
-
OpenApplication.instance.uri(
|
298
|
+
OpenApplication.instance.uri(link_url)
|
215
299
|
raise CliError, 'no such package'
|
216
300
|
end
|
217
301
|
package_entry=XmlSimple.xml_in(pkgdatares[:http].body, {'ForceArray' => false})
|
302
|
+
Log.dump(:package_entry,package_entry)
|
218
303
|
transfer_uri=self.class.get_fasp_uri_from_entry(package_entry)
|
219
|
-
|
220
|
-
transfer_spec['direction']='receive'
|
221
|
-
return Main.result_transfer(self.transfer.start(transfer_spec,{:src=>:node_gen3}))
|
304
|
+
pkg_id_uri=[{:id=>package_entry['id'],:uri=>transfer_uri}]
|
222
305
|
end # public link
|
223
|
-
# get command line parameters
|
224
|
-
delivid=self.options.get_option(:id,:mandatory)
|
225
|
-
# list of faspex ID/URI to download
|
226
|
-
pkg_id_uri=nil
|
227
|
-
skip_ids_data=[]
|
228
|
-
skip_ids_persistency=nil
|
229
|
-
if self.options.get_option(:once_only,:mandatory)
|
230
|
-
skip_ids_persistency=PersistencyActionOnce.new(
|
231
|
-
manager: @agents[:persistency],
|
232
|
-
data: skip_ids_data,
|
233
|
-
ids: ['faspex_recv',self.options.get_option(:url,:mandatory),self.options.get_option(:username,:mandatory),self.options.get_option(:box,:mandatory).to_s])
|
234
|
-
end
|
235
|
-
if delivid.eql?(VAL_ALL)
|
236
|
-
pkg_id_uri=mailbox_all_entries.map{|i|{:id=>i[PACKAGE_MATCH_FIELD],:uri=>self.class.get_fasp_uri_from_entry(i)}}
|
237
|
-
# TODO : remove ids from skip not present in inbox
|
238
|
-
# skip_ids_data.select!{|id|pkg_id_uri.select{|p|p[:id].eql?(id)}}
|
239
|
-
pkg_id_uri.select!{|i|!skip_ids_data.include?(i[:id])}
|
240
|
-
else
|
241
|
-
# TODO: delivery id is the right one if package was receive by group
|
242
|
-
endpoint=case self.options.get_option(:box,:mandatory)
|
243
|
-
when :inbox,:archive;'received'
|
244
|
-
when :sent;'sent'
|
245
|
-
end
|
246
|
-
entry_xml=api_v3.call({:operation=>'GET',:subpath=>"#{endpoint}/#{delivid}",:headers=>{'Accept'=>'application/xml'}})[:http].body
|
247
|
-
package_entry=XmlSimple.xml_in(entry_xml, {'ForceArray' => true})
|
248
|
-
pkg_id_uri=[{:id=>delivid,:uri=>self.class.get_fasp_uri_from_entry(package_entry)}]
|
249
|
-
end
|
250
306
|
Log.dump(:pkg_id_uri,pkg_id_uri)
|
251
307
|
return Main.result_status('no package') if pkg_id_uri.empty?
|
252
308
|
result_transfer=[]
|
@@ -255,20 +311,17 @@ module Aspera
|
|
255
311
|
# NOTE: only external users have token in faspe: link !
|
256
312
|
if !transfer_spec.has_key?('token')
|
257
313
|
sanitized=id_uri[:uri].gsub('&','&')
|
258
|
-
# TODO: file jira
|
259
|
-
#XXsanitized.gsub!(/%3D%3D$/,'==')
|
260
|
-
#XXsanitized.gsub!(/%3D$/,'=')
|
261
314
|
xmlpayload='<?xml version="1.0" encoding="UTF-8"?><url-list xmlns="http://schemas.asperasoft.com/xml/url-list"><url href="'+sanitized+'"/></url-list>'
|
262
315
|
transfer_spec['token']=api_v3.call({:operation=>'POST',:subpath=>'issue-token?direction=down',:headers=>{'Accept'=>'text/plain','Content-Type'=>'application/vnd.aspera.url-list+xml'},:text_body_params=>xmlpayload})[:http].body
|
263
316
|
end
|
264
317
|
transfer_spec['direction']='receive'
|
265
318
|
statuses=self.transfer.start(transfer_spec,{:src=>:node_gen3})
|
266
|
-
result_transfer.push({'package'=>id_uri[:id],
|
319
|
+
result_transfer.push({'package'=>id_uri[:id],Main::STATUS_FIELD=>statuses})
|
267
320
|
# skip only if all sessions completed
|
268
321
|
skip_ids_data.push(id_uri[:id]) if TransferAgent.session_status(statuses).eql?(:success)
|
269
322
|
end
|
270
323
|
skip_ids_persistency.save unless skip_ids_persistency.nil?
|
271
|
-
return
|
324
|
+
return Main.result_transfer_multiple(result_transfer)
|
272
325
|
end
|
273
326
|
when :source
|
274
327
|
command_source=self.options.get_next_command([ :list, :id, :name ])
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'aspera/cli/basic_auth_plugin'
|
2
2
|
require 'aspera/persistency_action_once'
|
3
|
+
require 'securerandom'
|
3
4
|
|
4
5
|
module Aspera
|
5
6
|
module Cli
|
@@ -8,82 +9,123 @@ module Aspera
|
|
8
9
|
VAL_ALL='ALL'
|
9
10
|
def initialize(env)
|
10
11
|
super(env)
|
11
|
-
|
12
|
-
|
12
|
+
options.add_opt_simple(:client_id,'API client identifier in application')
|
13
|
+
options.add_opt_simple(:client_secret,'API client secret in application')
|
14
|
+
options.add_opt_simple(:redirect_uri,'API client redirect URI')
|
15
|
+
options.add_opt_list(:auth,Oauth.auth_types.clone.push(:boot),'type of Oauth authentication')
|
16
|
+
options.add_opt_simple(:private_key,'RSA private key PEM value for JWT (prefix file path with @val:@file:)')
|
17
|
+
options.set_option(:auth,:jwt)
|
18
|
+
options.parse_options!
|
13
19
|
end
|
14
|
-
ACTIONS=[ :node, :package ]
|
15
20
|
|
16
|
-
|
21
|
+
def set_api
|
22
|
+
@faxpex5_api_base_url=options.get_option(:url,:mandatory)
|
23
|
+
faxpex5_api_v5_url="#{@faxpex5_api_base_url}/api/v5"
|
24
|
+
faxpex5_api_auth_url="#{@faxpex5_api_base_url}/auth"
|
25
|
+
case options.get_option(:auth,:mandatory)
|
26
|
+
when :boot
|
27
|
+
# the password here is the token copied directly from browser in developer mode
|
28
|
+
@api_v5=Rest.new({
|
29
|
+
:base_url => faxpex5_api_v5_url,
|
30
|
+
:headers => {'Authorization'=>options.get_option(:password,:mandatory)},
|
31
|
+
})
|
32
|
+
when :web
|
33
|
+
# opens a browser and ask user to auth using web
|
34
|
+
@api_v5=Rest.new({
|
35
|
+
:base_url => faxpex5_api_v5_url,
|
36
|
+
:auth => {
|
37
|
+
:type => :oauth2,
|
38
|
+
:base_url => faxpex5_api_auth_url,
|
39
|
+
:grant => :web,
|
40
|
+
:state => SecureRandom.uuid,
|
41
|
+
:client_id => options.get_option(:client_id,:mandatory),
|
42
|
+
:redirect_uri => options.get_option(:redirect_uri,:mandatory),
|
43
|
+
}})
|
44
|
+
when :jwt
|
45
|
+
# currently Faspex 5 beta 3 only supports non-user based apis (e.g. jobs)
|
46
|
+
app_client_id=options.get_option(:client_id,:mandatory)
|
47
|
+
@api_v5=Rest.new({
|
48
|
+
:base_url => faxpex5_api_v5_url,
|
49
|
+
:auth => {
|
50
|
+
:type => :oauth2,
|
51
|
+
:base_url => faxpex5_api_auth_url,
|
52
|
+
:grant => :jwt,
|
53
|
+
:f5_username => options.get_option(:username,:mandatory),
|
54
|
+
:f5_password => options.get_option(:password,:mandatory),
|
55
|
+
:client_id => app_client_id,
|
56
|
+
:client_secret => options.get_option(:client_secret,:mandatory),
|
57
|
+
:jwt_subject => "client:#{app_client_id}", # TODO Mmmm
|
58
|
+
:jwt_audience => app_client_id, # TODO Mmmm
|
59
|
+
:jwt_private_key_obj => OpenSSL::PKey::RSA.new(options.get_option(:private_key,:mandatory)),
|
60
|
+
:jwt_headers => {typ: 'JWT'}
|
61
|
+
}})
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
ACTIONS=[ :node, :package, :auth_client, :jobs ]
|
66
|
+
|
67
|
+
#
|
17
68
|
def execute_action
|
18
|
-
|
19
|
-
|
20
|
-
faxpex5_username=self.options.get_option(:username,:mandatory)
|
21
|
-
faxpex5_password=self.options.get_option(:password,:mandatory)
|
22
|
-
faxpex5_api_base_url+='/api/v5'
|
23
|
-
# create object for REST calls to Shares2
|
24
|
-
api_v5=Rest.new({
|
25
|
-
:base_url => faxpex5_api_base_url,
|
26
|
-
:auth => {
|
27
|
-
:type => :oauth2,
|
28
|
-
:base_url => faxpex5_api_base_url,
|
29
|
-
:grant => :body_data,
|
30
|
-
:token_field =>'auth_token',
|
31
|
-
:path_token => 'authenticate',
|
32
|
-
:path_authorize => :unused,
|
33
|
-
:userpass_body => {name: faxpex5_username,password: faxpex5_password}
|
34
|
-
}})
|
35
|
-
command=self.options.get_next_command(ACTIONS)
|
69
|
+
set_api
|
70
|
+
command=options.get_next_command(ACTIONS)
|
36
71
|
case command
|
72
|
+
when :auth_client
|
73
|
+
api_auth=Rest.new(@api_v5.params.merge({base_url: "#{@faxpex5_api_base_url}/auth"}))
|
74
|
+
return self.entity_action(api_auth,'oauth_clients',nil,:id,nil,true)
|
37
75
|
when :node
|
38
|
-
return self.entity_action(api_v5,'nodes',nil,:id,nil,true)
|
76
|
+
return self.entity_action(@api_v5,'nodes',nil,:id,nil,true)
|
77
|
+
when :jobs
|
78
|
+
# to test JWT
|
79
|
+
return self.entity_action(@api_v5,'jobs',nil,:id,nil,true)
|
39
80
|
when :package
|
40
|
-
command=
|
81
|
+
command=options.get_next_command([:list,:show,:send,:receive])
|
41
82
|
case command
|
42
83
|
when :list
|
43
|
-
parameters=
|
44
|
-
return {:type => :object_list, :data
|
84
|
+
parameters=options.get_option(:value,:optional)
|
85
|
+
return {:type => :object_list, :data=>@api_v5.read('packages',parameters)[:data]['packages']}
|
45
86
|
when :show
|
46
|
-
id=
|
47
|
-
return {:type => :single_object, :data
|
87
|
+
id=options.get_option(:id,:mandatory)
|
88
|
+
return {:type => :single_object, :data=>@api_v5.read("packages/#{id}")[:data]}
|
48
89
|
when :send
|
49
|
-
parameters=
|
50
|
-
raise CliBadArgument,'
|
51
|
-
package
|
52
|
-
transfer_spec
|
90
|
+
parameters=options.get_option(:value,:mandatory)
|
91
|
+
raise CliBadArgument,'value must be hash, refer to API' unless parameters.is_a?(Hash)
|
92
|
+
package=@api_v5.create('packages',parameters)[:data]
|
93
|
+
transfer_spec=@api_v5.create("packages/#{package['id']}/transfer_spec/upload",{transfer_type: 'Connect'})[:data]
|
53
94
|
transfer_spec.delete('authentication')
|
54
95
|
return Main.result_transfer(self.transfer.start(transfer_spec,{:src=>:node_gen3}))
|
55
96
|
when :receive
|
56
97
|
pkg_type='received'
|
57
|
-
pack_id=
|
98
|
+
pack_id=options.get_option(:id,:mandatory)
|
58
99
|
package_ids=[pack_id]
|
59
100
|
skip_ids_data=[]
|
60
101
|
skip_ids_persistency=nil
|
61
|
-
if
|
102
|
+
if options.get_option(:once_only,:mandatory)
|
103
|
+
# read ids from persistency
|
62
104
|
skip_ids_persistency=PersistencyActionOnce.new(
|
63
105
|
manager: @agents[:persistency],
|
64
106
|
data: skip_ids_data,
|
65
|
-
ids: ['faspex_recv',
|
107
|
+
ids: ['faspex_recv',options.get_option(:url,:mandatory),options.get_option(:username,:mandatory),pkg_type])
|
66
108
|
end
|
67
109
|
if pack_id.eql?(VAL_ALL)
|
68
|
-
#
|
69
|
-
parameters=
|
70
|
-
parameters||={
|
71
|
-
raise CliBadArgument,'value filter must be
|
72
|
-
package_ids
|
110
|
+
# TODO: if packages have same name, they will overwrite
|
111
|
+
parameters=options.get_option(:value,:optional)
|
112
|
+
parameters||={'type'=>'received','subtype'=>'mypackages','limit'=>1000}
|
113
|
+
raise CliBadArgument,'value filter must be Hash (API GET)' unless parameters.is_a?(Hash)
|
114
|
+
package_ids=@api_v5.read('packages',parameters)[:data]['packages'].map{|p|p['id']}
|
73
115
|
package_ids.select!{|i|!skip_ids_data.include?(i)}
|
74
116
|
end
|
75
117
|
result_transfer=[]
|
76
118
|
package_ids.each do |id|
|
77
119
|
# TODO: allow from sent as well ?
|
78
|
-
transfer_spec
|
120
|
+
transfer_spec=@api_v5.create("packages/#{id}/transfer_spec/download",{transfer_type: 'Connect', type: pkg_type})[:data]
|
79
121
|
transfer_spec.delete('authentication')
|
80
122
|
statuses=self.transfer.start(transfer_spec,{:src=>:node_gen3})
|
81
|
-
result_transfer.push({'package'=>id,
|
123
|
+
result_transfer.push({'package'=>id,Main::STATUS_FIELD=>statuses})
|
82
124
|
# skip only if all sessions completed
|
83
125
|
skip_ids_data.push(id) if TransferAgent.session_status(statuses).eql?(:success)
|
84
126
|
end
|
85
127
|
skip_ids_persistency.save unless skip_ids_persistency.nil?
|
86
|
-
return
|
128
|
+
return Main.result_transfer_multiple(result_transfer)
|
87
129
|
end
|
88
130
|
end
|
89
131
|
end
|
@@ -88,7 +88,7 @@ module Aspera
|
|
88
88
|
raise StandardError,"expect: nil, String or Array"
|
89
89
|
end
|
90
90
|
|
91
|
-
SIMPLE_ACTIONS=[:
|
91
|
+
SIMPLE_ACTIONS=[:health,:events, :space, :info, :license, :mkdir, :mklink, :mkfile, :rename, :delete, :search ]
|
92
92
|
|
93
93
|
COMMON_ACTIONS=[:browse, :upload, :download, :api_details ].concat(SIMPLE_ACTIONS)
|
94
94
|
|
@@ -96,7 +96,7 @@ module Aspera
|
|
96
96
|
# prefix_path is used to list remote sources in Faspex
|
97
97
|
def execute_simple_common(command,prefix_path)
|
98
98
|
case command
|
99
|
-
when :
|
99
|
+
when :health
|
100
100
|
nagios=Nagios.new
|
101
101
|
begin
|
102
102
|
info=@api_node.read('info')[:data]
|
@@ -341,7 +341,7 @@ module Aspera
|
|
341
341
|
raise "error"
|
342
342
|
end
|
343
343
|
when :access_key
|
344
|
-
return self.entity_action(@api_node,'access_keys',
|
344
|
+
return self.entity_action(@api_node,'access_keys',nil,:id,'self')
|
345
345
|
when :service
|
346
346
|
command=self.options.get_next_command([ :list, :create, :delete])
|
347
347
|
if [:delete].include?(command)
|