aspera-cli 4.29.1 → 4.30.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +4 -4
- data/CHANGELOG.md +119 -0
- data/CONTRIBUTING.md +8 -1
- data/README.md +2 -0
- data/TODO.md +4 -5
- data/bin/asession +2 -2
- data/docs/README.md +616 -86
- data/docs/test-mcp-with-ai.md +4 -0
- data/lib/aspera/agent/base.rb +62 -6
- data/lib/aspera/agent/factory.rb +127 -20
- data/lib/aspera/ascp/data_repository.rb +71 -0
- data/lib/aspera/ascp/installation.rb +16 -11
- data/lib/aspera/ascp/log_analyzer/lines.rb +4 -4
- data/lib/aspera/ascp/log_analyzer/log_file.rb +5 -3
- data/lib/aspera/ascp/log_analyzer/records.rb +11 -6
- data/lib/aspera/ascp/log_analyzer.rb +43 -18
- data/lib/aspera/ascp/log_locations.rb +2 -2
- data/lib/aspera/assert.rb +8 -0
- data/lib/aspera/bundle_registry.rb +528 -0
- data/lib/aspera/cli/argument.rb +110 -0
- data/lib/aspera/cli/bool_value.rb +41 -0
- data/lib/aspera/cli/bootstrapper.rb +31 -24
- data/lib/aspera/cli/command/mount.rb +53 -0
- data/lib/aspera/cli/command/registry.rb +434 -0
- data/lib/aspera/cli/command.rb +95 -0
- data/lib/aspera/cli/command_line.rb +91 -91
- data/lib/aspera/cli/complete.rb +22 -0
- data/lib/aspera/cli/completion_actions.rb +28 -26
- data/lib/aspera/cli/context.rb +29 -6
- data/lib/aspera/cli/error.rb +39 -0
- data/lib/aspera/cli/extended_value.rb +25 -4
- data/lib/aspera/cli/formatter.rb +8 -8
- data/lib/aspera/cli/hints.rb +17 -52
- data/lib/aspera/cli/http.rb +17 -12
- data/lib/aspera/cli/mailer.rb +7 -24
- data/lib/aspera/cli/mcp/tool.rb +10 -2
- data/lib/aspera/cli/option/declarator.rb +80 -0
- data/lib/aspera/cli/option/registry.rb +74 -0
- data/lib/aspera/cli/option/source.rb +38 -0
- data/lib/aspera/cli/option/type.rb +37 -0
- data/lib/aspera/cli/option/value.rb +376 -0
- data/lib/aspera/cli/option.rb +78 -0
- data/lib/aspera/cli/options.schema.yaml +28 -783
- data/lib/aspera/cli/parser.rb +73 -41
- data/lib/aspera/cli/plugins/base.rb +122 -42
- data/lib/aspera/cli/plugins/basic_auth.rb +13 -2
- data/lib/aspera/cli/plugins/config.rb +101 -167
- data/lib/aspera/cli/plugins/factory.rb +139 -43
- data/lib/aspera/cli/plugins/mcp.rb +61 -54
- data/lib/aspera/cli/plugins/oauth.rb +19 -6
- data/lib/aspera/cli/poll.rb +14 -20
- data/lib/aspera/cli/preset_actions.rb +11 -3
- data/lib/aspera/cli/preset_manager.rb +16 -6
- data/lib/aspera/cli/result.rb +2 -2
- data/lib/aspera/cli/runner.rb +71 -99
- data/lib/aspera/cli/secret_finder.rb +1 -1
- data/lib/aspera/cli/security.rb +102 -4
- data/lib/aspera/{preview/terminal.rb → cli/terminal_image.rb} +93 -94
- data/lib/aspera/cli/vault_manager.rb +3 -3
- data/lib/aspera/cli/version.rb +1 -1
- data/lib/aspera/cli/wizard.rb +9 -3
- data/lib/aspera/coverage.rb +1 -2
- data/lib/aspera/line_logger.rb +35 -6
- data/lib/aspera/log.rb +3 -2
- data/lib/aspera/oauth/client/base.rb +19 -1
- data/lib/aspera/oauth/client/factory.rb +1 -7
- data/lib/aspera/plugin.schema.yaml +178 -0
- data/lib/aspera/plugins/alee/api.rb +25 -0
- data/lib/aspera/{cli/plugins/alee.rb → plugins/alee/commands.rb} +10 -8
- data/lib/aspera/plugins/alee/plugin.yaml +3 -0
- data/lib/aspera/plugins/aoc/admin_resources.rb +148 -0
- data/lib/aspera/plugins/aoc/api.rb +783 -0
- data/lib/aspera/{cli/plugins/aoc.rb → plugins/aoc/commands.rb} +404 -330
- data/lib/aspera/plugins/aoc/graphql.rb +45 -0
- data/lib/aspera/plugins/aoc/plugin.yaml +31 -0
- data/lib/aspera/{schema → plugins/aoc/schemas}/IBM Aspera on Cloud API-0.2.6-enhanced.yaml +15042 -7076
- data/lib/aspera/plugins/aoc/schemas/options.yaml +47 -0
- data/lib/aspera/plugins/ats/api.rb +51 -0
- data/lib/aspera/{cli/plugins/ats.rb → plugins/ats/commands.rb} +33 -33
- data/lib/aspera/plugins/ats/plugin.yaml +6 -0
- data/lib/aspera/plugins/connect/agent.rb +199 -0
- data/lib/aspera/plugins/connect/plugin.yaml +11 -0
- data/lib/aspera/plugins/connect/schemas/agent_options.yaml +6 -0
- data/lib/aspera/{cli/plugins/console.rb → plugins/console/commands.rb} +41 -33
- data/lib/aspera/plugins/console/plugin.yaml +8 -0
- data/lib/aspera/plugins/cos/api.rb +114 -0
- data/lib/aspera/{cli/plugins/cos.rb → plugins/cos/commands.rb} +19 -16
- data/lib/aspera/plugins/cos/plugin.yaml +9 -0
- data/lib/aspera/plugins/cos/schemas/options.yaml +30 -0
- data/lib/aspera/plugins/desktop/agent.rb +165 -0
- data/lib/aspera/plugins/desktop/plugin.yaml +11 -0
- data/lib/aspera/plugins/desktop/schemas/agent_options.yaml +6 -0
- data/lib/aspera/plugins/direct/agent.rb +518 -0
- data/lib/aspera/plugins/direct/plugin.yaml +11 -0
- data/lib/aspera/plugins/direct/schemas/agent_options.yaml +86 -0
- data/lib/aspera/plugins/faspex4/gateway_options.rb +18 -0
- data/lib/aspera/plugins/faspex4/gw_servlet.rb +122 -0
- data/lib/aspera/plugins/faspex4/plugin.yaml +7 -0
- data/lib/aspera/plugins/faspex4/schemas/options.yaml +57 -0
- data/lib/aspera/plugins/faspex5/api.rb +269 -0
- data/lib/aspera/{cli/plugins/faspex5.rb → plugins/faspex5/commands.rb} +152 -114
- data/lib/aspera/plugins/faspex5/faspex4_post_proc_servlet.rb +241 -0
- data/lib/aspera/plugins/faspex5/plugin.yaml +14 -0
- data/lib/aspera/{schema → plugins/faspex5/schemas}/IBM Aspera Faspex API-5.0-enhanced.yaml +279 -76
- data/lib/aspera/plugins/faspex5/schemas/options.yaml +87 -0
- data/lib/aspera/{cli/plugins/faspio.rb → plugins/faspio/commands.rb} +11 -7
- data/lib/aspera/plugins/faspio/plugin.yaml +8 -0
- data/lib/aspera/{schema → plugins/faspio/schemas}/IBM Aspera faspio Gateway API-1.0.0-enhanced.yaml +4 -2
- data/lib/aspera/plugins/httpgw/agent.rb +126 -0
- data/lib/aspera/plugins/httpgw/api.rb +411 -0
- data/lib/aspera/{cli/plugins/httpgw.rb → plugins/httpgw/commands.rb} +9 -9
- data/lib/aspera/plugins/httpgw/plugin.yaml +12 -0
- data/lib/aspera/plugins/httpgw/schemas/agent_options.yaml +24 -0
- data/lib/aspera/plugins/node/agent.rb +184 -0
- data/lib/aspera/plugins/node/api.rb +699 -0
- data/lib/aspera/{cli/plugins/node.rb → plugins/node/commands.rb} +166 -141
- data/lib/aspera/plugins/node/emulator.rb +774 -0
- data/lib/aspera/plugins/node/plugin.yaml +20 -0
- data/lib/aspera/plugins/node/schemas/agent_options.yaml +20 -0
- data/lib/aspera/plugins/node/schemas/options.yaml +190 -0
- data/lib/aspera/{cli/plugins/orchestrator.rb → plugins/orchestrator/commands.rb} +139 -110
- data/lib/aspera/plugins/orchestrator/plugin.yaml +34 -0
- data/lib/aspera/{schema → plugins/orchestrator/schemas}/IBM Aspera Orchestrator API-v1-enhanced.yaml +486 -16
- data/lib/aspera/plugins/orchestrator/schemas/options.yaml +143 -0
- data/lib/aspera/plugins/orchestrator/workflow_checker.rb +692 -0
- data/lib/aspera/{cli/plugins/preview.rb → plugins/preview/commands.rb} +53 -51
- data/lib/aspera/plugins/preview/file_types.rb +121 -0
- data/lib/aspera/plugins/preview/generator.rb +350 -0
- data/lib/aspera/plugins/preview/plugin.yaml +12 -0
- data/lib/aspera/{preview/options.schema.yaml → plugins/preview/schemas/options.yaml} +1 -1
- data/lib/aspera/plugins/preview/utils.rb +213 -0
- data/lib/aspera/plugins/server/ascmd.rb +374 -0
- data/lib/aspera/{cli/plugins/server.rb → plugins/server/commands.rb} +48 -32
- data/lib/aspera/plugins/server/plugin.yaml +9 -0
- data/lib/aspera/plugins/server/schemas/options.yaml +30 -0
- data/lib/aspera/{cli/plugins/shares.rb → plugins/shares/commands.rb} +29 -21
- data/lib/aspera/plugins/shares/plugin.yaml +10 -0
- data/lib/aspera/plugins/shares/shares_web.rb +97 -0
- data/lib/aspera/plugins/transferd/agent.rb +258 -0
- data/lib/aspera/plugins/transferd/api.rb +180 -0
- data/lib/aspera/plugins/transferd/client.rb +67 -0
- data/lib/aspera/{cli/plugins/transferd.rb → plugins/transferd/commands.rb} +43 -42
- data/lib/aspera/plugins/transferd/config_commands.rb +38 -0
- data/lib/aspera/plugins/transferd/plugin.yaml +27 -0
- data/lib/aspera/plugins/transferd/product.rb +146 -0
- data/lib/aspera/plugins/transferd/schemas/agent_options.yaml +31 -0
- data/lib/aspera/plugins/transferd/schemas/options.yaml +80 -0
- data/lib/aspera/plugins/transferd/service.rb +617 -0
- data/lib/aspera/plugins/xfer/ascp_actions.rb +131 -0
- data/lib/aspera/plugins/xfer/ascp_logs_actions.rb +198 -0
- data/lib/aspera/plugins/xfer/async_transfer_store.rb +131 -0
- data/lib/aspera/plugins/xfer/config_commands.rb +119 -0
- data/lib/aspera/plugins/xfer/helper.rb +19 -0
- data/lib/aspera/plugins/xfer/plugin.yaml +42 -0
- data/lib/aspera/plugins/xfer/schemas/agent_extension.schema.yaml +26 -0
- data/lib/aspera/plugins/xfer/schemas/options.yaml +125 -0
- data/lib/aspera/plugins/xfer/sync_actions.rb +253 -0
- data/lib/aspera/plugins/xfer/transfer_actions.rb +176 -0
- data/lib/aspera/plugins/xfer/transfer_agent.rb +505 -0
- data/lib/aspera/products/cli_v3.rb +34 -0
- data/lib/aspera/products/connect.rb +1 -1
- data/lib/aspera/products/drive.rb +29 -0
- data/lib/aspera/products/hsts.rb +34 -0
- data/lib/aspera/products/transferd.rb +25 -3
- data/lib/aspera/products.rb +54 -0
- data/lib/aspera/prompt.rb +184 -0
- data/lib/aspera/proxy_auto_config.rb +3 -3
- data/lib/aspera/rest/aspera_errors.rb +4 -38
- data/lib/aspera/rest/error_analyzer.rb +6 -2
- data/lib/aspera/rest/list.rb +4 -5
- data/lib/aspera/schema/reader.rb +15 -0
- data/lib/aspera/schema/registry.rb +239 -45
- data/lib/aspera/schema/validator.rb +63 -17
- data/lib/aspera/sealed_hash.rb +4 -0
- data/lib/aspera/secret/hider.rb +159 -24
- data/lib/aspera/secret/reference.rb +8 -0
- data/lib/aspera/secret/resolver.rb +8 -4
- data/lib/aspera/secret/store/base.rb +10 -9
- data/lib/aspera/secret/store/encrypted_hash.rb +6 -6
- data/lib/aspera/secret/store/hashicorp_vault.rb +3 -3
- data/lib/aspera/secret/store/keeper.rb +2 -2
- data/lib/aspera/secret/store/macos_security.rb +2 -3
- data/lib/aspera/secret/store/one_password_api.rb +2 -2
- data/lib/aspera/secret/store/one_password_cli.rb +3 -3
- data/lib/aspera/secret/store/secret_service.rb +2 -2
- data/lib/aspera/ssl.rb +3 -3
- data/lib/aspera/standard_input.rb +20 -0
- data/lib/aspera/{schema → sync}/async_tables.yaml +1 -1
- data/lib/aspera/sync/database.rb +7 -0
- data/lib/aspera/sync/log_parser.rb +138 -0
- data/lib/aspera/sync/operations.rb +59 -34
- data/lib/aspera/transfer/command_line_builder.rb +248 -0
- data/lib/aspera/transfer/command_line_converter.rb +37 -0
- data/lib/aspera/transfer/faux_file.rb +2 -2
- data/lib/aspera/transfer/parameters.rb +9 -10
- data/lib/aspera/transfer/spec.rb +28 -1
- data/lib/aspera/transfer/spec.schema.yaml +30 -5
- data/lib/aspera/units/decimal.rb +1 -1
- data/lib/aspera/units/timestamp.rb +84 -0
- data/lib/aspera/uri_reader.rb +2 -2
- data/lib/aspera/web_auth/paste.rb +2 -2
- data/lib/aspera/web_server_simple.rb +10 -4
- data.tar.gz.sig +0 -0
- metadata +137 -80
- metadata.gz.sig +0 -0
- data/lib/aspera/agent/connect.rb +0 -188
- data/lib/aspera/agent/desktop.rb +0 -154
- data/lib/aspera/agent/direct.rb +0 -496
- data/lib/aspera/agent/httpgw.rb +0 -100
- data/lib/aspera/agent/node.rb +0 -166
- data/lib/aspera/agent/transferd.rb +0 -341
- data/lib/aspera/api/alee.rb +0 -19
- data/lib/aspera/api/aoc.rb +0 -776
- data/lib/aspera/api/ats.rb +0 -49
- data/lib/aspera/api/cos_node.rb +0 -107
- data/lib/aspera/api/faspex.rb +0 -258
- data/lib/aspera/api/httpgw.rb +0 -409
- data/lib/aspera/api/node.rb +0 -684
- data/lib/aspera/ascmd.rb +0 -248
- data/lib/aspera/cli/ascp_actions.rb +0 -113
- data/lib/aspera/cli/ascp_logs_actions.rb +0 -188
- data/lib/aspera/cli/async_transfer_store.rb +0 -129
- data/lib/aspera/cli/command_registry.rb +0 -371
- data/lib/aspera/cli/command_spec.rb +0 -273
- data/lib/aspera/cli/option_declarator.rb +0 -74
- data/lib/aspera/cli/option_registry.rb +0 -72
- data/lib/aspera/cli/option_types.rb +0 -120
- data/lib/aspera/cli/option_value.rb +0 -345
- data/lib/aspera/cli/prompt.rb +0 -186
- data/lib/aspera/cli/sync_actions.rb +0 -181
- data/lib/aspera/cli/transfer_actions.rb +0 -98
- data/lib/aspera/cli/transfer_agent.rb +0 -348
- data/lib/aspera/command_line_builder.rb +0 -244
- data/lib/aspera/command_line_converter.rb +0 -35
- data/lib/aspera/data_repository.rb +0 -69
- data/lib/aspera/faspex_gw.rb +0 -172
- data/lib/aspera/faspex_postproc.rb +0 -237
- data/lib/aspera/graphql.rb +0 -41
- data/lib/aspera/node_emulator.rb +0 -758
- data/lib/aspera/oauth/client/shares_web.rb +0 -94
- data/lib/aspera/orchestrator_workflow_checker.rb +0 -688
- data/lib/aspera/preview/file_types.rb +0 -119
- data/lib/aspera/preview/generator.rb +0 -345
- data/lib/aspera/preview/utils.rb +0 -211
- data/lib/aspera/products/other.rb +0 -92
- data/lib/aspera/products/transferd_service.rb +0 -610
- /data/lib/aspera/{data → ascp/data}/1 +0 -0
- /data/lib/aspera/{data → ascp/data}/2 +0 -0
- /data/lib/aspera/{data → ascp/data}/3 +0 -0
- /data/lib/aspera/{data → ascp/data}/4 +0 -0
- /data/lib/aspera/{data → ascp/data}/5 +0 -0
- /data/lib/aspera/{data → ascp/data}/6 +0 -0
- /data/lib/aspera/{api → plugins/aoc}/queries/bss_subscription_account.graphql +0 -0
- /data/lib/aspera/{api → plugins/aoc}/queries/bss_subscription_usage.graphql +0 -0
- /data/lib/aspera/{schema → plugins/aoc/schemas}/IBM Aspera on Cloud Automation API-1.0.5-enhanced.yaml +0 -0
- /data/lib/aspera/{schema → plugins/console/schemas}/IBM Aspera Console-enhanced.yaml +0 -0
- /data/lib/aspera/{schema → plugins/node/schemas}/IBM Aspera Node API-4.4.6.yaml +0 -0
- /data/lib/aspera/{preview → plugins/preview}/image_error.png +0 -0
- /data/lib/aspera/{preview → plugins/preview}/video_error.png +0 -0
- /data/lib/aspera/{schema → plugins/shares/schemas}/IBM_Aspera_Shares.yaml +0 -0
- /data/lib/{transferd_pb.rb → aspera/plugins/transferd/grpc/transferd_pb.rb} +0 -0
- /data/lib/{transferd_services_pb.rb → aspera/plugins/transferd/grpc/transferd_services_pb.rb} +0 -0
- /data/lib/aspera/{schema → plugins/transferd/schemas}/transferd-config.schema.json +0 -0
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../option'
|
|
7
|
+
require_relative 'type'
|
|
8
|
+
require_relative 'source'
|
|
9
|
+
require_relative '../bool_value'
|
|
10
|
+
require_relative '../complete'
|
|
11
|
+
require_relative '../error'
|
|
12
|
+
require_relative '../extended_value'
|
|
13
|
+
require_relative '../security'
|
|
14
|
+
require_relative '../deprecation'
|
|
15
|
+
require_relative '../../secret/hider'
|
|
16
|
+
require_relative '../../schema/registry'
|
|
17
|
+
require_relative '../../schema/validator'
|
|
18
|
+
require_relative '../../log'
|
|
19
|
+
require_relative '../../assert'
|
|
20
|
+
|
|
21
|
+
module Aspera
|
|
22
|
+
module Cli
|
|
23
|
+
class Option
|
|
24
|
+
# Declared option: type, value, and where the value is stored.
|
|
25
|
+
class Value
|
|
26
|
+
# [Symbol] Name of option
|
|
27
|
+
attr_reader :option
|
|
28
|
+
# [Array<Class>, nil] List of allowed types, `nil` for no validation
|
|
29
|
+
attr_reader :types
|
|
30
|
+
# [Symbol] How values are converted: :flag, :boolean, :integer, :float, :enum, :enum_list, :string_list, :other
|
|
31
|
+
attr_reader :kind
|
|
32
|
+
# [Symbol, nil] `Option::Source` of current value, `nil` if never set
|
|
33
|
+
attr_reader :source
|
|
34
|
+
attr_reader :sensitive, :schema, :deprecation
|
|
35
|
+
# [Symbol, nil] Most restrictive security level at which the option is available, `nil`: all levels, see `Security`
|
|
36
|
+
attr_reader :security
|
|
37
|
+
# [String, nil] For a `Hash` option: key of a `String` value
|
|
38
|
+
attr_reader :shorthand
|
|
39
|
+
# [Symbol, nil] Values proposed by shell completion, one of `Complete::KINDS`
|
|
40
|
+
attr_reader :complete
|
|
41
|
+
# [Array] List of allowed values (Symbols and specific values)
|
|
42
|
+
attr_accessor :values
|
|
43
|
+
# [String] Help section group name (set by Option::Registry)
|
|
44
|
+
attr_accessor :group
|
|
45
|
+
# [String, nil] Short option char (set by Option::Registry)
|
|
46
|
+
attr_accessor :short
|
|
47
|
+
# [Proc, nil] Block to call for flag options
|
|
48
|
+
attr_accessor :block
|
|
49
|
+
|
|
50
|
+
# @param option [Symbol] Name of option
|
|
51
|
+
# @param description [String, nil] Description for help; if nil, derived from schema
|
|
52
|
+
# @param allowed [nil,Class,Array<Class>,Array<Symbol>] Allowed values
|
|
53
|
+
# @param on_set [#call, nil] Called with the new value each time the value is set
|
|
54
|
+
# @param shorthand [String, nil] For a `Hash` option: a `String` value is stored as `{shorthand => value}`
|
|
55
|
+
# @param convert [#call, nil] For a `Hash` option: called with a new `Hash` value, returns the value to store, before merge (e.g. conversion of a deprecated form)
|
|
56
|
+
# @param deprecation [Hash, Deprecation, nil] Deprecation: `{last:, message:}`, see `Deprecation`
|
|
57
|
+
# @param schema [String] Declaration of schema
|
|
58
|
+
# @param complete [Symbol, nil] Values proposed by shell completion, one of `Complete::KINDS`
|
|
59
|
+
# @param security [Symbol, nil] Most restrictive security level at which the option is available (e.g. `:low`: executes code), see `Security`
|
|
60
|
+
# `allowed`:
|
|
61
|
+
# - `nil` No validation, so just a string
|
|
62
|
+
# - `Class` The single allowed Class
|
|
63
|
+
# - `Array<Class>` Multiple allowed classes
|
|
64
|
+
# - `Array<Symbol>` List of allowed values
|
|
65
|
+
def initialize(option:, description: nil, allowed: Type::STRING, on_set: nil, shorthand: nil, convert: nil, deprecation: nil, schema: nil, complete: nil, security: nil)
|
|
66
|
+
Log.log.trace1 { "option: #{option}, allowed: #{allowed}" }
|
|
67
|
+
@option = option
|
|
68
|
+
@description = description
|
|
69
|
+
@group = nil
|
|
70
|
+
@short = nil
|
|
71
|
+
@block = nil
|
|
72
|
+
# by default passwords and secrets are sensitive, else specify when declaring the option
|
|
73
|
+
@sensitive = Secret::Hider.instance.secret?(@option, '')
|
|
74
|
+
@deprecation = Deprecation.create(deprecation)
|
|
75
|
+
@schema = schema
|
|
76
|
+
@shorthand = shorthand
|
|
77
|
+
Aspera.assert(convert.nil? || convert.respond_to?(:call)) { "#{@option}: convert must respond to call" }
|
|
78
|
+
@convert = convert
|
|
79
|
+
Aspera.assert_values(complete, Complete::KINDS + [nil]) { "#{@option}: complete" }
|
|
80
|
+
@complete = complete
|
|
81
|
+
Aspera.assert_values(security, Security::LEVELS + [nil]) { "#{@option}: security" }
|
|
82
|
+
@security = security
|
|
83
|
+
@source = nil
|
|
84
|
+
@value = nil
|
|
85
|
+
Aspera.assert(on_set.nil? || on_set.respond_to?(:call)) { "#{@option}: on_set callback must respond to call" }
|
|
86
|
+
@on_set = on_set
|
|
87
|
+
@types = nil
|
|
88
|
+
@values = nil
|
|
89
|
+
@kind = :other
|
|
90
|
+
allowed = infer_allowed_from_schema(schema, allowed) if schema
|
|
91
|
+
apply_allowed(allowed) unless allowed.nil?
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# @return [String] description of the option: explicit one, or first line of schema description
|
|
95
|
+
def description
|
|
96
|
+
return @description unless @description.nil?
|
|
97
|
+
return if @schema.nil?
|
|
98
|
+
schema_node = Schema::Registry.instance.reader(@schema).current
|
|
99
|
+
first_line = (schema_node['title'] || schema_node['description'].to_s).lines.first.to_s.strip
|
|
100
|
+
first_line.end_with?('.') ? first_line[0..-2] : first_line
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# @return [String, nil] allowed values, or expected types when not plain `String`, e.g. `Hash|String`
|
|
104
|
+
def allowed_info
|
|
105
|
+
return @values.join('|') if @values&.any?
|
|
106
|
+
types = @types&.reject { |t| t.eql?(NilClass) }
|
|
107
|
+
return if types.nil? || types.empty? || types.eql?(Type::STRING)
|
|
108
|
+
types.map(&:name).join('|')
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# @return [Boolean] `true` if option takes no value
|
|
112
|
+
def flag? = @kind.eql?(:flag)
|
|
113
|
+
|
|
114
|
+
# @param value [Object] value given to option
|
|
115
|
+
# @return [Boolean] `true` if value asks for the schema of option
|
|
116
|
+
def schema_request?(value) = value.eql?(SchemaRequest::KEYWORD) && @types&.include?(Hash)
|
|
117
|
+
|
|
118
|
+
# Reset stored value to nil
|
|
119
|
+
# @return [nil]
|
|
120
|
+
def clear
|
|
121
|
+
store(nil, nil)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Get current option value
|
|
125
|
+
# @param log [Boolean] whether to log the value retrieval
|
|
126
|
+
# @return [Object] current value
|
|
127
|
+
def value(log: true)
|
|
128
|
+
Log.log.trace1 { "#{@option} -> (#{@value.class})#{Secret::Hider.instance.hidden_copy(@value)}" } if log
|
|
129
|
+
@value
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Assign value to option.
|
|
133
|
+
# Value can be a `String`, then evaluated with `ExtendedValue`, or directly a value.
|
|
134
|
+
# `Hash` and `Array` values are merged with current value.
|
|
135
|
+
# @param value [String, Object] Value to assign to option
|
|
136
|
+
# @param source [Symbol] `Option::Source` of value
|
|
137
|
+
# @param warn_deprecation [Boolean] Emit deprecation warning (false for internal transfers)
|
|
138
|
+
# @param merge [Boolean] Merge `Hash` and `Array` with current value (false: value is already complete)
|
|
139
|
+
# @param final [Boolean] The value is final: values from a lower source (preset, environment) are ignored, not merged nor checked
|
|
140
|
+
# @param configured [Boolean] Value of a preset read from the configuration (by its name): set by the operator, not restricted by the security level
|
|
141
|
+
# (a client cannot change the configuration at levels `medium` and `high`), see `Parser#add_option_preset`
|
|
142
|
+
# @return [nil]
|
|
143
|
+
# @raise [SchemaRequest] if value is `help` and schema is known
|
|
144
|
+
def assign_value(value, source:, warn_deprecation: true, merge: true, final: false, configured: false)
|
|
145
|
+
# Value from a source with lower priority than current value: only fills containers
|
|
146
|
+
lower = !@source.nil? && Option::Source.priority(source) < Option::Source.priority(@source)
|
|
147
|
+
# Final value (set by the program for the whole run): a lower source is ignored, even for a container
|
|
148
|
+
if lower && @final
|
|
149
|
+
Log.log.debug { "#{source}: #{@option}: ignored, final value set from #{@source}" }
|
|
150
|
+
return
|
|
151
|
+
end
|
|
152
|
+
if lower && ![Hash, Array].include?(@types&.first)
|
|
153
|
+
Log.log.debug { "#{source}: #{@option}: ignored, already set from #{@source}" }
|
|
154
|
+
return
|
|
155
|
+
end
|
|
156
|
+
Aspera.assert(!@deprecation, type: :warn) { "Option #{@option} is #{@deprecation}" } if warn_deprecation
|
|
157
|
+
# Values set by the program, the environment or the configuration are not restricted: those from command line, a preset given by the client, interactive input are
|
|
158
|
+
restricted = restricted_source?(source) && !configured
|
|
159
|
+
Security.instance.check_level(@security, "option #{@option}") if restricted
|
|
160
|
+
if schema_request?(value)
|
|
161
|
+
return if lower
|
|
162
|
+
raise SchemaRequest.new(:option, @option, @schema) unless @schema.nil?
|
|
163
|
+
# Schema depends on command: kept as-is, raised by Parser#get_option(schema:)
|
|
164
|
+
store(value, source)
|
|
165
|
+
return
|
|
166
|
+
end
|
|
167
|
+
new_value = coerce(ExtendedValue.instance.evaluate(value, context: "option: #{@option}", allowed: @types))
|
|
168
|
+
check_sub_options_security(new_value) if restricted
|
|
169
|
+
# Set by the one who starts the process: a secret (e.g. in a `Hash`) of the environment can be sent to a URL of the environment, see `Security#check_credentials_in`
|
|
170
|
+
Security.instance.add_configured(new_value) if source.eql?(:env)
|
|
171
|
+
new_value = {@shorthand => new_value} if @shorthand && new_value.is_a?(String)
|
|
172
|
+
declare_secrets(new_value)
|
|
173
|
+
Log.log.trace1 { "#{source}: #{@option} <- (#{new_value.class})#{Secret::Hider.instance.hidden_copy(new_value)}" }
|
|
174
|
+
Aspera.assert_type(new_value, *@types, type: BadArgument) { "Option #{@option}" } if @types
|
|
175
|
+
new_value = @convert.call(new_value) if @convert && new_value.is_a?(Hash)
|
|
176
|
+
if merge && (new_value.is_a?(Hash) || new_value.is_a?(Array))
|
|
177
|
+
current_value = @value
|
|
178
|
+
# An `Array` default value is replaced, not appended to
|
|
179
|
+
mergeable = current_value.is_a?(new_value.is_a?(Hash) ? Hash : Array) && !current_value.empty? &&
|
|
180
|
+
!(new_value.is_a?(Array) && [source, @source].include?(:default))
|
|
181
|
+
if lower
|
|
182
|
+
# Current value has priority: merge new value under it, unless explicitly emptied
|
|
183
|
+
return unless mergeable
|
|
184
|
+
new_value, current_value = current_value, new_value
|
|
185
|
+
source = @source
|
|
186
|
+
end
|
|
187
|
+
new_value = new_value.is_a?(Hash) ? current_value.deep_merge(new_value) : current_value + new_value if mergeable
|
|
188
|
+
end
|
|
189
|
+
# A value set by the program is not checked, e.g. `--out.img` sets option `image` with a value checked as part of option `out`
|
|
190
|
+
validate_schema(new_value, partial: true) unless source.eql?(:code)
|
|
191
|
+
store(new_value, source)
|
|
192
|
+
@final = true if final
|
|
193
|
+
nil
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Validate the value of the option once all sources are applied: `required` of the schema is enforced.
|
|
197
|
+
# @param value [Object] Value of the option
|
|
198
|
+
# @raise [BadArgument] if value does not match schema
|
|
199
|
+
def validate_complete(value)
|
|
200
|
+
validate_schema(value, partial: false)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
# Check that the option, and the sub-options present in a `Hash` value (`x-security` in schema), are available at current security level.
|
|
204
|
+
# Used for a value that is not assigned yet, e.g. to store in a preset.
|
|
205
|
+
# @param value [Object] Value of the option
|
|
206
|
+
# @raise [BadArgument] If refused at current level
|
|
207
|
+
def check_security(value)
|
|
208
|
+
Security.instance.check_level(@security, "option #{@option}")
|
|
209
|
+
check_sub_options_security(value)
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
private
|
|
213
|
+
|
|
214
|
+
# Values set by the program, or by the environment of the process (under control of the one who starts it), are not restricted:
|
|
215
|
+
# those from command line, presets and interactive input are, unless the preset is read from the configuration (`configured:` of #assign_value).
|
|
216
|
+
# @param source [Symbol] `Option::Source`
|
|
217
|
+
# @return [Boolean] `true` if a value from this source is checked against security level
|
|
218
|
+
def restricted_source?(source)
|
|
219
|
+
!%i[default code env].include?(source)
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
# @param value [Object] Value of the option
|
|
223
|
+
# @raise [BadArgument] If a sub-option with `x-security` in the schema is present and refused at current level
|
|
224
|
+
def check_sub_options_security(value)
|
|
225
|
+
return unless @schema && value.is_a?(Hash)
|
|
226
|
+
Schema::Registry.instance.reader(@schema).each_property do |property, _name, full_name, _required|
|
|
227
|
+
level = property['x-security']
|
|
228
|
+
next if level.nil?
|
|
229
|
+
# Value of the sub-option, if given (a `nil` value clears it)
|
|
230
|
+
given = full_name.split('.').reduce(value) { |node, key| node.is_a?(Hash) ? node.find { |k, _| k.to_s.eql?(key) }&.last : nil }
|
|
231
|
+
Security.instance.check_level(level.to_sym, "option #{@option}.#{full_name}") unless given.nil?
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
# Validate a structured value against the schema of the option.
|
|
236
|
+
# `null` values (removal of an entry) are ignored.
|
|
237
|
+
# @param value [Object] value to validate
|
|
238
|
+
# @param partial [Boolean] `true`: value may be completed by other sources, so `required` is not enforced
|
|
239
|
+
# @raise [BadArgument] if value does not match schema
|
|
240
|
+
def validate_schema(value, partial:)
|
|
241
|
+
return unless @schema && (value.is_a?(Hash) || value.is_a?(Array))
|
|
242
|
+
errors = Schema::Validator.instance.errors(value, @schema, partial: partial, ignore_null: true)
|
|
243
|
+
raise BadArgument, "Option #{@option}: #{errors.join('; ')} (use --#{@option.to_s.tr('_', '-')}=#{SchemaRequest::KEYWORD} for schema)" unless errors.empty?
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# Derive the `allowed:` value from the schema when not explicitly provided.
|
|
247
|
+
# Returns `allowed` unchanged when the schema provides no usable type information.
|
|
248
|
+
# @param schema [String] schema identifier
|
|
249
|
+
# @param allowed [Object] caller-supplied allowed value (may be nil or Type::STRING)
|
|
250
|
+
# @return [Object] resolved allowed (Hash, Array, or the original value)
|
|
251
|
+
def infer_allowed_from_schema(schema, allowed)
|
|
252
|
+
return allowed unless allowed.nil? || allowed.eql?(Type::STRING)
|
|
253
|
+
|
|
254
|
+
schema_reader = Schema::Registry.instance.reader(schema) rescue nil
|
|
255
|
+
schema_node = schema_reader&.current
|
|
256
|
+
return allowed unless schema_node
|
|
257
|
+
|
|
258
|
+
case schema_node['type']
|
|
259
|
+
when 'object' then return Hash
|
|
260
|
+
when 'array' then return Array
|
|
261
|
+
end
|
|
262
|
+
# No top-level type: inspect oneOf/anyOf branches; if all resolve to 'object', infer Hash
|
|
263
|
+
composite_key = (%w[oneOf anyOf] & schema_node.keys).first
|
|
264
|
+
return allowed unless composite_key
|
|
265
|
+
|
|
266
|
+
branch_types = schema_node[composite_key].map do |branch|
|
|
267
|
+
resolved = branch['$ref'] ? schema_reader.resolve_ref(branch['$ref']).current : branch
|
|
268
|
+
resolved['type']
|
|
269
|
+
end
|
|
270
|
+
if branch_types.all?('object')
|
|
271
|
+
Hash
|
|
272
|
+
else
|
|
273
|
+
Aspera.assert(
|
|
274
|
+
!allowed.nil? && !allowed.eql?(Type::STRING),
|
|
275
|
+
"option :#{@option}: schema '#{schema}' has mixed-type oneOf branches #{branch_types.uniq}: specify allowed: explicitly"
|
|
276
|
+
)
|
|
277
|
+
allowed
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
# Initialize @types, @values and @kind from the resolved `allowed` specifier.
|
|
282
|
+
# @param allowed [Class, Array<Class>, Array<Symbol>] resolved allowed value (never nil)
|
|
283
|
+
def apply_allowed(allowed)
|
|
284
|
+
allowed = [allowed] if allowed.is_a?(Class)
|
|
285
|
+
Aspera.assert_type(allowed, Array)
|
|
286
|
+
if allowed.eql?(Type::NONE)
|
|
287
|
+
@kind = :flag
|
|
288
|
+
@types = Type::NONE
|
|
289
|
+
elsif allowed.take(Type::SYMBOL_ARRAY.length) == Type::SYMBOL_ARRAY
|
|
290
|
+
# Array of defined symbol values
|
|
291
|
+
@kind = :enum_list
|
|
292
|
+
@types = Type::SYMBOL_ARRAY
|
|
293
|
+
@values = allowed[Type::SYMBOL_ARRAY.length..]
|
|
294
|
+
elsif allowed.all?(Symbol)
|
|
295
|
+
@kind = :enum
|
|
296
|
+
@types = Type::ENUM
|
|
297
|
+
@values = allowed
|
|
298
|
+
elsif allowed.all?(Class)
|
|
299
|
+
@types = allowed
|
|
300
|
+
@kind =
|
|
301
|
+
if allowed.sort_by(&:name).eql?(Type::BOOLEAN) then :boolean
|
|
302
|
+
elsif allowed.eql?(Type::INTEGER) then :integer
|
|
303
|
+
elsif allowed.eql?(Type::FLOAT) then :float
|
|
304
|
+
elsif allowed.eql?(Type::STRING_ARRAY) then :string_list
|
|
305
|
+
else :other
|
|
306
|
+
end
|
|
307
|
+
@values = BoolValue::ALL if @kind.eql?(:boolean)
|
|
308
|
+
else
|
|
309
|
+
Aspera.error_unexpected_value(allowed)
|
|
310
|
+
end
|
|
311
|
+
# Containers start empty, unless nil is allowed
|
|
312
|
+
default = {Array => [], Hash => {}}[@types.first]
|
|
313
|
+
store(default, :default) if !default.nil? && !@types.include?(NilClass) && @value.nil?
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
# Convert value from command line, env or preset (String) to the type of option
|
|
317
|
+
# @param value [Object] evaluated value
|
|
318
|
+
# @return [Object] converted value
|
|
319
|
+
def coerce(value)
|
|
320
|
+
case @kind
|
|
321
|
+
when :enum
|
|
322
|
+
# Boolean from dot-path value, e.g. `no` for `%i[no header read]`
|
|
323
|
+
value = (value ? BoolValue::YES_SYM : BoolValue::NO_SYM).to_s if BoolValue::TYPES.include?(value.class)
|
|
324
|
+
value.is_a?(String) ? Parser.get_from_list(value, @option, @values) : value
|
|
325
|
+
when :boolean
|
|
326
|
+
BoolValue.true?(value.is_a?(String) ? Parser.get_from_list(value, @option, BoolValue::ALL) : value)
|
|
327
|
+
when :integer
|
|
328
|
+
# Decimal, also with leading zeros (e.g. `08`)
|
|
329
|
+
if value.is_a?(String)
|
|
330
|
+
Integer(value, 10, exception: false).tap { |i| raise BadArgument, "Option #{@option}: invalid integer: #{value}" if i.nil? }
|
|
331
|
+
else
|
|
332
|
+
value.nil? ? value : Integer(value)
|
|
333
|
+
end
|
|
334
|
+
when :float
|
|
335
|
+
if value.is_a?(String)
|
|
336
|
+
Float(value, exception: false).tap { |f| raise BadArgument, "Option #{@option}: invalid number: #{value}" if f.nil? }
|
|
337
|
+
else
|
|
338
|
+
value.nil? ? value : Float(value)
|
|
339
|
+
end
|
|
340
|
+
when :string_list
|
|
341
|
+
value = [value] if value.is_a?(String)
|
|
342
|
+
# Not an `Array`: refused by the type check of `assign_value`
|
|
343
|
+
Aspera.assert_array_all(value, String, type: BadArgument) { "Option #{@option}" } if value.is_a?(Array)
|
|
344
|
+
value
|
|
345
|
+
when :enum_list
|
|
346
|
+
value = [value] if value.is_a?(String)
|
|
347
|
+
Aspera.assert_array_all(value, String, type: BadArgument)
|
|
348
|
+
value.map { |v| Parser.get_from_list(v, @option, @values) }
|
|
349
|
+
else
|
|
350
|
+
# nil on a Hash/Array option resets to empty container
|
|
351
|
+
value.nil? && [Hash, Array].include?(@types&.first) ? @types.first.new : value
|
|
352
|
+
end
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
# Secret values are hidden wherever they appear: logs, results
|
|
356
|
+
# @param value [Object] value of option
|
|
357
|
+
def declare_secrets(value)
|
|
358
|
+
if @sensitive
|
|
359
|
+
Secret::Hider.instance.add_secret_values(value)
|
|
360
|
+
else
|
|
361
|
+
Secret::Hider.instance.add_secrets_in(value)
|
|
362
|
+
end
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
# @param new_value [Object] value to store
|
|
366
|
+
# @param source [Symbol, nil] `Option::Source` of value
|
|
367
|
+
def store(new_value, source)
|
|
368
|
+
declare_secrets(new_value)
|
|
369
|
+
@value = new_value
|
|
370
|
+
@source = source
|
|
371
|
+
@on_set&.call(new_value)
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
end
|
|
375
|
+
end
|
|
376
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
module Aspera
|
|
7
|
+
module Cli
|
|
8
|
+
# Declares an option referenced by name from command declarations.
|
|
9
|
+
# Mirrors the existing `options.declare` call but associates the option with
|
|
10
|
+
# the command(s) that use it.
|
|
11
|
+
#
|
|
12
|
+
# @!attribute name [Symbol] Option name (same symbol used in options.declare)
|
|
13
|
+
# @!attribute description [String, nil] User-facing description; nil derives it from schema:
|
|
14
|
+
# @!attribute allowed [Array, nil] Allowed values (forwarded to options.declare)
|
|
15
|
+
# @!attribute default [Object, nil] Default value
|
|
16
|
+
# @!attribute short [String, nil] Single-character short form (e.g. 'x')
|
|
17
|
+
# @!attribute on_set [Symbol, Proc, #call, nil] Called with the new value each time the value is set
|
|
18
|
+
# (for a flag: called without argument when the flag is found)
|
|
19
|
+
# - Symbol: method of the plugin instance
|
|
20
|
+
# - Proc: executed with instance_exec on the plugin instance
|
|
21
|
+
# - other: object responding to `call`, e.g. `Log.instance.method(:level=)`
|
|
22
|
+
# - nil: no callback, the value is read with `get_option`
|
|
23
|
+
# @!attribute shorthand [String, nil] For a `Hash` option: a `String` value is stored as `{shorthand => value}`
|
|
24
|
+
# @!attribute deprecation [Hash, nil] Forwarded to options.declare as deprecation: `{last:, message:}`
|
|
25
|
+
# @!attribute schema [String, nil] JSON schema name; also derives description when nil
|
|
26
|
+
# @!attribute complete [Symbol, nil] Values proposed by shell completion, one of `Complete::KINDS` (e.g. `:file`)
|
|
27
|
+
# @!attribute security [Symbol, nil] Most restrictive security level at which the option is available (`:low`: executes code), see `Security`
|
|
28
|
+
Option = Struct.new(
|
|
29
|
+
:name,
|
|
30
|
+
:description,
|
|
31
|
+
:allowed,
|
|
32
|
+
:default,
|
|
33
|
+
:short,
|
|
34
|
+
:on_set,
|
|
35
|
+
:shorthand,
|
|
36
|
+
:deprecation,
|
|
37
|
+
:schema,
|
|
38
|
+
:complete,
|
|
39
|
+
:security,
|
|
40
|
+
keyword_init: true
|
|
41
|
+
) do
|
|
42
|
+
# Declare this option on a parser, resolving the `on_set` callback.
|
|
43
|
+
# @param parser [Parser] Parser to declare the option on
|
|
44
|
+
# @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks (plugin instance); nil: such callbacks are not bound
|
|
45
|
+
# @return [void]
|
|
46
|
+
def declare_on(parser, target: nil)
|
|
47
|
+
parser.declare(
|
|
48
|
+
name,
|
|
49
|
+
description: description,
|
|
50
|
+
short: short,
|
|
51
|
+
allowed: allowed,
|
|
52
|
+
default: default,
|
|
53
|
+
on_set: resolved_on_set(target),
|
|
54
|
+
shorthand: shorthand,
|
|
55
|
+
deprecation: deprecation,
|
|
56
|
+
schema: schema,
|
|
57
|
+
complete: complete,
|
|
58
|
+
security: security
|
|
59
|
+
)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
# @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks
|
|
65
|
+
# @return [#call, nil] `on_set` callback for `Parser#declare`
|
|
66
|
+
def resolved_on_set(target)
|
|
67
|
+
case on_set
|
|
68
|
+
when Symbol then target&.method(on_set)
|
|
69
|
+
when Proc
|
|
70
|
+
return if target.nil?
|
|
71
|
+
proc_on_set = on_set
|
|
72
|
+
->(*value) { target.instance_exec(*value, &proc_on_set) }
|
|
73
|
+
else on_set
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|