aspera-cli 4.0.0 → 4.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +843 -304
  3. data/bin/dascli +13 -0
  4. data/docs/Makefile +4 -4
  5. data/docs/README.erb.md +805 -172
  6. data/docs/test_env.conf +22 -3
  7. data/examples/aoc.rb +14 -3
  8. data/examples/faspex4.rb +89 -0
  9. data/lib/aspera/aoc.rb +87 -108
  10. data/lib/aspera/cli/formater.rb +2 -0
  11. data/lib/aspera/cli/main.rb +89 -49
  12. data/lib/aspera/cli/plugin.rb +9 -4
  13. data/lib/aspera/cli/plugins/alee.rb +1 -1
  14. data/lib/aspera/cli/plugins/aoc.rb +188 -173
  15. data/lib/aspera/cli/plugins/ats.rb +2 -2
  16. data/lib/aspera/cli/plugins/config.rb +218 -145
  17. data/lib/aspera/cli/plugins/console.rb +2 -2
  18. data/lib/aspera/cli/plugins/faspex.rb +114 -61
  19. data/lib/aspera/cli/plugins/faspex5.rb +85 -43
  20. data/lib/aspera/cli/plugins/node.rb +3 -3
  21. data/lib/aspera/cli/plugins/preview.rb +59 -45
  22. data/lib/aspera/cli/plugins/server.rb +23 -8
  23. data/lib/aspera/cli/transfer_agent.rb +77 -49
  24. data/lib/aspera/cli/version.rb +1 -1
  25. data/lib/aspera/command_line_builder.rb +49 -31
  26. data/lib/aspera/cos_node.rb +33 -28
  27. data/lib/aspera/environment.rb +2 -2
  28. data/lib/aspera/fasp/connect.rb +28 -21
  29. data/lib/aspera/fasp/http_gw.rb +140 -28
  30. data/lib/aspera/fasp/installation.rb +93 -46
  31. data/lib/aspera/fasp/local.rb +88 -45
  32. data/lib/aspera/fasp/manager.rb +15 -0
  33. data/lib/aspera/fasp/node.rb +4 -4
  34. data/lib/aspera/fasp/parameters.rb +59 -101
  35. data/lib/aspera/fasp/parameters.yaml +531 -0
  36. data/lib/aspera/fasp/resume_policy.rb +13 -12
  37. data/lib/aspera/fasp/uri.rb +1 -1
  38. data/lib/aspera/log.rb +1 -1
  39. data/lib/aspera/node.rb +61 -1
  40. data/lib/aspera/oauth.rb +49 -46
  41. data/lib/aspera/persistency_folder.rb +9 -4
  42. data/lib/aspera/preview/file_types.rb +53 -21
  43. data/lib/aspera/preview/generator.rb +3 -3
  44. data/lib/aspera/rest.rb +29 -18
  45. data/lib/aspera/secrets.rb +20 -0
  46. data/lib/aspera/sync.rb +40 -35
  47. data/lib/aspera/temp_file_manager.rb +19 -0
  48. data/lib/aspera/web_auth.rb +105 -0
  49. metadata +54 -20
  50. data/docs/transfer_spec.html +0 -99
@@ -4,6 +4,7 @@ require 'aspera/temp_file_manager'
4
4
  require 'securerandom'
5
5
  require 'base64'
6
6
  require 'json'
7
+ require 'yaml'
7
8
  require 'securerandom'
8
9
  require 'fileutils'
9
10
 
@@ -12,100 +13,67 @@ module Aspera
12
13
  # translate transfer specification to ascp parameter list
13
14
  class Parameters
14
15
  private
15
- # temp folder for file lists, must contain only file lists
16
+ # Temp folder for file lists, must contain only file lists
16
17
  # because of garbage collection takes any file there
17
18
  # this could be refined, as , for instance, on macos, temp folder is already user specific
18
19
  @@file_list_folder=TempFileManager.instance.new_file_path_global('asession_filelists')
19
- SEC_IN_DAY=86400
20
- # assume no transfer last longer than this
21
- # (garbage collect file list which were not deleted after transfer)
22
- FILE_LIST_AGE_MAX_SEC=5*SEC_IN_DAY
23
- PARAM_DEFINITION={
24
- # parameters with env vars
25
- 'remote_password' => { :type => :envvar, :variable=>'ASPERA_SCP_PASS'},
26
- 'token' => { :type => :envvar, :variable=>'ASPERA_SCP_TOKEN'},
27
- 'cookie' => { :type => :envvar, :variable=>'ASPERA_SCP_COOKIE'},
28
- 'ssh_private_key' => { :type => :envvar, :variable=>'ASPERA_SCP_KEY'},
29
- 'EX_at_rest_password' => { :type => :envvar, :variable=>'ASPERA_SCP_FILEPASS'},
30
- 'EX_proxy_password' => { :type => :envvar, :variable=>'ASPERA_PROXY_PASS'},
31
- 'EX_license_text' => { :type => :envvar, :variable=>'ASPERA_SCP_LICENSE'},
32
- # bool params
33
- 'create_dir' => { :type => :opt_without_arg, :option_switch=>'-d'},
34
- 'precalculate_job_size' => { :type => :opt_without_arg},
35
- 'keepalive' => { :type => :opt_without_arg},
36
- 'delete_before_transfer' => { :type => :opt_without_arg}, #TODO: doc readme
37
- 'preserve_access_time' => { :type => :opt_without_arg}, #TODO: doc
38
- 'preserve_creation_time' => { :type => :opt_without_arg}, #TODO: doc
39
- 'preserve_times' => { :type => :opt_without_arg}, #TODO: doc
40
- 'preserve_modification_time'=> { :type => :opt_without_arg}, #TODO: doc
41
- 'remove_empty_directories'=> { :type => :opt_without_arg}, #TODO: doc
42
- 'remove_after_transfer' => { :type => :opt_without_arg}, #TODO: doc
43
- 'remove_empty_source_directory'=> { :type => :opt_without_arg}, #TODO: doc
44
- # value params
45
- 'cipher' => { :type => :opt_with_arg, :option_switch=>'-c',:accepted_types=>String,:encode=>lambda{|cipher|cipher.tr('-','')}},
46
- 'resume_policy' => { :type => :opt_with_arg, :option_switch=>'-k',:accepted_types=>String,:default=>'sparse_csum',:translate_values=>{'none'=>0,'attrs'=>1,'sparse_csum'=>2,'full_csum'=>3}},
47
- 'direction' => { :type => :opt_with_arg, :option_switch=>'--mode',:accepted_types=>String,:translate_values=>{'receive'=>'recv','send'=>'send'}},
48
- 'remote_user' => { :type => :opt_with_arg, :option_switch=>'--user',:accepted_types=>String},
49
- 'remote_host' => { :type => :opt_with_arg, :option_switch=>'--host',:accepted_types=>String},
50
- 'ssh_port' => { :type => :opt_with_arg, :option_switch=>'-P',:accepted_types=>Integer},
51
- 'fasp_port' => { :type => :opt_with_arg, :option_switch=>'-O',:accepted_types=>Integer},
52
- 'dgram_size' => { :type => :opt_with_arg, :option_switch=>'-Z',:accepted_types=>Integer},
53
- 'target_rate_kbps' => { :type => :opt_with_arg, :option_switch=>'-l',:accepted_types=>Integer},
54
- 'min_rate_kbps' => { :type => :opt_with_arg, :option_switch=>'-m',:accepted_types=>Integer},
55
- 'rate_policy' => { :type => :opt_with_arg, :option_switch=>'--policy',:accepted_types=>String},
56
- 'http_fallback' => { :type => :opt_with_arg, :option_switch=>'-y',:accepted_types=>[String,*Aspera::CommandLineBuilder::BOOLEAN_CLASSES],:translate_values=>{'force'=>'F',true=>1,false=>0}},
57
- 'http_fallback_port' => { :type => :opt_with_arg, :option_switch=>'-t',:accepted_types=>Integer},
58
- 'source_root' => { :type => :opt_with_arg, :option_switch=>'--source-prefix64',:accepted_types=>String,:encode=>lambda{|prefix|Base64.strict_encode64(prefix)}},
59
- 'sshfp' => { :type => :opt_with_arg, :option_switch=>'--check-sshfp',:accepted_types=>String},
60
- 'symlink_policy' => { :type => :opt_with_arg, :option_switch=>'--symbolic-links',:accepted_types=>String},
61
- 'overwrite' => { :type => :opt_with_arg, :accepted_types=>String},
62
- 'exclude_newer_than' => { :type => :opt_with_arg, :accepted_types=>Integer},
63
- 'exclude_older_than' => { :type => :opt_with_arg, :accepted_types=>Integer},
64
- 'preserve_acls' => { :type => :opt_with_arg, :accepted_types=>String},
65
- 'move_after_transfer' => { :type => :opt_with_arg, :accepted_types=>String},
66
- 'multi_session_threshold' => { :type => :opt_with_arg, :accepted_types=>String},
67
- # non standard parameters
68
- 'EX_fasp_proxy_url' => { :type => :opt_with_arg, :option_switch=>'--proxy',:accepted_types=>String},
69
- 'EX_http_proxy_url' => { :type => :opt_with_arg, :option_switch=>'-x',:accepted_types=>String},
70
- 'EX_ssh_key_paths' => { :type => :opt_with_arg, :option_switch=>'-i',:accepted_types=>Array},
71
- 'EX_http_transfer_jpeg' => { :type => :opt_with_arg, :option_switch=>'-j',:accepted_types=>Integer},
72
- 'EX_multi_session_part' => { :type => :opt_with_arg, :option_switch=>'-C',:accepted_types=>String},
73
- 'EX_no_read' => { :type => :opt_without_arg, :option_switch=>'--no-read'},
74
- 'EX_no_write' => { :type => :opt_without_arg, :option_switch=>'--no-write'},
75
- 'EX_apply_local_docroot' => { :type => :opt_without_arg, :option_switch=>'--apply-local-docroot'},
76
- # TODO: manage those parameters, some are for connect only ? node api ?
77
- 'target_rate_cap_kbps' => { :type => :ignore, :accepted_types=>Integer},
78
- 'target_rate_percentage' => { :type => :ignore, :accepted_types=>String}, # -wf -l<rate>p
79
- 'min_rate_cap_kbps' => { :type => :ignore, :accepted_types=>Integer},
80
- 'rate_policy_allowed' => { :type => :ignore, :accepted_types=>String},
81
- 'fasp_url' => { :type => :ignore, :accepted_types=>String},
82
- 'lock_rate_policy' => { :type => :ignore, :accepted_types=>Aspera::CommandLineBuilder::BOOLEAN_CLASSES},
83
- 'lock_min_rate' => { :type => :ignore, :accepted_types=>Aspera::CommandLineBuilder::BOOLEAN_CLASSES},
84
- 'lock_target_rate' => { :type => :ignore, :accepted_types=>Aspera::CommandLineBuilder::BOOLEAN_CLASSES},
85
- #'authentication' => { :type => :ignore, :accepted_types=>String}, # = token
86
- 'https_fallback_port' => { :type => :ignore, :accepted_types=>Integer}, # same as http fallback, option -t ?
87
- 'content_protection' => { :type => :ignore, :accepted_types=>String},
88
- 'cipher_allowed' => { :type => :ignore, :accepted_types=>String},
89
- 'multi_session' => { :type => :ignore, :accepted_types=>Integer}, # managed
90
- # optional tags ( additional option to generate: {:space=>' ',:object_nl=>' ',:space_before=>'+',:array_nl=>'1'} )
91
- 'tags' => { :type => :opt_with_arg, :option_switch=>'--tags64',:accepted_types=>Hash,:encode=>lambda{|tags|Base64.strict_encode64(JSON.generate(tags))}},
92
- # special processing @builder.process_param( called individually
93
- 'use_ascp4' => { :type => :defer, :accepted_types=>Aspera::CommandLineBuilder::BOOLEAN_CLASSES},
94
- 'paths' => { :type => :defer, :accepted_types=>Array},
95
- 'EX_file_list' => { :type => :defer, :option_switch=>'--file-list', :accepted_types=>String},
96
- 'EX_file_pair_list' => { :type => :defer, :option_switch=>'--file-pair-list', :accepted_types=>String},
97
- 'EX_ascp_args' => { :type => :defer, :accepted_types=>Array},
98
- 'destination_root' => { :type => :defer, :accepted_types=>String},
99
- 'wss_enabled' => { :type => :defer, :accepted_types=>Aspera::CommandLineBuilder::BOOLEAN_CLASSES},
100
- 'wss_port' => { :type => :defer, :accepted_types=>Integer},
101
- }
102
-
103
- private_constant :SEC_IN_DAY,:FILE_LIST_AGE_MAX_SEC,:PARAM_DEFINITION
20
+ @@param_description_cache=nil
21
+ # @return normaiwed description of transfer spec parameters
22
+ def self.description
23
+ return @@param_description_cache unless @@param_description_cache.nil?
24
+ # config file in same folder with same name as this source
25
+ @@param_description_cache=YAML.load_file("#{__FILE__[0..-3]}yaml")
26
+ Aspera::CommandLineBuilder.normalize_description(@@param_description_cache)
27
+ end
28
+
29
+ # Agents shown in manual
30
+ SUPPORTED_AGENTS=[:direct,:node,:connect]
31
+ # Short names of columns in manual
32
+ SUPPORTED_AGENTS_SHORT=SUPPORTED_AGENTS.map{|a|a.to_s[0].to_sym}
33
+
34
+ # @return a table suitable to display a manual
35
+ def self.man_table
36
+ result=[]
37
+ description.keys.map do |k|
38
+ i=description[k]
39
+ param={name: k, type: [i[:accepted_types]].flatten.join(','),description: i[:desc]}
40
+ SUPPORTED_AGENTS.each do |a|
41
+ param[a.to_s[0].to_sym]=i[:context].nil? || i[:context].include?(a) ? 'Y' : ''
42
+ end
43
+ # only keep lines that are usable in supported agents
44
+ next if SUPPORTED_AGENTS_SHORT.inject(true){|m,i|m and param[i].empty?}
45
+ param[:cli]=case i[:cltype]
46
+ when :envvar; 'env:'+i[:clvarname]
47
+ when :opt_without_arg,:opt_with_arg; i[:option_switch]
48
+ else ''
49
+ end
50
+ if i.has_key?(:enum)
51
+ param[:description] << "\nAllowed values: #{i[:enum].join(', ')}"
52
+ end
53
+ result.push(param)
54
+ end
55
+ return result
56
+ end
57
+
58
+ # special encoding methods used in YAML (key: :encode)
59
+ def self.encode_cipher(v)
60
+ v.tr('-','')
61
+ end
62
+
63
+ # special encoding methods used in YAML (key: :encode)
64
+ def self.encode_source_root(v)
65
+ Base64.strict_encode64(v)
66
+ end
67
+
68
+ # special encoding methods used in YAML (key: :encode)
69
+ def self.encode_tags(v)
70
+ Base64.strict_encode64(JSON.generate(v))
71
+ end
104
72
 
105
73
  def initialize(job_spec,options)
106
74
  @job_spec=job_spec
107
- @builder=Aspera::CommandLineBuilder.new(@job_spec,PARAM_DEFINITION)
108
75
  @options=options
76
+ @builder=Aspera::CommandLineBuilder.new(@job_spec,self.class.description)
109
77
  end
110
78
 
111
79
  public
@@ -128,7 +96,7 @@ module Aspera
128
96
  # special cases
129
97
  @job_spec.delete('source_root') if @job_spec.has_key?('source_root') and @job_spec['source_root'].empty?
130
98
 
131
- # use web socket initiation ?
99
+ # use web socket session initiation ?
132
100
  if @builder.process_param('wss_enabled',:get_value) and @options[:wss]
133
101
  # by default use web socket session if available, unless removed by user
134
102
  @builder.add_command_line_options(['--ws-connect'])
@@ -154,8 +122,7 @@ module Aspera
154
122
  # destination will be base64 encoded, put before path arguments
155
123
  @builder.add_command_line_options(['--dest64'])
156
124
  end
157
-
158
- PARAM_DEFINITION['paths'][:mandatory]=!@job_spec.has_key?('keepalive')
125
+ @builder.params_definition['paths'][:mandatory]=!@job_spec.has_key?('keepalive')
159
126
  paths_array=@builder.process_param('paths',:get_value)
160
127
  unless paths_array.nil?
161
128
  # use file list if there is storage defined for it.
@@ -207,18 +174,9 @@ module Aspera
207
174
  # temp file list files are created here
208
175
  def self.file_list_folder=(v)
209
176
  @@file_list_folder=v
210
- unless @@file_list_folder.nil?
177
+ if !@@file_list_folder.nil?
211
178
  FileUtils.mkdir_p(@@file_list_folder)
212
- # garbage collect undeleted files
213
- Dir.entries(@@file_list_folder).each do |name|
214
- file_path=File.join(@@file_list_folder,name)
215
- age_sec=(Time.now - File.stat(file_path).mtime).to_i
216
- # check age of file, delete too old
217
- if File.file?(file_path) and age_sec > FILE_LIST_AGE_MAX_SEC
218
- Log.log.debug("garbage collecting #{name}")
219
- File.delete(file_path)
220
- end
221
- end
179
+ TempFileManager.instance.cleanup_expired(@@file_list_folder)
222
180
  end
223
181
  end
224
182