asperalm 0.8.9 → 0.8.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,11 @@
1
1
  require 'asperalm/cli/basic_auth_plugin'
2
+ require 'singleton'
2
3
 
3
4
  module Asperalm
4
5
  module Cli
5
6
  module Plugins
6
7
  class Console < BasicAuthPlugin
8
+ include Singleton
7
9
  alias super_declare_options declare_options
8
10
  def declare_options
9
11
  super_declare_options
@@ -3,11 +3,13 @@ require 'asperalm/cli/plugins/node'
3
3
  require 'asperalm/open_application'
4
4
  require 'asperalm/fasp/uri'
5
5
  require 'xmlsimple'
6
+ require 'singleton'
6
7
 
7
8
  module Asperalm
8
9
  module Cli
9
10
  module Plugins
10
11
  class Faspex < BasicAuthPlugin
12
+ include Singleton
11
13
  @@KEY_NODE='node'
12
14
  @@KEY_PATH='path'
13
15
  alias super_declare_options declare_options
@@ -115,7 +117,7 @@ module Asperalm
115
117
  all_inbox_xml=api_v3.call({:operation=>'GET',:subpath=>"#{Main.instance.options.get_option(:box,:mandatory).to_s}.atom",:headers=>{'Accept'=>'application/xml'}})[:http].body
116
118
  all_inbox_data=XmlSimple.xml_in(all_inbox_xml, {"ForceArray" => true})
117
119
  Log.dump(:all_inbox_data,all_inbox_data)
118
- return Plugin.result_empty unless all_inbox_data.has_key?('entry')
120
+ return Main.result_empty unless all_inbox_data.has_key?('entry')
119
121
  return {:data=>all_inbox_data['entry'],:type=>:object_list,:fields=>[PACKAGE_MATCH_FIELD,'title','items'], :textify => lambda { |table_data| Faspex.textify_package_list(table_data)} }
120
122
  when :send
121
123
  filelist = Main.instance.options.get_next_argument("file list",:multiple)
@@ -223,7 +225,7 @@ module Asperalm
223
225
  :basic_username=>node_config['username'],
224
226
  :basic_password=>node_config['password']})
225
227
  command=Main.instance.options.get_next_argument('command',Node.common_actions)
226
- return Node.new.execute_common(command,api_node,source_info[@@KEY_PATH])
228
+ return Node.execute_common(command,api_node,source_info[@@KEY_PATH])
227
229
  end
228
230
  end
229
231
  when :me
@@ -1,11 +1,13 @@
1
1
  require 'asperalm/cli/basic_auth_plugin'
2
2
  require 'base64'
3
3
  require 'zlib'
4
+ require 'singleton'
4
5
 
5
6
  module Asperalm
6
7
  module Cli
7
8
  module Plugins
8
9
  class Node < BasicAuthPlugin
10
+ include Singleton
9
11
  alias super_declare_options declare_options
10
12
  def declare_options
11
13
  super_declare_options
@@ -65,7 +67,7 @@ module Asperalm
65
67
  end
66
68
 
67
69
  # get path arguments from command line, and add prefix
68
- def get_next_arg_add_prefix(path_prefix,name,number=:single)
70
+ def self.get_next_arg_add_prefix(path_prefix,name,number=:single)
69
71
  thepath=Main.instance.options.get_next_argument(name,number)
70
72
  return thepath if path_prefix.nil?
71
73
  return File.join(path_prefix,thepath) if thepath.is_a?(String)
@@ -79,17 +81,17 @@ module Asperalm
79
81
 
80
82
  # common API to node and Shares
81
83
  # prefix_path is used to list remote sources in Faspex
82
- def execute_common(command,api_node,prefix_path=nil)
84
+ def self.execute_common(command,api_node,prefix_path=nil)
83
85
  case command
84
86
  when :events
85
87
  events=api_node.read('events')[:data]
86
88
  return { :type=>:object_list, :data => events}
87
89
  when :info
88
90
  node_info=api_node.read('info')[:data]
89
- return { :type=>:single_object, :data => node_info, :textify => lambda { |table_data| self.class.c_textify_bool_list_result(table_data,['capabilities','settings'])}}
91
+ return { :type=>:single_object, :data => node_info, :textify => lambda { |table_data| c_textify_bool_list_result(table_data,['capabilities','settings'])}}
90
92
  when :delete
91
93
  paths_to_delete = get_next_arg_add_prefix(prefix_path,"file list",:multiple)
92
- return self.class.c_delete_files(api_node,paths_to_delete,prefix_path)
94
+ return c_delete_files(api_node,paths_to_delete,prefix_path)
93
95
  when :space
94
96
  # TODO: could be a list of path
95
97
  path_list=get_next_arg_add_prefix(prefix_path,"folder path or ext.val. list")
@@ -97,30 +99,30 @@ module Asperalm
97
99
  resp=api_node.create('space',{ "paths" => path_list.map {|i| {:path=>i} } } )
98
100
  result={:data=>resp[:data]['paths'],:type=>:object_list}
99
101
  #return c_result_translate_rem_prefix(resp,'folder','created',prefix_path)
100
- return self.class.c_result_remove_prefix_path(result,'path',prefix_path)
102
+ return c_result_remove_prefix_path(result,'path',prefix_path)
101
103
  when :mkdir
102
104
  path_list=get_next_arg_add_prefix(prefix_path,"folder path or ext.val. list")
103
105
  path_list=[path_list] unless path_list.is_a?(Array)
104
106
  #TODO
105
107
  #resp=api_node.create('space',{ "paths" => path_list.map {|i| {:type=>:directory,:path=>i} } } )
106
108
  resp=api_node.create('files/create',{ "paths" => [{ :type => :directory, :path => path_list } ] } )
107
- return self.class.c_result_translate_rem_prefix(resp,'folder','created',prefix_path)
109
+ return c_result_translate_rem_prefix(resp,'folder','created',prefix_path)
108
110
  when :mklink
109
111
  target=get_next_arg_add_prefix(prefix_path,"target")
110
112
  path_list=get_next_arg_add_prefix(prefix_path,"link path")
111
113
  resp=api_node.create('files/create',{ "paths" => [{ :type => :symbolic_link, :path => path_list, :target => {:path => target} } ] } )
112
- return self.class.c_result_translate_rem_prefix(resp,'folder','created',prefix_path)
114
+ return c_result_translate_rem_prefix(resp,'folder','created',prefix_path)
113
115
  when :mkfile
114
116
  path_list=get_next_arg_add_prefix(prefix_path,"file path")
115
117
  contents64=Base64.strict_encode64(Main.instance.options.get_next_argument("contents"))
116
118
  resp=api_node.create('files/create',{ "paths" => [{ :type => :file, :path => path_list, :contents => contents64 } ] } )
117
- return self.class.c_result_translate_rem_prefix(resp,'folder','created',prefix_path)
119
+ return c_result_translate_rem_prefix(resp,'folder','created',prefix_path)
118
120
  when :rename
119
121
  path_base=get_next_arg_add_prefix(prefix_path,"path_base")
120
122
  path_src=get_next_arg_add_prefix(prefix_path,"path_src")
121
123
  path_dst=get_next_arg_add_prefix(prefix_path,"path_dst")
122
124
  resp=api_node.create('files/rename',{ "paths" => [{ "path" => path_base, "source" => path_src, "destination" => path_dst } ] } )
123
- return self.class.c_result_translate_rem_prefix(resp,'entry','moved',prefix_path)
125
+ return c_result_translate_rem_prefix(resp,'entry','moved',prefix_path)
124
126
  when :browse
125
127
  thepath=get_next_arg_add_prefix(prefix_path,"path")
126
128
  query={ :path => thepath}
@@ -128,10 +130,10 @@ module Asperalm
128
130
  query.merge!(additional_query) unless additional_query.nil?
129
131
  send_result=api_node.create('files/browse', query)
130
132
  #send_result={:data=>{'items'=>[{'file'=>"filename1","permissions"=>[{'name'=>'read'},{'name'=>'write'}]}]}}
131
- return Plugin.result_empty if !send_result[:data].has_key?('items')
132
- result={ :data => send_result[:data]['items'] , :type => :object_list, :textify => lambda { |table_data| self.class.c_textify_browse(table_data) } }
133
+ return Main.result_empty if !send_result[:data].has_key?('items')
134
+ result={ :data => send_result[:data]['items'] , :type => :object_list, :textify => lambda { |table_data| c_textify_browse(table_data) } }
133
135
  Main.instance.display_status("Items: #{send_result[:data]['item_count']}/#{send_result[:data]['total_count']}")
134
- return self.class.c_result_remove_prefix_path(result,'path',prefix_path)
136
+ return c_result_remove_prefix_path(result,'path',prefix_path)
135
137
  when :upload
136
138
  filelist = Main.instance.options.get_next_argument("source file list",:multiple)
137
139
  Log.log.debug("file list=#{filelist}")
@@ -160,7 +162,7 @@ module Asperalm
160
162
  api_node=basic_auth_api()
161
163
  command=Main.instance.options.get_next_argument('command',action_list)
162
164
  case command
163
- when *self.class.common_actions; return execute_common(command,api_node)
165
+ when *self.class.common_actions; return self.class.execute_common(command,api_node)
164
166
  when :async
165
167
  command=Main.instance.options.get_next_argument('command',[:list,:summary,:counters])
166
168
  if [:summary,:counters].include?(command)
@@ -172,11 +174,11 @@ module Asperalm
172
174
  return { :type => :value_list, :data => resp, :name=>'id' }
173
175
  when :summary
174
176
  resp=api_node.create('async/summary',{"syncs"=>[asyncid]})[:data]["sync_summaries"].first
175
- return Plugin.result_empty if resp.nil?
177
+ return Main.result_empty if resp.nil?
176
178
  return { :type => :single_object, :data => resp }
177
179
  when :counters
178
180
  resp=api_node.create('async/counters',{"syncs"=>[asyncid]})[:data]["sync_counters"].first[asyncid].last
179
- return Plugin.result_empty if resp.nil?
181
+ return Main.result_empty if resp.nil?
180
182
  return { :type => :single_object, :data => resp }
181
183
  end
182
184
  when :stream
@@ -240,10 +242,10 @@ module Asperalm
240
242
  # @json:'{"type":"WATCHFOLDERD","run_as":{"user":"user1"}}'
241
243
  params=Main.instance.options.get_next_argument("Run creation data (structure)")
242
244
  resp=api_node.create('rund/services',params)
243
- return Plugin.result_status("#{resp[:data]['id']} created")
245
+ return Main.result_status("#{resp[:data]['id']} created")
244
246
  when :delete
245
247
  resp=api_node.delete("rund/services/#{svcid}")
246
- return Plugin.result_status("#{svcid} deleted")
248
+ return Main.result_status("#{svcid} deleted")
247
249
  end
248
250
  when :watch_folder
249
251
  res_class_path='v3/watchfolders'
@@ -256,7 +258,7 @@ module Asperalm
256
258
  case command
257
259
  when :create
258
260
  resp=api_node.create(res_class_path,Main.instance.options.get_option(:value,:mandatory))
259
- return Plugin.result_status("#{resp[:data]['id']} created")
261
+ return Main.result_status("#{resp[:data]['id']} created")
260
262
  when :list
261
263
  resp=api_node.read(res_class_path,Main.instance.options.get_option(:value,:optional))
262
264
  # :fields=>['id','root_file_id','storage','license']
@@ -265,10 +267,10 @@ module Asperalm
265
267
  return {:type=>:single_object, :data=>api_node.read(one_res_path)[:data]}
266
268
  when :modify
267
269
  api_node.update(one_res_path,Main.instance.options.get_option(:value,:mandatory))
268
- return Plugin.result_status("#{one_res_id} updated")
270
+ return Main.result_status("#{one_res_id} updated")
269
271
  when :delete
270
272
  api_node.delete(one_res_path)
271
- return Plugin.result_status("#{one_res_id} deleted")
273
+ return Main.result_status("#{one_res_id} deleted")
272
274
  when :state
273
275
  return { :type=>:single_object, :data => api_node.read("#{one_res_path}/state")[:data] }
274
276
  end
@@ -297,7 +299,7 @@ module Asperalm
297
299
  when :modify
298
300
  request_data.deep_merge!(validation) unless validation.nil?
299
301
  api_node.update('services/rest/transfers/v1/files',request_data)
300
- return Plugin.result_status('updated')
302
+ return Main.result_status('updated')
301
303
  end
302
304
  end
303
305
  when :asperabrowser
@@ -309,7 +311,7 @@ module Asperalm
309
311
  # encode parameters so that it looks good in url
310
312
  encoded_params=Base64.strict_encode64(Zlib::Deflate.deflate(JSON.generate(browse_params))).gsub(/=+$/, '').tr('+/', '-_').reverse
311
313
  OpenApplication.instance.uri(Main.instance.options.get_option(:asperabrowserurl)+'?goto='+encoded_params)
312
- return Plugin.result_status('done')
314
+ return Main.result_status('done')
313
315
  end # case command
314
316
  raise "ERROR: shall not reach this line"
315
317
  end # execute_action
@@ -1,10 +1,12 @@
1
1
  require 'asperalm/cli/plugins/node'
2
2
  require 'xmlsimple'
3
+ require 'singleton'
3
4
 
4
5
  module Asperalm
5
6
  module Cli
6
7
  module Plugins
7
8
  class Orchestrator < BasicAuthPlugin
9
+ include Singleton
8
10
 
9
11
  alias super_declare_options declare_options
10
12
  def declare_options
@@ -3,6 +3,7 @@ require 'asperalm/preview/generator'
3
3
  require 'asperalm/preview/options'
4
4
  require 'asperalm/preview/utils'
5
5
  require 'date'
6
+ require 'singleton'
6
7
 
7
8
  # for older rubies
8
9
  unless Hash.method_defined?(:dig)
@@ -19,6 +20,7 @@ module Asperalm
19
20
  module Cli
20
21
  module Plugins
21
22
  class Preview < BasicAuthPlugin
23
+ include Singleton
22
24
 
23
25
  attr_accessor :option_overwrite
24
26
  attr_accessor :option_previews_folder
@@ -379,26 +381,26 @@ module Asperalm
379
381
  case command
380
382
  when :scan
381
383
  scan_folder_files({ 'id' => @access_key_self['root_file_id'], 'name' => '/', 'type' => 'folder', 'path' => '/' })
382
- return Plugin.result_status('scan finished')
384
+ return Main.result_status('scan finished')
383
385
  when :events
384
386
  process_file_events
385
- return Plugin.result_status('events finished')
387
+ return Main.result_status('events finished')
386
388
  when :folder
387
389
  file_id=Main.instance.options.get_next_argument('file id')
388
390
  file_info=@api_node.read("files/#{file_id}")[:data]
389
391
  scan_folder_files(file_info)
390
- return Plugin.result_status('file finished')
392
+ return Main.result_status('file finished')
391
393
  when :check
392
394
  Asperalm::Preview::Utils.check_tools(@skip_types)
393
- return Plugin.result_status('tools validated')
395
+ return Main.result_status('tools validated')
394
396
  when :test
395
397
  source = Main.instance.options.get_next_argument("source file")
396
398
  format = Main.instance.options.get_next_argument("format",Asperalm::Preview::Generator.preview_formats)
397
399
  dest=preview_filename(format)
398
400
  g=Asperalm::Preview::Generator.new(source,dest)
399
- return Plugin.result_status("format not supported") unless g.supported?
401
+ return Main.result_status("format not supported") unless g.supported?
400
402
  g.generate
401
- return Plugin.result_status("generated: #{dest}")
403
+ return Main.result_status("generated: #{dest}")
402
404
  end
403
405
  end # execute_action
404
406
  end # Preview
@@ -1,12 +1,14 @@
1
1
  require 'asperalm/cli/basic_auth_plugin'
2
2
  require 'asperalm/ascmd'
3
3
  require 'asperalm/ssh'
4
+ require 'singleton'
4
5
 
5
6
  module Asperalm
6
7
  module Cli
7
8
  module Plugins
8
9
  # implement basic remote access with FASP/SSH
9
10
  class Server < BasicAuthPlugin
11
+ include Singleton
10
12
  class LocalExecutor
11
13
  def execute(cmd,input=nil)
12
14
  `#{cmd}`
@@ -105,7 +107,7 @@ module Asperalm
105
107
  return {:type=>:single_object,:data=>result,:fields=>['section','name','value','default'],:option_expand_last=>true}
106
108
  end
107
109
  end
108
- return Plugin.result_status(result)
110
+ return Main.result_status(result)
109
111
  when :upload
110
112
  filelist = Main.instance.options.get_next_argument("source list",:multiple)
111
113
  transfer_spec.merge!({
@@ -125,10 +127,10 @@ module Asperalm
125
127
  ascmd=Asperalm::AsCmd.new(shell_executor)
126
128
  result=ascmd.send(:execute_single,command,args)
127
129
  case command
128
- when :mkdir; return Plugin.result_success
129
- when :mv; return Plugin.result_success
130
- when :cp; return Plugin.result_success
131
- when :rm; return Plugin.result_success
130
+ when :mkdir; return Main.result_success
131
+ when :mv; return Main.result_success
132
+ when :cp; return Main.result_success
133
+ when :rm; return Main.result_success
132
134
  when :ls; return {:type=>:object_list,:data=>key_symb_to_str_list(result),:fields=>['zmode','zuid','zgid','size','mtime','name']}
133
135
  when :info; return {:type=>:single_object,:data=>key_symb_to_str_single(result)}
134
136
  when :df; return {:type=>:object_list,:data=>key_symb_to_str_list(result)}
@@ -1,9 +1,11 @@
1
1
  require 'asperalm/cli/plugins/node'
2
+ require 'singleton'
2
3
 
3
4
  module Asperalm
4
5
  module Cli
5
6
  module Plugins
6
7
  class Shares < BasicAuthPlugin
8
+ include Singleton
7
9
  alias super_declare_options declare_options
8
10
  def declare_options
9
11
  super_declare_options
@@ -18,7 +20,7 @@ module Asperalm
18
20
  api_shares_node=basic_auth_api('node_api')
19
21
  command=Main.instance.options.get_next_argument('command',Node.common_actions)
20
22
  case command
21
- when *Node.common_actions; Node.new.execute_common(command,api_shares_node)
23
+ when *Node.common_actions; Node.execute_common(command,api_shares_node)
22
24
  else raise "INTERNAL ERROR, unknown command: [#{command}]"
23
25
  end
24
26
  when :admin
@@ -1,10 +1,12 @@
1
1
  require 'asperalm/cli/plugins/node'
2
2
  require 'uri'
3
+ require 'singleton'
3
4
 
4
5
  module Asperalm
5
6
  module Cli
6
7
  module Plugins
7
8
  class Shares2 < BasicAuthPlugin
9
+ include Singleton
8
10
  alias super_declare_options declare_options
9
11
  def declare_options
10
12
  super_declare_options
@@ -79,7 +81,7 @@ module Asperalm
79
81
  return {:data=>@api_shares2_oauth.read(resource_path,args)[:data],:fields=>default_fields,:type=>:object_list}
80
82
  when :delete
81
83
  @api_shares2_oauth.delete(set_resource_path_by_id_or_name(path_prefix,resource_sym))
82
- return Plugin.result_status('deleted')
84
+ return Main.result_status('deleted')
83
85
  when :info
84
86
  return {:type=>:other_struct,:data=>@api_shares2_oauth.read(set_resource_path_by_id_or_name(path_prefix,resource_sym),args)[:data]}
85
87
  else raise :ERROR
@@ -93,7 +95,7 @@ module Asperalm
93
95
  case command
94
96
  when :repository
95
97
  command=Main.instance.options.get_next_argument('command',Node.common_actions)
96
- return Node.new.execute_common(command,@api_node)
98
+ return Node.execute_common(command,@api_node)
97
99
  when :appinfo
98
100
  node_info=@api_node.call({:operation=>'GET',:subpath=>'app',:headers=>{'Accept'=>'application/json','Content-Type'=>'application/json'}})[:data]
99
101
  return { :type=>:single_object ,:data => node_info }
@@ -1,11 +1,13 @@
1
1
  require 'asperalm/cli/plugin'
2
2
  require 'asperalm/sync'
3
+ require 'singleton'
3
4
 
4
5
  module Asperalm
5
6
  module Cli
6
7
  module Plugins
7
8
  # list and download connect client versions, select FASP implementation
8
9
  class Sync < Plugin
10
+ include Singleton
9
11
  def declare_options
10
12
  Main.instance.options.add_opt_simple(:parameters,"extended value for session set definition")
11
13
  end
@@ -20,9 +22,9 @@ module Asperalm
20
22
  res=system(env_args[:env],['async','async'],*env_args[:args])
21
23
  Log.log.debug("result=#{res}")
22
24
  case res
23
- when true; return Plugin.result_success
24
- when false; return Plugin.result_status("failed: #{$?}")
25
- when nil; return Plugin.result_status("not started: #{$?}")
25
+ when true; return Main.result_success
26
+ when false; return Main.result_status("failed: #{$?}")
27
+ when nil; return Main.result_status("not started: #{$?}")
26
28
  else raise "internal error: unspecified case"
27
29
  end
28
30
  end # command
@@ -1,11 +1,13 @@
1
1
  require 'asperalm/cli/basic_auth_plugin'
2
2
  require "base64"
3
+ require 'singleton'
3
4
 
4
5
  module Asperalm
5
6
  module Cli
6
7
  module Plugins
7
8
  # experiments
8
9
  class Xnode < BasicAuthPlugin
10
+ include Singleton
9
11
  alias super_declare_options declare_options
10
12
  # "transfer_filter"=>"t['status'].eql?('completed') and t['start_spec']['remote_user'].eql?('faspex')", :file_filter=>"f['status'].eql?('completed') and 0 != f['size'] and t['start_spec']['direction'].eql?('send')"
11
13
  def declare_options
@@ -72,7 +74,7 @@ module Asperalm
72
74
  else
73
75
  Log.log.info("nothing to delete")
74
76
  end
75
- return Plugin.result_nothing
77
+ return Main.result_nothing
76
78
  when :forward
77
79
  # detect transfer sessions since last call
78
80
  transfers=self.class.get_transfers_iteration(api_node,{:active_only=>false})
@@ -83,7 +85,7 @@ module Asperalm
83
85
  end
84
86
  if filelist.empty?
85
87
  Log.log.debug("NO TRANSFER".red)
86
- return Plugin.result_nothing
88
+ return Main.result_nothing
87
89
  end
88
90
  Log.log.debug("file list=#{filelist}")
89
91
  # get download transfer spec on destination node
@@ -0,0 +1,147 @@
1
+ require 'asperalm/fasp/local'
2
+ require 'asperalm/fasp/connect'
3
+ require 'asperalm/fasp/node'
4
+ require 'singleton'
5
+
6
+ module Asperalm
7
+ module Cli
8
+ # options to select one of the transfer agents
9
+ class TransferAgent
10
+ include Singleton
11
+ private
12
+ def initialize
13
+ @transfer_spec_default={}
14
+ @agent=nil
15
+ end
16
+ public
17
+
18
+ def option_transfer_spec; @transfer_spec_default; end
19
+
20
+ def option_transfer_spec=(value); @transfer_spec_default.merge!(value); end
21
+
22
+ def option_to_folder; @transfer_spec_default['destination_root']; end
23
+
24
+ def option_to_folder=(value); @transfer_spec_default.merge!({'destination_root'=>value}); end
25
+
26
+ def declare_transfer_options
27
+ Main.instance.options.set_obj_attr(:ts,self,:option_transfer_spec)
28
+ Main.instance.options.set_obj_attr(:to_folder,self,:option_to_folder)
29
+ Main.instance.options.add_opt_simple(:ts,"override transfer spec values (Hash, use @json: prefix), current=#{Main.instance.options.get_option(:ts,:optional)}")
30
+ Main.instance.options.add_opt_simple(:to_folder,"destination folder for downloaded files")
31
+ Main.instance.options.add_opt_list(:transfer,[:direct,:connect,:node],"type of transfer")
32
+ Main.instance.options.add_opt_simple(:transfer_node,"name of configuration used to transfer when using --transfer=node")
33
+ Main.instance.options.set_option(:transfer,:direct)
34
+ end
35
+
36
+ def agent
37
+ if @agent.nil?
38
+ case Main.instance.options.get_option(:transfer,:mandatory)
39
+ when :direct
40
+ @agent=Fasp::Local.instance
41
+ if !Main.instance.options.get_option(:fasp_proxy,:optional).nil?
42
+ @transfer_spec_default['EX_fasp_proxy_url']=Main.instance.options.get_option(:fasp_proxy,:optional)
43
+ end
44
+ if !Main.instance.options.get_option(:http_proxy,:optional).nil?
45
+ @transfer_spec_default['EX_http_proxy_url']=Main.instance.options.get_option(:http_proxy,:optional)
46
+ end
47
+ # TODO: option to choose progress format
48
+ # here we disable native stdout progress
49
+ @agent.quiet=true
50
+ Log.log.debug(">>>>#{@transfer_spec_default}".red)
51
+ when :connect
52
+ @agent=Fasp::Connect.instance
53
+ when :node
54
+ # support: @param:<name>
55
+ # support extended values
56
+ transfer_node_spec=Main.instance.options.get_option(:transfer_node,:optional)
57
+ # of not specified, use default node
58
+ case transfer_node_spec
59
+ when 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=config_presets[param_set_name]
63
+ when /^@param:/
64
+ param_set_name=transfer_node_spec.gsub!(/^@param:/,'')
65
+ Log.log.debug("param_set_name=#{param_set_name}")
66
+ raise CliBadArgument,"no such parameter set: [#{param_set_name}] in config file" if !config_presets.has_key?(param_set_name)
67
+ node_config=config_presets[param_set_name]
68
+ else
69
+ node_config=ExtendedValue.parse(:transfer_node,transfer_node_spec)
70
+ end
71
+ Log.log.debug("node=#{node_config}")
72
+ raise CliBadArgument,"the node configuration shall be a hash, use either @json:<json> or @param:<parameter set name>" if !node_config.is_a?(Hash)
73
+ # now check there are required parameters
74
+ sym_config={}
75
+ [:url,:username,:password].each do |param|
76
+ raise CliBadArgument,"missing parameter [#{param}] in node specification: #{node_config}" if !node_config.has_key?(param.to_s)
77
+ sym_config[param]=node_config[param.to_s]
78
+ end
79
+ @agent=Fasp::Node.instance
80
+ 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]})
81
+ else raise "ERROR"
82
+ end
83
+ @agent.add_listener(Listener::Logger.new)
84
+ @agent.add_listener(Listener::ProgressMulti.new)
85
+ end
86
+ return @agent
87
+ end
88
+
89
+ # return destination folder for transfers
90
+ # sets default if needed
91
+ # param: 'send' or 'receive'
92
+ def destination_folder(direction)
93
+ # set default if needed
94
+ if @transfer_spec_default['destination_root'].nil?
95
+ # default: / on remote, . on local
96
+ case direction
97
+ when 'send'
98
+ @transfer_spec_default['destination_root']='/'
99
+ when 'receive'
100
+ @transfer_spec_default['destination_root']='.'
101
+ else
102
+ raise "wrong direction: #{direction}"
103
+ end
104
+ end
105
+ return @transfer_spec_default['destination_root']
106
+ end
107
+
108
+ # plugins shall use this method to start a transfer
109
+ # @param: ts_source specifies how destination_root is set (how transfer spec was generated)
110
+ # and not the default one
111
+ def start_transfer_wait_result(transfer_spec,ts_source)
112
+ # initialize transfert agent
113
+ self.agent
114
+ case transfer_spec['direction']
115
+ when 'receive'
116
+ # init default if required in any case
117
+ destination_folder(transfer_spec['direction'])
118
+ when 'send'
119
+ case ts_source
120
+ when :direct
121
+ # init default if required
122
+ destination_folder(transfer_spec['direction'])
123
+ when :node_gen3
124
+ # in that case, destination is set in return by application (API/upload_setup)
125
+ # but to_folder was used in intial api call
126
+ @transfer_spec_default.delete('destination_root')
127
+ when :node_gen4
128
+ @transfer_spec_default['destination_root']='/'
129
+ else
130
+ raise StandardError,"InternalError: unsupported value: #{ts_source}"
131
+ end
132
+ end
133
+
134
+ transfer_spec.merge!(@transfer_spec_default)
135
+ # add bypass keys if there is a token, also prevents connect plugin to ask password
136
+ transfer_spec['authentication']='token' if transfer_spec.has_key?('token')
137
+ Log.log.debug("mgr is a #{@agent.class}")
138
+ @agent.start_transfer(transfer_spec)
139
+ return Main.result_nothing
140
+ end
141
+
142
+ def shutdown(p)
143
+ @agent.shutdown(p) unless @agent.nil?
144
+ end
145
+ end
146
+ end
147
+ end