aspera-cli 4.7.0 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +1267 -999
  4. data/bin/ascli +20 -1
  5. data/bin/asession +37 -34
  6. data/docs/test_env.conf +7 -3
  7. data/examples/aoc.rb +13 -12
  8. data/examples/dascli +23 -0
  9. data/examples/faspex4.rb +34 -29
  10. data/examples/{transfer.rb → node.rb} +31 -59
  11. data/examples/server.rb +93 -0
  12. data/lib/aspera/aoc.rb +153 -143
  13. data/lib/aspera/ascmd.rb +56 -45
  14. data/lib/aspera/ats_api.rb +9 -6
  15. data/lib/aspera/cli/basic_auth_plugin.rb +18 -16
  16. data/lib/aspera/cli/extended_value.rb +33 -30
  17. data/lib/aspera/cli/formater.rb +105 -111
  18. data/lib/aspera/cli/info.rb +3 -2
  19. data/lib/aspera/cli/listener/line_dump.rb +1 -0
  20. data/lib/aspera/cli/listener/logger.rb +1 -0
  21. data/lib/aspera/cli/listener/progress.rb +13 -12
  22. data/lib/aspera/cli/listener/progress_multi.rb +21 -20
  23. data/lib/aspera/cli/main.rb +110 -90
  24. data/lib/aspera/cli/manager.rb +99 -88
  25. data/lib/aspera/cli/plugin.rb +98 -39
  26. data/lib/aspera/cli/plugins/alee.rb +6 -5
  27. data/lib/aspera/cli/plugins/aoc.rb +581 -450
  28. data/lib/aspera/cli/plugins/ats.rb +84 -83
  29. data/lib/aspera/cli/plugins/bss.rb +30 -27
  30. data/lib/aspera/cli/plugins/config.rb +488 -397
  31. data/lib/aspera/cli/plugins/console.rb +17 -15
  32. data/lib/aspera/cli/plugins/cos.rb +26 -35
  33. data/lib/aspera/cli/plugins/faspex.rb +206 -172
  34. data/lib/aspera/cli/plugins/faspex5.rb +109 -74
  35. data/lib/aspera/cli/plugins/node.rb +379 -189
  36. data/lib/aspera/cli/plugins/orchestrator.rb +71 -65
  37. data/lib/aspera/cli/plugins/preview.rb +131 -122
  38. data/lib/aspera/cli/plugins/server.rb +50 -150
  39. data/lib/aspera/cli/plugins/shares.rb +61 -27
  40. data/lib/aspera/cli/plugins/sync.rb +15 -14
  41. data/lib/aspera/cli/transfer_agent.rb +75 -64
  42. data/lib/aspera/cli/version.rb +2 -1
  43. data/lib/aspera/colors.rb +29 -28
  44. data/lib/aspera/command_line_builder.rb +50 -43
  45. data/lib/aspera/cos_node.rb +64 -38
  46. data/lib/aspera/data_repository.rb +1 -0
  47. data/lib/aspera/environment.rb +33 -10
  48. data/lib/aspera/fasp/agent_base.rb +35 -30
  49. data/lib/aspera/fasp/agent_connect.rb +35 -30
  50. data/lib/aspera/fasp/agent_direct.rb +68 -60
  51. data/lib/aspera/fasp/agent_httpgw.rb +71 -64
  52. data/lib/aspera/fasp/agent_node.rb +24 -23
  53. data/lib/aspera/fasp/agent_trsdk.rb +19 -20
  54. data/lib/aspera/fasp/error.rb +2 -1
  55. data/lib/aspera/fasp/error_info.rb +79 -68
  56. data/lib/aspera/fasp/installation.rb +130 -126
  57. data/lib/aspera/fasp/listener.rb +1 -0
  58. data/lib/aspera/fasp/parameters.rb +71 -60
  59. data/lib/aspera/fasp/parameters.yaml +69 -17
  60. data/lib/aspera/fasp/resume_policy.rb +14 -11
  61. data/lib/aspera/fasp/transfer_spec.rb +6 -5
  62. data/lib/aspera/fasp/uri.rb +25 -24
  63. data/lib/aspera/faspex_gw.rb +83 -72
  64. data/lib/aspera/hash_ext.rb +23 -13
  65. data/lib/aspera/id_generator.rb +16 -13
  66. data/lib/aspera/keychain/encrypted_hash.rb +61 -46
  67. data/lib/aspera/keychain/macos_security.rb +26 -24
  68. data/lib/aspera/log.rb +35 -39
  69. data/lib/aspera/nagios.rb +36 -28
  70. data/lib/aspera/node.rb +19 -19
  71. data/lib/aspera/oauth.rb +120 -100
  72. data/lib/aspera/open_application.rb +25 -22
  73. data/lib/aspera/persistency_action_once.rb +9 -8
  74. data/lib/aspera/persistency_folder.rb +13 -9
  75. data/lib/aspera/preview/file_types.rb +261 -266
  76. data/lib/aspera/preview/generator.rb +74 -73
  77. data/lib/aspera/preview/image_error.png +0 -0
  78. data/lib/aspera/preview/options.rb +7 -6
  79. data/lib/aspera/preview/utils.rb +30 -33
  80. data/lib/aspera/preview/video_error.png +0 -0
  81. data/lib/aspera/proxy_auto_config.rb +27 -23
  82. data/lib/aspera/rest.rb +73 -74
  83. data/lib/aspera/rest_call_error.rb +1 -0
  84. data/lib/aspera/rest_error_analyzer.rb +23 -19
  85. data/lib/aspera/rest_errors_aspera.rb +43 -40
  86. data/lib/aspera/secret_hider.rb +74 -0
  87. data/lib/aspera/ssh.rb +13 -10
  88. data/lib/aspera/sync.rb +49 -47
  89. data/lib/aspera/temp_file_manager.rb +7 -5
  90. data/lib/aspera/timer_limiter.rb +9 -8
  91. data/lib/aspera/uri_reader.rb +17 -18
  92. data/lib/aspera/web_auth.rb +17 -15
  93. data.tar.gz.sig +5 -0
  94. metadata +119 -35
  95. metadata.gz.sig +0 -0
  96. data/bin/dascli +0 -13
data/bin/ascli CHANGED
@@ -1,7 +1,26 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
+
3
4
  require 'rubygems'
4
- $LOAD_PATH.unshift(File.realpath(File.dirname(File.realpath(__FILE__))+'/../lib'))
5
+ require 'securerandom'
6
+ GEM_ROOT=File.realpath(File.join(File.dirname(File.realpath(__FILE__)),'..'))
7
+ # coverage for tests
8
+ if ENV.has_key?('ENABLE_COVERAGE')
9
+ require 'simplecov'
10
+ SimpleCov.root(GEM_ROOT)
11
+ SimpleCov.enable_for_subprocesses if SimpleCov.respond_to?(:enable_for_subprocesses)
12
+ # keep cache data for 1 day (must be longer that time to run the whole test suite)
13
+ SimpleCov.merge_timeout(86400)
14
+ SimpleCov.command_name(SecureRandom.uuid)
15
+ SimpleCov.at_exit do
16
+ original_file_descriptor = $stdout
17
+ $stdout.reopen(File.join(GEM_ROOT,'simplecov.log'))
18
+ SimpleCov.result.format!
19
+ $stdout.reopen(original_file_descriptor)
20
+ end
21
+ SimpleCov.start
22
+ end
23
+ $LOAD_PATH.unshift(File.join(GEM_ROOT,'lib'))
5
24
  require 'aspera/cli/main'
6
25
  require 'aspera/environment'
7
26
  Encoding.default_internal = Encoding::UTF_8
data/bin/asession CHANGED
@@ -1,82 +1,85 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
+
3
4
  # Laurent Martin/2017
4
- $LOAD_PATH.unshift(File.dirname(__FILE__)+"/../lib")
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
5
6
  require 'aspera/fasp/agent_direct'
6
7
  require 'aspera/cli/listener/line_dump'
7
8
  require 'aspera/cli/extended_value'
8
9
  require 'aspera/log'
9
10
  require 'json'
10
11
  # extended transfer spec parameter to change log level
11
- TS_LOGLEVEL='EX_loglevel'
12
+ TS_LOGLEVEL = 'EX_loglevel'
12
13
  # by default go to /tmp/username.filelist
13
- TS_TMP_FILELIST_FOLDER='EX_file_list_folder'
14
+ TS_TMP_FILELIST_FOLDER = 'EX_file_list_folder'
14
15
 
16
+ SAMPLE_DEMO='"remote_host":"demo.asperasoft.com","remote_user":"asperaweb","ssh_port":33001,"remote_password":"demoaspera"'
17
+ SAMPLE_DEMO2='"direction":"receive","destination_root":"./test.dir"'
15
18
  def assert_usage(assertion,errmsg)
16
19
  return if assertion
17
- STDERR.puts('ERROR: '.red.blink+errmsg) if errmsg
18
- STDERR.puts('USAGE')
19
- STDERR.puts(' asession')
20
- STDERR.puts(' asession -h|--help')
21
- STDERR.puts(' asession <transfer spec extended value>')
22
- STDERR.puts(' ')
23
- STDERR.puts(' If no argument is provided, default will be used: @json:@stdin')
24
- STDERR.puts(' -h, --help display this message')
25
- STDERR.puts(' <transfer spec extended value> a JSON value for transfer_spec, using the prefix: @json:')
26
- STDERR.puts(' The value can be either:')
27
- STDERR.puts(" the JSON description itself, e.g. @json:'{\"xx\":\"yy\",...}'")
28
- STDERR.puts(' @json:@stdin, if the JSON is provided from stdin')
29
- STDERR.puts(' @json:@file:<path>, if the JSON is provided from a file')
30
- STDERR.puts(' Asynchronous commands can be provided on STDIN, examples:')
31
- STDERR.puts(' {"type":"START","source":"/aspera-test-dir-tiny/200KB.2"}')
32
- STDERR.puts(' {"type":"START","source":"xx","destination":"yy"}')
33
- STDERR.puts(' {"type":"DONE"}')
34
- STDERR.puts('Note: debug information can be placed on STDERR, using the "'+TS_LOGLEVEL+'" parameter in transfer spec (debug=0)')
35
- STDERR.puts('EXAMPLES')
36
- STDERR.puts(%q( asession @json:'{"remote_host":"demo.asperasoft.com","remote_user":"asperaweb","ssh_port":33001,"remote_password":"demoaspera","direction":"receive","destination_root":"./test.dir","paths":[{"source":"/aspera-test-dir-tiny/200KB.1"}]}'))
37
- STDERR.puts(%q( echo '{"remote_host":...}'|asession @json:@stdin))
20
+ $stderr.puts('ERROR: '.red.blink + errmsg) if errmsg
21
+ $stderr.puts('USAGE')
22
+ $stderr.puts(' asession')
23
+ $stderr.puts(' asession -h|--help')
24
+ $stderr.puts(' asession <transfer spec extended value>')
25
+ $stderr.puts(' ')
26
+ $stderr.puts(' If no argument is provided, default will be used: @json:@stdin')
27
+ $stderr.puts(' -h, --help display this message')
28
+ $stderr.puts(' <transfer spec extended value> a JSON value for transfer_spec, using the prefix: @json:')
29
+ $stderr.puts(' The value can be either:')
30
+ $stderr.puts(" the JSON description itself, e.g. @json:'{\"xx\":\"yy\",...}'")
31
+ $stderr.puts(' @json:@stdin, if the JSON is provided from stdin')
32
+ $stderr.puts(' @json:@file:<path>, if the JSON is provided from a file')
33
+ $stderr.puts(' Asynchronous commands can be provided on STDIN, examples:')
34
+ $stderr.puts(' {"type":"START","source":"/aspera-test-dir-tiny/200KB.2"}')
35
+ $stderr.puts(' {"type":"START","source":"xx","destination":"yy"}')
36
+ $stderr.puts(' {"type":"DONE"}')
37
+ $stderr.puts(%Q(Note: debug information can be placed on STDERR, using the "#{TS_LOGLEVEL}" parameter in transfer spec (debug=0)))
38
+ $stderr.puts('EXAMPLES')
39
+ $stderr.puts(%Q( asession @json:'{#{SAMPLE_DEMO},#{SAMPLE_DEMO2},"paths":[{"source":"/aspera-test-dir-tiny/200KB.1"}]}'))
40
+ $stderr.puts(%q( echo '{"remote_host":...}'|asession @json:@stdin))
38
41
  Process.exit(1)
39
42
  end
40
43
 
41
- parameter_source_err_msg=' (argument), did you specify: "@json:" ?'
44
+ parameter_source_err_msg = ' (argument), did you specify: "@json:" ?'
42
45
  # by default assume JSON input on stdin if no argument
43
46
  if ARGV.empty?
44
47
  ARGV.push('@json:@stdin')
45
- parameter_source_err_msg=' (JSON on stdin)'
48
+ parameter_source_err_msg = ' (JSON on stdin)'
46
49
  end
47
50
  # anyway expect only one argument: session information
48
51
  assert_usage(ARGV.length.eql?(1),'exactly one argument is expected')
49
52
  assert_usage(!['-h','--help'].include?(ARGV.first),nil)
50
53
  # parse transfer spec
51
54
  begin
52
- transfer_spec_arg=ARGV.pop
53
- transfer_spec=Aspera::Cli::ExtendedValue.instance.evaluate(transfer_spec_arg)
54
- rescue => e
55
+ transfer_spec_arg = ARGV.pop
56
+ transfer_spec = Aspera::Cli::ExtendedValue.instance.evaluate(transfer_spec_arg)
57
+ rescue
55
58
  assert_usage(false,"Cannot extract transfer spec from: #{transfer_spec_arg}")
56
59
  end
57
60
  # ensure right type
58
61
  assert_usage(transfer_spec.is_a?(Hash),"the value must be a hash table#{parameter_source_err_msg}")
59
62
  # additional debug capability
60
63
  if transfer_spec.has_key?(TS_LOGLEVEL)
61
- Aspera::Log.instance.level=transfer_spec[TS_LOGLEVEL]
64
+ Aspera::Log.instance.level = transfer_spec[TS_LOGLEVEL]
62
65
  transfer_spec.delete(TS_LOGLEVEL)
63
66
  end
64
67
  # possibly override temp folder
65
68
  if transfer_spec.has_key?(TS_TMP_FILELIST_FOLDER)
66
- Aspera::Fasp::Parameters.file_list_folder=transfer_spec[TS_TMP_FILELIST_FOLDER]
69
+ Aspera::Fasp::Parameters.file_list_folder = transfer_spec[TS_TMP_FILELIST_FOLDER]
67
70
  transfer_spec.delete(TS_TMP_FILELIST_FOLDER)
68
71
  end
69
72
  # get local agent (ascp), disable ascp output on stdout to not mix with JSON events
70
- client=Aspera::Fasp::AgentDirect.new({quiet: true})
73
+ client = Aspera::Fasp::AgentDirect.new({quiet: true})
71
74
  # display JSON instead of legacy Lines
72
75
  client.add_listener(Aspera::Cli::Listener::LineDump.new)
73
76
  # start transfer (asynchronous)
74
- job_id=client.start_transfer(transfer_spec)
77
+ job_id = client.start_transfer(transfer_spec)
75
78
  # async commands
76
79
  Thread.new do
77
80
  begin
78
81
  loop do
79
- data=JSON.parse(STDIN.gets)
82
+ data = JSON.parse($stdin.gets)
80
83
  client.send_command(job_id,0,data)
81
84
  end
82
85
  rescue
data/docs/test_env.conf CHANGED
@@ -19,6 +19,7 @@ default:
19
19
  cli_default:
20
20
  interactive: your value here
21
21
  smtp: your value here
22
+ secrets: your value here
22
23
  local_user:
23
24
  ssh_keys: your value here
24
25
  smtp_config:
@@ -65,7 +66,6 @@ tst_faspex5:
65
66
  client_secret: your value here
66
67
  private_key: your value here
67
68
  username: your value here
68
- password: your value here
69
69
  tst_shares:
70
70
  url: your value here
71
71
  username: your value here
@@ -126,6 +126,8 @@ misc:
126
126
  faspex_publink_send_to_dropbox: your value here
127
127
  faspex_dbx: your value here
128
128
  faspex_wkg: your value here
129
+ faspex_src: your value here
130
+ faspex5_meta: your value here
129
131
  shares_upload: your value here
130
132
  console_smart_id: your value here
131
133
  console_smart_file: your value here
@@ -146,8 +148,8 @@ misc:
146
148
  aoc_shbx_ws: your value here
147
149
  aoc_shbx_name: your value here
148
150
  aoc_shbx_meta: your value here
149
- aoc_node1_name: your value here
150
- aoc_node1_secret: your value here
151
+ aoc_ak_name: your value here
152
+ aoc_ak_secret: your value here
151
153
  icos_bucket_key: your value here
152
154
  icos_bucket_secret: your value here
153
155
  icos_bucket_name: your value here
@@ -161,3 +163,5 @@ misc:
161
163
  aoc_user_email: your value here
162
164
  aoc_workspace2: your value here
163
165
  http_gw_fqdn_port: your value here
166
+ tst_secrets:
167
+ eudemo-sedemo: your value here
data/examples/aoc.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
+
3
4
  require 'aspera/aoc'
4
5
  require 'aspera/log'
5
6
 
6
- Aspera::Log.instance.level=:debug
7
+ Aspera::Log.instance.level = :debug
7
8
 
8
9
  if !ARGV.length.eql?(3)
9
10
  Aspera::Log.log.error("wrong number of args: #{ARGV.length}")
@@ -12,18 +13,18 @@ if !ARGV.length.eql?(3)
12
13
  Process.exit(1)
13
14
  end
14
15
 
15
- aoc_url=ARGV[0]
16
- aoc_user=ARGV[1]
17
- aoc_key_value=ARGV[2]
16
+ aoc_url = ARGV[0]
17
+ aoc_user = ARGV[1]
18
+ aoc_key_value = ARGV[2]
18
19
 
19
- aocapi=Aspera::AoC.new(
20
- url: aoc_url,
21
- auth: :jwt,
22
- private_key: aoc_key_value,
23
- username: aoc_user,
24
- scope: 'user:all',
25
- subpath: 'api/v1')
20
+ aocapi = Aspera::AoC.new(
21
+ url: aoc_url,
22
+ auth: :jwt,
23
+ private_key: aoc_key_value,
24
+ username: aoc_user,
25
+ scope: 'user:all',
26
+ subpath: 'api/v1')
26
27
 
27
- self_user_data=aocapi.read('self')
28
+ self_user_data = aocapi.read('self')
28
29
 
29
30
  Aspera::Log.dump('self',self_user_data)
data/examples/dascli ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env bash
2
+ : ${image:=martinlaurent/ascli}
3
+ # by default take latest version
4
+ : ${version:=latest}
5
+ imgtag=$image:$version
6
+ # same location as in Dockerfile: main config folder for ascli in container
7
+ ascli_home_container=/home/cliuser/.aspera/ascli
8
+ # convenience: special argument to install the image
9
+ case "$1" in install) docker pull $imgtag; exit 0; esac
10
+ # set default location for config folder on host if necessary
11
+ : ${ASCLI_HOME:=$HOME/.aspera/ascli}
12
+ if test ! -d $ASCLI_HOME;then
13
+ echo "creating foder: $ASCLI_HOME"
14
+ # create it if necessary to allow mounting the volume in container
15
+ mkdir -p "$ASCLI_HOME"
16
+ fi
17
+ exec docker run \
18
+ --rm \
19
+ --tty \
20
+ --interactive \
21
+ --volume "$ASCLI_HOME:$ascli_home_container" \
22
+ $imgtag \
23
+ ascli "$@"
data/examples/faspex4.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
+
3
4
  # find Faspex API here: https://developer.ibm.com/apis/catalog/?search=faspex
4
5
  # this example makes use of class Aspera::Rest for REST calls, alternatively class RestClient of gem rest-client could be used
5
6
  # this example makes use of class Aspera::Fasp::AgentDirect for transfers, alternatively the official "Transfer SDK" could be used
@@ -8,10 +9,10 @@ require 'aspera/rest'
8
9
  require 'aspera/log'
9
10
  require 'aspera/fasp/agent_direct'
10
11
 
11
- tmpdir=ENV['tmp']||Dir.tmpdir || '.'
12
+ tmpdir = ENV['tmp'] || Dir.tmpdir || '.'
12
13
 
13
14
  # Set high log level for the example, decrease to :warn usually
14
- Aspera::Log.instance.level=:debug
15
+ Aspera::Log.instance.level = :debug
15
16
 
16
17
  # Set folder where SDK is installed (mandatory)
17
18
  # (if ascp is not there, the lib will try to find in usual locations)
@@ -25,23 +26,23 @@ if !ARGV.length.eql?(3)
25
26
  Process.exit(1)
26
27
  end
27
28
 
28
- faspex_url=ARGV[0] # typically: https://faspex.example.com/aspera/faspex
29
- faspex_user=ARGV[1]
30
- faspex_pass=ARGV[2]
29
+ faspex_url = ARGV[0] # typically: https://faspex.example.com/aspera/faspex
30
+ faspex_user = ARGV[1]
31
+ faspex_pass = ARGV[2]
31
32
 
32
- # comment out this if certificate is valid, keep line to ignore certificate
33
- Aspera::Rest.insecure=true
33
+ # uncomment this if certificate is self signed
34
+ # Rest.session_cb = lambda{|http|http.verify_mode = OpenSSL::SSL::VERIFY_NONE}
34
35
 
35
36
  # 1: Faspex 4 API v3
36
37
  #---------------
37
38
 
38
39
  # create REST API object
39
- api_v3=Aspera::Rest.new({
40
+ api_v3 = Aspera::Rest.new({
40
41
  base_url: faspex_url,
41
- auth: {
42
- type: :basic,
43
- username: faspex_user,
44
- password: faspex_pass
42
+ auth: {
43
+ type: :basic,
44
+ username: faspex_user,
45
+ password: faspex_pass
45
46
  }})
46
47
 
47
48
  # very simple api call
@@ -51,22 +52,26 @@ api_v3.read('me')
51
52
  #---------------
52
53
 
53
54
  # create a sample file to send
54
- file_to_send=File.join(tmpdir,'myfile.bin')
55
+ file_to_send = File.join(tmpdir,'myfile.bin')
55
56
  File.write(file_to_send, 'sample data')
56
57
  # package creation parameters
57
- package_create_params={'delivery'=>{'title'=>'test package','recipients'=>['aspera.user1@gmail.com'],'sources'=>[{'paths'=>[file_to_send]}]}}
58
- pkg_created=api_v3.create('send',package_create_params)[:data]
58
+ package_create_params = {'delivery' => {
59
+ 'title' => 'test package',
60
+ 'recipients' => ['aspera.user1@gmail.com'],
61
+ 'sources' => [{'paths' => [file_to_send]}]
62
+ }}
63
+ pkg_created = api_v3.create('send',package_create_params)[:data]
59
64
  # get transfer specification (normally: only one)
60
- transfer_spec=pkg_created['xfer_sessions'].first
65
+ transfer_spec = pkg_created['xfer_sessions'].first
61
66
  # set paths of files to send
62
- transfer_spec['paths']=[{'source'=>file_to_send}]
67
+ transfer_spec['paths'] = [{'source' => file_to_send}]
63
68
  # get local agent (ascp), disable ascp output on stdout to not mix with JSON events
64
- transfer_client=Aspera::Fasp::AgentDirect.new({quiet: true})
69
+ transfer_client = Aspera::Fasp::AgentDirect.new({quiet: true})
65
70
  # start transfer (asynchronous)
66
- job_id=transfer_client.start_transfer(transfer_spec)
71
+ job_id = transfer_client.start_transfer(transfer_spec)
67
72
  Aspera::Log.dump('job_id',job_id)
68
73
  # wait for all transfer completion (for the example)
69
- result=transfer_client.wait_for_transfers_completion
74
+ result = transfer_client.wait_for_transfers_completion
70
75
  # notify of any transfer error
71
76
  result.reject{|i|i.eql?(:success)}.each do |e|
72
77
  Aspera::Log.log.error("A transfer error occured: #{e.message}")
@@ -74,16 +79,16 @@ end
74
79
 
75
80
  # 3: Faspex 4 API v4
76
81
  #---------------
77
- api_v4=Aspera::Rest.new({
78
- base_url: faspex_url+'/api',
82
+ api_v4 = Aspera::Rest.new({
83
+ base_url: faspex_url + '/api',
79
84
  auth: {
80
- type: :oauth2,
81
- base_url: faspex_url+'/auth/oauth2',
82
- auth: {type: :basic, username: faspex_user, password: faspex_pass},
83
- crtype: :generic,
84
- generic: {grant_type: 'password'},
85
- scope: 'admin'
86
- }})
85
+ type: :oauth2,
86
+ base_url: faspex_url + '/auth/oauth2',
87
+ auth: {type: :basic, username: faspex_user, password: faspex_pass},
88
+ crtype: :generic,
89
+ generic: {grant_type: 'password'},
90
+ scope: 'admin'
91
+ }})
87
92
 
88
93
  # Use it. Note that Faspex 4 API v4 is totally different from Faspex 4 v3 APIs, see ref on line 2
89
94
  Aspera::Log.dump('users',api_v4.read('users')[:data])
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
+
3
4
  # Example: transfer a file using one of the provided transfer agents
4
5
  # location of ascp can be specified with env var "ascp"
5
6
  # temp folder can be specified with env var "tmp"
@@ -12,19 +13,20 @@ require 'aspera/rest_errors_aspera'
12
13
  require 'json'
13
14
  require 'tmpdir'
14
15
 
15
- tmpdir=ENV['tmp']||Dir.tmpdir || '.'
16
+ tmpdir = ENV['tmp'] || Dir.tmpdir || '.'
17
+
18
+ raise 'Usage: PASSWORD=<password> $0 https://<address>:<port> <node user>' unless ARGV.length.eql?(2) && ENV.has_key?('PASSWORD')
16
19
 
17
- DEMO_CONFIG=[
18
- 'ssh://asperaweb@eudemo.asperademo.com:33001',
19
- 'https://node_asperaweb@eudemo.asperademo.com:9092',
20
- 'demoaspera'
21
- ]
20
+ # example : https://node_asperaweb@eudemo.asperademo.com:9092
21
+ node_uri = URI.parse(ARGV.shift)
22
+ node_user = ARGV.shift
23
+ node_pass = ENV['PASSWORD']
22
24
 
23
25
  ##############################################################
24
26
  # generic initialisation : configuration of FaspManager
25
27
 
26
28
  # set trace level for sample, set to :debug to see complete list of debug information
27
- Aspera::Log.instance.level=:debug
29
+ Aspera::Log.instance.level = :debug
28
30
 
29
31
  # register aspera REST call error handlers
30
32
  Aspera::RestErrorsAspera.register_handlers
@@ -32,21 +34,21 @@ Aspera::RestErrorsAspera.register_handlers
32
34
  # some required files are generated here (keys, certs)
33
35
  Aspera::Fasp::Installation.instance.folder = tmpdir
34
36
  # set path to your copy of ascp binary (else, let the system find)
35
- Aspera::Fasp::Installation.instance.ascp_path=ENV['ascp'] if ENV.has_key?('ascp')
37
+ Aspera::Fasp::Installation.instance.ascp_path = ENV['ascp'] if ENV.has_key?('ascp')
36
38
  # another way is to detect installed products and use one of them
37
39
  #Aspera::Fasp::Installation.instance.installed_products.each{|p|puts("found: #{p[:name]}")}
38
40
  #Aspera::Fasp::Installation.instance.use_ascp_from_product('Aspera Connect')
39
41
  # or install:
40
42
  #
41
43
 
42
- # get FASP Manager singleton based on above ascp location
43
- fasp_manager=Aspera::Fasp::AgentDirect.new
44
+ # get Transfer Agent
45
+ transfer_agent = Aspera::Fasp::AgentDirect.new
44
46
 
45
47
  # Note that it would also be possible to start transfers using other agents
46
48
  #require 'aspera/fasp/connect'
47
- #fasp_manager=Aspera::Fasp::Connect.new
49
+ #transfer_agent=Aspera::Fasp::Connect.new
48
50
  #require 'aspera/fasp/node'
49
- #fasp_manager=Aspera::Fasp::Node.new(Aspera::Rest.new(...))
51
+ #transfer_agent=Aspera::Fasp::Node.new(Aspera::Rest.new(...))
50
52
 
51
53
  ##############################################################
52
54
  # Optional : register an event listener
@@ -59,66 +61,36 @@ class MyListener < Aspera::Fasp::Listener
59
61
  end
60
62
 
61
63
  # register the sample listener to display events
62
- fasp_manager.add_listener(MyListener.new)
63
-
64
- ##############################################################
65
- # first example: download by SSH credentials
66
-
67
- # manually build teansfer spec
68
- transfer_spec={
69
- #'remote_host' =>'demo.asperasoft.com',
70
- 'remote_host' =>URI.parse(DEMO_CONFIG[0]).host,
71
- 'ssh_port' =>URI.parse(DEMO_CONFIG[0]).port,
72
- 'remote_user' =>URI.parse(DEMO_CONFIG[0]).user,
73
- 'remote_password' =>DEMO_CONFIG[2],
74
- 'direction' =>'receive',
75
- 'destination_root'=>tmpdir,
76
- 'paths' =>[{'source'=>'aspera-test-dir-tiny/200KB.1'}]
77
- }
78
- # start transfer in separate thread
79
- # method returns as soon as transfer thread is created
80
- # it des not wait for completion, or even for session startup
81
- fasp_manager.start_transfer(transfer_spec)
82
-
83
- # optional: helper method: wait for completion of transfers
84
- # here we started a single transfer session (no multisession parameter)
85
- # get array of status, one for each session (so, a single value array)
86
- # each status is either :success or "error message"
87
- transfer_result=fasp_manager.wait_for_transfers_completion
88
- $stdout.puts(JSON.generate(transfer_result))
89
- # get list of errors only
90
- errors=transfer_result.reject{|i|i.eql?(:success)}
91
- # the transfer was not success, as there is at least one error
92
- raise "Error(s) occured: #{errors.join(',')}" if !errors.empty?
64
+ transfer_agent.add_listener(MyListener.new)
93
65
 
94
66
  ##############################################################
95
- # second example: upload with node authorization
67
+ # Upload with node authorization
96
68
 
97
69
  # create rest client for Node API on a public demo system, using public demo credentials
98
- node_api=Aspera::Rest.new({
99
- base_url: DEMO_CONFIG[1],
100
- auth: {
101
- type: :basic,
102
- username: URI.parse(DEMO_CONFIG[1]).user,
103
- password: DEMO_CONFIG[2]
70
+ node_api = Aspera::Rest.new({
71
+ base_url: node_uri.to_s,
72
+ auth: {
73
+ type: :basic,
74
+ username: node_user,
75
+ password: node_pass
104
76
  }})
105
77
  # define sample file(s) and destination folder
106
- sources=["#{tmpdir}/sample_file.txt"]
107
- destination='/Upload'
78
+ sources = ["#{tmpdir}/sample_file.txt"]
79
+ destination = '/Upload'
108
80
  # create sample file(s)
109
81
  sources.each{|p|File.write(p,'Hello World!')}
110
82
  # request transfer authorization to node for a single transfer (This is a node api v3 call)
111
- send_result=node_api.create('files/upload_setup',{ transfer_requests: [{ transfer_request: { paths: [{ destination: destination }] } }] })[:data]
83
+ send_result = node_api.create('files/upload_setup',{ transfer_requests: [{ transfer_request: { paths: [{ destination: destination }] } }] })[:data]
112
84
  # we normally have only one transfer spec in list, so just get the first transfer_spec
113
- transfer_spec=send_result['transfer_specs'].first['transfer_spec']
85
+ transfer_spec = send_result['transfer_specs'].first['transfer_spec']
114
86
  # add list of files to upload
115
- transfer_spec['paths']=sources.map{|p|{'source'=>p}}
87
+ transfer_spec['paths'] = sources.map{|p|{'source' => p}}
116
88
  # set authentication type to "token" (will trigger use of bypass SSH key)
117
- transfer_spec['authentication']='token'
89
+ transfer_spec['authentication'] = 'token'
118
90
  # from here : same as example 1
119
- fasp_manager.start_transfer(transfer_spec)
91
+ transfer_agent.start_transfer(transfer_spec)
120
92
  # optional: wait for transfer completion helper function to get events
121
- transfer_result=fasp_manager.wait_for_transfers_completion
122
- errors=transfer_result.reject{|i|i.eql?(:success)}
93
+ transfer_result = transfer_agent.wait_for_transfers_completion
94
+ errors = transfer_result.reject{|i|i.eql?(:success)}
123
95
  # the transfer was not success, as there is at least one error
124
96
  raise "Error(s) occured: #{errors.join(',')}" if !errors.empty?
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Example: transfer a file using one of the provided transfer agents
5
+ # location of ascp can be specified with env var "ascp"
6
+ # temp folder can be specified with env var "tmp"
7
+ require 'aspera/fasp/agent_direct'
8
+ require 'aspera/fasp/listener'
9
+ require 'aspera/fasp/installation'
10
+ require 'aspera/log'
11
+ require 'aspera/rest'
12
+ require 'aspera/rest_errors_aspera'
13
+ require 'json'
14
+ require 'tmpdir'
15
+
16
+ tmpdir = ENV['tmp'] || Dir.tmpdir || '.'
17
+
18
+ raise 'Usage: PASSWORD=<password> $0 ssh://<address>:<port> <transfer user>' unless ARGV.length.eql?(2) && ENV.has_key?('PASSWORD')
19
+
20
+ # example : ssh://asperaweb@eudemo.asperademo.com:33001
21
+ server_uri = URI.parse(ARGV.shift)
22
+ server_user = ARGV.shift
23
+ server_pass = ENV['PASSWORD']
24
+
25
+ ##############################################################
26
+ # generic initialisation : configuration of FaspManager
27
+
28
+ # set trace level for sample, set to :debug to see complete list of debug information
29
+ Aspera::Log.instance.level = :debug
30
+
31
+ # register aspera REST call error handlers
32
+ Aspera::RestErrorsAspera.register_handlers
33
+
34
+ # some required files are generated here (keys, certs)
35
+ Aspera::Fasp::Installation.instance.folder = tmpdir
36
+ # set path to your copy of ascp binary (else, let the system find)
37
+ Aspera::Fasp::Installation.instance.ascp_path = ENV['ascp'] if ENV.has_key?('ascp')
38
+ # another way is to detect installed products and use one of them
39
+ #Aspera::Fasp::Installation.instance.installed_products.each{|p|puts("found: #{p[:name]}")}
40
+ #Aspera::Fasp::Installation.instance.use_ascp_from_product('Aspera Connect')
41
+ # or install:
42
+ #
43
+
44
+ # get Transfer Agent
45
+ transfer_agent = Aspera::Fasp::AgentDirect.new
46
+
47
+ # Note that it would also be possible to start transfers using other agents
48
+ #require 'aspera/fasp/connect'
49
+ #transfer_agent=Aspera::Fasp::Connect.new
50
+ #require 'aspera/fasp/node'
51
+ #transfer_agent=Aspera::Fasp::Node.new(Aspera::Rest.new(...))
52
+
53
+ ##############################################################
54
+ # Optional : register an event listener
55
+
56
+ # example of event listener that displays events on stdout
57
+ class MyListener < Aspera::Fasp::Listener
58
+ # this is the callback called during transfers, here we only display the received information
59
+ # but it could be used to get detailed error information, check "type" field is "ERROR"
60
+ def event_enhanced(data);$stdout.puts(JSON.generate(data));$stdout.flush;end
61
+ end
62
+
63
+ # register the sample listener to display events
64
+ transfer_agent.add_listener(MyListener.new)
65
+
66
+ ##############################################################
67
+ # first example: download by SSH credentials
68
+
69
+ # manually build teansfer spec
70
+ transfer_spec = {
71
+ 'remote_host' => server_uri.host,
72
+ 'ssh_port' => server_uri.port,
73
+ 'remote_user' => server_user,
74
+ 'remote_password' => server_pass,
75
+ 'direction' => 'receive',
76
+ 'destination_root' => tmpdir,
77
+ 'paths' => [{'source' => 'aspera-test-dir-tiny/200KB.1'}]
78
+ }
79
+ # start transfer in separate thread
80
+ # method returns as soon as transfer thread is created
81
+ # it des not wait for completion, or even for session startup
82
+ transfer_agent.start_transfer(transfer_spec)
83
+
84
+ # optional: helper method: wait for completion of transfers
85
+ # here we started a single transfer session (no multisession parameter)
86
+ # get array of status, one for each session (so, a single value array)
87
+ # each status is either :success or "error message"
88
+ transfer_result = transfer_agent.wait_for_transfers_completion
89
+ $stdout.puts(JSON.generate(transfer_result))
90
+ # get list of errors only
91
+ errors = transfer_result.reject{|i|i.eql?(:success)}
92
+ # the transfer was not success, as there is at least one error
93
+ raise "Error(s) occured: #{errors.join(',')}" if !errors.empty?