asperalm 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d266cb6fecccce2ad3e97cf3af5d5137b33b5a02
4
- data.tar.gz: aa5bf1d708ffde18f4f6cdca3237327c01e17e1c
3
+ metadata.gz: d1553dfd9451b29eb64396ffdc8fb1514dece1cf
4
+ data.tar.gz: 2ef7983a1c2487712a70edf856b0af40b737d621
5
5
  SHA512:
6
- metadata.gz: 2f4b2b1c28401d1e15eb0f18db63c6f95101fb9ab165f482af5ea4359a95244fc7c9da96505076c0c627cdc00d29bfdbdc09a4c6bd8b644eff726e86754a9370
7
- data.tar.gz: 66d89af327517ccc006683cf421ca46729db999e9383a2d3f7caa25531c49242ff39743af38b68d8d902954a1620f98900e5f9592f2cf617c02ef9c30a3a945d
6
+ metadata.gz: 415980795e21412739d02889ed9d713f240853f353d0be483f8a11759589a1cb6047a79b587975d7cefb970157530a41ad82ff3af27a940a001e01583085eda6
7
+ data.tar.gz: 9a60dc24d55738cfdb985a3f9457b6f16938bfa268dea0dd2325fb428e5ef69b245cfe7eaf5a905dad8a8e852df1c72f0d763f21f64621605a346bf479d95714
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Asperalm - A Ruby library for Aspera transfers and "Amelia", the _Multi Layer IBM Aspera_ Command Line Tool
2
2
 
3
- Version : 0.9.7
3
+ Version : 0.9.8
4
4
 
5
5
 
6
6
  _Laurent/2016-2018_
@@ -37,7 +37,7 @@ Once the gem is installed, `mlia` shall be accessible:
37
37
 
38
38
  ```bash
39
39
  $ mlia --version
40
- 0.9.7
40
+ 0.9.8
41
41
  ```
42
42
 
43
43
  ## First use
@@ -907,6 +907,7 @@ mlia aspera admin set_client_key ERuzXGuPA @file:$(APIKEY)
907
907
  mlia aspera files browse /
908
908
  mlia aspera files download --to-folder=sample_dest_folder --download=node --sources=@args /200KB.1
909
909
  mlia aspera files download --to-folder=sample_dest_folder --transfer=connect --sources=@args /200KB.1
910
+ mlia aspera files transfer --from-folder=/ --to-folder=xxx --sources=@args 200KB.1
910
911
  mlia aspera files upload --to-folder=/ --sources=@args sample_file.bin
911
912
  mlia aspera packages list
912
913
  mlia aspera packages list --format=csv --fields=id|head -n 1)
@@ -945,6 +946,7 @@ mlia config overview
945
946
  mlia console transfer current list
946
947
  mlia faspex package list
947
948
  mlia faspex package list --fields=delivery_id --format=csv --box=sent|tail -n 1) --box=sent
949
+ mlia faspex package recv --to-folder=sample_dest_folder --id=ALL --once-only=yes
948
950
  mlia faspex package send --delivery-info=@json:'{"title":"my title","recipients":["laurent.martin.aspera@fr.ibm.com"]}' --sources=@args sample_file.bin
949
951
  mlia faspex package send --load-params=reset --url=my_url_here --username=my_username_here --password=my_password_here --insecure=yes --note="my note" --title="my title" --recipient="laurent.martin.aspera@fr.ibm.com" ~/200KB.1
950
952
  mlia faspex recv_publink 'https://faspex.mycompany.com/aspera/faspex/external_deliveries/78780?passcode=a003aaf2f53e3869126b908525084db6bebc7031' --insecure=yes
@@ -1009,7 +1011,7 @@ mlia sync start --parameters=@json:'{"sessions":[{"name":"test","reset":true,"re
1009
1011
  ```bash
1010
1012
  $ mlia -h
1011
1013
  NAME
1012
- mlia -- a command line tool for Aspera Applications (v0.9.7)
1014
+ mlia -- a command line tool for Aspera Applications (v0.9.8)
1013
1015
 
1014
1016
  SYNOPSIS
1015
1017
  mlia COMMANDS [OPTIONS] [ARGS]
@@ -1123,6 +1125,7 @@ OPTIONS:
1123
1125
  --link=VALUE link to shared resource
1124
1126
  --public-token=VALUE token value of public link
1125
1127
  --new-user-option=VALUE new user creation option
1128
+ --from-folder=VALUE share to share source folder
1126
1129
 
1127
1130
  COMMAND: xnode
1128
1131
  SUBCOMMANDS: postprocess, cleanup, forward
@@ -1157,6 +1160,7 @@ OPTIONS:
1157
1160
  --source-name=VALUE create package from remote source (by name)
1158
1161
  --storage=VALUE Faspex local storage definition
1159
1162
  --box=ENUM package box: inbox, sent, archive
1163
+ --once-only=ENUM keep track of already downloaded packages: yes, no
1160
1164
 
1161
1165
  COMMAND: shares2
1162
1166
  SUBCOMMANDS: repository, organization, project, team, share, appinfo, userinfo, admin
@@ -2239,6 +2243,11 @@ Gems, or remove your ed25519 key from your `.ssh` folder to solve the issue.
2239
2243
 
2240
2244
  # Release Notes
2241
2245
 
2246
+ * version 0.9.8
2247
+
2248
+ * Faspex: use option once_only set to yes to enable cargo like function. id=NEW deprecated.
2249
+ * AoC: share to share transfer with command "transfer"
2250
+
2242
2251
  * version 0.9.7
2243
2252
 
2244
2253
  * homogeneous transfer spec for node and local
@@ -72,4 +72,6 @@ Thread.new do
72
72
  end
73
73
  end
74
74
  # no exit code: status is success (0)
75
- client.shutdown(true)
75
+ client.wait_for_transfers_completion
76
+ client.shutdown
77
+
@@ -1 +1 @@
1
- 0.9.7
1
+ 0.9.8
@@ -354,6 +354,10 @@ module Asperalm
354
354
  # :status displays a simple message
355
355
  display_message(:info,results[:data])
356
356
  return
357
+ when :text # no table
358
+ # :status displays a simple message
359
+ display_message(:data,results[:data])
360
+ return
357
361
  when :other_struct # no table
358
362
  # :other_struct is any other type of structure
359
363
  display_message(:data,PP.pp(results[:data],''))
@@ -452,14 +456,27 @@ module Asperalm
452
456
 
453
457
  public
454
458
 
455
- def start_transfer_wait_result(transfer_spec,options)
456
- return TransferAgent.instance.start_transfer_wait_result(transfer_spec,options)
459
+ # if return_result, @return CLI result
460
+ # else, return list of statuses
461
+ # in any case, wait for completion of all jobs
462
+ def start_transfer(transfer_spec,options,return_result=true)
463
+ # TODO: if not one shot, then wait for status
464
+ statuses=TransferAgent.instance.start(transfer_spec,options)
465
+ if return_result
466
+ TransferAgent.instance.exception_on_error(statuses)
467
+ return self.class.result_nothing
468
+ end
469
+ return statuses
457
470
  end
458
471
 
459
472
  def destination_folder(direction)
460
473
  return TransferAgent.instance.destination_folder(direction)
461
474
  end
462
475
 
476
+ def ts_source_paths
477
+ return TransferAgent.instance.ts_source_paths
478
+ end
479
+
463
480
  def display_status(status)
464
481
  display_message(:info,status)
465
482
  end
@@ -540,8 +557,8 @@ module Asperalm
540
557
  end
541
558
  # execute and display
542
559
  display_results(command_plugin.execute_action)
543
- # wait for session termination
544
- TransferAgent.instance.shutdown(true)
560
+ # finish
561
+ TransferAgent.instance.shutdown
545
562
  @opt_mgr.fail_if_unprocessed
546
563
  rescue CliBadArgument => e; exception_info=[e,'Argument',:usage]
547
564
  rescue CliNoSuchId => e; exception_info=[e,'Identifier']
@@ -35,6 +35,7 @@ module Asperalm
35
35
  Main.instance.options.add_opt_simple(:link,"link to shared resource")
36
36
  Main.instance.options.add_opt_simple(:public_token,"token value of public link")
37
37
  Main.instance.options.add_opt_simple(:new_user_option,"new user creation option")
38
+ Main.instance.options.add_opt_simple(:from_folder,"share to share source folder")
38
39
  Main.instance.options.set_option(:download_mode,:fasp)
39
40
  Main.instance.options.set_option(:bulk,:no)
40
41
  Main.instance.options.set_option(:redirect_uri,'http://localhost:12345')
@@ -42,8 +43,12 @@ module Asperalm
42
43
  Main.instance.options.set_option(:new_user_option,{'package_contact'=>true})
43
44
  end
44
45
 
46
+ def self.start_transfer(api_files,app,direction,node_info,file_id,ts_add={})
47
+ return Main.instance.start_transfer(*api_files.tr_spec(app,direction,node_info,file_id,ts_add))
48
+ end
49
+
45
50
  def self.execute_node_gen4_action(api_files,home_node_id,home_file_id)
46
- command_repo=Main.instance.options.get_next_command([ :access_key, :browse, :mkdir, :rename, :delete, :upload, :download, :node, :file ])
51
+ command_repo=Main.instance.options.get_next_command([ :access_key, :browse, :mkdir, :rename, :delete, :upload, :download, :transfer, :node, :file ])
47
52
  case command_repo
48
53
  when :access_key
49
54
  node_info,file_id = api_files.find_nodeinfo_and_fileid(home_node_id,home_file_id)
@@ -76,11 +81,28 @@ module Asperalm
76
81
  node_api=api_files.get_files_node_api(node_info,FilesApi::SCOPE_NODE_USER)
77
82
  result=node_api.delete("files/#{file_id}")[:data]
78
83
  return Main.result_status("deleted: #{thepath}")
84
+ when :transfer
85
+ client_action='send'
86
+ from_folder=Main.instance.options.get_option(:from_folder,:mandatory)
87
+ node_server_info,node_server_file_id = api_files.find_nodeinfo_and_fileid(home_node_id,home_file_id,Main.instance.destination_folder(client_action))
88
+ node_client_info,node_client_file_id = api_files.find_nodeinfo_and_fileid(home_node_id,home_file_id,from_folder)
89
+ node_client_api=api_files.get_files_node_api(node_client_info,FilesApi::SCOPE_NODE_USER)
90
+ # force node as agent
91
+ Main.instance.options.set_option(:transfer,:node)
92
+ # force node api in agent
93
+ Fasp::Node.instance.node_api=node_client_api
94
+ # additional node to node TS info
95
+ add_ts={
96
+ 'remote_access_key' => node_server_info['access_key'],
97
+ 'destination_root_id' => node_server_file_id,
98
+ 'source_root_id' => node_client_file_id
99
+ }
100
+ return start_transfer(api_files,'files',client_action,node_client_info,node_client_file_id,add_ts)
79
101
  when :upload
80
102
  node_info,file_id = api_files.find_nodeinfo_and_fileid(home_node_id,home_file_id,Main.instance.destination_folder('send'))
81
- return Main.instance.start_transfer_wait_result(*api_files.tr_spec('files','send',node_info,file_id,{}))
103
+ return start_transfer(api_files,'files','send',node_info,file_id)
82
104
  when :download
83
- source_paths=TransferAgent.instance.transfer_paths_from_options
105
+ source_paths=Main.instance.ts_source_paths
84
106
  source_folder=source_paths.shift['source']
85
107
  if source_paths.empty?
86
108
  source_folder=source_folder.split(FilesApi::PATH_SEPARATOR)
@@ -91,8 +113,8 @@ module Asperalm
91
113
  when :fasp
92
114
  node_info,file_id = api_files.find_nodeinfo_and_fileid(home_node_id,home_file_id,source_folder)
93
115
  # override paths with just filename
94
- return Main.instance.start_transfer_wait_result(
95
- *api_files.tr_spec('files','receive',node_info,file_id,{'paths'=>source_paths}))
116
+ add_ts={'paths'=>source_paths}
117
+ return start_transfer(api_files,'files','receive',node_info,file_id,add_ts)
96
118
  when :node_http
97
119
  raise CliBadArgument,"one file at a time only in HTTP mode" if source_paths.length > 1
98
120
  file_name = source_paths.first['source']
@@ -307,7 +329,7 @@ module Asperalm
307
329
  package_creation['workspace_id']=@workspace_id
308
330
 
309
331
  # list of files to include in package
310
- package_creation['file_names']=TransferAgent.instance.transfer_paths_from_options.map{|i|File.basename(i['source'])}
332
+ package_creation['file_names']=Main.instance.ts_source_paths.map{|i|File.basename(i['source'])}
311
333
 
312
334
  new_user_option=Main.instance.options.get_option(:new_user_option,:mandatory)
313
335
 
@@ -330,17 +352,19 @@ module Asperalm
330
352
 
331
353
  # tell Aspera what to expect in package: 1 transfer (can also be done after transfer)
332
354
  resp=@api_files_user.update("packages/#{the_package['id']}",{'sent'=>true,'transfers_expected'=>1})[:data]
333
- return Main.instance.start_transfer_wait_result(*@api_files_user.tr_spec('packages','send',node_info,the_package['contents_file_id'],{
334
- 'tags'=>{'aspera'=>{'files'=>{'package_id'=>the_package['id'],'package_operation'=>'upload'}}},
335
- }))
355
+ add_ts={
356
+ 'tags'=>{'aspera'=>{'files'=>{'package_id'=>the_package['id'],'package_operation'=>'upload'}}}
357
+ }
358
+ return self.class.start_transfer(@api_files_user,'packages','send',node_info,the_package['contents_file_id'],add_ts)
336
359
  when :recv
337
360
  package_id=Main.instance.options.get_option(:id,:mandatory)
338
361
  the_package=@api_files_user.read("packages/#{package_id}")[:data]
339
362
  node_info=@api_files_user.read("nodes/#{the_package['node_id']}")[:data]
340
- return Main.instance.start_transfer_wait_result(*@api_files_user.tr_spec('packages','receive',node_info,the_package['contents_file_id'],{
363
+ add_ts={
341
364
  'tags' => {'aspera'=>{'files'=>{'package_id'=>the_package['id'],'package_operation'=>'download'}}},
342
365
  'paths' => [{'source'=>'.'}]
343
- }))
366
+ }
367
+ return self.class.start_transfer(@api_files_user,'packages','receive',node_info,the_package['contents_file_id'],add_ts)
344
368
  when :show
345
369
  package_id=Main.instance.options.get_next_argument('package ID')
346
370
  the_package=@api_files_user.read("packages/#{package_id}")[:data]
@@ -1,6 +1,7 @@
1
1
  require 'asperalm/cli/basic_auth_plugin'
2
2
  require 'asperalm/cli/plugins/node'
3
3
  require 'asperalm/cli/plugins/config'
4
+ require 'asperalm/persistency_file'
4
5
  require 'asperalm/cli/extended_value'
5
6
  require 'asperalm/open_application'
6
7
  require 'asperalm/fasp/uri'
@@ -15,7 +16,6 @@ module Asperalm
15
16
  @@KEY_NODE='node'
16
17
  @@KEY_PATH='path'
17
18
  @@VAL_ALL='ALL'
18
- @@VAL_NEW='NEW'
19
19
  alias super_declare_options declare_options
20
20
  def declare_options
21
21
  super_declare_options
@@ -23,7 +23,9 @@ module Asperalm
23
23
  Main.instance.options.add_opt_simple(:source_name,"create package from remote source (by name)")
24
24
  Main.instance.options.add_opt_simple(:storage,"Faspex local storage definition")
25
25
  Main.instance.options.add_opt_list(:box,[:inbox,:sent,:archive],"package box")
26
+ Main.instance.options.add_opt_boolean(:once_only,"keep track of already downloaded packages")
26
27
  Main.instance.options.set_option(:box,:inbox)
28
+ Main.instance.options.set_option(:once_only,:false)
27
29
  end
28
30
 
29
31
  # extract elements from anonymous faspex link
@@ -83,7 +85,6 @@ module Asperalm
83
85
  :base_url => faspex_api_base+'/api',
84
86
  :auth_type => :oauth2,
85
87
  :oauth_base_url => faspex_api_base+'/auth/oauth2',
86
- :oauth_path_token => 'token',
87
88
  :oauth_type => :header_userpass,
88
89
  :oauth_user_name => Main.instance.options.get_option(:username,:mandatory),
89
90
  :oauth_user_pass => Main.instance.options.get_option(:password,:mandatory),
@@ -98,15 +99,15 @@ module Asperalm
98
99
  # we match recv command on atom feed on this field
99
100
  PACKAGE_MATCH_FIELD='package_id'
100
101
 
101
- def mailbox_entries
102
+ def mailbox_all_entries
102
103
  mailbox=Main.instance.options.get_option(:box,:mandatory).to_s
103
104
  all_inbox_xml=api_v3.call({:operation=>'GET',:subpath=>"#{mailbox}.atom",:headers=>{'Accept'=>'application/xml'}})[:http].body
104
105
  all_inbox_data=XmlSimple.xml_in(all_inbox_xml, {"ForceArray" => true})
105
106
  Log.dump(:all_inbox_data,all_inbox_data)
106
107
  result=all_inbox_data.has_key?('entry') ? all_inbox_data['entry'] : []
107
- result.each do |e|
108
- e[PACKAGE_MATCH_FIELD]=e['to'].first['recipient_delivery_id'].first
109
- end
108
+ result.each do |e|
109
+ e[PACKAGE_MATCH_FIELD]=e['to'].first['recipient_delivery_id'].first
110
+ end
110
111
  return result
111
112
  end
112
113
 
@@ -117,16 +118,29 @@ module Asperalm
117
118
  command_pkg=Main.instance.options.get_next_command([ :send, :recv, :list ])
118
119
  case command_pkg
119
120
  when :list
120
- return {:type=>:object_list,:data=>self.mailbox_entries,:fields=>[PACKAGE_MATCH_FIELD,'title','items'], :textify => lambda { |table_data| Faspex.textify_package_list(table_data)} }
121
+ return {:type=>:object_list,:data=>self.mailbox_all_entries,:fields=>[PACKAGE_MATCH_FIELD,'title','items'], :textify => lambda { |table_data| Faspex.textify_package_list(table_data)} }
121
122
  when :recv
122
123
  delivid=Main.instance.options.get_option(:id,:mandatory)
123
124
  mailbox=Main.instance.options.get_option(:box,:mandatory).to_s
125
+ once_only=Main.instance.options.get_option(:once_only,:mandatory)
124
126
  uris_to_download=nil
127
+ skip_ids=[]
128
+ ids_to_download=[]
125
129
  case delivid
126
130
  when @@VAL_ALL
127
- uris_to_download=self.mailbox_entries.map{|e|self.class.get_fasp_uri_from_entry(e)}
128
- when @@VAL_NEW
129
- raise "TODO"
131
+ if once_only
132
+ persistency_file=PersistencyFile.new('faspex_recv',Cli::Plugins::Config.instance.config_folder)
133
+ persistency_file.set_unique(
134
+ nil,
135
+ [Main.instance.options.get_option(:username,:mandatory),Main.instance.options.get_option(:box,:mandatory).to_s],
136
+ Main.instance.options.get_option(:url,:mandatory))
137
+ data=persistency_file.read_from_file
138
+ unless data.nil?
139
+ skip_ids=JSON.parse(data)
140
+ end
141
+ end
142
+ # todo
143
+ uris_to_download=self.mailbox_all_entries.select{|e| !skip_ids.include?(e[PACKAGE_MATCH_FIELD])}.map{|e|ids_to_download.push(e[PACKAGE_MATCH_FIELD]);self.class.get_fasp_uri_from_entry(e)}
130
144
  else
131
145
  # I dont know which delivery id is the right one if package was receive by group
132
146
  entry_xml=api_v3.call({:operation=>'GET',:subpath=>"#{mailbox}/#{delivid}",:headers=>{'Accept'=>'application/xml'}})[:http].body
@@ -135,8 +149,10 @@ module Asperalm
135
149
  uris_to_download=[transfer_uri]
136
150
  end
137
151
  Log.dump(:uris_to_download,uris_to_download)
138
- last_status=Main.result_status('no package')
152
+ return Main.result_status('no package') if uris_to_download.empty?
153
+ result_transfer=[]
139
154
  uris_to_download.each do |transfer_uri|
155
+ this_id=ids_to_download.shift
140
156
  transfer_spec=Fasp::Uri.new(transfer_uri).transfer_spec
141
157
  # NOTE: only external users have token in faspe: link !
142
158
  if !transfer_spec.has_key?('token')
@@ -145,15 +161,25 @@ module Asperalm
145
161
  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
146
162
  end
147
163
  transfer_spec['direction']='receive'
148
- last_status=Main.instance.start_transfer_wait_result(transfer_spec,{:src=>:node_gen3})
164
+ statuses=Main.instance.start_transfer(transfer_spec,{:src=>:node_gen3},false)
165
+ result_transfer.push({'package'=>this_id,'status'=>statuses.map{|i|i.to_s}.join(',')})
166
+ begin
167
+ TransferAgent.instance.exception_on_error(statuses)
168
+ # shall be same order
169
+ skip_ids.push(this_id)
170
+ rescue
171
+ end
172
+ end
173
+ if once_only and !skip_ids.empty?
174
+ persistency_file.write_to_file(JSON.generate(skip_ids))
149
175
  end
150
- return last_status
176
+ return {:type=>:object_list,:data=>result_transfer}
151
177
  when :send
152
178
  delivery_info=Main.instance.options.get_option(:delivery_info,:mandatory)
153
179
  raise CliBadArgument,"delivery_info must be hash, refer to doc" unless delivery_info.is_a?(Hash)
154
180
  delivery_info['sources']||=[{'paths'=>[]}]
155
181
  first_source=delivery_info['sources'].first
156
- first_source['paths'].push(*TransferAgent.instance.transfer_paths_from_options.map{|i|i['source']})
182
+ first_source['paths'].push(*Main.instance.ts_source_paths.map{|i|i['source']})
157
183
  source_name=Main.instance.options.get_option(:source_name,:optional)
158
184
  if !source_name.nil?
159
185
  source_list=api_v3.call({:operation=>'GET',:subpath=>"source_shares",:headers=>{'Accept'=>'application/json'}})[:data]['items']
@@ -173,14 +199,14 @@ module Asperalm
173
199
  transfer_spec=send_result['xfer_sessions'].first
174
200
  # use source from cmd line, this one nly contains destination (already in dest root)
175
201
  transfer_spec.delete('paths')
176
- return Main.instance.start_transfer_wait_result(transfer_spec,{:src=>:node_gen3})
202
+ return Main.instance.start_transfer(transfer_spec,{:src=>:node_gen3})
177
203
  end
178
204
  when :source
179
205
  command_source=Main.instance.options.get_next_command([ :list, :id, :name ])
180
206
  source_list=api_v3.call({:operation=>'GET',:subpath=>"source_shares",:headers=>{'Accept'=>'application/json'}})[:data]['items']
181
207
  case command_source
182
208
  when :list
183
- return {:data=>source_list,:type=>:object_list}
209
+ return {:type=>:object_list,:data=>source_list}
184
210
  else # :id or :name
185
211
  source_match_val=Main.instance.options.get_next_argument('source id or name')
186
212
  source_ids=source_list.select { |i| i[command_source.to_s].to_s.eql?(source_match_val) }
@@ -229,7 +255,7 @@ module Asperalm
229
255
  case command_pkg
230
256
  when :list
231
257
  dropbox_list=api_v3.call({:operation=>'GET',:subpath=>"/aspera/faspex/dropboxes",:headers=>{'Accept'=>'application/json'}})[:data]
232
- return {:data=>dropbox_list['items'], :type=>:object_list, :fields=>['name','id','description','can_read','can_write']}
258
+ return {:type=>:object_list, :data=>dropbox_list['items'], :fields=>['name','id','description','can_read','can_write']}
233
259
  # when :create
234
260
  #
235
261
  end
@@ -247,7 +273,7 @@ module Asperalm
247
273
  transfer_uri=self.class.get_fasp_uri_from_entry(package_entry)
248
274
  transfer_spec=Fasp::Uri.new(transfer_uri).transfer_spec
249
275
  transfer_spec['direction']='receive'
250
- return Main.instance.start_transfer_wait_result(transfer_spec,{:src=>:node_gen3})
276
+ return Main.instance.start_transfer(transfer_spec,{:src=>:node_gen3})
251
277
  when :v4
252
278
  command=Main.instance.options.get_next_command([:dropbox, :dmembership, :workgroup,:wmembership,:user,:metadata_profile])
253
279
  case command
@@ -281,7 +307,7 @@ module Asperalm
281
307
  u['first_name'],u['last_name'] = u['displayName'].split(' ',2)
282
308
  u['x']=true
283
309
  end
284
- return {:data=>users,:type=>:object_list}
310
+ return {:type=>:object_list,:data=>users}
285
311
  end # command
286
312
  end
287
313
  end
@@ -141,13 +141,13 @@ module Asperalm
141
141
  transfer_spec=send_result[:data]['transfer_specs'].first['transfer_spec']
142
142
  # delete this part, as the returned value contains only destination, and note sources
143
143
  transfer_spec.delete('paths')
144
- return Main.instance.start_transfer_wait_result(transfer_spec,{:src=>:node_gen3})
144
+ return Main.instance.start_transfer(transfer_spec,{:src=>:node_gen3})
145
145
  when :download
146
- send_result=api_node.create('files/download_setup',{ :transfer_requests => [ { :transfer_request => { :paths => TransferAgent.instance.transfer_paths_from_options } } ] } )
146
+ send_result=api_node.create('files/download_setup',{ :transfer_requests => [ { :transfer_request => { :paths => Main.instance.ts_source_paths } } ] } )
147
147
  raise send_result[:data]['transfer_specs'][0]['error']['user_message'] if send_result[:data]['transfer_specs'][0].has_key?('error')
148
148
  raise "expecting one session exactly" if send_result[:data]['transfer_specs'].length != 1
149
149
  transfer_spec=send_result[:data]['transfer_specs'].first['transfer_spec']
150
- return Main.instance.start_transfer_wait_result(transfer_spec,{:src=>:node_gen3})
150
+ return Main.instance.start_transfer(transfer_spec,{:src=>:node_gen3})
151
151
  end
152
152
  end
153
153
 
@@ -22,21 +22,19 @@ module Asperalm
22
22
 
23
23
  # one can either add extnsion ".json" or add url parameter: format=json
24
24
  # id can be a parameter id=x, or at the end of url, for workflows: work_order[workflow_id]=wf_id
25
- def call_API(endpoint,id=nil,url_params=nil,format=:json)
25
+ def call_API(endpoint,id=nil,url_params={:format=>:json},accept=nil)
26
26
  # calls are GET
27
27
  call_definition={:operation=>'GET',:subpath=>endpoint}
28
28
  # specify id if necessary
29
- call_definition[:subpath]=call_definition[:subpath]+'/'+id if !id.nil?
30
- # set format if necessary
31
- if !format.nil?
32
- url_params={} if url_params.nil?
33
- url_params['format']=format
34
- # needs a patch to work ...
35
- #call_definition[:subpath]=call_definition[:subpath]+'.'+format.to_s
36
- call_definition[:headers]={'Accept'=>'application/'+format.to_s}
29
+ call_definition[:subpath]=call_definition[:subpath]+'/'+id unless id.nil?
30
+ unless url_params.nil?
31
+ if url_params.has_key?(:format)
32
+ call_definition[:headers]={'Accept'=>'application/'+url_params[:format].to_s}
33
+ end
34
+ call_definition[:headers]={'Accept'=>accept} unless accept.nil?
35
+ # add params if necessary
36
+ call_definition[:url_params]=url_params
37
37
  end
38
- # add params if necessary
39
- call_definition[:url_params]=url_params if !url_params.nil?
40
38
  return @api_orch.call(call_definition)
41
39
  end
42
40
 
@@ -58,7 +56,7 @@ module Asperalm
58
56
  command1=Main.instance.options.get_next_command(action_list)
59
57
  case command1
60
58
  when :info
61
- result=call_API("logon",nil,nil,nil)
59
+ result=call_API('logon',nil,nil)
62
60
  version='unknown'
63
61
  if m=result[:http].body.match(/\(v([0-9.-]+)\)/)
64
62
  version=m[1]
@@ -66,11 +64,11 @@ module Asperalm
66
64
  return {:type=>:single_object,:data=>{'version'=>version}}
67
65
  when :processes
68
66
  # TODO: json format is not respected in AO
69
- result=call_API("api/processes_status",nil,nil,:xml)
67
+ result=call_API('api/processes_status',nil,{:format=>:xml})
70
68
  res_s=XmlSimple.xml_in(result[:http].body, {"ForceArray" => true})
71
69
  return {:type=>:object_list,:data=>res_s["process"]}
72
70
  when :plugins
73
- result=call_API("api/plugin_version")[:data]
71
+ result=call_API('api/plugin_version')[:data]
74
72
  return {:type=>:object_list,:data=>result['Plugin']}
75
73
  when :workflow
76
74
  command=Main.instance.options.get_next_command([:list, :status, :inputs, :details, :start])
@@ -79,46 +77,50 @@ module Asperalm
79
77
  end
80
78
  case command
81
79
  when :status
82
- result=call_API("api/workflows_status")[:data]
80
+ result=call_API('api/workflows_status')[:data]
83
81
  return {:type=>:object_list,:data=>result['workflows']['workflow']}
84
82
  when :list
85
- result=call_API("workflow_reporter/workflows_list/0")[:data]
83
+ result=call_API('workflow_reporter/workflows_list/0')[:data]
86
84
  return {:type=>:object_list,:data=>result['workflows']['workflow'],:fields=>["id","portable_id","name","published_status","published_revision_id","latest_revision_id","last_modification"]}
87
85
  when :details
88
- result=call_API("api/workflow_details",wf_id)[:data]
86
+ result=call_API('api/workflow_details',wf_id)[:data]
89
87
  return {:type=>:object_list,:data=>result['workflows']['workflow']['statuses']}
90
88
  when :inputs
91
- result=call_API("api/workflow_inputs_spec",wf_id)[:data]
89
+ result=call_API('api/workflow_inputs_spec',wf_id)[:data]
92
90
  return {:type=>:single_object,:data=>result['workflow_inputs_spec']}
93
91
  when :start
94
92
  result={
95
93
  :type=>:single_object,
96
94
  :data=>nil
97
95
  }
98
- call_params={}
96
+ call_params={:format=>:json}
97
+ override_accept=nil
99
98
  # set external parameters if any
100
99
  Main.instance.options.get_option(:params,:mandatory).each do |name,value|
101
100
  call_params["external_parameters[#{name}]"] = value
102
101
  end
103
102
  # synchronous call ?
104
- call_params["synchronous"]=true if Main.instance.options.get_option(:synchronous,:mandatory)
103
+ call_params['synchronous']=true if Main.instance.options.get_option(:synchronous,:mandatory)
105
104
  # expected result for synchro call ?
106
105
  expected=Main.instance.options.get_option(:result,:optional)
107
- if !expected.nil?
106
+ unless expected.nil?
108
107
  result[:type] = :status
109
108
  fields=expected.split(/:/)
110
109
  raise "Expects: work_step:result_name format, but got #{expected}" if fields.length != 2
111
- call_params["explicit_output_step"]=fields[0]
112
- call_params["explicit_output_variable"]=fields[1]
110
+ call_params['explicit_output_step']=fields[0]
111
+ call_params['explicit_output_variable']=fields[1]
113
112
  # implicitely, call is synchronous
114
- call_params["synchronous"]=true
113
+ call_params['synchronous']=true
114
+ end
115
+ if call_params['synchronous']
116
+ result[:type]=:text
117
+ override_accept='text/plain'
115
118
  end
116
- result[:data]=call_API("api/initiate",wf_id,call_params)[:data]
119
+ result[:data]=call_API('api/initiate',wf_id,call_params,override_accept)[:data]
117
120
  return result
118
- end
119
- else
120
- raise "ERROR, unknown command: [#{command}]"
121
- end
121
+ end # wf command
122
+ else raise "ERROR, unknown command: [#{command}]"
123
+ end # case command
122
124
  end # execute_action
123
125
  end # Orchestrator
124
126
  end # Plugins
@@ -204,7 +204,7 @@ module Asperalm
204
204
  'node' => { 'access_key' => @access_key_self['id'], 'file_id' => folder_id }}}
205
205
  })
206
206
  tspec['destination_root']=destination unless destination.nil?
207
- Main.instance.start_transfer_wait_result(tspec,{:src=>:node_gen4})
207
+ Main.instance.start_transfer(tspec,{:src=>:node_gen4})
208
208
  end
209
209
 
210
210
  def get_infos_local(gen_infos,entry,local_entry_preview_dir)
@@ -109,9 +109,9 @@ module Asperalm
109
109
  end
110
110
  return Main.result_status(result)
111
111
  when :upload
112
- return Main.instance.start_transfer_wait_result(transfer_spec.merge('direction'=>'send'),{:src=>:direct})
112
+ return Main.instance.start_transfer(transfer_spec.merge('direction'=>'send'),{:src=>:direct})
113
113
  when :download
114
- return Main.instance.start_transfer_wait_result(transfer_spec.merge('direction'=>'receive'),{:src=>:direct})
114
+ return Main.instance.start_transfer(transfer_spec.merge('direction'=>'receive'),{:src=>:direct})
115
115
  when *Asperalm::AsCmd.action_list
116
116
  args=Main.instance.options.get_next_argument('ascmd command arguments',:multiple,:optional)
117
117
  ascmd=Asperalm::AsCmd.new(shell_executor)
@@ -28,7 +28,6 @@ module Asperalm
28
28
  :base_url => shares2_api_base_url,
29
29
  :auth_type => :oauth2,
30
30
  :oauth_base_url => shares2_api_base_url+'/oauth2',
31
- :oauth_path_token => 'token',
32
31
  :oauth_type => :header_userpass,
33
32
  :oauth_user_name => shares2_username,
34
33
  :oauth_user_pass => shares2_password
@@ -96,7 +96,7 @@ module Asperalm
96
96
  raise Fasp::Error,transfer_data['error']['user_message'] if transfer_data.has_key?('error')
97
97
  transfer_spec=transfer_data['transfer_spec']
98
98
  # execute transfer
99
- return Main.instance.start_transfer_wait_result(transfer_spec,{:src=>:node_gen3})
99
+ return Main.instance.start_transfer(transfer_spec,{:src=>:node_gen3})
100
100
  when :postprocess
101
101
  transfers=self.class.get_transfers_iteration(api_node,{:view=>'summary',:direction=>'receive',:active_only=>false})
102
102
  return { :type=>:object_list,:data => transfers }
@@ -52,25 +52,28 @@ module Asperalm
52
52
  when :connect
53
53
  @agent=Fasp::Connect.instance
54
54
  when :node
55
- # support: @param:<name>
56
- # support extended values
57
- node_config=Main.instance.options.get_option(:transfer_node,:optional)
58
- # of not specified, use default node
59
- if node_config.nil?
60
- param_set_name=Plugins::Config.instance.get_plugin_default_config_name(:node)
61
- raise CliBadArgument,"No default node configured, Please specify --transfer-node" if param_set_name.nil?
62
- node_config=Plugins::Config.instance.preset_by_name(param_set_name)
63
- end
64
- Log.log.debug("node=#{node_config}")
65
- raise CliBadArgument,"the node configuration shall be a hash, use either @json:<json> or @preset:<parameter set name>" if !node_config.is_a?(Hash)
66
- # now check there are required parameters
67
- sym_config={}
68
- [:url,:username,:password].each do |param|
69
- raise CliBadArgument,"missing parameter [#{param}] in node specification: #{node_config}" if !node_config.has_key?(param.to_s)
70
- sym_config[param]=node_config[param.to_s]
71
- end
72
55
  @agent=Fasp::Node.instance
73
- Fasp::Node.instance.node_api=Rest.new({:base_url=>sym_config[:url],:auth_type=>:basic,:basic_username=>sym_config[:username], :basic_password=>sym_config[:password]})
56
+ # way for code to setup alternate node api in avance
57
+ if @agent.node_api.nil?
58
+ # support: @param:<name>
59
+ # support extended values
60
+ node_config=Main.instance.options.get_option(:transfer_node,:optional)
61
+ # of not specified, use default node
62
+ if node_config.nil?
63
+ param_set_name=Plugins::Config.instance.get_plugin_default_config_name(:node)
64
+ raise CliBadArgument,"No default node configured, Please specify --transfer-node" if param_set_name.nil?
65
+ node_config=Plugins::Config.instance.preset_by_name(param_set_name)
66
+ end
67
+ Log.log.debug("node=#{node_config}")
68
+ raise CliBadArgument,"the node configuration shall be a hash, use either @json:<json> or @preset:<parameter set name>" if !node_config.is_a?(Hash)
69
+ # now check there are required parameters
70
+ sym_config={}
71
+ [:url,:username,:password].each do |param|
72
+ raise CliBadArgument,"missing parameter [#{param}] in node specification: #{node_config}" if !node_config.has_key?(param.to_s)
73
+ sym_config[param]=node_config[param.to_s]
74
+ end
75
+ @agent.node_api=Rest.new({:base_url=>sym_config[:url],:auth_type=>:basic,:basic_username=>sym_config[:username], :basic_password=>sym_config[:password]})
76
+ end
74
77
  else raise "ERROR"
75
78
  end
76
79
  @agent.add_listener(Listener::Logger.new)
@@ -96,9 +99,9 @@ module Asperalm
96
99
  return dest_folder
97
100
  end
98
101
 
99
- # get list of {:source=>(mandatory), :destination=>(optional)}
100
- def transfer_paths_from_options(override_with=nil)
101
- return override_with unless override_with.nil?
102
+ # get paths suitable for transfer spec from command line
103
+ # @return {:source=>(mandatory), :destination=>(optional)}
104
+ def ts_source_paths
102
105
  return @transfer_paths unless @transfer_paths.nil?
103
106
  # start with lower priority
104
107
  @transfer_paths=@transfer_spec_cmdline['paths'] if @transfer_spec_cmdline.has_key?('paths')
@@ -116,7 +119,7 @@ module Asperalm
116
119
  # plugins shall use this method to start a transfer
117
120
  # @param: options[:src] specifies how destination_root is set (how transfer spec was generated)
118
121
  # and not the default one
119
- def start_transfer_wait_result(transfer_spec,options)
122
+ def start(transfer_spec,options)
120
123
  raise "transfer_spec must be hash" unless transfer_spec.is_a?(Hash)
121
124
  raise "options must be hash" unless options.is_a?(Hash)
122
125
  # initialize transfert agent
@@ -145,18 +148,27 @@ module Asperalm
145
148
  options.delete(:src)
146
149
 
147
150
  # update command line paths, unless destination already has one
148
- @transfer_spec_cmdline['paths']=transfer_paths_from_options(transfer_spec['paths'])
151
+ @transfer_spec_cmdline['paths']=transfer_spec['paths'] || ts_source_paths
149
152
 
150
153
  transfer_spec.merge!(@transfer_spec_cmdline)
151
154
  # add bypass keys if there is a token, also prevents connect plugin to ask password
152
155
  transfer_spec['authentication']='token' if transfer_spec.has_key?('token')
153
156
  Log.log.debug("mgr is a #{@agent.class}")
154
157
  @agent.start_transfer(transfer_spec,options)
155
- return Main.result_nothing
158
+ return @agent.wait_for_transfers_completion
159
+ end
160
+
161
+ def shutdown
162
+ @agent.shutdown unless @agent.nil?
163
+ end
164
+
165
+ def wait_for_transfers_completion
166
+ @agent.wait_for_transfers_completion unless @agent.nil?
156
167
  end
157
168
 
158
- def shutdown(p)
159
- @agent.shutdown(p) unless @agent.nil?
169
+ def exception_on_error(list)
170
+ return if list.nil?
171
+ raise "at least one transfer failed" unless list.select{|i|!i.eql?(:success)}.empty?
160
172
  end
161
173
  end
162
174
  end
@@ -52,38 +52,41 @@ module Asperalm
52
52
  @connect_api.create('transfers/start',connect_transfer_args)
53
53
  end
54
54
 
55
- def shutdown(wait_for_sessions=false)
56
- if wait_for_sessions
57
- connect_activity_args={'aspera_connect_settings'=>{'app_id'=>@connect_app_id}}
58
- started=false
59
- loop do
60
- result=@connect_api.create('transfers/activity',connect_activity_args)[:data]
61
- if result['transfers']
62
- trdata=result['transfers'].select{|i| i['aspera_connect_settings'] and i['aspera_connect_settings']['request_id'].eql?(@request_id)}.first
63
- raise "problem with connect, please kill it" unless trdata
64
- # TODO: get session id
65
- case trdata['status']
66
- when 'completed'
67
- notify_listeners("emulated",{'Type'=>'DONE'})
68
- break
69
- when 'initiating'
70
- puts 'starting'
71
- when 'running'
72
- #puts "running: sessions:#{trdata["sessions"].length}, #{trdata["sessions"].map{|i| i['bytes_transferred']}.join(',')}"
73
- if !started and trdata["bytes_expected"] != 0
74
- notify_listeners("emulated",{'Type'=>'NOTIFICATION','PreTransferBytes'=>trdata["bytes_expected"]})
75
- started=true
76
- else
77
- notify_listeners("emulated",{'Type'=>'STATS','Bytescont'=>trdata["bytes_written"]})
78
- end
55
+ def shutdown
56
+ Log.log.debug("no shutdown needed")
57
+ end
58
+
59
+ def wait_for_transfers_completion
60
+ connect_activity_args={'aspera_connect_settings'=>{'app_id'=>@connect_app_id}}
61
+ started=false
62
+ loop do
63
+ result=@connect_api.create('transfers/activity',connect_activity_args)[:data]
64
+ if result['transfers']
65
+ trdata=result['transfers'].select{|i| i['aspera_connect_settings'] and i['aspera_connect_settings']['request_id'].eql?(@request_id)}.first
66
+ raise "problem with connect, please kill it" unless trdata
67
+ # TODO: get session id
68
+ case trdata['status']
69
+ when 'completed'
70
+ notify_listeners("emulated",{'Type'=>'DONE'})
71
+ break
72
+ when 'initiating'
73
+ puts 'starting'
74
+ when 'running'
75
+ #puts "running: sessions:#{trdata["sessions"].length}, #{trdata["sessions"].map{|i| i['bytes_transferred']}.join(',')}"
76
+ if !started and trdata["bytes_expected"] != 0
77
+ notify_listeners("emulated",{'Type'=>'NOTIFICATION','PreTransferBytes'=>trdata["bytes_expected"]})
78
+ started=true
79
79
  else
80
- raise Fasp::Error.new("#{trdata['status']}: #{trdata['error_desc']}")
80
+ notify_listeners("emulated",{'Type'=>'STATS','Bytescont'=>trdata["bytes_written"]})
81
81
  end
82
+ else
83
+ raise Fasp::Error.new("#{trdata['status']}: #{trdata['error_desc']}")
82
84
  end
83
- sleep 1
84
85
  end
86
+ sleep 1
85
87
  end
86
- end
88
+ return [] #TODO
89
+ end # wait
87
90
  end # Connect
88
91
  end
89
92
  end
@@ -111,30 +111,32 @@ module Asperalm
111
111
  return job_id
112
112
  end # start_transfer
113
113
 
114
- # terminates monitor thread
115
- def shutdown(wait_for_sessions=false)
116
- Log.log.debug("fasp local shutdown")
117
- if wait_for_sessions
118
- Log.log.debug("wait_for_sessions: #{@jobs.values.inject(0){|m,j|m+j[:sessions].count}}")
119
- @mutex.synchronize do
120
- loop do
121
- running=0
122
- @jobs.values.each do |job|
123
- job[:sessions].each do |session|
124
- case session[:state]
125
- when :failed; raise StandardError,"at least one session failed: #{session[:error]}"
126
- when :success # ignore
127
- else running+=1
128
- end
114
+ def wait_for_transfers_completion
115
+ Log.log.debug("wait_for_sessions: #{@jobs.values.inject(0){|m,j|m+j[:sessions].count}}")
116
+ @mutex.synchronize do
117
+ loop do
118
+ running=0
119
+ result=[]
120
+ @jobs.each do |id,job|
121
+ job[:sessions].each do |session|
122
+ case session[:state]
123
+ when :failed; result.push(session[:error])
124
+ when :success; result.push(:success)
125
+ else running+=1
129
126
  end
130
127
  end
131
- break if running.eql?(0)
132
- Log.log.debug("wait for completed: running: #{running}")
133
- # wait for session termination
134
- @cond_var.wait(@mutex)
135
- end # loop
136
- end # mutex
137
- end
128
+ end
129
+ return result if running.eql?(0)
130
+ Log.log.debug("wait for completed: running: #{running}")
131
+ # wait for session termination
132
+ @cond_var.wait(@mutex)
133
+ end # loop
134
+ end # mutex
135
+ end
136
+
137
+ # terminates monitor thread
138
+ def shutdown
139
+ Log.log.debug("fasp local shutdown")
138
140
  Log.log.debug("send signal to monitor")
139
141
  # tell monitor to stop
140
142
  @mutex.synchronize do
@@ -58,10 +58,17 @@ module Asperalm
58
58
  def start_transfer(transfer_spec)
59
59
  raise "virtual method"
60
60
  end
61
+
62
+ # wait for termination of all transfers
63
+ # @return list of : :success or error message
64
+ def wait_for_transfers_completion
65
+ raise "virtual method"
66
+ end
61
67
 
62
- def shutdown(wait_for_sessions=false)
68
+ def shutdown
63
69
  raise "virtual method"
64
70
  end
71
+
65
72
  end
66
73
  end
67
74
  end
@@ -11,7 +11,7 @@ module Asperalm
11
11
  super
12
12
  end
13
13
  public
14
- attr_writer :node_api
14
+ attr_accessor :node_api
15
15
 
16
16
  def start_transfer(transfer_spec,options=nil)
17
17
  #transfer_spec.keys.select{|i|i.start_with?('EX_')}.each{|i|transfer_spec.delete(i)}
@@ -20,7 +20,10 @@ module Asperalm
20
20
  @transfer_id=resp[:data]['id']
21
21
  end
22
22
 
23
- def shutdown(wait_for_sessions=false)
23
+ def shutdown
24
+ Log.log.debug("no shutdown needed")
25
+ end
26
+ def wait_for_transfers_completion
24
27
  started=false
25
28
  # lets emulate management events to display progress bar
26
29
  loop do
@@ -48,6 +51,7 @@ module Asperalm
48
51
  end
49
52
  sleep 1
50
53
  end
54
+ return [] #TODO
51
55
  end
52
56
  end
53
57
  end
@@ -44,12 +44,10 @@ module Asperalm
44
44
  organization,instance_domain=parse_url(aoc_org_url)
45
45
  base_url='https://api.'+instance_domain+'/api/v1'
46
46
  return {
47
- :base_url => base_url,
48
- :auth_type => :oauth2,
49
- :oauth_base_url => "#{base_url}/oauth2/#{organization}",
50
- :oauth_path_login => 'authorize',
51
- :oauth_path_token => 'token',
52
- :oauth_jwt_audience => 'https://api.asperafiles.com/api/v1/oauth2/token'
47
+ :base_url => base_url,
48
+ :auth_type => :oauth2,
49
+ :oauth_base_url => "#{base_url}/oauth2/#{organization}",
50
+ :oauth_jwt_audience => 'https://api.asperafiles.com/api/v1/oauth2/token'
53
51
  }
54
52
  end
55
53
 
@@ -138,7 +136,7 @@ module Asperalm
138
136
  Log.log.debug "folder_contents: #{folder_contents}"
139
137
  matching_folders = folder_contents[:data].select { |i| i['name'].eql?(current_element_name)}
140
138
  #Log.log.debug "matching_folders: #{matching_folders}"
141
- raise CliBadArgument, "no such folder: #{current_element_name} in #{folder_contents[:data].map { |i| i['name']}}" if matching_folders.empty?
139
+ raise "no such folder: #{current_element_name} in #{folder_contents[:data].map { |i| i['name']}}" if matching_folders.empty?
142
140
  current_file_info = matching_folders.first
143
141
  # process type of file
144
142
  case current_file_info['type']
@@ -146,7 +144,7 @@ module Asperalm
146
144
  current_file_id=current_file_info["id"]
147
145
  # a file shall be terminal
148
146
  if !current_path_elements.empty? then
149
- raise CliBadArgument, "#{current_element_name} is a file, expecting folder to find: #{current_path_elements}"
147
+ raise "#{current_element_name} is a file, expecting folder to find: #{current_path_elements}"
150
148
  end
151
149
  when 'link'
152
150
  current_node_info=self.read("nodes/#{current_file_info['target_node_id']}")[:data]
@@ -50,6 +50,22 @@ module Asperalm
50
50
  # prefix of REST parameters used for oauth
51
51
  @@PARAM_PREFIX='oauth_'
52
52
 
53
+ # for supported parameters, look in the code for @params
54
+ # parameters are provided all with oauth_ prefix :
55
+ # :base_url
56
+ # :client_id
57
+ # :client_secret
58
+ # :redirect_uri
59
+ # :jwt_audience
60
+ # :jwt_private_key_obj
61
+ # :jwt_subject
62
+ # :path_authorize
63
+ # :path_token (default: 'token')
64
+ # :scope
65
+ # :type
66
+ # :url_token
67
+ # :user_name
68
+ # :user_pass
53
69
  def initialize(rest_params)
54
70
  Log.log.debug "auth=#{rest_params}"
55
71
  # just keep keys starting with :oauth_, and remove this prefix
@@ -57,6 +73,9 @@ module Asperalm
57
73
  map{|k|k.to_s}.
58
74
  select{|k|k.start_with?(@@PARAM_PREFIX)}.
59
75
  inject({}){|h,k|h[k[@@PARAM_PREFIX.length..-1].to_sym]=rest_params[k.to_sym];h}
76
+ # default values
77
+ @params[:path_token]||='token'
78
+ @params[:path_authorize]||='authorize'
60
79
  @api=Rest.new({
61
80
  :base_url => @params[:base_url],
62
81
  :auth_type => :basic,
@@ -204,7 +223,7 @@ module Asperalm
204
223
  when :web
205
224
  check_code=SecureRandom.uuid
206
225
  login_page_url=Rest.build_uri(
207
- "#{@params[:base_url]}/#{@params[:path_login]}",
226
+ "#{@params[:base_url]}/#{@params[:path_authorize]}",
208
227
  client_id_and_scope.merge({
209
228
  :response_type => 'code',
210
229
  :redirect_uri => @params[:redirect_uri],
@@ -112,7 +112,7 @@ module Asperalm
112
112
  # :basic_username [:basic]
113
113
  # :basic_password [:basic]
114
114
  # :auth_url_creds [:url]
115
- # :oauth_* [:oauth2]
115
+ # :oauth_* [:oauth2] see Oauth class
116
116
  def initialize(a_rest_params)
117
117
  raise "ERROR: expecting Hash" unless a_rest_params.is_a?(Hash)
118
118
  raise "ERROR: expecting base_url" unless a_rest_params[:base_url].is_a?(String)
@@ -232,10 +232,14 @@ module Asperalm
232
232
  Log.log.debug "result: code=#{result[:http].code}"
233
233
  raise RestCallError.new(req,result[:http]) unless result[:http].code.start_with?('2')
234
234
  if call_data.has_key?(:headers) and
235
- call_data[:headers].has_key?('Accept') and
236
- call_data[:headers]['Accept'].eql?('application/json') then
235
+ call_data[:headers].has_key?('Accept') then
237
236
  Log.log.debug "result: body=#{result[:http].body}"
238
- result[:data]=JSON.parse(result[:http].body) if !result[:http].body.nil?
237
+ case call_data[:headers]['Accept']
238
+ when 'application/json'
239
+ result[:data]=JSON.parse(result[:http].body) if !result[:http].body.nil?
240
+ when 'text/plain'
241
+ result[:data]=result[:http].body
242
+ end
239
243
  end
240
244
  rescue RestCallError => e
241
245
  # not authorized: oauth token expired
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asperalm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-08 00:00:00.000000000 Z
11
+ date: 2018-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xml-simple