aspera-cli 4.25.4 → 4.26.0.pre

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.
@@ -7,13 +7,14 @@ module Aspera
7
7
  class DotContainer
8
8
  class << self
9
9
  # Insert extended value `value` into struct `result` at `path`
10
- # @param path [String] Dotted path in container
11
- # @param value [String] Last value to insert
12
- # @param result [NilClass, Hash, Array] current value
13
- # @return [Hash, Array]
10
+ # @param path [Array<String>] Path in container
11
+ # @param value [Object] Value to insert in deep container
12
+ # @param result [nil, Hash, Array] Current container to use (or nil to create a new one)
13
+ # @return [Hash, Array] Container
14
14
  def dotted_to_container(path, value, result = nil)
15
+ Aspera.assert_array_all(path, String)
15
16
  # Typed keys
16
- keys = path.split(OPTION_DOTTED_SEPARATOR).map{ |k| int_or_string(k)}
17
+ keys = path.map{ |k| int_or_string(k)}
17
18
  # Create, or re-use first level container
18
19
  current = (result ||= new_hash_or_array_from_key(keys.first))
19
20
  # walk the path, and create sub-containers if necessary
@@ -78,7 +79,7 @@ module Aspera
78
79
  to_insert = current.map{ |i| i['name']}
79
80
  # Array of Hashes with only 'name' and 'value' keys -> Hash of key/values
80
81
  elsif current.all?{ |i| i.is_a?(Hash) && i.keys.sort == %w[name value]}
81
- add_elements(path, current.each_with_object({}){ |i, h| h[i['name']] = i['value']})
82
+ add_elements(path, current.to_h{ |i| [i['name'], i['value']]})
82
83
  else
83
84
  add_elements(path, current.each_with_index.map{ |v, i| [i, v]})
84
85
  end
@@ -86,7 +87,7 @@ module Aspera
86
87
  to_insert = current
87
88
  end
88
89
  end
89
- result[path.map(&:to_s).join(OPTION_DOTTED_SEPARATOR)] = to_insert unless to_insert.nil?
90
+ result[path.join(SEPARATOR)] = to_insert unless to_insert.nil?
90
91
  end
91
92
  result
92
93
  end
@@ -101,8 +102,7 @@ module Aspera
101
102
  nil
102
103
  end
103
104
 
104
- # "."
105
- OPTION_DOTTED_SEPARATOR = '.'
106
- private_constant :OPTION_DOTTED_SEPARATOR
105
+ # Dot-path separator: `.`
106
+ SEPARATOR = '.'
107
107
  end
108
108
  end
data/lib/aspera/log.rb CHANGED
@@ -26,7 +26,7 @@ class Logger
26
26
  # Hash
27
27
  # key [Integer] Log level (e.g. 0 for DEBUG)
28
28
  # value [Symbol] Uppercase log level label (e.g. :DEBUG)
29
- SEVERITY_LABEL = Severity.constants.each_with_object({}){ |name, hash| hash[Severity.const_get(name)] = name}
29
+ SEVERITY_LABEL = Severity.constants.to_h{ |name| [Severity.const_get(name), name]}
30
30
 
31
31
  # Override
32
32
  # @param severity [Integer] Log severity as int
@@ -33,7 +33,7 @@ module Aspera
33
33
 
34
34
  # type: NOTE CAUTION WARNING IMPORTANT TIP INFO
35
35
  def admonition(lines, type: 'INFO')
36
- "> [!{type}]\n#{lines.map{ |l| "> #{l}"}.join("\n")}\n\n"
36
+ "> [!#{type}]\n#{lines.map{ |l| "> #{l}"}.join("\n")}\n\n"
37
37
  end
38
38
 
39
39
  def code(lines, type: 'shell')
@@ -79,7 +79,7 @@ module Aspera
79
79
  end
80
80
 
81
81
  def current_items(persist_category)
82
- current_files(persist_category).each_with_object({}){ |i, h| h[File.basename(i, FILE_SUFFIX)] = File.read(i)}
82
+ current_files(persist_category).to_h{ |i| [File.basename(i, FILE_SUFFIX), File.read(i)]}
83
83
  end
84
84
 
85
85
  private
data/lib/aspera/rest.rb CHANGED
@@ -371,8 +371,11 @@ module Aspera
371
371
  end
372
372
  result_http = nil
373
373
  result_data = nil
374
+ # initialize with number of initial retries allowed, nil gives zero
375
+ tries_remain_redirect = @redirect_max
374
376
  # start a block to be able to retry the actual HTTP request in case of OAuth token expiration
375
377
  begin
378
+ Log.log.debug("send request (retries=#{tries_remain_redirect})")
376
379
  # TODO: shall we percent encode subpath (spaces) test with access key delete with space in id
377
380
  # URI.escape()
378
381
  separator = ['', '/'].include?(subpath) ? '' : '/'
@@ -406,9 +409,6 @@ module Aspera
406
409
  Log.dump(:req_body, req.body, level: :trace1)
407
410
  # we try the call, and will retry on some error types
408
411
  error_tries ||= 1 + RestParameters.instance.retry_max
409
- # initialize with number of initial retries allowed, nil gives zero
410
- tries_remain_redirect = @redirect_max if tries_remain_redirect.nil?
411
- Log.log.debug("send request (retries=#{tries_remain_redirect})")
412
412
  result_mime = nil
413
413
  file_saved = false
414
414
  # make http request (pipelined)
@@ -572,34 +572,6 @@ module Aspera
572
572
  return call(operation: 'CANCEL', subpath: subpath, **kwargs)
573
573
  end
574
574
 
575
- # Query entity by general search (read with parameter `q`)
576
- # TODO: not generic enough ? move somewhere ? inheritance ?
577
- # @param subpath [String] Path of entity in API
578
- # @param search_name [String] Name of searched entity
579
- # @param query [Hash] Additional search query parameters
580
- # @returns [Hash] A single entity matching the search, or an exception if not found or multiple found
581
- def lookup_by_name(subpath, search_name, query: nil)
582
- query = {} if query.nil?
583
- # returns entities matching the query (it matches against several fields in case insensitive way)
584
- matching_items = read(subpath, query.merge({'q' => search_name}))
585
- # API style: {totalcount:, ...} cspell: disable-line
586
- matching_items = matching_items[subpath] if matching_items.is_a?(Hash)
587
- Aspera.assert_type(matching_items, Array)
588
- case matching_items.length
589
- when 1 then return matching_items.first
590
- when 0 then raise EntityNotFound, %Q{No such #{subpath}: "#{search_name}"}
591
- else
592
- # multiple case insensitive partial matches, try case insensitive full match
593
- # (anyway AoC does not allow creation of 2 entities with same case insensitive name)
594
- name_matches = matching_items.select{ |i| i['name'].casecmp?(search_name)}
595
- case name_matches.length
596
- when 1 then return name_matches.first
597
- when 0 then raise %Q(#{subpath}: Multiple case insensitive partial match for: "#{search_name}": #{matching_items.map{ |i| i['name']}} but no case insensitive full match. Please be more specific or give exact name.)
598
- else raise "Two entities cannot have the same case insensitive name: #{name_matches.map{ |i| i['name']}}"
599
- end
600
- end
601
- end
602
-
603
575
  UNAVAILABLE_CODES = ['503']
604
576
 
605
577
  private_constant :UNAVAILABLE_CODES
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aspera
4
+ # List and lookup methods for Rest
5
+ # include in classes inheriting Rest
6
+ module RestList
7
+ # Query entity by general search (read with parameter `q`)
8
+ #
9
+ # @param subpath [String] Path of entity in API
10
+ # @param search_name [String] Name of searched entity
11
+ # @param query [Hash] Optional additional search query parameters
12
+ # @returns [Hash] A single entity matching the search, or an exception if not found or multiple found
13
+ def lookup_by_name(subpath, search_name, query: nil)
14
+ query = {} if query.nil?
15
+ # returns entities matching the query (it matches against several fields in case insensitive way)
16
+ matching_items = read(subpath, query.merge({'q' => search_name}))
17
+ # API style: {totalcount:, ...} cspell: disable-line
18
+ matching_items = matching_items[subpath] if matching_items.is_a?(Hash)
19
+ Aspera.assert_type(matching_items, Array)
20
+ case matching_items.length
21
+ when 1 then return matching_items.first
22
+ when 0 then raise EntityNotFound, %Q{No such #{subpath}: "#{search_name}"}
23
+ else
24
+ # multiple case insensitive partial matches, try case insensitive full match
25
+ # (anyway AoC does not allow creation of 2 entities with same case insensitive name)
26
+ name_matches = matching_items.select{ |i| i['name'].casecmp?(search_name)}
27
+ case name_matches.length
28
+ when 1 then return name_matches.first
29
+ when 0 then raise %Q(#{subpath}: Multiple case insensitive partial match for: "#{search_name}": #{matching_items.map{ |i| i['name']}} but no case insensitive full match. Please be more specific or give exact name.)
30
+ else raise "Two entities cannot have the same case insensitive name: #{name_matches.map{ |i| i['name']}}"
31
+ end
32
+ end
33
+ end
34
+
35
+ # Get a (full or partial) list of all entities of a given type with query: offset/limit
36
+ # @param entity [String,Symbol] API endpoint of entity to list
37
+ # @param items_key [String] Key in the result to get the list of items (Default: same as `entity`)
38
+ # @param query [Hash,nil] Additional query parameters
39
+ # @return [Array<(Array<Hash>, Integer)>] items, total_count
40
+ def list_entities_limit_offset_total_count(
41
+ entity:,
42
+ items_key: nil,
43
+ query: nil
44
+ )
45
+ entity = entity.to_s if entity.is_a?(Symbol)
46
+ items_key = entity.split('/').last if items_key.nil?
47
+ query = {} if query.nil?
48
+ Aspera.assert_type(entity, String)
49
+ Aspera.assert_type(items_key, String)
50
+ Aspera.assert_type(query, Hash)
51
+ Log.log.debug{"list_entities t=#{entity} k=#{items_key} q=#{query}"}
52
+ result = []
53
+ offset = 0
54
+ max_items = query.delete(MAX_ITEMS)
55
+ remain_pages = query.delete(MAX_PAGES)
56
+ # Merge default parameters, by default 100 per page
57
+ query = {'limit'=> PER_PAGE_DEFAULT}.merge(query)
58
+ total_count = nil
59
+ loop do
60
+ query['offset'] = offset
61
+ page_result = read(entity, query)
62
+ Aspera.assert_type(page_result[items_key], Array)
63
+ result.concat(page_result[items_key])
64
+ # Reach the limit set by user ?
65
+ if !max_items.nil? && (result.length >= max_items)
66
+ result = result.slice(0, max_items)
67
+ break
68
+ end
69
+ total_count ||= page_result['total_count']
70
+ break if result.length >= total_count
71
+ remain_pages -= 1 unless remain_pages.nil?
72
+ break if remain_pages == 0
73
+ offset += page_result[items_key].length
74
+ RestParameters.instance.spinner_cb.call("#{result.length} / #{total_count || '?'}")
75
+ end
76
+ RestParameters.instance.spinner_cb.call(action: :success)
77
+ return result, total_count
78
+ end
79
+
80
+ # Lookup an entity id from its name.
81
+ # Uses query `q` if `query` is `:default` and `field` is `name`.
82
+ # @param entity [String] Type of entity to lookup, by default it is the path, and it is also the field name in result
83
+ # @param value [String] Value to lookup
84
+ # @param field [String] Field to match, by default it is `'name'`
85
+ # @param items_key [String] Key in the result to get the list of items (override entity)
86
+ # @param query [Hash] Additional query parameters (Default: `:default`)
87
+ def lookup_entity_by_field(entity:, value:, field: 'name', items_key: nil, query: :default)
88
+ if query.eql?(:default)
89
+ Aspera.assert(field.eql?('name')){'Default query is on name only'}
90
+ query = {'q'=> value}
91
+ end
92
+ lookup_entity_generic(entity: entity, field: field, value: value){list_entities_limit_offset_total_count(entity: entity, items_key: items_key, query: query).first}
93
+ end
94
+
95
+ # Lookup entity by field and value.
96
+ # Extracts a single result from the list returned by the block.
97
+ #
98
+ # @param entity [String] Type of entity to lookup (path, and by default it is also the field name in result)
99
+ # @param value [String] Value to match against the field.
100
+ # @param field [String] Field to match in the hashes (defaults to 'name').
101
+ # @yield [] A mandatory block that returns an Array of Hashes.
102
+ # @return [Hash] The unique matching object.
103
+ # @raise [Cli::BadIdentifier] If 0 or >1 matches are found.
104
+ def lookup_entity_generic(entity:, value:, field: 'name')
105
+ Aspera.assert(block_given?)
106
+ found = yield
107
+ Aspera.assert_array_all(found, Hash)
108
+ found = found.select{ |i| i[field].eql?(value)}
109
+ return found.first if found.length.eql?(1)
110
+ raise Cli::BadIdentifier.new(entity, value, field: field, count: found.length)
111
+ end
112
+ PER_PAGE_DEFAULT = 1000
113
+ private_constant :PER_PAGE_DEFAULT
114
+ module_function :lookup_entity_generic
115
+ end
116
+ end
@@ -342,7 +342,7 @@ module Aspera
342
342
  CONF_SCHEMA = CommandLineBuilder.read_schema(__dir__, 'conf')
343
343
  CMDLINE_PARAMS_KEYS = %w[instance sessions].freeze
344
344
  ASYNC_ADMIN_EXECUTABLE = 'asyncadmin'
345
- PRIVATE_FOLDER = '.private-asp'
345
+ PRIVATE_FOLDER = "#{Environment.instance.os.eql?(Environment::OS_WINDOWS) ? '~' : '.'}private-asp"
346
346
  ASYNC_DB = 'snap.db'
347
347
  PARAM_KEYS = %w[local sessions].freeze
348
348
 
@@ -38,19 +38,19 @@ module Aspera
38
38
  @file_list_folder ||= TempFileManager.instance.new_file_path_global('asession_filelists')
39
39
  end
40
40
 
41
- # File list is provided directly with ascp arguments
42
- # @columns ascp_args [Array,NilClass] ascp arguments
41
+ # File list is provided directly with `ascp` arguments
42
+ # @columns ascp_args [Array,NilClass] `ascp` arguments
43
43
  def ascp_args_file_list?(ascp_args)
44
44
  ascp_args&.any?{ |i| FILE_LIST_OPTIONS.include?(i)}
45
45
  end
46
46
  end
47
47
 
48
- # @param job_spec [Hash] Transfer spec
49
- # @param ascp_args [Array] Other ascp args
50
- # @param quiet [Boolean] Remove ascp output
51
- # @param trusted_certs [Array] Trusted certificates
52
- # @param client_ssh_key [:rsa,:dsa] :rsa or :dsa
53
- # @param check_ignore_cb [Proc] Callback
48
+ # @param job_spec [Hash] Transfer specification
49
+ # @param ascp_args [Array] Other `ascp` args
50
+ # @param quiet [Boolean] Remove `ascp` progress bar if `true`
51
+ # @param client_ssh_key [:rsa,:dsa] Type of Aspera Client SSH key to use.
52
+ # @param trusted_certs [Array<String>] List of path to trusted certificates stores when using WSS
53
+ # @param check_ignore_cb [Proc] Callback to check if WSS connection shall ignore certificate validity
54
54
  def initialize(
55
55
  job_spec,
56
56
  ascp_args: nil,
data/lib/aspera/yaml.rb CHANGED
@@ -25,7 +25,7 @@ module Aspera
25
25
  counts.each do |key_str, count|
26
26
  next if count <= 1
27
27
  path = (parent_path + [key_str]).join('.')
28
- occurrences = key_nodes[key_str].map{ |kn| kn.start_line ? kn.start_line + 1 : 'unknown'}.map(&:to_s).join(', ')
28
+ occurrences = key_nodes[key_str].map{ |kn| kn.start_line ? kn.start_line + 1 : 'unknown'}.join(', ')
29
29
  duplicate_keys << "#{path}: #{occurrences}"
30
30
  end
31
31
  else
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aspera-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.25.4
4
+ version: 4.26.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent Martin
@@ -424,6 +424,7 @@ files:
424
424
  - lib/aspera/rest_call_error.rb
425
425
  - lib/aspera/rest_error_analyzer.rb
426
426
  - lib/aspera/rest_errors_aspera.rb
427
+ - lib/aspera/rest_list.rb
427
428
  - lib/aspera/secret_hider.rb
428
429
  - lib/aspera/ssh.rb
429
430
  - lib/aspera/ssl.rb
@@ -456,7 +457,7 @@ metadata:
456
457
  source_code_uri: https://github.com/IBM/aspera-cli/tree/main/lib/aspera
457
458
  changelog_uri: https://github.com/IBM/aspera-cli/blob/main/CHANGELOG.md
458
459
  rubygems_uri: https://rubygems.org/gems/aspera-cli
459
- documentation_uri: https://www.rubydoc.info/gems/aspera-cli
460
+ documentation_uri: https://ibm.biz/ascli-doc
460
461
  rdoc_options: []
461
462
  require_paths:
462
463
  - lib
@@ -472,7 +473,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
472
473
  version: '0'
473
474
  requirements:
474
475
  - Read the manual for any requirement
475
- rubygems_version: 4.0.3
476
+ rubygems_version: 4.0.6
476
477
  specification_version: 4
477
478
  summary: 'Execute actions using command line on IBM Aspera Server products: Aspera
478
479
  on Cloud, Faspex, Shares, Node, Console, Orchestrator, High Speed Transfer Server'
metadata.gz.sig CHANGED
Binary file