aspera-cli 4.5.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 (104) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +1 -0
  3. data/README.md +1894 -1574
  4. data/bin/ascli +21 -1
  5. data/bin/asession +38 -34
  6. data/docs/test_env.conf +14 -3
  7. data/examples/aoc.rb +17 -15
  8. data/examples/dascli +26 -0
  9. data/examples/faspex4.rb +42 -35
  10. data/examples/proxy.pac +1 -1
  11. data/examples/transfer.rb +38 -37
  12. data/lib/aspera/aoc.rb +245 -205
  13. data/lib/aspera/ascmd.rb +111 -90
  14. data/lib/aspera/ats_api.rb +16 -14
  15. data/lib/aspera/cli/basic_auth_plugin.rb +19 -18
  16. data/lib/aspera/cli/extended_value.rb +50 -39
  17. data/lib/aspera/cli/formater.rb +161 -135
  18. data/lib/aspera/cli/info.rb +18 -0
  19. data/lib/aspera/cli/listener/line_dump.rb +4 -2
  20. data/lib/aspera/cli/listener/logger.rb +3 -1
  21. data/lib/aspera/cli/listener/progress.rb +20 -21
  22. data/lib/aspera/cli/listener/progress_multi.rb +29 -31
  23. data/lib/aspera/cli/main.rb +194 -183
  24. data/lib/aspera/cli/manager.rb +213 -206
  25. data/lib/aspera/cli/plugin.rb +71 -49
  26. data/lib/aspera/cli/plugins/alee.rb +8 -7
  27. data/lib/aspera/cli/plugins/aoc.rb +675 -558
  28. data/lib/aspera/cli/plugins/ats.rb +116 -109
  29. data/lib/aspera/cli/plugins/bss.rb +35 -34
  30. data/lib/aspera/cli/plugins/config.rb +722 -542
  31. data/lib/aspera/cli/plugins/console.rb +28 -22
  32. data/lib/aspera/cli/plugins/cos.rb +28 -37
  33. data/lib/aspera/cli/plugins/faspex.rb +281 -227
  34. data/lib/aspera/cli/plugins/faspex5.rb +129 -84
  35. data/lib/aspera/cli/plugins/node.rb +426 -232
  36. data/lib/aspera/cli/plugins/orchestrator.rb +106 -98
  37. data/lib/aspera/cli/plugins/preview.rb +196 -191
  38. data/lib/aspera/cli/plugins/server.rb +131 -126
  39. data/lib/aspera/cli/plugins/shares.rb +49 -36
  40. data/lib/aspera/cli/plugins/sync.rb +27 -28
  41. data/lib/aspera/cli/transfer_agent.rb +84 -79
  42. data/lib/aspera/cli/version.rb +3 -1
  43. data/lib/aspera/colors.rb +37 -28
  44. data/lib/aspera/command_line_builder.rb +84 -63
  45. data/lib/aspera/cos_node.rb +68 -34
  46. data/lib/aspera/data_repository.rb +4 -2
  47. data/lib/aspera/environment.rb +61 -46
  48. data/lib/aspera/fasp/agent_base.rb +36 -31
  49. data/lib/aspera/fasp/agent_connect.rb +44 -37
  50. data/lib/aspera/fasp/agent_direct.rb +101 -104
  51. data/lib/aspera/fasp/agent_httpgw.rb +91 -90
  52. data/lib/aspera/fasp/agent_node.rb +36 -33
  53. data/lib/aspera/fasp/agent_trsdk.rb +28 -31
  54. data/lib/aspera/fasp/error.rb +3 -1
  55. data/lib/aspera/fasp/error_info.rb +81 -54
  56. data/lib/aspera/fasp/installation.rb +171 -151
  57. data/lib/aspera/fasp/listener.rb +2 -0
  58. data/lib/aspera/fasp/parameters.rb +105 -111
  59. data/lib/aspera/fasp/parameters.yaml +305 -249
  60. data/lib/aspera/fasp/resume_policy.rb +20 -20
  61. data/lib/aspera/fasp/transfer_spec.rb +27 -0
  62. data/lib/aspera/fasp/uri.rb +31 -29
  63. data/lib/aspera/faspex_gw.rb +95 -118
  64. data/lib/aspera/hash_ext.rb +12 -13
  65. data/lib/aspera/id_generator.rb +11 -9
  66. data/lib/aspera/keychain/encrypted_hash.rb +73 -57
  67. data/lib/aspera/keychain/macos_security.rb +27 -29
  68. data/lib/aspera/log.rb +40 -39
  69. data/lib/aspera/nagios.rb +24 -22
  70. data/lib/aspera/node.rb +38 -30
  71. data/lib/aspera/oauth.rb +217 -248
  72. data/lib/aspera/open_application.rb +9 -7
  73. data/lib/aspera/persistency_action_once.rb +15 -14
  74. data/lib/aspera/persistency_folder.rb +15 -18
  75. data/lib/aspera/preview/file_types.rb +266 -270
  76. data/lib/aspera/preview/generator.rb +94 -92
  77. data/lib/aspera/preview/image_error.png +0 -0
  78. data/lib/aspera/preview/options.rb +20 -17
  79. data/lib/aspera/preview/utils.rb +99 -102
  80. data/lib/aspera/preview/video_error.png +0 -0
  81. data/lib/aspera/{proxy_auto_config.erb.js → proxy_auto_config.js} +23 -31
  82. data/lib/aspera/proxy_auto_config.rb +114 -21
  83. data/lib/aspera/rest.rb +144 -142
  84. data/lib/aspera/rest_call_error.rb +3 -2
  85. data/lib/aspera/rest_error_analyzer.rb +31 -31
  86. data/lib/aspera/rest_errors_aspera.rb +18 -16
  87. data/lib/aspera/secret_hider.rb +68 -0
  88. data/lib/aspera/ssh.rb +20 -16
  89. data/lib/aspera/sync.rb +57 -54
  90. data/lib/aspera/temp_file_manager.rb +20 -14
  91. data/lib/aspera/timer_limiter.rb +10 -8
  92. data/lib/aspera/uri_reader.rb +14 -15
  93. data/lib/aspera/web_auth.rb +85 -80
  94. data.tar.gz.sig +0 -0
  95. metadata +169 -40
  96. metadata.gz.sig +2 -0
  97. data/bin/dascli +0 -13
  98. data/docs/Makefile +0 -63
  99. data/docs/README.erb.md +0 -4221
  100. data/docs/README.md +0 -13
  101. data/docs/diagrams.txt +0 -49
  102. data/docs/doc_tools.rb +0 -58
  103. data/lib/aspera/cli/plugins/shares2.rb +0 -114
  104. data/lib/aspera/fasp/default.rb +0 -17
data/bin/ascli CHANGED
@@ -1,6 +1,26 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'rubygems'
3
- $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'))
4
24
  require 'aspera/cli/main'
5
25
  require 'aspera/environment'
6
26
  Encoding.default_internal = Encoding::UTF_8
data/bin/asession CHANGED
@@ -1,81 +1,85 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  # Laurent Martin/2017
3
- $LOAD_PATH.unshift(File.dirname(__FILE__)+"/../lib")
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
6
  require 'aspera/fasp/agent_direct'
5
7
  require 'aspera/cli/listener/line_dump'
6
8
  require 'aspera/cli/extended_value'
7
9
  require 'aspera/log'
8
10
  require 'json'
9
11
  # extended transfer spec parameter to change log level
10
- TS_LOGLEVEL='EX_loglevel'
12
+ TS_LOGLEVEL = 'EX_loglevel'
11
13
  # by default go to /tmp/username.filelist
12
- TS_TMP_FILELIST_FOLDER='EX_file_list_folder'
14
+ TS_TMP_FILELIST_FOLDER = 'EX_file_list_folder'
13
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"'
14
18
  def assert_usage(assertion,errmsg)
15
19
  return if assertion
16
- STDERR.puts('ERROR: '.red.blink+errmsg) if errmsg
17
- STDERR.puts('USAGE')
18
- STDERR.puts(' asession')
19
- STDERR.puts(' asession -h|--help')
20
- STDERR.puts(' asession <transfer spec extended value>')
21
- STDERR.puts(' ')
22
- STDERR.puts(' If no argument is provided, default will be used: @json:@stdin')
23
- STDERR.puts(' -h, --help display this message')
24
- STDERR.puts(' <transfer spec extended value> a JSON value for transfer_spec, using the prefix: @json:')
25
- STDERR.puts(' The value can be either:')
26
- STDERR.puts(" the JSON description itself, e.g. @json:'{\"xx\":\"yy\",...}'")
27
- STDERR.puts(' @json:@stdin, if the JSON is provided from stdin')
28
- STDERR.puts(' @json:@file:<path>, if the JSON is provided from a file')
29
- STDERR.puts(' Asynchronous commands can be provided on STDIN, examples:')
30
- STDERR.puts(' {"type":"START","source":"/aspera-test-dir-tiny/200KB.2"}')
31
- STDERR.puts(' {"type":"START","source":"xx","destination":"yy"}')
32
- STDERR.puts(' {"type":"DONE"}')
33
- STDERR.puts('Note: debug information can be placed on STDERR, using the "'+TS_LOGLEVEL+'" parameter in transfer spec (debug=0)')
34
- STDERR.puts('EXAMPLES')
35
- 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"}]}'))
36
- 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))
37
41
  Process.exit(1)
38
42
  end
39
43
 
40
- parameter_source_err_msg=' (argument), did you specify: "@json:" ?'
44
+ parameter_source_err_msg = ' (argument), did you specify: "@json:" ?'
41
45
  # by default assume JSON input on stdin if no argument
42
46
  if ARGV.empty?
43
47
  ARGV.push('@json:@stdin')
44
- parameter_source_err_msg=' (JSON on stdin)'
48
+ parameter_source_err_msg = ' (JSON on stdin)'
45
49
  end
46
50
  # anyway expect only one argument: session information
47
51
  assert_usage(ARGV.length.eql?(1),'exactly one argument is expected')
48
52
  assert_usage(!['-h','--help'].include?(ARGV.first),nil)
49
53
  # parse transfer spec
50
54
  begin
51
- transfer_spec_arg=ARGV.pop
52
- transfer_spec=Aspera::Cli::ExtendedValue.instance.evaluate(transfer_spec_arg)
53
- rescue => e
55
+ transfer_spec_arg = ARGV.pop
56
+ transfer_spec = Aspera::Cli::ExtendedValue.instance.evaluate(transfer_spec_arg)
57
+ rescue
54
58
  assert_usage(false,"Cannot extract transfer spec from: #{transfer_spec_arg}")
55
59
  end
56
60
  # ensure right type
57
61
  assert_usage(transfer_spec.is_a?(Hash),"the value must be a hash table#{parameter_source_err_msg}")
58
62
  # additional debug capability
59
63
  if transfer_spec.has_key?(TS_LOGLEVEL)
60
- Aspera::Log.instance.level=transfer_spec[TS_LOGLEVEL]
64
+ Aspera::Log.instance.level = transfer_spec[TS_LOGLEVEL]
61
65
  transfer_spec.delete(TS_LOGLEVEL)
62
66
  end
63
67
  # possibly override temp folder
64
68
  if transfer_spec.has_key?(TS_TMP_FILELIST_FOLDER)
65
- 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]
66
70
  transfer_spec.delete(TS_TMP_FILELIST_FOLDER)
67
71
  end
68
72
  # get local agent (ascp), disable ascp output on stdout to not mix with JSON events
69
- client=Aspera::Fasp::AgentDirect.new({quiet: true})
73
+ client = Aspera::Fasp::AgentDirect.new({quiet: true})
70
74
  # display JSON instead of legacy Lines
71
75
  client.add_listener(Aspera::Cli::Listener::LineDump.new)
72
76
  # start transfer (asynchronous)
73
- job_id=client.start_transfer(transfer_spec)
77
+ job_id = client.start_transfer(transfer_spec)
74
78
  # async commands
75
79
  Thread.new do
76
80
  begin
77
81
  loop do
78
- data=JSON.parse(STDIN.gets)
82
+ data = JSON.parse($stdin.gets)
79
83
  client.send_command(job_id,0,data)
80
84
  end
81
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
@@ -124,6 +128,10 @@ misc:
124
128
  faspex_publink_recv_from_fxuser: your value here
125
129
  faspex_publink_send_to_fxuser: your value here
126
130
  faspex_publink_send_to_dropbox: your value here
131
+ faspex_dbx: your value here
132
+ faspex_wkg: your value here
133
+ faspex_src: your value here
134
+ faspex5_meta: your value here
127
135
  shares_upload: your value here
128
136
  console_smart_id: your value here
129
137
  console_smart_file: your value here
@@ -143,8 +151,9 @@ misc:
143
151
  aoc_publink_folder: your value here
144
152
  aoc_shbx_ws: your value here
145
153
  aoc_shbx_name: your value here
146
- aoc_node1_name: your value here
147
- aoc_node1_secret: your value here
154
+ aoc_shbx_meta: your value here
155
+ aoc_ak_name: your value here
156
+ aoc_ak_secret: your value here
148
157
  icos_bucket_key: your value here
149
158
  icos_bucket_secret: your value here
150
159
  icos_bucket_name: your value here
@@ -158,3 +167,5 @@ misc:
158
167
  aoc_user_email: your value here
159
168
  aoc_workspace2: your value here
160
169
  http_gw_fqdn_port: your value here
170
+ tst_secrets:
171
+ st1: your value here
data/examples/aoc.rb CHANGED
@@ -1,28 +1,30 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'aspera/aoc'
3
5
  require 'aspera/log'
4
6
 
5
- Aspera::Log.instance.level=:debug
7
+ Aspera::Log.instance.level = :debug
6
8
 
7
- if ! ARGV.length.eql?(3)
9
+ if !ARGV.length.eql?(3)
8
10
  Aspera::Log.log.error("wrong number of args: #{ARGV.length}")
9
- Aspera::Log.log.error("Usage: #{$0} <aoc URL> <aoc username> <aoc private key content>")
10
- Aspera::Log.log.error("Example: #{$0} https://myorg.ibmaspera.com john@example.com $(cat /home/john/my_key.pem)")
11
+ Aspera::Log.log.error("Usage: #{$PROGRAM_NAME} <aoc URL> <aoc username> <aoc private key content>")
12
+ Aspera::Log.log.error("Example: #{$PROGRAM_NAME} https://myorg.ibmaspera.com john@example.com $(cat /home/john/my_key.pem)")
11
13
  Process.exit(1)
12
14
  end
13
15
 
14
- aoc_url=ARGV[0]
15
- aoc_user=ARGV[1]
16
- aoc_key_value=ARGV[2]
16
+ aoc_url = ARGV[0]
17
+ aoc_user = ARGV[1]
18
+ aoc_key_value = ARGV[2]
17
19
 
18
- aocapi=Aspera::AoC.new(
19
- url: aoc_url,
20
- auth: :jwt,
21
- private_key: aoc_key_value,
22
- username: aoc_user,
23
- scope: 'user:all',
24
- 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')
25
27
 
26
- self_user_data=aocapi.read('self')
28
+ self_user_data = aocapi.read('self')
27
29
 
28
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,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  # find Faspex API here: https://developer.ibm.com/apis/catalog/?search=faspex
3
5
  # this example makes use of class Aspera::Rest for REST calls, alternatively class RestClient of gem rest-client could be used
4
6
  # this example makes use of class Aspera::Fasp::AgentDirect for transfers, alternatively the official "Transfer SDK" could be used
@@ -7,40 +9,40 @@ require 'aspera/rest'
7
9
  require 'aspera/log'
8
10
  require 'aspera/fasp/agent_direct'
9
11
 
10
- tmpdir=ENV['tmp']||Dir.tmpdir || '.'
12
+ tmpdir = ENV['tmp'] || Dir.tmpdir || '.'
11
13
 
12
14
  # Set high log level for the example, decrease to :warn usually
13
- Aspera::Log.instance.level=:debug
15
+ Aspera::Log.instance.level = :debug
14
16
 
15
17
  # Set folder where SDK is installed (mandatory)
16
18
  # (if ascp is not there, the lib will try to find in usual locations)
17
19
  # (if data files are not there, they will be created)
18
20
  Aspera::Fasp::Installation.instance.folder = tmpdir
19
21
 
20
- if ! ARGV.length.eql?(3)
22
+ if !ARGV.length.eql?(3)
21
23
  Aspera::Log.log.error("Wrong number of args: #{ARGV.length}")
22
- Aspera::Log.log.error("Usage: #{$0} <faspex URL> <faspex username> <faspex password>")
23
- Aspera::Log.log.error("Example: #{$0} https://faspex.com/aspera/faspex john p@sSw0rd")
24
+ Aspera::Log.log.error("Usage: #{$PROGRAM_NAME} <faspex URL> <faspex username> <faspex password>")
25
+ Aspera::Log.log.error("Example: #{$PROGRAM_NAME} https://faspex.com/aspera/faspex john p@sSw0rd")
24
26
  Process.exit(1)
25
27
  end
26
28
 
27
- faspex_url=ARGV[0] # typically: https://faspex.example.com/aspera/faspex
28
- faspex_user=ARGV[1]
29
- 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]
30
32
 
31
- # comment out this if certificate is valid, keep line to ignore certificate
32
- 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}
33
35
 
34
36
  # 1: Faspex 4 API v3
35
37
  #---------------
36
38
 
37
39
  # create REST API object
38
- api_v3=Aspera::Rest.new({
39
- :base_url => faspex_url,
40
- :auth => {
41
- :type => :basic,
42
- :username => faspex_user,
43
- :password => faspex_pass
40
+ api_v3 = Aspera::Rest.new({
41
+ base_url: faspex_url,
42
+ auth: {
43
+ type: :basic,
44
+ username: faspex_user,
45
+ password: faspex_pass
44
46
  }})
45
47
 
46
48
  # very simple api call
@@ -50,37 +52,42 @@ api_v3.read('me')
50
52
  #---------------
51
53
 
52
54
  # create a sample file to send
53
- file_to_send=File.join(tmpdir,'myfile.bin')
54
- File.open(file_to_send, "w") {|f| f.write("sample data") }
55
+ file_to_send = File.join(tmpdir,'myfile.bin')
56
+ File.write(file_to_send, 'sample data')
55
57
  # package creation parameters
56
- package_create_params={'delivery'=>{'title'=>'test package','recipients'=>['aspera.user1@gmail.com'],'sources'=>[{'paths'=>[file_to_send]}]}}
57
- 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]
58
64
  # get transfer specification (normally: only one)
59
- transfer_spec=pkg_created['xfer_sessions'].first
65
+ transfer_spec = pkg_created['xfer_sessions'].first
60
66
  # set paths of files to send
61
- transfer_spec['paths']=[{'source'=>file_to_send}]
67
+ transfer_spec['paths'] = [{'source' => file_to_send}]
62
68
  # get local agent (ascp), disable ascp output on stdout to not mix with JSON events
63
- transfer_client=Aspera::Fasp::AgentDirect.new({quiet: true})
69
+ transfer_client = Aspera::Fasp::AgentDirect.new({quiet: true})
64
70
  # start transfer (asynchronous)
65
- job_id=transfer_client.start_transfer(transfer_spec)
71
+ job_id = transfer_client.start_transfer(transfer_spec)
72
+ Aspera::Log.dump('job_id',job_id)
66
73
  # wait for all transfer completion (for the example)
67
- result=transfer_client.wait_for_transfers_completion
74
+ result = transfer_client.wait_for_transfers_completion
68
75
  # notify of any transfer error
69
- result.select{|i|!i.eql?(:success)}.each do |e|
76
+ result.reject{|i|i.eql?(:success)}.each do |e|
70
77
  Aspera::Log.log.error("A transfer error occured: #{e.message}")
71
78
  end
72
79
 
73
80
  # 3: Faspex 4 API v4
74
81
  #---------------
75
- api_v4=Aspera::Rest.new({
76
- :base_url => faspex_url+'/api',
77
- :auth => {
78
- :type => :oauth2,
79
- :base_url => faspex_url+'/auth/oauth2',
80
- :grant => :header_userpass,
81
- :user_name => faspex_user,
82
- :user_pass => faspex_pass,
83
- :scope => 'admin'
82
+ api_v4 = Aspera::Rest.new({
83
+ base_url: faspex_url + '/api',
84
+ auth: {
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'
84
91
  }})
85
92
 
86
93
  # Use it. Note that Faspex 4 API v4 is totally different from Faspex 4 v3 APIs, see ref on line 2
data/examples/proxy.pac CHANGED
@@ -1,4 +1,4 @@
1
- /* demo proxy pac for Amelia */
1
+ /* demo proxy pac for ascli */
2
2
  function FindProxyForURL(url, host) {
3
3
  /* Normalize the URL for pattern matching */
4
4
  url = url.toLowerCase();
data/examples/transfer.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  # Example: transfer a file using one of the provided transfer agents
3
5
  # location of ascp can be specified with env var "ascp"
4
6
  # temp folder can be specified with env var "tmp"
@@ -11,35 +13,35 @@ require 'aspera/rest_errors_aspera'
11
13
  require 'json'
12
14
  require 'tmpdir'
13
15
 
14
- tmpdir=ENV['tmp']||Dir.tmpdir || '.'
16
+ tmpdir = ENV['tmp'] || Dir.tmpdir || '.'
15
17
 
16
- DEMO_CONFIG=[
18
+ DEMO_CONFIG = [
17
19
  'ssh://asperaweb@eudemo.asperademo.com:33001',
18
20
  'https://node_asperaweb@eudemo.asperademo.com:9092',
19
- 'demoaspera',
20
- ]
21
+ 'demoaspera'
22
+ ].freeze
21
23
 
22
24
  ##############################################################
23
25
  # generic initialisation : configuration of FaspManager
24
26
 
25
27
  # set trace level for sample, set to :debug to see complete list of debug information
26
- Aspera::Log.instance.level=:debug
28
+ Aspera::Log.instance.level = :debug
27
29
 
28
30
  # register aspera REST call error handlers
29
- Aspera::RestErrorsAspera.registerHandlers
31
+ Aspera::RestErrorsAspera.register_handlers
30
32
 
31
33
  # some required files are generated here (keys, certs)
32
34
  Aspera::Fasp::Installation.instance.folder = tmpdir
33
35
  # set path to your copy of ascp binary (else, let the system find)
34
- 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')
35
37
  # another way is to detect installed products and use one of them
36
38
  #Aspera::Fasp::Installation.instance.installed_products.each{|p|puts("found: #{p[:name]}")}
37
39
  #Aspera::Fasp::Installation.instance.use_ascp_from_product('Aspera Connect')
38
40
  # or install:
39
- #
41
+ #
40
42
 
41
43
  # get FASP Manager singleton based on above ascp location
42
- fasp_manager=Aspera::Fasp::AgentDirect.new
44
+ fasp_manager = Aspera::Fasp::AgentDirect.new
43
45
 
44
46
  # Note that it would also be possible to start transfers using other agents
45
47
  #require 'aspera/fasp/connect'
@@ -54,7 +56,7 @@ fasp_manager=Aspera::Fasp::AgentDirect.new
54
56
  class MyListener < Aspera::Fasp::Listener
55
57
  # this is the callback called during transfers, here we only display the received information
56
58
  # but it could be used to get detailed error information, check "type" field is "ERROR"
57
- def event_enhanced(data);STDOUT.puts(JSON.generate(data));STDOUT.flush;end
59
+ def event_enhanced(data);$stdout.puts(JSON.generate(data));$stdout.flush;end
58
60
  end
59
61
 
60
62
  # register the sample listener to display events
@@ -64,15 +66,15 @@ fasp_manager.add_listener(MyListener.new)
64
66
  # first example: download by SSH credentials
65
67
 
66
68
  # manually build teansfer spec
67
- transfer_spec={
69
+ transfer_spec = {
68
70
  #'remote_host' =>'demo.asperasoft.com',
69
- 'remote_host' =>URI.parse(DEMO_CONFIG[0]).host,
70
- 'ssh_port' =>URI.parse(DEMO_CONFIG[0]).port,
71
- 'remote_user' =>URI.parse(DEMO_CONFIG[0]).user,
72
- 'remote_password' =>DEMO_CONFIG[2],
73
- 'direction' =>'receive',
74
- 'destination_root'=>tmpdir,
75
- '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'}]
76
78
  }
77
79
  # start transfer in separate thread
78
80
  # method returns as soon as transfer thread is created
@@ -83,10 +85,10 @@ fasp_manager.start_transfer(transfer_spec)
83
85
  # here we started a single transfer session (no multisession parameter)
84
86
  # get array of status, one for each session (so, a single value array)
85
87
  # each status is either :success or "error message"
86
- transfer_result=fasp_manager.wait_for_transfers_completion
87
- STDOUT.puts(JSON.generate(transfer_result))
88
+ transfer_result = fasp_manager.wait_for_transfers_completion
89
+ $stdout.puts(JSON.generate(transfer_result))
88
90
  # get list of errors only
89
- errors=transfer_result.select{|i|!i.eql?(:success)}
91
+ errors = transfer_result.reject{|i|i.eql?(:success)}
90
92
  # the transfer was not success, as there is at least one error
91
93
  raise "Error(s) occured: #{errors.join(',')}" if !errors.empty?
92
94
 
@@ -94,31 +96,30 @@ raise "Error(s) occured: #{errors.join(',')}" if !errors.empty?
94
96
  # second example: upload with node authorization
95
97
 
96
98
  # create rest client for Node API on a public demo system, using public demo credentials
97
- node_api=Aspera::Rest.new({
98
- :base_url => DEMO_CONFIG[1],
99
- :auth => {
100
- :type => :basic,
101
- :username => URI.parse(DEMO_CONFIG[1]).user,
102
- :password => DEMO_CONFIG[2]
99
+ node_api = Aspera::Rest.new({
100
+ base_url: DEMO_CONFIG[1],
101
+ auth: {
102
+ type: :basic,
103
+ username: URI.parse(DEMO_CONFIG[1]).user,
104
+ password: DEMO_CONFIG[2]
103
105
  }})
104
106
  # define sample file(s) and destination folder
105
- sources=["#{tmpdir}/sample_file.txt"]
106
- destination='/Upload'
107
+ sources = ["#{tmpdir}/sample_file.txt"]
108
+ destination = '/Upload'
107
109
  # create sample file(s)
108
- sources.each{|p|File.write(p,"Hello World!")}
110
+ sources.each{|p|File.write(p,'Hello World!')}
109
111
  # request transfer authorization to node for a single transfer (This is a node api v3 call)
110
- 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]
111
113
  # we normally have only one transfer spec in list, so just get the first transfer_spec
112
- transfer_spec=send_result['transfer_specs'].first['transfer_spec']
114
+ transfer_spec = send_result['transfer_specs'].first['transfer_spec']
113
115
  # add list of files to upload
114
- transfer_spec['paths']=sources.map{|p|{'source'=>p}}
116
+ transfer_spec['paths'] = sources.map{|p|{'source' => p}}
115
117
  # set authentication type to "token" (will trigger use of bypass SSH key)
116
- transfer_spec['authentication']='token'
118
+ transfer_spec['authentication'] = 'token'
117
119
  # from here : same as example 1
118
120
  fasp_manager.start_transfer(transfer_spec)
119
121
  # optional: wait for transfer completion helper function to get events
120
- transfer_result=fasp_manager.wait_for_transfers_completion
121
- errors=transfer_result.select{|i|!i.eql?(:success)}
122
+ transfer_result = fasp_manager.wait_for_transfers_completion
123
+ errors = transfer_result.reject{|i|i.eql?(:success)}
122
124
  # the transfer was not success, as there is at least one error
123
125
  raise "Error(s) occured: #{errors.join(',')}" if !errors.empty?
124
-