aspera-cli 4.7.0 → 4.8.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 (94) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +1 -0
  3. data/README.md +844 -861
  4. data/bin/ascli +20 -1
  5. data/bin/asession +37 -34
  6. data/docs/test_env.conf +11 -3
  7. data/examples/aoc.rb +13 -12
  8. data/examples/dascli +26 -0
  9. data/examples/faspex4.rb +34 -29
  10. data/examples/transfer.rb +30 -29
  11. data/lib/aspera/aoc.rb +151 -143
  12. data/lib/aspera/ascmd.rb +56 -45
  13. data/lib/aspera/ats_api.rb +6 -5
  14. data/lib/aspera/cli/basic_auth_plugin.rb +18 -16
  15. data/lib/aspera/cli/extended_value.rb +32 -30
  16. data/lib/aspera/cli/formater.rb +103 -111
  17. data/lib/aspera/cli/info.rb +2 -1
  18. data/lib/aspera/cli/listener/line_dump.rb +1 -0
  19. data/lib/aspera/cli/listener/logger.rb +1 -0
  20. data/lib/aspera/cli/listener/progress.rb +13 -12
  21. data/lib/aspera/cli/listener/progress_multi.rb +21 -20
  22. data/lib/aspera/cli/main.rb +106 -89
  23. data/lib/aspera/cli/manager.rb +96 -85
  24. data/lib/aspera/cli/plugin.rb +50 -32
  25. data/lib/aspera/cli/plugins/alee.rb +6 -5
  26. data/lib/aspera/cli/plugins/aoc.rb +521 -426
  27. data/lib/aspera/cli/plugins/ats.rb +84 -83
  28. data/lib/aspera/cli/plugins/bss.rb +30 -27
  29. data/lib/aspera/cli/plugins/config.rb +483 -397
  30. data/lib/aspera/cli/plugins/console.rb +17 -15
  31. data/lib/aspera/cli/plugins/cos.rb +26 -35
  32. data/lib/aspera/cli/plugins/faspex.rb +201 -168
  33. data/lib/aspera/cli/plugins/faspex5.rb +109 -74
  34. data/lib/aspera/cli/plugins/node.rb +378 -189
  35. data/lib/aspera/cli/plugins/orchestrator.rb +71 -65
  36. data/lib/aspera/cli/plugins/preview.rb +131 -122
  37. data/lib/aspera/cli/plugins/server.rb +94 -93
  38. data/lib/aspera/cli/plugins/shares.rb +42 -28
  39. data/lib/aspera/cli/plugins/sync.rb +15 -14
  40. data/lib/aspera/cli/transfer_agent.rb +56 -52
  41. data/lib/aspera/cli/version.rb +2 -1
  42. data/lib/aspera/colors.rb +29 -28
  43. data/lib/aspera/command_line_builder.rb +50 -43
  44. data/lib/aspera/cos_node.rb +64 -38
  45. data/lib/aspera/data_repository.rb +1 -0
  46. data/lib/aspera/environment.rb +18 -8
  47. data/lib/aspera/fasp/agent_base.rb +26 -23
  48. data/lib/aspera/fasp/agent_connect.rb +35 -30
  49. data/lib/aspera/fasp/agent_direct.rb +68 -60
  50. data/lib/aspera/fasp/agent_httpgw.rb +71 -64
  51. data/lib/aspera/fasp/agent_node.rb +24 -23
  52. data/lib/aspera/fasp/agent_trsdk.rb +19 -20
  53. data/lib/aspera/fasp/error.rb +2 -1
  54. data/lib/aspera/fasp/error_info.rb +79 -68
  55. data/lib/aspera/fasp/installation.rb +122 -114
  56. data/lib/aspera/fasp/listener.rb +1 -0
  57. data/lib/aspera/fasp/parameters.rb +44 -41
  58. data/lib/aspera/fasp/resume_policy.rb +14 -11
  59. data/lib/aspera/fasp/transfer_spec.rb +6 -5
  60. data/lib/aspera/fasp/uri.rb +25 -24
  61. data/lib/aspera/faspex_gw.rb +83 -72
  62. data/lib/aspera/hash_ext.rb +10 -12
  63. data/lib/aspera/id_generator.rb +8 -7
  64. data/lib/aspera/keychain/encrypted_hash.rb +60 -45
  65. data/lib/aspera/keychain/macos_security.rb +26 -24
  66. data/lib/aspera/log.rb +34 -38
  67. data/lib/aspera/nagios.rb +14 -13
  68. data/lib/aspera/node.rb +19 -19
  69. data/lib/aspera/oauth.rb +121 -101
  70. data/lib/aspera/open_application.rb +6 -5
  71. data/lib/aspera/persistency_action_once.rb +9 -8
  72. data/lib/aspera/persistency_folder.rb +10 -9
  73. data/lib/aspera/preview/file_types.rb +261 -266
  74. data/lib/aspera/preview/generator.rb +74 -73
  75. data/lib/aspera/preview/image_error.png +0 -0
  76. data/lib/aspera/preview/options.rb +7 -6
  77. data/lib/aspera/preview/utils.rb +30 -33
  78. data/lib/aspera/preview/video_error.png +0 -0
  79. data/lib/aspera/proxy_auto_config.rb +25 -23
  80. data/lib/aspera/rest.rb +73 -74
  81. data/lib/aspera/rest_call_error.rb +1 -0
  82. data/lib/aspera/rest_error_analyzer.rb +11 -9
  83. data/lib/aspera/rest_errors_aspera.rb +5 -4
  84. data/lib/aspera/secret_hider.rb +68 -0
  85. data/lib/aspera/ssh.rb +12 -10
  86. data/lib/aspera/sync.rb +49 -47
  87. data/lib/aspera/temp_file_manager.rb +7 -5
  88. data/lib/aspera/timer_limiter.rb +9 -8
  89. data/lib/aspera/uri_reader.rb +11 -14
  90. data/lib/aspera/web_auth.rb +17 -15
  91. data.tar.gz.sig +0 -0
  92. metadata +117 -34
  93. metadata.gz.sig +2 -0
  94. 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:
@@ -60,12 +61,12 @@ tst_faspex5_web:
60
61
  client_secret: your value here
61
62
  tst_faspex5:
62
63
  url: your value here
64
+ insecure: your value here
63
65
  auth: your value here
64
66
  client_id: your value here
65
67
  client_secret: your value here
66
68
  private_key: your value here
67
69
  username: your value here
68
- password: your value here
69
70
  tst_shares:
70
71
  url: your value here
71
72
  username: your value here
@@ -97,6 +98,7 @@ tst_orch:
97
98
  url: your value here
98
99
  username: your value here
99
100
  password: your value here
101
+ insecure: your value here
100
102
  tst_ats:
101
103
  ibm_api_key: your value here
102
104
  ats_key: your value here
@@ -106,6 +108,7 @@ tst_bss:
106
108
  password: your value here
107
109
  tst_ak_preview:
108
110
  url: your value here
111
+ insecure: your value here
109
112
  username: your value here
110
113
  password: your value here
111
114
  mimemagic: your value here
@@ -113,6 +116,7 @@ tst_node_preview:
113
116
  url: your value here
114
117
  username: your value here
115
118
  password: your value here
119
+ insecure: your value here
116
120
  tst_cos:
117
121
  apikey: your value here
118
122
  crn: your value here
@@ -126,6 +130,8 @@ misc:
126
130
  faspex_publink_send_to_dropbox: your value here
127
131
  faspex_dbx: your value here
128
132
  faspex_wkg: your value here
133
+ faspex_src: your value here
134
+ faspex5_meta: your value here
129
135
  shares_upload: your value here
130
136
  console_smart_id: your value here
131
137
  console_smart_file: your value here
@@ -146,8 +152,8 @@ misc:
146
152
  aoc_shbx_ws: your value here
147
153
  aoc_shbx_name: your value here
148
154
  aoc_shbx_meta: your value here
149
- aoc_node1_name: your value here
150
- aoc_node1_secret: your value here
155
+ aoc_ak_name: your value here
156
+ aoc_ak_secret: your value here
151
157
  icos_bucket_key: your value here
152
158
  icos_bucket_secret: your value here
153
159
  icos_bucket_name: your value here
@@ -161,3 +167,5 @@ misc:
161
167
  aoc_user_email: your value here
162
168
  aoc_workspace2: your value here
163
169
  http_gw_fqdn_port: your value here
170
+ tst_secrets:
171
+ st1: 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,26 @@
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: generic top folder for apps
7
+ appdir=/usr/src/app
8
+ # same location as in Dockerfile: main config folder for ascli in container
9
+ ascli_home_container=${appdir}/config
10
+ # convenience: special argument to install the image
11
+ case "$1" in install) docker pull $imgtag; exit 0; esac
12
+ # set default location for config folder on host if necessary
13
+ : ${ASCLI_HOME:=$HOME/.aspera/ascli}
14
+ if test ! -d $ASCLI_HOME;then
15
+ echo "creating foder: $ASCLI_HOME"
16
+ # create it if necessary to allow mounting the volume in container
17
+ mkdir -p "$ASCLI_HOME"
18
+ fi
19
+ exec docker run \
20
+ --rm \
21
+ --tty \
22
+ --interactive \
23
+ --env ASCLI_HOME="$ascli_home_container" \
24
+ --volume "$ASCLI_HOME:$ascli_home_container" \
25
+ $imgtag \
26
+ 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])
data/examples/transfer.rb CHANGED
@@ -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,19 @@ 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 || '.'
16
17
 
17
- DEMO_CONFIG=[
18
+ DEMO_CONFIG = [
18
19
  'ssh://asperaweb@eudemo.asperademo.com:33001',
19
20
  'https://node_asperaweb@eudemo.asperademo.com:9092',
20
21
  'demoaspera'
21
- ]
22
+ ].freeze
22
23
 
23
24
  ##############################################################
24
25
  # generic initialisation : configuration of FaspManager
25
26
 
26
27
  # set trace level for sample, set to :debug to see complete list of debug information
27
- Aspera::Log.instance.level=:debug
28
+ Aspera::Log.instance.level = :debug
28
29
 
29
30
  # register aspera REST call error handlers
30
31
  Aspera::RestErrorsAspera.register_handlers
@@ -32,7 +33,7 @@ Aspera::RestErrorsAspera.register_handlers
32
33
  # some required files are generated here (keys, certs)
33
34
  Aspera::Fasp::Installation.instance.folder = tmpdir
34
35
  # 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')
36
+ Aspera::Fasp::Installation.instance.ascp_path = ENV['ascp'] if ENV.has_key?('ascp')
36
37
  # another way is to detect installed products and use one of them
37
38
  #Aspera::Fasp::Installation.instance.installed_products.each{|p|puts("found: #{p[:name]}")}
38
39
  #Aspera::Fasp::Installation.instance.use_ascp_from_product('Aspera Connect')
@@ -40,7 +41,7 @@ Aspera::Fasp::Installation.instance.ascp_path=ENV['ascp'] if ENV.has_key?('ascp'
40
41
  #
41
42
 
42
43
  # get FASP Manager singleton based on above ascp location
43
- fasp_manager=Aspera::Fasp::AgentDirect.new
44
+ fasp_manager = Aspera::Fasp::AgentDirect.new
44
45
 
45
46
  # Note that it would also be possible to start transfers using other agents
46
47
  #require 'aspera/fasp/connect'
@@ -65,15 +66,15 @@ fasp_manager.add_listener(MyListener.new)
65
66
  # first example: download by SSH credentials
66
67
 
67
68
  # manually build teansfer spec
68
- transfer_spec={
69
+ transfer_spec = {
69
70
  #'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'}]
71
+ 'remote_host' => URI.parse(DEMO_CONFIG[0]).host,
72
+ 'ssh_port' => URI.parse(DEMO_CONFIG[0]).port,
73
+ 'remote_user' => URI.parse(DEMO_CONFIG[0]).user,
74
+ 'remote_password' => DEMO_CONFIG[2],
75
+ 'direction' => 'receive',
76
+ 'destination_root' => tmpdir,
77
+ 'paths' => [{'source' => 'aspera-test-dir-tiny/200KB.1'}]
77
78
  }
78
79
  # start transfer in separate thread
79
80
  # method returns as soon as transfer thread is created
@@ -84,10 +85,10 @@ fasp_manager.start_transfer(transfer_spec)
84
85
  # here we started a single transfer session (no multisession parameter)
85
86
  # get array of status, one for each session (so, a single value array)
86
87
  # each status is either :success or "error message"
87
- transfer_result=fasp_manager.wait_for_transfers_completion
88
+ transfer_result = fasp_manager.wait_for_transfers_completion
88
89
  $stdout.puts(JSON.generate(transfer_result))
89
90
  # get list of errors only
90
- errors=transfer_result.reject{|i|i.eql?(:success)}
91
+ errors = transfer_result.reject{|i|i.eql?(:success)}
91
92
  # the transfer was not success, as there is at least one error
92
93
  raise "Error(s) occured: #{errors.join(',')}" if !errors.empty?
93
94
 
@@ -95,30 +96,30 @@ raise "Error(s) occured: #{errors.join(',')}" if !errors.empty?
95
96
  # second example: upload with node authorization
96
97
 
97
98
  # create rest client for Node API on a public demo system, using public demo credentials
98
- node_api=Aspera::Rest.new({
99
+ node_api = Aspera::Rest.new({
99
100
  base_url: DEMO_CONFIG[1],
100
- auth: {
101
- type: :basic,
102
- username: URI.parse(DEMO_CONFIG[1]).user,
103
- password: DEMO_CONFIG[2]
101
+ auth: {
102
+ type: :basic,
103
+ username: URI.parse(DEMO_CONFIG[1]).user,
104
+ password: DEMO_CONFIG[2]
104
105
  }})
105
106
  # define sample file(s) and destination folder
106
- sources=["#{tmpdir}/sample_file.txt"]
107
- destination='/Upload'
107
+ sources = ["#{tmpdir}/sample_file.txt"]
108
+ destination = '/Upload'
108
109
  # create sample file(s)
109
110
  sources.each{|p|File.write(p,'Hello World!')}
110
111
  # 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]
112
+ send_result = node_api.create('files/upload_setup',{ transfer_requests: [{ transfer_request: { paths: [{ destination: destination }] } }] })[:data]
112
113
  # 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']
114
+ transfer_spec = send_result['transfer_specs'].first['transfer_spec']
114
115
  # add list of files to upload
115
- transfer_spec['paths']=sources.map{|p|{'source'=>p}}
116
+ transfer_spec['paths'] = sources.map{|p|{'source' => p}}
116
117
  # set authentication type to "token" (will trigger use of bypass SSH key)
117
- transfer_spec['authentication']='token'
118
+ transfer_spec['authentication'] = 'token'
118
119
  # from here : same as example 1
119
120
  fasp_manager.start_transfer(transfer_spec)
120
121
  # 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)}
122
+ transfer_result = fasp_manager.wait_for_transfers_completion
123
+ errors = transfer_result.reject{|i|i.eql?(:success)}
123
124
  # the transfer was not success, as there is at least one error
124
125
  raise "Error(s) occured: #{errors.join(',')}" if !errors.empty?