asperalm 0.7.5 → 0.7.5.1

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
  SHA256:
3
- metadata.gz: c9523d1c13fb4e071ae98480351cda01e699321d9875848ce435f6c6c713659a
4
- data.tar.gz: 463dac496b7f69ae2e2124c8fb6b1d8334fbf376c5800fe2ee941c49c814c25a
3
+ metadata.gz: d8fd181727efa5f832bb2680d3d3a2714e429829f3979b04cefeab9aed27d33a
4
+ data.tar.gz: 1552db35bc1569fe529c092798f791e80c213baec4d3f0d33c70a013dd415f59
5
5
  SHA512:
6
- metadata.gz: 70d67ffa274941f868ae09e29b1aca68a09a49c01c93d7a92fa31c48485df55c011694672850c39a1142d1f1061a3f8f17630ad1b3a2a8723162db88a16a22fe
7
- data.tar.gz: 659adc07842407976c6e1cf78a5dc6a362ea396fac9d8156f997d9de6bf2e0d1af9fac96df05b833de7b11e1916a8a5d95ab691636aaefc05a1ebfc8f69b8f7c
6
+ metadata.gz: 962432f7134d2b0a77b52d0ac5bd05abcfe5e323aa10398e5b05fb453524cd8f8486f4e9758096b99ff5b62a5bddfed70378a0e193f70dd49fc55a8f84042371
7
+ data.tar.gz: 1397dc707e5fe5eb8819d4cdc4c1a329a331677062f2c587b9138c133865d6b989a522b6f77f7b40a994a72b2520bd93e5fe02a551957fa14da181ac2703f566
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Asperalm - Laurent's Aspera Command Line Interface and Ruby Library
2
2
 
3
- Version : 0.7.5
3
+ Version : 0.7.5.1
4
4
 
5
5
 
6
6
  _Laurent/2016-2018_
@@ -34,7 +34,7 @@ Once the gem is installed, the `aslmcli` shall be accessible:
34
34
 
35
35
  ```bash
36
36
  $ aslmcli --version
37
- 0.7.5
37
+ 0.7.5.1
38
38
 
39
39
  ```
40
40
 
@@ -321,7 +321,9 @@ The value of options and arguments can optionally be retrieved using one of the
321
321
 
322
322
  * @val:VALUE , prevent further special prefix processing, e.g. `--username=@val:laurent` sets the option `username` to value `laurent`.
323
323
  * @file:PATH , read value from a file (prefix "~/" is replaced with the users home folder), e.g. --key=@file:~/.ssh/mykey
324
+ * @path:PATH , performs path expansion (prefix "~/" is replaced with the users home folder), e.g. --config-file=@path:~/sample_config.yml
324
325
  * @env:ENVVAR , read from a named env var, e.g.--password=@env:MYPASSVAR
326
+ * @stdin , read from stdin
325
327
 
326
328
  In addition it is possible to decode a value, using one or multiple decoders :
327
329
 
@@ -901,6 +903,7 @@ aslmcli shares2 organization list
901
903
  aslmcli shares2 project list --organization=Sport
902
904
  aslmcli shares2 repository browse /
903
905
  aslmcli shares2 userinfo
906
+ aslmcli sync start --parameters=@json:'{"sessions":[{"name":"test","remote_dir":"/sync_test","local_dir":"contents","host":"10.25.0.8","user":"user1","private_key_path":"/Users/laurent/.ssh/id_rsa"}]}'
904
907
 
905
908
  ...and more
906
909
  ```
@@ -910,7 +913,7 @@ aslmcli shares2 userinfo
910
913
  ```bash
911
914
  $ aslmcli -h
912
915
  NAME
913
- aslmcli -- a command line tool for Aspera Applications (v0.7.5)
916
+ aslmcli -- a command line tool for Aspera Applications (v0.7.5.1)
914
917
 
915
918
  SYNOPSIS
916
919
  aslmcli COMMANDS [OPTIONS] [ARGS]
@@ -927,7 +930,7 @@ COMMANDS
927
930
 
928
931
  OPTIONS
929
932
  Options begin with a '-' (minus), and value is provided on command line.
930
- Special values are supported beginning with special prefix, like: @val: @file: @env: @["base64", "json", "zlib", "ruby", "csvt"]:.
933
+ Special values are supported beginning with special prefix, like: @val: @file: @path: @env: @stdin: @["base64", "json", "zlib", "ruby", "csvt"]:.
931
934
  Dates format is 'DD-MM-YY HH:MM:SS', or 'now' or '-<num>h'
932
935
 
933
936
  ARGS
@@ -944,7 +947,7 @@ OPTIONS: global
944
947
  -N, --no-default do not load default configuration for plugin
945
948
  -v, --version display version
946
949
  --ui=ENUM method to start browser: text, graphical
947
- --log-level=ENUM Log level: error, fatal, unknown, debug, info, warn
950
+ --log-level=ENUM Log level: info, warn, error, fatal, unknown, debug
948
951
  --logger=ENUM log method: stderr, stdout, syslog
949
952
  --format=ENUM output format: table, ruby, json, jsonpp, yaml, csv
950
953
  --transfer=ENUM type of transfer: direct, connect, node
@@ -1102,6 +1105,11 @@ OPTIONS:
1102
1105
  --validate-mime=ENUM use magic number validation: yes, no
1103
1106
  --check-extension=ENUM check extra file extensions: yes, no
1104
1107
 
1108
+ COMMAND: sync
1109
+ SUBCOMMANDS: start
1110
+ OPTIONS:
1111
+ --parameters=VALUE extended value for session set definition
1112
+
1105
1113
  COMMAND: server
1106
1114
  SUBCOMMANDS: nodeadmin, userdata, configurator, download, upload, browse, delete, rename, ls, rm, mv, du, info, mkdir, cp, df, md5sum
1107
1115
  OPTIONS:
@@ -1723,6 +1731,11 @@ delete all my access keys:
1723
1731
  for k in $(aslmcli ats access_key list --field=id --format=csv);do aslmcli ats access_key id $k delete;done
1724
1732
  ```
1725
1733
 
1734
+ ## IBM Aspera Sync
1735
+
1736
+ A basic plugin to start an "async" using aslmcli. The main advantage is the possibility
1737
+ to start from ma configuration file, using aslmcli standard options.
1738
+
1726
1739
  ## Preview
1727
1740
 
1728
1741
  The preview plugin provides generation of previews for Aspera on Cloud.
@@ -1977,6 +1990,10 @@ This means that you do not have ruby support for ED25519 SSH keys. You may eithe
1977
1990
  Gems, or remove your ed25519 key from your `.ssh` folder to solve the issue.
1978
1991
 
1979
1992
  # Release Notes
1993
+ * version 0.7.6
1994
+
1995
+ * add "sync" plugin
1996
+
1980
1997
  * version 0.7
1981
1998
 
1982
1999
  * Breaking change: AoC package recv take option if for package instead of argument.
@@ -1 +1 @@
1
- 0.7.5
1
+ 0.7.5.1
@@ -11,7 +11,7 @@ module Asperalm
11
11
  @@DECODERS=['base64', 'json', 'zlib', 'ruby', 'csvt']
12
12
 
13
13
  # there shall be zero or one reader only
14
- def self.readers; ['val', 'file', 'env'].push(@@DECODERS); end
14
+ def self.readers; ['val', 'file', 'path', 'env', 'stdin'].push(@@DECODERS); end
15
15
 
16
16
  # parse an option value, special behavior for file:, env:, val:
17
17
  def self.parse(name_or_descr,value)
@@ -23,13 +23,15 @@ module Asperalm
23
23
  value=m[2]
24
24
  end
25
25
  # then read value
26
- if m=value.match(%r{^@file:(.*)}) then
26
+ if m=value.match(/^@val:(.*)/) then
27
+ value=m[1]
28
+ elsif m=value.match(%r{^@file:(.*)}) then
27
29
  value=File.read(File.expand_path(m[1]))
28
30
  #raise CliBadArgument,"cannot open file \"#{value}\" for #{name_or_descr}" if ! File.exist?(value)
31
+ elsif m=value.match(/^@path:(.*)/) then
32
+ value=File.expand_path(m[1])
29
33
  elsif m=value.match(/^@env:(.*)/) then
30
34
  value=ENV[m[1]]
31
- elsif m=value.match(/^@val:(.*)/) then
32
- value=m[1]
33
35
  elsif value.eql?('@stdin') then
34
36
  value=STDIN.gets
35
37
  end
@@ -7,6 +7,7 @@ require 'asperalm/fasp/client/node'
7
7
  require 'asperalm/fasp/listener_logger'
8
8
  require 'asperalm/fasp/listener_progress'
9
9
  require 'asperalm/open_application'
10
+ require 'asperalm/temp_file_manager'
10
11
  require 'asperalm/log'
11
12
  require 'asperalm/oauth'
12
13
  require 'asperalm/files_api'
@@ -511,6 +512,7 @@ module Asperalm
511
512
  end
512
513
 
513
514
  def process_exception_exit(e,reason,propose_help=:none)
515
+ TempFileManager.instance.cleanup
514
516
  STDERR.puts "ERROR:".bg_red().gray().blink()+" "+reason+": "+e.message
515
517
  STDERR.puts "Use '-h' option to get help." if propose_help.eql?(:usage)
516
518
  if Log.instance.level.eql?(:debug)
@@ -887,7 +889,8 @@ module Asperalm
887
889
  rescue StandardError => e; process_exception_exit(e,"Other",:debug)
888
890
  rescue Interrupt => e; process_exception_exit(e,"Interruption",:debug)
889
891
  end
890
- return self
892
+ TempFileManager.instance.cleanup
893
+ return nil
891
894
  end
892
895
  end # Main
893
896
  end # Cli
@@ -208,6 +208,7 @@ module Asperalm
208
208
  #declare_option(option_symbol)
209
209
  end
210
210
  value=ExtendedValue.parse(option_symbol,value)
211
+ Log.log.debug("set_option, extended=#{value}")
211
212
  if @declared_options[option_symbol][:values].eql?(@@BOOLEAN_VALUES)
212
213
  value=enum_to_bool(value)
213
214
  end
@@ -5,7 +5,7 @@ require 'asperalm/open_application'
5
5
  module Asperalm
6
6
  module Cli
7
7
  module Plugins
8
- # list and download connect client versions
8
+ # list and download connect client versions, select FASP implementation
9
9
  class Client < Plugin
10
10
  CONNECT_WEB_URL = 'http://d3gcli72yxqn2z.cloudfront.net/connect'
11
11
  CONNECT_VERSIONS = 'connectversions.js'
@@ -17,7 +17,7 @@ module Asperalm
17
17
  return table_data.select {|i| ! i['key'].eql?('links') }
18
18
  end
19
19
 
20
- # retrieve structure with all versions available
20
+ # retrieve structure from cloud (CDN) with all versions available
21
21
  def connect_versions
22
22
  if @connect_versions.nil?
23
23
  api_connect_cdn=Rest.new({:base_url=>CONNECT_WEB_URL})
@@ -38,10 +38,9 @@ module Asperalm
38
38
  command=self.options.get_next_argument('command',action_list)
39
39
  case command
40
40
  when :current # shows files used
41
- return {:type=>:object_list, :data=>Fasp::Installation.instance.paths.map {|k,v| {'name'=>k,'path'=>v[:path]}}}
41
+ return {:type=>:object_list, :data=>Fasp::Installation.instance.paths.map{|k,v|{'name'=>k,'path'=>v[:path]}}}
42
42
  when :available
43
- all=Fasp::Installation.instance.installed_products
44
- return {:type=>:object_list, :data=>all, :fields=>[:name,:app_root]}
43
+ return {:type=>:object_list, :data=>Fasp::Installation.instance.installed_products, :fields=>['name','app_root']}
45
44
  when :connect
46
45
  command=self.options.get_next_argument('command',[:list,:id])
47
46
  case command
@@ -0,0 +1,33 @@
1
+ require 'asperalm/cli/plugin'
2
+ require 'asperalm/sync'
3
+
4
+ module Asperalm
5
+ module Cli
6
+ module Plugins
7
+ # list and download connect client versions, select FASP implementation
8
+ class Sync < Plugin
9
+ def declare_options
10
+ self.options.add_opt_simple(:parameters,"extended value for session set definition")
11
+ end
12
+
13
+ def action_list; [ :start ];end
14
+
15
+ def execute_action
16
+ command=self.options.get_next_argument('command',action_list)
17
+ case command
18
+ when :start
19
+ args,env=Asperalm::Sync.new(self.options.get_option(:parameters,:mandatory)).compute_args
20
+ res=system(env,['async','async'],*args)
21
+ Log.log.debug("result=#{res}")
22
+ 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: #{$?}")
26
+ else raise "internal error: unspecified case"
27
+ end
28
+ end # command
29
+ end # execute_action
30
+ end # Sync
31
+ end # Plugins
32
+ end # Cli
33
+ end # Asperalm
@@ -0,0 +1,114 @@
1
+ module Asperalm
2
+ # helper to build command line from spec in hash
3
+ # constructor takes hash: { 'param1':'value1', ...}
4
+ # process_param is called repeatedly with all known parameters
5
+ # then resulting param list and env var are read from member values :result_*
6
+ class CommandLineBuilder
7
+ BOOLEAN_CLASSES=[TrueClass,FalseClass]
8
+
9
+ # @param job_params
10
+ def initialize(job_params)
11
+ @job_params=job_params.clone # shallow copy is sufficient
12
+ @result_env={}
13
+ @result_args=[]
14
+ @used_ts_keys=[]
15
+ end
16
+
17
+ def env_args
18
+ Log.log.debug("ENV=#{@result_env}, ARGS=#{@result_args}")
19
+ return @result_env,@result_args
20
+ end
21
+
22
+ # transform yes/no to trye/false
23
+ def self.yes_to_true(value)
24
+ case value
25
+ when 'yes'; return true
26
+ when 'no'; return false
27
+ end
28
+ raise "unsupported value: #{value}"
29
+ end
30
+
31
+ # add options directly to ascp command line
32
+ def add_command_line_options(options)
33
+ return if options.nil?
34
+ options.each{|o|@result_args.push(o.to_s)}
35
+ end
36
+
37
+ # check that all provided parameters were used
38
+ def check_all_used
39
+ # warn about non translated arguments
40
+ @job_params.each_pair{|key,val|Log.log.error("unrecognized parameter: #{key} = \"#{val}\"") if !@used_ts_keys.include?(key)}
41
+ end
42
+
43
+ # default value for command line based on option name
44
+ def switch_name(ts_name,options)
45
+ return options[:option_switch] if options.has_key?(:option_switch)
46
+ return '--'+ts_name.to_s.gsub('_','-')
47
+ end
48
+
49
+ def env_name(ts_name,options)
50
+ return options[:variable]
51
+ end
52
+
53
+ # Process a parameter from transfer specification and generate command line param or env var
54
+ # @param ts_name : key in transfer spec
55
+ # @param option_type : type of processing
56
+ # @param options : options for type
57
+ def process_param(ts_name,option_type,options={})
58
+ # by default : not mandatory
59
+ options[:mandatory]||=false
60
+ # by default : string, unless it's without arg
61
+ options[:accepted_types]||=option_type.eql?(:opt_without_arg) ? BOOLEAN_CLASSES : [String]
62
+
63
+ # check mandatory parameter (nil is valid value)
64
+ raise Fasp::Error.new("mandatory parameter: #{ts_name}") if options[:mandatory] and !@job_params.has_key?(ts_name)
65
+ parameter_value=@job_params[ts_name]
66
+ parameter_value=options[:default] if parameter_value.nil? and options.has_key?(:default)
67
+ # check provided type
68
+ raise Fasp::Error.new("#{ts_name} is : #{parameter_value.class} (#{parameter_value}), shall be #{options[:accepted_types]}, ") unless parameter_value.nil? or options[:accepted_types].inject(false){|m,v|m or parameter_value.is_a?(v)}
69
+ @used_ts_keys.push(ts_name)
70
+
71
+ # process only non-nil values
72
+ return nil if parameter_value.nil?
73
+
74
+ if options.has_key?(:translate_values)
75
+ # translate using conversion table
76
+ new_value=options[:translate_values][parameter_value]
77
+ raise "unsupported value: #{parameter_value}" if new_value.nil?
78
+ parameter_value=new_value
79
+ end
80
+ raise "unsupported value: #{parameter_value}" unless options[:accepted_values].nil? or options[:accepted_values].include?(parameter_value)
81
+ if options[:encode]
82
+ newvalue=options[:encode].call(parameter_value)
83
+ raise Fasp::Error.new("unsupported #{ts_name}: #{parameter_value}") if newvalue.nil?
84
+ parameter_value=newvalue
85
+ end
86
+
87
+ case option_type
88
+ when :ignore # ignore this parameter
89
+ return
90
+ when :get_value # just get value
91
+ return parameter_value
92
+ when :envvar # set in env var
93
+ # define ascp parameter in env var from transfer spec
94
+ @result_env[env_name(ts_name,options)] = parameter_value
95
+ when :opt_without_arg # if present and true : just add option without value
96
+ add_param=false
97
+ case parameter_value
98
+ when false# nothing to put on command line, no creation by default
99
+ when true; add_param=true
100
+ else raise Fasp::Error.new("unsupported #{ts_name}: #{parameter_value}")
101
+ end
102
+ add_param=!add_param if options[:add_on_false]
103
+ add_command_line_options([switch_name(ts_name,options)]) if add_param
104
+ when :opt_with_arg # transform into command line option with value
105
+ #parameter_value=parameter_value.to_s if parameter_value.is_a?(Integer)
106
+ parameter_value=[parameter_value] unless parameter_value.is_a?(Array)
107
+ # if transfer_spec value is an array, applies option many times
108
+ parameter_value.each{|v|add_command_line_options([switch_name(ts_name,options),v])}
109
+ else
110
+ raise "Error"
111
+ end
112
+ end
113
+ end
114
+ end
@@ -36,6 +36,7 @@ module Asperalm
36
36
  if transfer_spec['authentication'].eql?("token")
37
37
  # add Aspera private keys for web access, token based authorization
38
38
  transfer_spec['EX_ssh_key_paths'] = [ Installation.instance.path(:ssh_bypass_key_dsa), Installation.instance.path(:ssh_bypass_key_rsa) ]
39
+ # mwouais...
39
40
  transfer_spec['drowssap_etomer'.reverse] = "%08x-%04x-%04x-%04x-%04x%08x" % "t1(\xBF;\xF3E\xB5\xAB\x14F\x02\xC6\x7F)P".unpack("NnnnnN")
40
41
  end
41
42
  # add fallback cert and key
@@ -72,6 +73,7 @@ module Asperalm
72
73
  ascp_arguments.unshift('-M', mgt_sock.addr[1].to_s)
73
74
  # start ascp in sub process
74
75
  Log.log.debug "execute: #{ascp_params[:env].map{|k,v| "#{k}=\"#{v}\""}.join(' ')} \"#{ascp_path}\" \"#{ascp_arguments.join('" "')}\""
76
+ # start process
75
77
  ascp_pid = Process.spawn(ascp_params[:env],[ascp_path,ascp_path],*ascp_arguments)
76
78
  # in parent, wait for connection to socket max 3 seconds
77
79
  Log.log.debug "before accept for pid (#{ascp_pid})"
@@ -1,7 +1,8 @@
1
+ require 'asperalm/log'
2
+ require 'asperalm/command_line_builder'
1
3
  require 'securerandom'
2
- require "asperalm/log"
3
- require "base64"
4
- require "json"
4
+ require 'base64'
5
+ require 'json'
5
6
 
6
7
  module Asperalm
7
8
  module Fasp
@@ -13,198 +14,99 @@ module Asperalm
13
14
 
14
15
  def self.file_list_folder=(v); @@file_list_folder=v;end
15
16
 
16
- def initialize(transfer_spec)
17
- @transfer_spec=transfer_spec.clone # shallow copy is sufficient
18
- @result_env={}
19
- @result_args=[]
20
- @used_ts_keys=[]
21
- @created_files=[]
22
- end
23
-
24
- def compute_args
25
- transfer_spec_to_args_env
26
- end
27
-
28
- def cleanup_files
29
- @created_files.each do |filepath|
30
- File.delete(filepath)
31
- end
32
- @created_files=[]
33
- end
34
-
35
- private
36
-
37
- BOOLEAN_CLASSES=[TrueClass,FalseClass]
38
-
39
- def temp_filelist_path
40
- FileUtils::mkdir_p(@@file_list_folder) unless Dir.exist?(@@file_list_folder)
41
- new_file=File.join(@@file_list_folder,SecureRandom.uuid)
42
- @created_files.push(new_file)
43
- return new_file
44
- end
45
-
46
- # Process a parameter from transfer specification and generate command line param or env var
47
- # @param ts_name : key in transfer spec
48
- # @param option_type : type of processing
49
- # @param options : options for type
50
- def process_param(ts_name,option_type,options={})
51
- # by default : not mandatory
52
- options[:mandatory]||=false
53
- # by default : string, unless it's without arg
54
- options[:accepted_types]||=option_type.eql?(:opt_without_arg) ? BOOLEAN_CLASSES : [String]
55
-
56
- # check mandatory parameter (nil is valid value)
57
- raise Fasp::Error.new("mandatory parameter: #{ts_name}") if options[:mandatory] and !@transfer_spec.has_key?(ts_name)
58
- parameter_value=@transfer_spec[ts_name]
59
- parameter_value=options[:default] if parameter_value.nil? and options.has_key?(:default)
60
- # check provided type
61
- raise Fasp::Error.new("#{ts_name} is : #{parameter_value.class} (#{parameter_value}), shall be #{options[:accepted_types]}, ") unless parameter_value.nil? or options[:accepted_types].inject(false){|m,v|m or parameter_value.is_a?(v)}
62
- @used_ts_keys.push(ts_name)
63
-
64
- # process only non-nil values
65
- return nil if parameter_value.nil?
66
-
67
- if options.has_key?(:translate_values)
68
- # translate using conversion table
69
- new_value=options[:translate_values][parameter_value]
70
- raise "unsupported value: #{parameter_value}" if new_value.nil?
71
- parameter_value=new_value
72
- end
73
- raise "unsupported value: #{parameter_value}" unless options[:accepted_values].nil? or options[:accepted_values].include?(parameter_value)
74
- if options[:encode]
75
- newvalue=options[:encode].call(parameter_value)
76
- raise Fasp::Error.new("unsupported #{ts_name}: #{parameter_value}") if newvalue.nil?
77
- parameter_value=newvalue
78
- end
79
-
80
- case option_type
81
- when :ignore # ignore this parameter
82
- return
83
- when :get_value # just get value
84
- return parameter_value
85
- when :envvar # set in env var
86
- # define ascp parameter in env var from transfer spec
87
- @result_env[options[:variable]] = parameter_value
88
- when :opt_without_arg # if present and true : just add option without value
89
- add_param=false
90
- case parameter_value
91
- when false# nothing to put on command line, no creation by default
92
- when true; add_param=true
93
- else raise Fasp::Error.new("unsupported #{ts_name}: #{parameter_value}")
94
- end
95
- add_param=!add_param if options[:add_on_false]
96
- add_ascp_options([options[:option_switch]]) if add_param
97
- when :opt_with_arg # transform into command line option with value
98
- #parameter_value=parameter_value.to_s if parameter_value.is_a?(Integer)
99
- parameter_value=[parameter_value] unless parameter_value.is_a?(Array)
100
- # if transfer_spec value is an array, applies option many times
101
- parameter_value.each{|v|add_ascp_options([options[:option_switch],v])}
102
- else
103
- raise "Error"
104
- end
105
- end
106
-
107
- # add options directly to ascp command line
108
- def add_ascp_options(options)
109
- return if options.nil?
110
- options.each{|o|@result_args.push(o.to_s)}
17
+ def initialize(job_spec)
18
+ @job_spec=job_spec
19
+ @builder=CommandLineBuilder.new(@job_spec)
111
20
  end
112
21
 
113
22
  # translate transfer spec to env vars and command line arguments for ascp
114
23
  # NOTE: parameters starting with "EX_" (extended) are not standard
115
- def transfer_spec_to_args_env
24
+ def compute_args
116
25
  # some ssh credentials are required to avoid interactive password input
117
- if !@transfer_spec.has_key?('remote_password') and
118
- !@transfer_spec.has_key?('EX_ssh_key_value') and
119
- !@transfer_spec.has_key?('EX_ssh_key_paths') then
26
+ if !@job_spec.has_key?('remote_password') and
27
+ !@job_spec.has_key?('EX_ssh_key_value') and
28
+ !@job_spec.has_key?('EX_ssh_key_paths') then
120
29
  raise Fasp::Error.new('required: ssh key (value or path) or password')
121
30
  end
122
31
 
123
32
  # parameters with env vars
124
- process_param('remote_password',:envvar,:variable=>'ASPERA_SCP_PASS')
125
- process_param('token',:envvar,:variable=>'ASPERA_SCP_TOKEN')
126
- process_param('cookie',:envvar,:variable=>'ASPERA_SCP_COOKIE')
127
- process_param('EX_ssh_key_value',:envvar,:variable=>'ASPERA_SCP_KEY')
128
- process_param('EX_at_rest_password',:envvar,:variable=>'ASPERA_SCP_FILEPASS')
129
- process_param('EX_proxy_password',:envvar,:variable=>'ASPERA_PROXY_PASS')
130
-
131
- process_param('create_dir',:opt_without_arg,:option_switch=>'-d')
132
- process_param('precalculate_job_size',:opt_without_arg,:option_switch=>'--precalculate-job-size')
133
- process_param('EX_quiet',:opt_without_arg,:option_switch=>'-q')
134
-
135
- process_param('cipher',:opt_with_arg,:option_switch=>'-c',:accepted_types=>[String],:translate_values=>{'aes128'=>'aes128','aes-128'=>'aes128','aes192'=>'aes192','aes-192'=>'aes192','aes256'=>'aes256','aes-256'=>'aes256','none'=>'none'})
136
- process_param('resume_policy',:opt_with_arg,:option_switch=>'-k',:accepted_types=>[String],:default=>'sparse_csum',:translate_values=>{'none'=>0,'attrs'=>1,'sparse_csum'=>2,'full_csum'=>3})
137
- process_param('direction',:opt_with_arg,:option_switch=>'--mode',:accepted_types=>[String],:translate_values=>{'receive'=>'recv','send'=>'send'})
138
- process_param('remote_user',:opt_with_arg,:option_switch=>'--user',:accepted_types=>[String])
139
- process_param('remote_host',:opt_with_arg,:option_switch=>'--host',:accepted_types=>[String])
140
- process_param('ssh_port',:opt_with_arg,:option_switch=>'-P',:accepted_types=>[Integer])
141
- process_param('fasp_port',:opt_with_arg,:option_switch=>'-O',:accepted_types=>[Integer])
142
- process_param('dgram_size',:opt_with_arg,:option_switch=>'-Z',:accepted_types=>[Integer])
143
- process_param('target_rate_kbps',:opt_with_arg,:option_switch=>'-l',:accepted_types=>[Integer])
144
- process_param('min_rate_kbps',:opt_with_arg,:option_switch=>'-m',:accepted_types=>[Integer])
145
- process_param('rate_policy',:opt_with_arg,:option_switch=>'--policy',:accepted_types=>[String])
146
- process_param('http_fallback',:opt_with_arg,:option_switch=>'-y',:accepted_types=>[String,*BOOLEAN_CLASSES],:translate_values=>{'force'=>'F',true=>1,false=>0})
147
- process_param('http_fallback_port',:opt_with_arg,:option_switch=>'-t',:accepted_types=>[Integer])
148
- process_param('source_root',:opt_with_arg,:option_switch=>'--source-prefix64',:accepted_types=>[String],:encode=>lambda{|prefix|Base64.strict_encode64(prefix)})
149
- process_param('sshfp',:opt_with_arg,:option_switch=>'--check-sshfp',:accepted_types=>[String])
150
- process_param('symlink_policy',:opt_with_arg,:option_switch=>'--symbolic-links',:accepted_types=>[String])
151
- process_param('overwrite',:opt_with_arg,:option_switch=>'--overwrite',:accepted_types=>[String])
152
-
153
- process_param('EX_fallback_key',:opt_with_arg,:option_switch=>'-Y',:accepted_types=>[String])
154
- process_param('EX_fallback_cert',:opt_with_arg,:option_switch=>'-I',:accepted_types=>[String])
155
- process_param('EX_fasp_proxy_url',:opt_with_arg,:option_switch=>'--proxy',:accepted_types=>[String])
156
- process_param('EX_http_proxy_url',:opt_with_arg,:option_switch=>'-x',:accepted_types=>[String])
157
- process_param('EX_ssh_key_paths',:opt_with_arg,:option_switch=>'-i',:accepted_types=>[Array])
158
- process_param('EX_http_transfer_jpeg',:opt_with_arg,:option_switch=>'-j',:accepted_types=>[Integer])
159
- process_param('EX_multi_session_threshold',:opt_with_arg,:option_switch=>'--multi-session-threshold',:accepted_types=>[String])
160
- process_param('EX_multi_session_part',:opt_with_arg,:option_switch=>'-C',:accepted_types=>[String])
33
+ @builder.process_param('remote_password',:envvar,:variable=>'ASPERA_SCP_PASS')
34
+ @builder.process_param('token',:envvar,:variable=>'ASPERA_SCP_TOKEN')
35
+ @builder.process_param('cookie',:envvar,:variable=>'ASPERA_SCP_COOKIE')
36
+ @builder.process_param('EX_ssh_key_value',:envvar,:variable=>'ASPERA_SCP_KEY')
37
+ @builder.process_param('EX_at_rest_password',:envvar,:variable=>'ASPERA_SCP_FILEPASS')
38
+ @builder.process_param('EX_proxy_password',:envvar,:variable=>'ASPERA_PROXY_PASS')
39
+
40
+ @builder.process_param('create_dir',:opt_without_arg,:option_switch=>'-d')
41
+ @builder.process_param('precalculate_job_size',:opt_without_arg,:option_switch=>'--precalculate-job-size')
42
+ @builder.process_param('EX_quiet',:opt_without_arg,:option_switch=>'-q')
43
+
44
+ @builder.process_param('cipher',:opt_with_arg,:option_switch=>'-c',:accepted_types=>[String],:translate_values=>{'aes128'=>'aes128','aes-128'=>'aes128','aes192'=>'aes192','aes-192'=>'aes192','aes256'=>'aes256','aes-256'=>'aes256','none'=>'none'})
45
+ @builder.process_param('resume_policy',:opt_with_arg,:option_switch=>'-k',:accepted_types=>[String],:default=>'sparse_csum',:translate_values=>{'none'=>0,'attrs'=>1,'sparse_csum'=>2,'full_csum'=>3})
46
+ @builder.process_param('direction',:opt_with_arg,:option_switch=>'--mode',:accepted_types=>[String],:translate_values=>{'receive'=>'recv','send'=>'send'})
47
+ @builder.process_param('remote_user',:opt_with_arg,:option_switch=>'--user',:accepted_types=>[String])
48
+ @builder.process_param('remote_host',:opt_with_arg,:option_switch=>'--host',:accepted_types=>[String])
49
+ @builder.process_param('ssh_port',:opt_with_arg,:option_switch=>'-P',:accepted_types=>[Integer])
50
+ @builder.process_param('fasp_port',:opt_with_arg,:option_switch=>'-O',:accepted_types=>[Integer])
51
+ @builder.process_param('dgram_size',:opt_with_arg,:option_switch=>'-Z',:accepted_types=>[Integer])
52
+ @builder.process_param('target_rate_kbps',:opt_with_arg,:option_switch=>'-l',:accepted_types=>[Integer])
53
+ @builder.process_param('min_rate_kbps',:opt_with_arg,:option_switch=>'-m',:accepted_types=>[Integer])
54
+ @builder.process_param('rate_policy',:opt_with_arg,:option_switch=>'--policy',:accepted_types=>[String])
55
+ @builder.process_param('http_fallback',:opt_with_arg,:option_switch=>'-y',:accepted_types=>[String,*CommandLineBuilder::BOOLEAN_CLASSES],:translate_values=>{'force'=>'F',true=>1,false=>0})
56
+ @builder.process_param('http_fallback_port',:opt_with_arg,:option_switch=>'-t',:accepted_types=>[Integer])
57
+ @builder.process_param('source_root',:opt_with_arg,:option_switch=>'--source-prefix64',:accepted_types=>[String],:encode=>lambda{|prefix|Base64.strict_encode64(prefix)})
58
+ @builder.process_param('sshfp',:opt_with_arg,:option_switch=>'--check-sshfp',:accepted_types=>[String])
59
+ @builder.process_param('symlink_policy',:opt_with_arg,:option_switch=>'--symbolic-links',:accepted_types=>[String])
60
+ @builder.process_param('overwrite',:opt_with_arg,:option_switch=>'--overwrite',:accepted_types=>[String])
61
+
62
+ @builder.process_param('EX_fallback_key',:opt_with_arg,:option_switch=>'-Y',:accepted_types=>[String])
63
+ @builder.process_param('EX_fallback_cert',:opt_with_arg,:option_switch=>'-I',:accepted_types=>[String])
64
+ @builder.process_param('EX_fasp_proxy_url',:opt_with_arg,:option_switch=>'--proxy',:accepted_types=>[String])
65
+ @builder.process_param('EX_http_proxy_url',:opt_with_arg,:option_switch=>'-x',:accepted_types=>[String])
66
+ @builder.process_param('EX_ssh_key_paths',:opt_with_arg,:option_switch=>'-i',:accepted_types=>[Array])
67
+ @builder.process_param('EX_http_transfer_jpeg',:opt_with_arg,:option_switch=>'-j',:accepted_types=>[Integer])
68
+ @builder.process_param('EX_multi_session_threshold',:opt_with_arg,:option_switch=>'--multi-session-threshold',:accepted_types=>[String])
69
+ @builder.process_param('EX_multi_session_part',:opt_with_arg,:option_switch=>'-C',:accepted_types=>[String])
161
70
 
162
71
  # TODO: manage those parameters, some are for connect only ? node api ?
163
- process_param('target_rate_cap_kbps',:ignore,:accepted_types=>[Integer])
164
- process_param('target_rate_percentage',:ignore,:accepted_types=>[String]) # -wf -l<rate>p
165
- process_param('min_rate_cap_kbps',:ignore,:accepted_types=>[Integer])
166
- process_param('rate_policy_allowed',:ignore,:accepted_types=>[String])
167
- process_param('fasp_url',:ignore,:accepted_types=>[String])
168
- process_param('lock_rate_policy',:ignore,:accepted_types=>BOOLEAN_CLASSES)
169
- process_param('lock_min_rate',:ignore,:accepted_types=>BOOLEAN_CLASSES)
170
- process_param('lock_target_rate',:ignore,:accepted_types=>BOOLEAN_CLASSES)
171
- process_param('authentication',:ignore,:accepted_types=>[String]) # = token
172
- process_param('https_fallback_port',:ignore,:accepted_types=>[Integer]) # same as http fallback, option -t ?
173
- process_param('content_protection',:ignore,:accepted_types=>[String])
174
- process_param('cipher_allowed',:ignore,:accepted_types=>[String])
175
- process_param('multi_session',:ignore,:accepted_types=>[Integer])
176
- process_param('multi_session_threshold',:ignore,:accepted_types=>[Integer])
72
+ @builder.process_param('target_rate_cap_kbps',:ignore,:accepted_types=>[Integer])
73
+ @builder.process_param('target_rate_percentage',:ignore,:accepted_types=>[String]) # -wf -l<rate>p
74
+ @builder.process_param('min_rate_cap_kbps',:ignore,:accepted_types=>[Integer])
75
+ @builder.process_param('rate_policy_allowed',:ignore,:accepted_types=>[String])
76
+ @builder.process_param('fasp_url',:ignore,:accepted_types=>[String])
77
+ @builder.process_param('lock_rate_policy',:ignore,:accepted_types=>CommandLineBuilder::BOOLEAN_CLASSES)
78
+ @builder.process_param('lock_min_rate',:ignore,:accepted_types=>CommandLineBuilder::BOOLEAN_CLASSES)
79
+ @builder.process_param('lock_target_rate',:ignore,:accepted_types=>CommandLineBuilder::BOOLEAN_CLASSES)
80
+ @builder.process_param('authentication',:ignore,:accepted_types=>[String]) # = token
81
+ @builder.process_param('https_fallback_port',:ignore,:accepted_types=>[Integer]) # same as http fallback, option -t ?
82
+ @builder.process_param('content_protection',:ignore,:accepted_types=>[String])
83
+ @builder.process_param('cipher_allowed',:ignore,:accepted_types=>[String])
84
+ @builder.process_param('multi_session',:ignore,:accepted_types=>[Integer])
85
+ @builder.process_param('multi_session_threshold',:ignore,:accepted_types=>[Integer])
177
86
 
178
87
  # optional tags ( additional option to generate: {:space=>' ',:object_nl=>' ',:space_before=>'+',:array_nl=>'1'} )
179
- process_param('tags',:opt_with_arg,:option_switch=>'--tags64',:accepted_types=>[Hash],:encode=>lambda{|tags|Base64.strict_encode64(JSON.generate(tags))})
88
+ @builder.process_param('tags',:opt_with_arg,:option_switch=>'--tags64',:accepted_types=>[Hash],:encode=>lambda{|tags|Base64.strict_encode64(JSON.generate(tags))})
180
89
 
181
90
  # optional args, at the end to override previous ones (to allow override)
182
- add_ascp_options(process_param('EX_ascp_args',:get_value,:accepted_types=>[Array]))
91
+ @builder.add_command_line_options(@builder.process_param('EX_ascp_args',:get_value,:accepted_types=>[Array]))
183
92
 
184
93
  # destination will be base64 encoded, put before path arguments
185
- add_ascp_options(['--dest64'])
94
+ @builder.add_command_line_options(['--dest64'])
186
95
 
187
96
  # source list: TODO : use file list or file pair list, avoid command line lists
188
- add_ascp_options(process_param('paths',:get_value,:accepted_types=>[Array],:mandatory=>true).map{|i|i['source']})
97
+ @builder.add_command_line_options(@builder.process_param('paths',:get_value,:accepted_types=>[Array],:mandatory=>true).map{|i|i['source']})
189
98
 
190
99
  # destination, use base64 encoding, as defined previously
191
- add_ascp_options([Base64.strict_encode64(process_param('destination_root',:get_value,:accepted_types=>[String],:mandatory=>true))])
100
+ @builder.add_command_line_options([Base64.strict_encode64(@builder.process_param('destination_root',:get_value,:accepted_types=>[String],:mandatory=>true))])
192
101
 
193
102
  # symbol must be index of Installation.paths
194
- ascp_version=process_param('use_ascp4',:get_value) ? :ascp4 : :ascp
103
+ ascp_version=@builder.process_param('use_ascp4',:get_value) ? :ascp4 : :ascp
195
104
 
196
- # warn about non translated arguments
197
- @transfer_spec.each_pair{|key,val|Log.log.error("unhandled parameter: #{key} = \"#{val}\"") if !@used_ts_keys.include?(key)}
105
+ @builder.check_all_used
198
106
 
199
- return {:args=>@result_args,:env=>@result_env,:ascp_version=>ascp_version}
200
- end
107
+ ascp_env,ascp_args=@builder.env_args
201
108
 
202
- def self.yes_to_true(value)
203
- case value
204
- when 'yes'; return true
205
- when 'no'; return false
206
- end
207
- raise "unsupported value: #{value}"
109
+ return {:args=>ascp_args,:env=>ascp_env,:ascp_version=>ascp_version}
208
110
  end
209
111
 
210
112
  end # Parameters
@@ -1,5 +1,5 @@
1
1
  require "asperalm/log"
2
- require "asperalm/fasp/parameters"
2
+ require "asperalm/command_line_builder"
3
3
 
4
4
  module Asperalm
5
5
  module Fasp
@@ -31,10 +31,10 @@ module Asperalm
31
31
  when 'enc'; result_ts['cipher']=value.gsub('-','') # aes-128 -> aes128
32
32
  when 'tags64'; result_ts['tags']=JSON.parse(Base64.strict_decode64(value))
33
33
  when 'bwcap'; result_ts['target_rate_cap_kbps']=value.to_i
34
- when 'createpath'; result_ts['create_dir']=Parameters.yes_to_true(value)
35
- when 'fallback'; result_ts['http_fallback']=Parameters.yes_to_true(value)
36
- when 'lockpolicy'; result_ts['lock_rate_policy']=Parameters.yes_to_true(value)
37
- when 'lockminrate'; result_ts['lock_min_rate']=Parameters.yes_to_true(value)
34
+ when 'createpath'; result_ts['create_dir']=CommandLineBuilder.yes_to_true(value)
35
+ when 'fallback'; result_ts['http_fallback']=CommandLineBuilder.yes_to_true(value)
36
+ when 'lockpolicy'; result_ts['lock_rate_policy']=CommandLineBuilder.yes_to_true(value)
37
+ when 'lockminrate'; result_ts['lock_min_rate']=CommandLineBuilder.yes_to_true(value)
38
38
  when 'auth'; Log.log.debug("ignoring #{name}=#{value}") # TODO: translate into transfer spec ? yes/no
39
39
  when 'v'; Log.log.debug("ignoring #{name}=#{value}") # TODO: translate into transfer spec ? 2
40
40
  when 'protect'; Log.log.debug("ignoring #{name}=#{value}") # TODO: translate into transfer spec ?
@@ -43,6 +43,6 @@ module Asperalm
43
43
  end
44
44
  return result_ts
45
45
  end
46
- end # Parameters
46
+ end # Uri
47
47
  end # Fasp
48
48
  end # Asperalm
@@ -0,0 +1,70 @@
1
+ module Asperalm
2
+ # builds command line arg for async
3
+ class Sync
4
+ def initialize(sync_params)
5
+ @sync_params=sync_params
6
+ end
7
+
8
+ MANDATORY_KEYS=['instance','sessions']
9
+
10
+ def compute_args
11
+ raise StandardError,"parameter must be Hash" unless @sync_params.is_a?(Hash)
12
+ raise StandardError,"parameter hash must have at least 'sessions', and optionally 'instance' keys." unless @sync_params.keys.push('instance').uniq.sort.eql?(MANDATORY_KEYS)
13
+ raise StandardError,"sessions key must be hash" unless @sync_params['sessions'].is_a?(Array)
14
+
15
+ all_args=[]
16
+ all_env={}
17
+
18
+ if @sync_params.has_key?('instance')
19
+ raise StandardError,"instance key must be hash" unless @sync_params['instance'].is_a?(Hash)
20
+ instance_builder=CommandLineBuilder.new(@sync_params['instance'])
21
+ instance_builder.process_param('alt_logdir',:opt_with_arg,:accepted_types=>[String])
22
+ instance_builder.process_param('apply_local_docroot',:opt_without_arg)
23
+ instance_builder.process_param('watchd',:opt_with_arg,:accepted_types=>[String])
24
+ instance_builder.check_all_used
25
+ instance_env,instance_args=instance_builder.env_args
26
+ all_env.merge!(instance_env)
27
+ all_args.push(*instance_args)
28
+ end
29
+
30
+ @sync_params['sessions'].each do |session_params|
31
+ raise StandardError,"sessions must contain hashes" unless session_params.is_a?(Hash)
32
+ puts(">>>[#{session_params}]")
33
+ session_builder=CommandLineBuilder.new(session_params)
34
+ # note: only one env var, but multiple sessions... may be a problem
35
+ session_builder.process_param('name',:opt_with_arg,:accepted_types=>[String])
36
+ session_builder.process_param('local_dir',:opt_with_arg,:accepted_types=>[String])
37
+ session_builder.process_param('remote_dir',:opt_with_arg,:accepted_types=>[String])
38
+ session_builder.process_param('host',:opt_with_arg,:accepted_types=>[String])
39
+ session_builder.process_param('user',:opt_with_arg,:accepted_types=>[String])
40
+ session_builder.process_param('private_key_path',:opt_with_arg,:accepted_types=>[String])
41
+ session_builder.process_param('direction',:opt_with_arg,:accepted_types=>[String])
42
+ session_builder.process_param('checksum',:opt_with_arg,:accepted_types=>[String])
43
+ session_builder.process_param('tcp_port',:opt_with_arg,:accepted_types=>[Integer])
44
+ session_builder.process_param('rate_policy',:opt_with_arg,:accepted_types=>[String])
45
+ session_builder.process_param('target_rate',:opt_with_arg,:accepted_types=>[String])
46
+ session_builder.process_param('cooloff',:opt_with_arg,:accepted_types=>[Integer])
47
+ session_builder.process_param('pending_max',:opt_with_arg,:accepted_types=>[Integer])
48
+ session_builder.process_param('scan_intensity',:opt_with_arg,:accepted_types=>[String])
49
+ session_builder.process_param('cipher',:opt_with_arg,:accepted_types=>[String])
50
+ session_builder.process_param('transfer_threads',:opt_with_arg,:accepted_types=>[Integer])
51
+ session_builder.process_param('preserve_time',:opt_without_arg)
52
+ session_builder.process_param('preserve_access_time',:opt_without_arg)
53
+ session_builder.process_param('preserve_modification_time',:opt_without_arg)
54
+ session_builder.process_param('preserve_uid',:opt_without_arg)
55
+ session_builder.process_param('preserve_gid',:opt_without_arg)
56
+ session_builder.process_param('create_dir',:opt_without_arg)
57
+ session_builder.process_param('remote_password',:envvar,:variable=>'ASPERA_SCP_PASS')
58
+ session_builder.process_param('cookie',:envvar,:variable=>'ASPERA_SCP_COOKIE')
59
+ session_builder.process_param('token',:envvar,:variable=>'ASPERA_SCP_TOKEN')
60
+ session_builder.process_param('license',:envvar,:variable=>'ASPERA_SCP_LICENSE')
61
+ session_builder.check_all_used
62
+ session_env,session_args=session_builder.env_args
63
+ all_env.merge!(session_env)
64
+ all_args.push(*session_args)
65
+ end
66
+
67
+ return all_args, all_env
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,21 @@
1
+ require 'singleton'
2
+ module Asperalm
3
+ class TempFileManager
4
+ include Singleton
5
+ def initialize
6
+ @created_files=[]
7
+ end
8
+ def temp_filelist_path(temp_folder)
9
+ FileUtils::mkdir_p(temp_folder) unless Dir.exist?(temp_folder)
10
+ new_file=File.join(temp_folder,SecureRandom.uuid)
11
+ @created_files.push(new_file)
12
+ return new_file
13
+ end
14
+ def cleanup
15
+ @created_files.each do |filepath|
16
+ File.delete(filepath)
17
+ end
18
+ @created_files=[]
19
+ end
20
+ end
21
+ end
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.7.5
4
+ version: 0.7.5.1
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-07-19 00:00:00.000000000 Z
11
+ date: 2018-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xml-simple
@@ -212,9 +212,11 @@ files:
212
212
  - lib/asperalm/cli/plugins/server.rb
213
213
  - lib/asperalm/cli/plugins/shares.rb
214
214
  - lib/asperalm/cli/plugins/shares2.rb
215
+ - lib/asperalm/cli/plugins/sync.rb
215
216
  - lib/asperalm/cli/plugins/xnode.rb
216
217
  - lib/asperalm/cli/thor.rb
217
218
  - lib/asperalm/colors.rb
219
+ - lib/asperalm/command_line_builder.rb
218
220
  - lib/asperalm/fasp/client/base.rb
219
221
  - lib/asperalm/fasp/client/connect.rb
220
222
  - lib/asperalm/fasp/client/local.rb
@@ -238,6 +240,8 @@ files:
238
240
  - lib/asperalm/preview/utils.rb
239
241
  - lib/asperalm/rest.rb
240
242
  - lib/asperalm/ssh.rb
243
+ - lib/asperalm/sync.rb
244
+ - lib/asperalm/temp_file_manager.rb
241
245
  homepage: http://www.asperasoft.com
242
246
  licenses:
243
247
  - Apache-2.0