Module: Aspera

Defined in:
lib/aspera/mime.rb,
lib/aspera/log.rb,
lib/aspera/ssh.rb,
lib/aspera/ssl.rb,
lib/aspera/yaml.rb,
lib/aspera/assert.rb,
lib/aspera/nagios.rb,
lib/aspera/prompt.rb,
lib/aspera/inflate.rb,
lib/aspera/rainbow.rb,
lib/aspera/cli/http.rb,
lib/aspera/cli/info.rb,
lib/aspera/cli/poll.rb,
lib/aspera/coverage.rb,
lib/aspera/markdown.rb,
lib/aspera/products.rb,
lib/aspera/web_page.rb,
lib/aspera/cli/error.rb,
lib/aspera/cli/hints.rb,
lib/aspera/exec_spec.rb,
lib/aspera/rest/list.rb,
lib/aspera/rest/util.rb,
lib/aspera/agent/base.rb,
lib/aspera/cli/mailer.rb,
lib/aspera/cli/option.rb,
lib/aspera/cli/parser.rb,
lib/aspera/cli/result.rb,
lib/aspera/cli/runner.rb,
lib/aspera/cli/wizard.rb,
lib/aspera/uri_reader.rb,
lib/aspera/cli/command.rb,
lib/aspera/cli/context.rb,
lib/aspera/cli/version.rb,
lib/aspera/environment.rb,
lib/aspera/line_logger.rb,
lib/aspera/link_header.rb,
lib/aspera/rest/client.rb,
lib/aspera/sealed_hash.rb,
lib/aspera/cli/argument.rb,
lib/aspera/cli/complete.rb,
lib/aspera/cli/mcp/tool.rb,
lib/aspera/cli/security.rb,
lib/aspera/id_generator.rb,
lib/aspera/secret/hider.rb,
lib/aspera/agent/factory.rb,
lib/aspera/cli/formatter.rb,
lib/aspera/dot_container.rb,
lib/aspera/products/hsts.rb,
lib/aspera/schema/reader.rb,
lib/aspera/sync/database.rb,
lib/aspera/timer_limiter.rb,
lib/aspera/transfer/spec.rb,
lib/aspera/units/decimal.rb,
lib/aspera/cli/bool_value.rb,
lib/aspera/cli/web_secret.rb,
lib/aspera/products/drive.rb,
lib/aspera/standard_input.rb,
lib/aspera/transfer/error.rb,
lib/aspera/units/duration.rb,
lib/aspera/web_auth/paste.rb,
lib/aspera/web_auth/relay.rb,
lib/aspera/ascp/management.rb,
lib/aspera/bundle_registry.rb,
lib/aspera/cli/deprecation.rb,
lib/aspera/cli/gem_checker.rb,
lib/aspera/cli/mcp/secrets.rb,
lib/aspera/cli/option/type.rb,
lib/aspera/cli/plugins/mcp.rb,
lib/aspera/json_rpc/client.rb,
lib/aspera/plugins/aoc/api.rb,
lib/aspera/plugins/ats/api.rb,
lib/aspera/plugins/cos/api.rb,
lib/aspera/products/cli_v3.rb,
lib/aspera/rest/call_error.rb,
lib/aspera/rest/parameters.rb,
lib/aspera/schema/registry.rb,
lib/aspera/secret/resolver.rb,
lib/aspera/secret/strength.rb,
lib/aspera/servlet_helpers.rb,
lib/aspera/sync/log_parser.rb,
lib/aspera/sync/operations.rb,
lib/aspera/transfer/result.rb,
lib/aspera/units/timestamp.rb,
lib/aspera/web_auth/server.rb,
lib/aspera/cli/bootstrapper.rb,
lib/aspera/cli/command_line.rb,
lib/aspera/cli/option/value.rb,
lib/aspera/cli/plugins/base.rb,
lib/aspera/cli/table_fitter.rb,
lib/aspera/json_rpc/version.rb,
lib/aspera/oauth/client/jwt.rb,
lib/aspera/oauth/client/web.rb,
lib/aspera/plugins/alee/api.rb,
lib/aspera/plugins/node/api.rb,
lib/aspera/products/connect.rb,
lib/aspera/products/desktop.rb,
lib/aspera/schema/validator.rb,
lib/aspera/secret/reference.rb,
lib/aspera/transfer/resumer.rb,
lib/aspera/ascp/installation.rb,
lib/aspera/ascp/log_analyzer.rb,
lib/aspera/cli/command/mount.rb,
lib/aspera/cli/option/source.rb,
lib/aspera/cli/plugins/oauth.rb,
lib/aspera/cli/secret_finder.rb,
lib/aspera/cli/vault_actions.rb,
lib/aspera/cli/vault_manager.rb,
lib/aspera/oauth/client/base.rb,
lib/aspera/oauth/client/boot.rb,
lib/aspera/oauth/server/pkce.rb,
lib/aspera/proxy_auto_config.rb,
lib/aspera/secret/store/base.rb,
lib/aspera/temp_file_manager.rb,
lib/aspera/web_auth/receiver.rb,
lib/aspera/web_server_simple.rb,
lib/aspera/ascp/log_locations.rb,
lib/aspera/cli/extended_value.rb,
lib/aspera/cli/plugins/config.rb,
lib/aspera/cli/preset_actions.rb,
lib/aspera/cli/preset_manager.rb,
lib/aspera/cli/special_values.rb,
lib/aspera/cli/terminal_image.rb,
lib/aspera/persistency_folder.rb,
lib/aspera/plugins/httpgw/api.rb,
lib/aspera/plugins/node/agent.rb,
lib/aspera/products/transferd.rb,
lib/aspera/rest/aspera_errors.rb,
lib/aspera/transfer/faux_file.rb,
lib/aspera/ascp/session_errors.rb,
lib/aspera/cli/option/registry.rb,
lib/aspera/cli/plugins/factory.rb,
lib/aspera/formatter_interface.rb,
lib/aspera/plugins/aoc/graphql.rb,
lib/aspera/plugins/faspex5/api.rb,
lib/aspera/plugins/xfer/helper.rb,
lib/aspera/rest/error_analyzer.rb,
lib/aspera/secret/store/keeper.rb,
lib/aspera/transfer/parameters.rb,
lib/aspera/ascp/data_repository.rb,
lib/aspera/cli/command/registry.rb,
lib/aspera/cli/mcp/http_servlet.rb,
lib/aspera/oauth/client/factory.rb,
lib/aspera/oauth/client/generic.rb,
lib/aspera/plugins/aoc/commands.rb,
lib/aspera/plugins/ats/commands.rb,
lib/aspera/plugins/cos/commands.rb,
lib/aspera/plugins/direct/agent.rb,
lib/aspera/plugins/httpgw/agent.rb,
lib/aspera/plugins/server/ascmd.rb,
lib/aspera/schema/documentation.rb,
lib/aspera/secret/store/factory.rb,
lib/aspera/cli/option/declarator.rb,
lib/aspera/cli/transfer_progress.rb,
lib/aspera/oauth/client/url_json.rb,
lib/aspera/plugins/alee/commands.rb,
lib/aspera/plugins/connect/agent.rb,
lib/aspera/plugins/desktop/agent.rb,
lib/aspera/plugins/node/commands.rb,
lib/aspera/plugins/node/emulator.rb,
lib/aspera/plugins/preview/utils.rb,
lib/aspera/plugins/transferd/api.rb,
lib/aspera/cli/completion_actions.rb,
lib/aspera/cli/plugins/basic_auth.rb,
lib/aspera/cli/terminal_formatter.rb,
lib/aspera/ascp/log_analyzer/lines.rb,
lib/aspera/ascp/log_analyzer/rules.rb,
lib/aspera/persistency_action_once.rb,
lib/aspera/plugins/faspio/commands.rb,
lib/aspera/plugins/httpgw/commands.rb,
lib/aspera/plugins/server/commands.rb,
lib/aspera/plugins/shares/commands.rb,
lib/aspera/plugins/transferd/agent.rb,
lib/aspera/ascp/log_analyzer/advice.rb,
lib/aspera/plugins/console/commands.rb,
lib/aspera/plugins/faspex5/commands.rb,
lib/aspera/plugins/preview/commands.rb,
lib/aspera/plugins/transferd/client.rb,
lib/aspera/ascp/log_analyzer/records.rb,
lib/aspera/ascp/log_analyzer/session.rb,
lib/aspera/plugins/preview/generator.rb,
lib/aspera/plugins/shares/shares_web.rb,
lib/aspera/plugins/transferd/product.rb,
lib/aspera/plugins/transferd/service.rb,
lib/aspera/plugins/xfer/ascp_actions.rb,
lib/aspera/plugins/xfer/sync_actions.rb,
lib/aspera/ascp/log_analyzer/log_file.rb,
lib/aspera/plugins/faspex4/gw_servlet.rb,
lib/aspera/plugins/preview/file_types.rb,
lib/aspera/plugins/transferd/commands.rb,
lib/aspera/plugins/aoc/admin_resources.rb,
lib/aspera/plugins/xfer/transfer_agent.rb,
lib/aspera/secret/store/encrypted_hash.rb,
lib/aspera/secret/store/macos_security.rb,
lib/aspera/secret/store/secret_service.rb,
lib/aspera/plugins/xfer/config_commands.rb,
lib/aspera/secret/store/hashicorp_vault.rb,
lib/aspera/ascp/log_analyzer/diagnostics.rb,
lib/aspera/oauth/client/json_credentials.rb,
lib/aspera/plugins/orchestrator/commands.rb,
lib/aspera/plugins/xfer/transfer_actions.rb,
lib/aspera/secret/store/one_password_api.rb,
lib/aspera/secret/store/one_password_cli.rb,
lib/aspera/transfer/command_line_builder.rb,
lib/aspera/plugins/xfer/ascp_logs_actions.rb,
lib/aspera/secret/store/one_password_base.rb,
lib/aspera/plugins/faspex4/gateway_options.rb,
lib/aspera/transfer/command_line_converter.rb,
lib/aspera/plugins/transferd/config_commands.rb,
lib/aspera/plugins/xfer/async_transfer_store.rb,
lib/aspera/plugins/orchestrator/workflow_checker.rb,
lib/aspera/plugins/faspex5/faspex4_post_proc_servlet.rb

Overview

SPDX-FileCopyrightText: IBM Corp. SPDX-License-Identifier: Apache-2.0

Defined Under Namespace

Modules: Agent, Ascp, Cli, Colors, Coverage, FormatterInterface, Inflate, JsonRpc, Markdown, Mime, OAuth, Plugins, Products, Prompt, Rest, SSL, Schema, SealedHash, Secret, ServletHelpers, Sync, Transfer, Units, UriReader, WebAuth, WebPage, Yaml Classes: AssertError, AuthenticationError, BundleRegistry, DotContainer, EntityNotFound, Environment, EnvironmentError, Error, ExecSpec, IdGenerator, InternalError, LineLogger, LinkHeader, Log, Nagios, ParameterError, PersistencyActionOnce, PersistencyFolder, ProxyAutoConfig, Ssh, StandardInput, TempFileManager, TimerLimiter, WebServerSimple

Class Method Summary collapse

Class Method Details

.assert(assertion, info = nil, type: AssertError) ⇒ Object

Assert that a condition is true, else raise exception The block is executed in the context of the Aspera module

Parameters:

  • assertion (Boolean) —

    Must be true

  • info (String, nil) (defaults to: nil) —

    Fixed message in case assert fails, else use block

  • type (Exception, Symbol) (defaults to: AssertError) —

    Exception to raise, or Symbol for Log.log level

Yield Returns:

  • (String) —

    A string that describes the problem for complex messages

Raises:



58
59
60
61
62
63
64
65
# File 'lib/aspera/assert.rb', line 58

def assert(assertion, info = nil, type: AssertError)
  raise InternalError, 'bad assert: both info and block given' unless info.nil? || !block_given?
  return if assertion
  message = 'assertion failed'
  info = yield if block_given?
  message = type.eql?(AssertError) ? "#{message}: #{info}" : info if info
  report_error(type, message)
end

.assert_array_all(array, klass, type: AssertError) ⇒ Object

Assert that all value of array are of the same specified type.

Parameters:

  • array (Array) —

    The array to check

  • klass (Class) —

    The expected type of elements

  • type (Exception, Symbol) (defaults to: AssertError) —

    Exception to raise, or Symbol for Log.log

Yield Returns:

  • (String) —

    Additional description to prepend to the error message



81
82
83
84
# File 'lib/aspera/assert.rb', line 81

def assert_array_all(array, klass, type: AssertError)
  assert_type(array, Array, type: AssertError) { 'array' }
  assert(array.all?(klass), type: type) { "#{"#{yield}: " if block_given?}expecting all as #{klass}, but have #{array.map(&:class).uniq}" }
end

.assert_hash_all(hash, key_class, value_class, type: AssertError) ⇒ Object

Assert value is Hash, keys have type, and Values have type

Parameters:

  • hash (Hash) —

    The hash to check

  • key_class (Class) —

    The expected type of keys (or nil for no check)

  • value_class (Class) —

    The expected type of values (or nil for no check)

  • type (Exception, Symbol) (defaults to: AssertError) —

    Exception to raise, or Symbol for Log.log

Yield Returns:

  • (String) —

    Additional description to prepend to the error message



92
93
94
95
96
# File 'lib/aspera/assert.rb', line 92

def assert_hash_all(hash, key_class, value_class, type: AssertError)
  assert_type(hash, Hash, type: AssertError) { 'hash' }
  assert_array_all(hash.keys, key_class, type: type) { "#{"#{yield}: " if block_given?}keys" } unless key_class.nil?
  assert_array_all(hash.values, value_class, type: type) { "#{"#{yield}: " if block_given?}values" } unless value_class.nil?
end

.assert_type(value, *classes, type: AssertError) ⇒ Object

Assert that value has the given type

Parameters:

  • value (Object) —

    The value to check

  • classes (Class, Array) —

    The expected type(s)

  • type (Exception, Symbol) (defaults to: AssertError) —

    Exception to raise, or Symbol for Log.log

Yield Returns:

  • (String) —

    Additional description to prepend to the error message



72
73
74
# File 'lib/aspera/assert.rb', line 72

def assert_type(value, *classes, type: AssertError)
  assert(classes.any? { |k| value.is_a?(k) }, type: type) { "#{"#{yield}: " if block_given?}expecting type #{classes.join(', ')}, but have (#{value.class})#{value.inspect}" }
end

.assert_values(value, values, type: AssertError) ⇒ Object

Assert that value is one of the given values

Parameters:

  • value (Object) —

    Value to check

  • values (Array) —

    Accepted values

  • type (Exception, Symbol) (defaults to: AssertError) —

    Exception to raise, or Symbol for Log.log

Yield Returns:

  • (String) —

    Additional description to prepend to the error message



103
104
105
106
107
108
109
110
# File 'lib/aspera/assert.rb', line 103

def assert_values(value, values, type: AssertError)
  assert_type(values, Array, type: AssertError) { 'values' }
  assert(values.include?(value), type: type) do
    val_list = values.inspect
    val_list = "one of #{val_list}" if values.is_a?(Array)
    "#{"#{yield}: " if block_given?}expecting #{val_list}, but have #{value.inspect}"
  end
end

.error_not_implemented ⇒ Object

Not implemented error

Raises:



126
127
128
# File 'lib/aspera/assert.rb', line 126

def error_not_implemented
  raise Error, 'Feature not yet implemented'
end

.error_unexpected_value(value, type: InternalError) ⇒ Object

The value is not one of the expected values

Parameters:

  • value (Object) —

    The wrong value

  • type (Exception, Symbol) (defaults to: InternalError) —

    Exception to raise, or Symbol for Log.log

Yield Returns:

  • (String) —

    Additional description to prepend to the error message



116
117
118
# File 'lib/aspera/assert.rb', line 116

def error_unexpected_value(value, type: InternalError)
  report_error(type, "#{"#{yield}: " if block_given?}unexpected value: #{value.inspect}")
end

.error_unreachable_line ⇒ Object

The line with this shall never be reached

Raises:



121
122
123
# File 'lib/aspera/assert.rb', line 121

def error_unreachable_line
  raise InternalError, "unreachable line reached: #{caller(2..2).first}"
end

.report_error(type, message) ⇒ nil

Replaces raise in assertion Allows sending exception, or just error log, when type is :error

Parameters:

  • type (Exception, Symbol) —

    Send to log if symbol, else raise exception

  • message (String) —

    Message for error.

Returns:

  • (nil)

Raises:

  • (Exception)


42
43
44
45
46
47
48
49
50
# File 'lib/aspera/assert.rb', line 42

def report_error(type, message)
  if type.is_a?(Symbol)
    require_relative 'log'
    Log.log.send(type, message)
  else
    raise type, message
  end
  nil
end

.require_method!(name) ⇒ Object

Use in superclass to require the given method in subclass.



131
132
133
134
135
# File 'lib/aspera/assert.rb', line 131

def require_method!(name)
  define_method(name) do |*_args|
    raise NotImplementedError, "#{self.class} must implement the #{name} method"
  end
end