aspera-cli 4.0.0.pre1 → 4.0.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,9 +43,8 @@ module Aspera
43
43
  if transfer_spec.has_key?('token') and
44
44
  !transfer_spec.has_key?('remote_password') and
45
45
  !transfer_spec.has_key?('EX_ssh_key_paths')
46
- keys=Installation.instance.bypass_keys
47
- transfer_spec['remote_password'] = keys.shift
48
- transfer_spec['EX_ssh_key_paths'] = keys
46
+ # transfer_spec['remote_password'] = Installation.instance.bypass_pass # not used
47
+ transfer_spec['EX_ssh_key_paths'] = Installation.instance.bypass_keys
49
48
  end
50
49
 
51
50
  # compute known args
@@ -1,5 +1,5 @@
1
1
  require 'aspera/log'
2
- require 'aspera/on_cloud'
2
+ require 'aspera/aoc'
3
3
  require 'aspera/cli/main'
4
4
  require 'webrick'
5
5
  require 'webrick/https'
@@ -55,7 +55,7 @@ module Aspera
55
55
  node_info=@aoc_api_user.read("nodes/#{the_package['node_id']}")[:data]
56
56
 
57
57
  # get transfer token (for node)
58
- node_auth_bearer_token=@aoc_api_user.oauth_token(scope: OnCloud.node_scope(node_info['access_key'],OnCloud::SCOPE_NODE_USER))
58
+ node_auth_bearer_token=@aoc_api_user.oauth_token(scope: AoC.node_scope(node_info['access_key'],AoC::SCOPE_NODE_USER))
59
59
 
60
60
  # tell Files what to expect in package: 1 transfer (can also be done after transfer)
61
61
  @aoc_api_user.update("packages/#{the_package['id']}",{"sent"=>true,"transfers_expected"=>1})
@@ -1,4 +1,5 @@
1
1
  require 'aspera/log'
2
+ require 'aspera/environment'
2
3
  require 'rbconfig'
3
4
  require 'singleton'
4
5
 
@@ -12,37 +13,23 @@ module Aspera
12
13
  def self.user_interfaces; [ :text, :graphical ]; end
13
14
 
14
15
  def self.default_gui_mode
15
- case current_os_type
16
- when :windows,:mac
17
- return :graphical
18
- else # unix family
19
- if ENV.has_key?("DISPLAY") and !ENV["DISPLAY"].empty?
20
- return :graphical
21
- end
22
- return :text
23
- end
24
- end
25
-
26
- def self.current_os_type
27
- case RbConfig::CONFIG['host_os']
28
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
29
- return :windows
30
- when /darwin|mac os/
31
- return :mac
32
- else # unix family
33
- return :unix
34
- end
16
+ return :graphical if [Aspera::Environment::OS_WINDOWS,Aspera::Environment::OS_X].include?(Aspera::Environment.os)
17
+ # unix family
18
+ return :graphical if ENV.has_key?("DISPLAY") and !ENV["DISPLAY"].empty?
19
+ return :text
35
20
  end
36
21
 
37
22
  # command must be non blocking
38
23
  def self.uri_graphical(uri)
39
- case current_os_type
40
- when :mac
24
+ case Aspera::Environment.os
25
+ when Aspera::Environment::OS_X
41
26
  return system('open',uri.to_s)
42
- when :windows
27
+ when Aspera::Environment::OS_WINDOWS
43
28
  return system('start explorer "'+uri.to_s+'"')
44
- else # unix family
29
+ when Aspera::Environment::OS_LINUX
45
30
  return system("xdg-open '#{uri.to_s}'")
31
+ else
32
+ raise "no graphical open method for #{Aspera::Environment.os}"
46
33
  end
47
34
  end
48
35
 
@@ -194,7 +194,7 @@ module Aspera
194
194
  ],
195
195
  out_f: @destination_file_path,
196
196
  out_p: [
197
- '-vf',"fps=5,scale=120:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse",
197
+ '-vf','fps=5,scale=120:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse',
198
198
  '-loop',0,
199
199
  '-f','gif'
200
200
  ])
@@ -203,7 +203,6 @@ module Aspera
203
203
  def convert_office_to_png()
204
204
  tmp_pdf_file=File.join(this_tmpdir,File.basename(@source_file_path,File.extname(@source_file_path))+'.pdf')
205
205
  Utils.external_command(:unoconv,[
206
-
207
206
  '-f','pdf',
208
207
  '-o',tmp_pdf_file,
209
208
  @source_file_path])
@@ -213,7 +212,6 @@ module Aspera
213
212
  def convert_pdf_to_png(source_file_path=nil)
214
213
  source_file_path||=@source_file_path
215
214
  Utils.external_command(:convert,[
216
-
217
215
  '-size',"x#{@options.thumb_img_size}",
218
216
  '-background','white',
219
217
  '-flatten',
@@ -223,7 +221,6 @@ module Aspera
223
221
 
224
222
  def convert_image_to_png()
225
223
  Utils.external_command(:convert,[
226
-
227
224
  '-auto-orient',
228
225
  '-thumbnail',"#{@options.thumb_img_size}x#{@options.thumb_img_size}>",
229
226
  '-quality',95,
@@ -239,7 +236,6 @@ module Aspera
239
236
  # get 100 first lines of text file
240
237
  first_lines=File.open(@source_file_path){|f|100.times.map{f.readline rescue ''}}.join
241
238
  Utils.external_command(:convert,[
242
-
243
239
  '-size',"#{@options.thumb_img_size}x#{@options.thumb_img_size}",
244
240
  'xc:white',
245
241
  '-font','Courier',
@@ -7,6 +7,7 @@ require 'net/http'
7
7
  require 'net/https'
8
8
  require 'json'
9
9
  require 'base64'
10
+ require 'ruby-progressbar'
10
11
 
11
12
  # add cancel method to http
12
13
  class Net::HTTP::Cancel < Net::HTTPRequest
@@ -27,6 +28,54 @@ module Aspera
27
28
  # and error are analyzed in RestErrorAnalyzer
28
29
  class Rest
29
30
  private
31
+ # set to true enables debug in HTTP class
32
+ @@debug=false
33
+ # true if https ignore certificate
34
+ @@insecure=false
35
+ @@user_agent='Ruby'
36
+
37
+ public
38
+ def self.insecure=(v); @@insecure=v;Log.log.debug("insecure => #{@@insecure}".red);end
39
+
40
+ def self.insecure; @@insecure;end
41
+
42
+ def self.user_agent=(v); @@user_agent=v;Log.log.debug("user_agent => #{@@user_agent}".red);end
43
+
44
+ def self.user_agent; @@user_agent;end
45
+
46
+ def self.debug=(flag); @@debug=flag; Log.log.debug("debug http => #{flag}"); end
47
+
48
+ def self.basic_creds(user,pass); return "Basic #{Base64.strict_encode64("#{user}:#{pass}")}";end
49
+
50
+ # build URI from URL and parameters and check it is http or https
51
+ def self.build_uri(url,params=nil)
52
+ uri=URI.parse(url)
53
+ raise "REST endpoint shall be http(s)" unless ['http','https'].include?(uri.scheme)
54
+ if !params.nil?
55
+ # support array url params, there is no standard. Either p[]=1&p[]=2, or p=1&p=2
56
+ if params.is_a?(Hash)
57
+ orig=params
58
+ params=[]
59
+ orig.each do |k,v|
60
+ case v
61
+ when Array
62
+ suffix=v.first.eql?('[]') ? v.shift : ''
63
+ v.each do |e|
64
+ params.push([k+suffix,e])
65
+ end
66
+ else
67
+ params.push([k,v])
68
+ end
69
+ end
70
+ end
71
+ # CGI.unescape to transform back %5D into []
72
+ uri.query=CGI.unescape(URI.encode_www_form(params))
73
+ end
74
+ return uri
75
+ end
76
+
77
+ private
78
+
30
79
  # create and start keep alive connection on demand
31
80
  def http_session
32
81
  if @http_session.nil?
@@ -46,26 +95,8 @@ module Aspera
46
95
  return @http_session
47
96
  end
48
97
 
49
- # set to true enables debug in HTTP class
50
- @@debug=false
51
- # true if https ignore certificate
52
- @@insecure=false
53
- @@user_agent='Ruby'
54
-
55
98
  public
56
99
 
57
- def self.insecure=(v); @@insecure=v;Log.log.debug("insecure => #{@@insecure}".red);end
58
-
59
- def self.insecure; @@insecure;end
60
-
61
- def self.user_agent=(v); @@user_agent=v;Log.log.debug("user_agent => #{@@user_agent}".red);end
62
-
63
- def self.user_agent; @@user_agent;end
64
-
65
- def self.debug=(flag); @@debug=flag; Log.log.debug("debug http => #{flag}"); end
66
-
67
- def self.basic_creds(user,pass); return "Basic #{Base64.strict_encode64("#{user}:#{pass}")}";end
68
-
69
100
  attr_reader :params
70
101
 
71
102
  # @param a_rest_params default call parameters and authentication (:auth) :
@@ -105,33 +136,6 @@ module Aspera
105
136
  return @oauth.get_authorization(options)
106
137
  end
107
138
 
108
- # build URI from URL and parameters and check it is http or https
109
- def self.build_uri(url,params=nil)
110
- uri=URI.parse(url)
111
- raise "REST endpoint shall be http(s)" unless ['http','https'].include?(uri.scheme)
112
- if !params.nil?
113
- # support array url params, there is no standard. Either p[]=1&p[]=2, or p=1&p=2
114
- if params.is_a?(Hash)
115
- orig=params
116
- params=[]
117
- orig.each do |k,v|
118
- case v
119
- when Array
120
- suffix=v.first.eql?('[]') ? v.shift : ''
121
- v.each do |e|
122
- params.push([k+suffix,e])
123
- end
124
- else
125
- params.push([k,v])
126
- end
127
- end
128
- end
129
- # CGI.unescape to transform back %5D into []
130
- uri.query=CGI.unescape(URI.encode_www_form(params))
131
- end
132
- return uri
133
- end
134
-
135
139
  # HTTP/S REST call
136
140
  # call_data has keys:
137
141
  # :auth
@@ -167,7 +171,7 @@ module Aspera
167
171
  end
168
172
  # TODO: shall we percent encode subpath (spaces) test with access key delete with space in id
169
173
  # URI.escape()
170
- uri=self.class.build_uri("#{@params[:base_url]}/#{call_data[:subpath]}",call_data[:url_params])
174
+ uri=self.class.build_uri("#{@params[:base_url]}#{call_data[:subpath].nil? ? '' : '/'}#{call_data[:subpath]}",call_data[:url_params])
171
175
  Log.log.debug("URI=#{uri}")
172
176
  begin
173
177
  # instanciate request object based on string name
@@ -209,7 +213,6 @@ module Aspera
209
213
  http_session.request(req) do |response|
210
214
  result[:http] = response
211
215
  if call_data.has_key?(:save_to_file)
212
- require 'ruby-progressbar'
213
216
  total_size=result[:http]['Content-Length'].to_i
214
217
  progress=ProgressBar.create(
215
218
  :format => '%a %B %p%% %r KB/sec %e',
@@ -218,11 +221,14 @@ module Aspera
218
221
  :total => total_size)
219
222
  Log.log.debug("before write file")
220
223
  target_file=call_data[:save_to_file]
224
+ # override user's path to path in header
221
225
  if !response['Content-Disposition'].nil? and m=response['Content-Disposition'].match(/filename="([^"]+)"/)
222
226
  target_file=m[1]
223
227
  end
228
+ # download with temp filename
229
+ target_file_tmp=target_file+'.http.partial'
224
230
  Log.log.debug("saving to: #{target_file}")
225
- File.open(target_file, "wb") do |file|
231
+ File.open(target_file_tmp, "wb") do |file|
226
232
  result[:http].read_body do |fragment|
227
233
  file.write(fragment)
228
234
  new_process=progress.progress+fragment.length
@@ -230,6 +236,8 @@ module Aspera
230
236
  progress.progress=new_process
231
237
  end
232
238
  end
239
+ # rename at the end
240
+ File.rename(target_file_tmp, target_file)
233
241
  progress=nil
234
242
  end
235
243
  end
@@ -6,10 +6,12 @@ module Aspera
6
6
  # analyze error codes returned by REST calls and raise ruby exception
7
7
  class RestErrorAnalyzer
8
8
  include Singleton
9
+ attr_accessor :log_file
9
10
  # the singleton object is registered with application specific handlers
10
11
  def initialize
11
12
  # list of handlers
12
13
  @error_handlers=[]
14
+ @log_file=nil
13
15
  self.add_handler('Type Generic') do |type,context|
14
16
  if !context[:response].code.start_with?('2')
15
17
  # add generic information
@@ -85,14 +87,13 @@ module Aspera
85
87
  # @param msg one error message to add to list
86
88
  def self.add_error(context,type,msg)
87
89
  context[:messages].push(msg)
90
+ logfile=instance.log_file
88
91
  # log error for further analysis (file must exist to activate)
89
- exc_log_file=File.join(Fasp::Installation.instance.config_folder,'exceptions.log')
90
- if File.exist?(exc_log_file)
91
- File.open(exc_log_file,'a+') do |f|
92
+ if !logfile.nil? and File.exist?(logfile)
93
+ File.open(logfile,'a+') do |f|
92
94
  f.write("\n=#{type}=====\n#{context[:request].method} #{context[:request].path}\n#{context[:response].code}\n#{JSON.generate(context[:data])}\n#{context[:messages].join("\n")}")
93
95
  end
94
96
  end
95
97
  end
96
-
97
98
  end
98
99
  end
@@ -22,7 +22,7 @@ module Aspera
22
22
  # ensure that provided folder exists, or create it, generate a unique filename
23
23
  # @return path to that unique file
24
24
  def new_file_path_in_folder(temp_folder,add_base='')
25
- FileUtils::mkdir_p(temp_folder) unless Dir.exist?(temp_folder)
25
+ FileUtils.mkdir_p(temp_folder) unless Dir.exist?(temp_folder)
26
26
  new_file=File.join(temp_folder,add_base+SecureRandom.uuid)
27
27
  @created_files.push(new_file)
28
28
  return new_file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aspera-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.pre1
4
+ version: 4.0.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-16 00:00:00.000000000 Z
11
+ date: 2021-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xml-simple
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: jwt
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.5.6
33
+ version: '2.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.5.6
40
+ version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: ruby-progressbar
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -56,14 +56,14 @@ dependencies:
56
56
  name: net-ssh
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '4.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '4.0'
69
69
  - !ruby/object:Gem::Dependency
@@ -122,49 +122,63 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.9'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubyzip
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: bundler
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - ">="
143
+ - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: '1.14'
145
+ version: '2.0'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - ">="
150
+ - - "~>"
137
151
  - !ruby/object:Gem::Version
138
- version: '1.14'
152
+ version: '2.0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: rake
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - ">="
157
+ - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '10.0'
159
+ version: '13.0'
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - ">="
164
+ - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: '10.0'
166
+ version: '13.0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: rspec
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
- - - ">="
171
+ - - "~>"
158
172
  - !ruby/object:Gem::Version
159
173
  version: '3.0'
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
- - - ">="
178
+ - - "~>"
165
179
  - !ruby/object:Gem::Version
166
180
  version: '3.0'
167
- description: A powerful CLI for IBM Aspera products
181
+ description: Command line interface for IBM Aspera products
168
182
  email:
169
183
  - laurent.martin.aspera@fr.ibm.com
170
184
  executables:
@@ -180,12 +194,12 @@ files:
180
194
  - docs/README.erb.md
181
195
  - docs/README.md
182
196
  - docs/diagrams.txt
183
- - docs/secrets.make
184
197
  - docs/test_env.conf
185
198
  - docs/transfer_spec.html
186
199
  - examples/aoc.rb
187
200
  - examples/proxy.pac
188
201
  - examples/transfer.rb
202
+ - lib/aspera/aoc.rb
189
203
  - lib/aspera/api_detector.rb
190
204
  - lib/aspera/ascmd.rb
191
205
  - lib/aspera/ats_api.rb
@@ -200,6 +214,7 @@ files:
200
214
  - lib/aspera/cli/manager.rb
201
215
  - lib/aspera/cli/plugin.rb
202
216
  - lib/aspera/cli/plugins/alee.rb
217
+ - lib/aspera/cli/plugins/aoc.rb
203
218
  - lib/aspera/cli/plugins/ats.rb
204
219
  - lib/aspera/cli/plugins/bss.rb
205
220
  - lib/aspera/cli/plugins/config.rb
@@ -208,18 +223,26 @@ files:
208
223
  - lib/aspera/cli/plugins/faspex.rb
209
224
  - lib/aspera/cli/plugins/faspex5.rb
210
225
  - lib/aspera/cli/plugins/node.rb
211
- - lib/aspera/cli/plugins/oncloud.rb
212
226
  - lib/aspera/cli/plugins/orchestrator.rb
213
227
  - lib/aspera/cli/plugins/preview.rb
214
228
  - lib/aspera/cli/plugins/server.rb
215
229
  - lib/aspera/cli/plugins/shares.rb
216
230
  - lib/aspera/cli/plugins/shares2.rb
217
231
  - lib/aspera/cli/plugins/sync.rb
218
- - lib/aspera/cli/plugins/xnode.rb
219
232
  - lib/aspera/cli/transfer_agent.rb
220
233
  - lib/aspera/cli/version.rb
221
234
  - lib/aspera/colors.rb
222
235
  - lib/aspera/command_line_builder.rb
236
+ - lib/aspera/cos_node.rb
237
+ - lib/aspera/data/1
238
+ - lib/aspera/data/2
239
+ - lib/aspera/data/3
240
+ - lib/aspera/data/4
241
+ - lib/aspera/data/5
242
+ - lib/aspera/data/6
243
+ - lib/aspera/data/7
244
+ - lib/aspera/data_repository.rb
245
+ - lib/aspera/environment.rb
223
246
  - lib/aspera/fasp/aoc.rb
224
247
  - lib/aspera/fasp/connect.rb
225
248
  - lib/aspera/fasp/error.rb
@@ -239,7 +262,6 @@ files:
239
262
  - lib/aspera/nagios.rb
240
263
  - lib/aspera/node.rb
241
264
  - lib/aspera/oauth.rb
242
- - lib/aspera/on_cloud.rb
243
265
  - lib/aspera/open_application.rb
244
266
  - lib/aspera/persistency_action_once.rb
245
267
  - lib/aspera/persistency_folder.rb
@@ -264,6 +286,10 @@ licenses:
264
286
  - Apache-2.0
265
287
  metadata:
266
288
  allowed_push_host: https://rubygems.org
289
+ homepage_uri: https://github.com/IBM/aspera-cli
290
+ source_code_uri: https://github.com/IBM/aspera-cli
291
+ changelog_uri: https://github.com/IBM/aspera-cli
292
+ rubygems_uri: https://rubygems.org/gems/aspera-cli
267
293
  post_install_message:
268
294
  rdoc_options: []
269
295
  require_paths:
@@ -272,7 +298,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
272
298
  requirements:
273
299
  - - ">"
274
300
  - !ruby/object:Gem::Version
275
- version: '2.0'
301
+ version: '2.4'
276
302
  required_rubygems_version: !ruby/object:Gem::Requirement
277
303
  requirements:
278
304
  - - ">"
@@ -283,6 +309,6 @@ requirements:
283
309
  rubygems_version: 3.0.3
284
310
  signing_key:
285
311
  specification_version: 4
286
- summary: 'Command line tool for Aspera Server products: Aspera on Cloud, Faspex, Shares,
287
- Node, Console, Orchestrator, Transfer Server'
312
+ summary: 'Execute actions using command line on IBM Aspera Server products: Aspera
313
+ on Cloud, Faspex, Shares, Node, Console, Orchestrator, Transfer Server'
288
314
  test_files: []