aspera-cli 4.27.5 → 4.29.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 +0 -0
- data/BUGS.md +5 -10
- data/CHANGELOG.md +301 -4
- data/CODE_OF_CONDUCT.md +18 -0
- data/CONTRIBUTING.md +139 -58
- data/GOVERNANCE.md +30 -0
- data/LICENSE +201 -0
- data/README.md +103 -26
- data/SECURITY.md +70 -0
- data/bin/ascli +8 -5
- data/bin/asession +10 -7
- data/docs/README.md +2551 -772
- data/docs/test-mcp-with-ai.md +13 -11
- data/lib/aspera/agent/base.rb +23 -2
- data/lib/aspera/agent/connect.rb +16 -12
- data/lib/aspera/agent/desktop.rb +10 -7
- data/lib/aspera/agent/direct.rb +34 -22
- data/lib/aspera/agent/factory.rb +8 -4
- data/lib/aspera/agent/httpgw.rb +7 -5
- data/lib/aspera/agent/node.rb +15 -7
- data/lib/aspera/agent/transferd.rb +167 -43
- data/lib/aspera/api/alee.rb +4 -1
- data/lib/aspera/api/aoc.rb +14 -11
- data/lib/aspera/api/ats.rb +4 -2
- data/lib/aspera/api/cos_node.rb +8 -5
- data/lib/aspera/api/faspex.rb +16 -9
- data/lib/aspera/api/httpgw.rb +9 -6
- data/lib/aspera/api/node.rb +23 -19
- data/lib/aspera/ascmd.rb +8 -5
- data/lib/aspera/ascp/installation.rb +84 -42
- data/lib/aspera/ascp/log.schema.yaml +1084 -0
- data/lib/aspera/ascp/log_analyzer/advice.rb +97 -0
- data/lib/aspera/ascp/log_analyzer/diagnostics.rb +344 -0
- data/lib/aspera/ascp/log_analyzer/lines.rb +75 -0
- data/lib/aspera/ascp/log_analyzer/log_file.rb +593 -0
- data/lib/aspera/ascp/log_analyzer/records.rb +379 -0
- data/lib/aspera/ascp/log_analyzer/rules.rb +172 -0
- data/lib/aspera/ascp/log_analyzer/session.rb +782 -0
- data/lib/aspera/ascp/log_analyzer.rb +354 -0
- data/lib/aspera/ascp/management.rb +102 -48
- data/lib/aspera/ascp/session_errors.rb +217 -0
- data/lib/aspera/assert.rb +4 -0
- data/lib/aspera/cli/ascp_actions.rb +16 -37
- data/lib/aspera/cli/ascp_logs_actions.rb +176 -0
- data/lib/aspera/cli/async_transfer_store.rb +7 -4
- data/lib/aspera/cli/bootstrapper.rb +37 -34
- data/lib/aspera/cli/command_line.rb +24 -6
- data/lib/aspera/cli/command_registry.rb +49 -4
- data/lib/aspera/cli/command_spec.rb +34 -4
- data/lib/aspera/cli/completion/ascli.bash +53 -5
- data/lib/aspera/cli/completion/ascli.fish +27 -8
- data/lib/aspera/cli/completion/ascli.ps1 +63 -0
- data/lib/aspera/cli/completion/ascli.zsh +36 -4
- data/lib/aspera/cli/completion_actions.rb +594 -0
- data/lib/aspera/cli/context.rb +9 -4
- data/lib/aspera/cli/deprecation.rb +5 -2
- data/lib/aspera/cli/error.rb +45 -0
- data/lib/aspera/cli/extended_value.rb +83 -24
- data/lib/aspera/cli/formatter.rb +142 -73
- data/lib/aspera/cli/gem_checker.rb +9 -6
- data/lib/aspera/cli/hints.rb +22 -11
- data/lib/aspera/cli/http.rb +17 -13
- data/lib/aspera/cli/info.rb +17 -6
- data/lib/aspera/cli/mailer.rb +7 -4
- data/lib/aspera/cli/mcp/http_servlet.rb +155 -0
- data/lib/aspera/cli/mcp/secrets.rb +146 -0
- data/lib/aspera/cli/mcp/tool.rb +232 -0
- data/lib/aspera/cli/option_declarator.rb +10 -4
- data/lib/aspera/cli/option_registry.rb +6 -3
- data/lib/aspera/cli/option_types.rb +17 -2
- data/lib/aspera/cli/option_value.rb +72 -11
- data/lib/aspera/cli/options.schema.yaml +856 -81
- data/lib/aspera/cli/parser.rb +64 -31
- data/lib/aspera/cli/plugins/alee.rb +7 -4
- data/lib/aspera/cli/plugins/aoc.rb +250 -44
- data/lib/aspera/cli/plugins/ats.rb +9 -8
- data/lib/aspera/cli/plugins/base.rb +51 -25
- data/lib/aspera/cli/plugins/basic_auth.rb +5 -2
- data/lib/aspera/cli/plugins/config.rb +207 -141
- data/lib/aspera/cli/plugins/console.rb +9 -4
- data/lib/aspera/cli/plugins/cos.rb +8 -4
- data/lib/aspera/cli/plugins/factory.rb +22 -8
- data/lib/aspera/cli/plugins/faspex5.rb +37 -44
- data/lib/aspera/cli/plugins/faspio.rb +41 -8
- data/lib/aspera/cli/plugins/httpgw.rb +8 -4
- data/lib/aspera/cli/plugins/mcp.rb +186 -121
- data/lib/aspera/cli/plugins/node.rb +41 -34
- data/lib/aspera/cli/plugins/oauth.rb +5 -1
- data/lib/aspera/cli/plugins/orchestrator.rb +572 -59
- data/lib/aspera/cli/plugins/preview.rb +69 -44
- data/lib/aspera/cli/plugins/server.rb +66 -12
- data/lib/aspera/cli/plugins/shares.rb +288 -48
- data/lib/aspera/cli/plugins/transferd.rb +223 -0
- data/lib/aspera/cli/preset_actions.rb +155 -33
- data/lib/aspera/cli/preset_manager.rb +72 -16
- data/lib/aspera/cli/prompt.rb +7 -2
- data/lib/aspera/cli/result.rb +28 -11
- data/lib/aspera/cli/runner.rb +193 -80
- data/lib/aspera/cli/secret_finder.rb +4 -1
- data/lib/aspera/cli/security.rb +204 -0
- data/lib/aspera/cli/special_values.rb +4 -1
- data/lib/aspera/cli/sync_actions.rb +13 -10
- data/lib/aspera/cli/table_fitter.rb +119 -0
- data/lib/aspera/cli/terminal_formatter.rb +32 -40
- data/lib/aspera/cli/transfer_actions.rb +11 -8
- data/lib/aspera/cli/transfer_agent.rb +31 -19
- data/lib/aspera/cli/transfer_progress.rb +13 -45
- data/lib/aspera/cli/vault_actions.rb +45 -0
- data/lib/aspera/cli/vault_manager.rb +197 -50
- data/lib/aspera/cli/version.rb +4 -1
- data/lib/aspera/cli/web_secret.html.erb +61 -0
- data/lib/aspera/cli/web_secret.rb +222 -0
- data/lib/aspera/cli/wizard.rb +58 -45
- data/lib/aspera/command_line_builder.rb +35 -5
- data/lib/aspera/command_line_converter.rb +4 -1
- data/lib/aspera/coverage.rb +103 -33
- data/lib/aspera/data_repository.rb +42 -25
- data/lib/aspera/dot_container.rb +4 -1
- data/lib/aspera/duration.rb +45 -0
- data/lib/aspera/environment.rb +106 -33
- data/lib/aspera/exec_spec.rb +9 -5
- data/lib/aspera/faspex_gw.rb +105 -35
- data/lib/aspera/faspex_postproc.rb +193 -47
- data/lib/aspera/formatter_interface.rb +4 -2
- data/lib/aspera/graphql.rb +5 -1
- data/lib/aspera/hash_ext.rb +3 -0
- data/lib/aspera/id_generator.rb +6 -3
- data/lib/aspera/json_rpc/client.rb +55 -35
- data/lib/aspera/json_rpc/version.rb +4 -0
- data/lib/aspera/line_logger.rb +4 -1
- data/lib/aspera/link_header.rb +4 -1
- data/lib/aspera/log.rb +20 -10
- data/lib/aspera/markdown.rb +155 -115
- data/lib/aspera/mime.rb +9 -0
- data/lib/aspera/nagios.rb +9 -5
- data/lib/aspera/node_emulator.rb +111 -112
- data/lib/aspera/oauth/client/base.rb +163 -0
- data/lib/aspera/oauth/{boot.rb → client/boot.rb} +8 -4
- data/lib/aspera/oauth/{factory.rb → client/factory.rb} +13 -3
- data/lib/aspera/oauth/{generic.rb → client/generic.rb} +5 -1
- data/lib/aspera/oauth/{json_credentials.rb → client/json_credentials.rb} +4 -1
- data/lib/aspera/oauth/{jwt.rb → client/jwt.rb} +6 -3
- data/lib/aspera/oauth/client/shares_web.rb +85 -0
- data/lib/aspera/oauth/{url_json.rb → client/url_json.rb} +4 -1
- data/lib/aspera/oauth/client/web.rb +84 -0
- data/lib/aspera/oauth/server/authorize.html.erb +34 -0
- data/lib/aspera/oauth/server/pkce.rb +427 -0
- data/lib/aspera/orchestrator_workflow_checker.rb +679 -0
- data/lib/aspera/persistency_action_once.rb +5 -3
- data/lib/aspera/persistency_folder.rb +6 -3
- data/lib/aspera/preview/file_types.rb +6 -3
- data/lib/aspera/preview/generator.rb +9 -5
- data/lib/aspera/preview/options.schema.yaml +3 -3
- data/lib/aspera/preview/terminal.rb +11 -6
- data/lib/aspera/preview/utils.rb +6 -4
- data/lib/aspera/products/connect.rb +5 -2
- data/lib/aspera/products/desktop.rb +4 -1
- data/lib/aspera/products/other.rb +4 -2
- data/lib/aspera/products/transferd.rb +6 -2
- data/lib/aspera/products/transferd_service.rb +610 -0
- data/lib/aspera/proxy_auto_config.js +2 -2
- data/lib/aspera/proxy_auto_config.rb +5 -2
- data/lib/aspera/rainbow.rb +30 -1
- data/lib/aspera/rest/aspera_errors.rb +55 -60
- data/lib/aspera/rest/call_error.rb +3 -0
- data/lib/aspera/rest/client.rb +42 -42
- data/lib/aspera/rest/error_analyzer.rb +14 -2
- data/lib/aspera/rest/list.rb +14 -10
- data/lib/aspera/rest/parameters.rb +3 -0
- data/lib/aspera/rest/util.rb +13 -4
- data/lib/aspera/rest.rb +9 -7
- data/lib/aspera/schema/IBM Aspera Faspex API-5.0-enhanced.yaml +9 -11
- data/lib/aspera/schema/IBM Aspera Orchestrator API-v1-enhanced.yaml +4089 -0
- data/lib/aspera/schema/IBM Aspera faspio Gateway API-1.0.0-enhanced.yaml +1097 -0
- data/lib/aspera/schema/IBM Aspera on Cloud API-0.2.6-enhanced.yaml +11 -11
- data/lib/aspera/schema/IBM Aspera on Cloud Automation API-1.0.5-enhanced.yaml +2437 -1437
- data/lib/aspera/schema/IBM_Aspera_Shares.yaml +819 -7
- data/lib/aspera/schema/async_tables.yaml +11 -10
- data/lib/aspera/schema/documentation.rb +56 -78
- data/lib/aspera/schema/reader.rb +46 -11
- data/lib/aspera/schema/registry.rb +45 -24
- data/lib/aspera/schema/transferd-config.schema.json +333 -0
- data/lib/aspera/schema/validator.rb +4 -1
- data/lib/aspera/sealed_hash.rb +166 -0
- data/lib/aspera/secret/hider.rb +201 -0
- data/lib/aspera/secret/reference.rb +150 -0
- data/lib/aspera/secret/resolver.rb +212 -0
- data/lib/aspera/secret/store/base.rb +153 -0
- data/lib/aspera/secret/store/encrypted_hash.rb +329 -0
- data/lib/aspera/secret/store/factory.rb +103 -0
- data/lib/aspera/secret/store/hashicorp_vault.rb +390 -0
- data/lib/aspera/secret/store/keeper.rb +141 -0
- data/lib/aspera/secret/store/macos_security.rb +284 -0
- data/lib/aspera/secret/store/one_password_api.rb +99 -0
- data/lib/aspera/secret/store/one_password_base.rb +42 -0
- data/lib/aspera/secret/store/one_password_cli.rb +110 -0
- data/lib/aspera/secret/store/secret_service.rb +125 -0
- data/lib/aspera/secret/strength.rb +119 -0
- data/lib/aspera/servlet_helpers.rb +114 -0
- data/lib/aspera/ssh.rb +10 -7
- data/lib/aspera/ssl.rb +5 -2
- data/lib/aspera/string_ext.rb +3 -0
- data/lib/aspera/sync/args.schema.yaml +6 -1
- data/lib/aspera/sync/conf.schema.yaml +25 -10
- data/lib/aspera/sync/database.rb +3 -0
- data/lib/aspera/sync/operations.rb +34 -12
- data/lib/aspera/temp_file_manager.rb +85 -22
- data/lib/aspera/timer_limiter.rb +3 -0
- data/lib/aspera/transfer/error.rb +4 -1
- data/lib/aspera/transfer/faux_file.rb +4 -1
- data/lib/aspera/transfer/parameters.rb +22 -14
- data/lib/aspera/transfer/result.rb +3 -0
- data/lib/aspera/transfer/resumer.rb +6 -4
- data/lib/aspera/transfer/spec.rb +45 -18
- data/lib/aspera/transfer/spec.schema.yaml +8 -5
- data/lib/aspera/transfer/units.rb +75 -0
- data/lib/aspera/uri_reader.rb +57 -7
- data/lib/aspera/web_auth/index.html.erb +20 -0
- data/lib/aspera/web_auth/paste.rb +109 -0
- data/lib/aspera/web_auth/receiver.rb +50 -0
- data/lib/aspera/web_auth/relay.rb +76 -0
- data/lib/aspera/web_auth/reply.html.erb +150 -0
- data/lib/aspera/web_auth/server.rb +59 -14
- data/lib/aspera/web_page.html.erb +262 -0
- data/lib/aspera/web_page.rb +66 -0
- data/lib/aspera/web_server_simple.rb +82 -13
- data/lib/aspera/yaml.rb +5 -1
- data/llms.txt +81 -0
- data/skills/ascli/SKILL.md +88 -0
- data.tar.gz.sig +0 -0
- metadata +116 -48
- metadata.gz.sig +0 -0
- data/lib/aspera/cli/mcp_tool.rb +0 -189
- data/lib/aspera/keychain/base.rb +0 -25
- data/lib/aspera/keychain/encrypted_hash.rb +0 -188
- data/lib/aspera/keychain/factory.rb +0 -59
- data/lib/aspera/keychain/hashicorp_vault.rb +0 -74
- data/lib/aspera/keychain/macos_security.rb +0 -171
- data/lib/aspera/keychain/one_password_api.rb +0 -86
- data/lib/aspera/keychain/one_password_base.rb +0 -34
- data/lib/aspera/keychain/one_password_cli.rb +0 -98
- data/lib/aspera/oauth/base.rb +0 -141
- data/lib/aspera/oauth/web.rb +0 -57
- data/lib/aspera/oauth.rb +0 -9
- data/lib/aspera/schema/IBM Aspera Orchestrator API-v1.yaml +0 -1784
- data/lib/aspera/schema/IBM Aspera faspio Gateway API-1.0.0.yaml +0 -249
- data/lib/aspera/secret_hider.rb +0 -117
- data/lib/aspera/web_auth/index.html +0 -147
data/lib/aspera/cli/parser.rb
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'preset_manager'
|
|
7
|
+
require_relative 'extended_value'
|
|
8
|
+
require_relative 'error'
|
|
9
|
+
require_relative 'special_values'
|
|
10
|
+
require_relative 'terminal_formatter'
|
|
11
|
+
require_relative 'option_types'
|
|
12
|
+
require_relative 'option_value'
|
|
13
|
+
require_relative 'option_registry'
|
|
14
|
+
require_relative 'command_line'
|
|
15
|
+
require_relative 'prompt'
|
|
16
|
+
require_relative '../schema/validator'
|
|
17
|
+
require_relative '../log'
|
|
18
|
+
require_relative '../assert'
|
|
19
|
+
require_relative '../dot_container'
|
|
20
|
+
require_relative '../rainbow'
|
|
16
21
|
require 'terminal-table'
|
|
17
|
-
require 'aspera/rainbow'
|
|
18
22
|
using Rainbow
|
|
19
23
|
|
|
20
24
|
module Aspera
|
|
@@ -90,16 +94,18 @@ module Aspera
|
|
|
90
94
|
|
|
91
95
|
# Using dotted hash notation, convert value to bool, int, float or extended value
|
|
92
96
|
# `true` and `yes` are converted to `true`, `false` and `no` to `false`
|
|
93
|
-
# @param value
|
|
97
|
+
# @param value [String] The value to convert to appropriate type
|
|
98
|
+
# @param context [String] Where the value comes from, for error messages
|
|
99
|
+
# @param allowed [Class, Array, nil] Types accepted for an extended value
|
|
94
100
|
# @return [Boolean, Integer, Float, String, Array, Hash] the converted value
|
|
95
|
-
def smart_convert(value)
|
|
101
|
+
def smart_convert(value, context: 'dotted expression', allowed: nil)
|
|
96
102
|
case value
|
|
97
103
|
when 'true', BoolValue::YES_SYM.to_s then true
|
|
98
104
|
when 'false', BoolValue::NO_SYM.to_s then false
|
|
99
105
|
else
|
|
100
106
|
Integer(value, 10, exception: false) ||
|
|
101
107
|
Float(value, exception: false) ||
|
|
102
|
-
ExtendedValue.instance.evaluate(value, context:
|
|
108
|
+
ExtendedValue.instance.evaluate(value, context: context, allowed: allowed)
|
|
103
109
|
end
|
|
104
110
|
end
|
|
105
111
|
end
|
|
@@ -146,10 +152,13 @@ module Aspera
|
|
|
146
152
|
# @param on_set [#call] Called with the new value each time the value is set (e.g. a `Method`, or a lambda).
|
|
147
153
|
# For a flag (`Type::NONE`): called without argument when the flag is found
|
|
148
154
|
# @param shorthand [String] For a `Hash` option: a `String` value is stored as `{shorthand => value}`
|
|
155
|
+
# @param convert [#call] For a `Hash` option: called with a new `Hash` value, returns the value to store, before merge (e.g. conversion of a deprecated form)
|
|
149
156
|
# @param deprecation [Hash, nil] deprecation: `{last:, message:}`, see `Deprecation`
|
|
150
157
|
# @param schema [String] schema path documenting the Hash form of this option
|
|
158
|
+
# @param complete [Symbol, nil] values proposed by shell completion, one of `Complete::KINDS`
|
|
159
|
+
# @param security [Symbol, nil] most restrictive security level at which the option is available, see `Security`
|
|
151
160
|
# @param block [Proc] Block to execute when option is found
|
|
152
|
-
def declare(option_symbol, description: nil, short: nil, allowed: nil, default: nil, on_set: nil, shorthand: nil, deprecation: nil, schema: nil, &block)
|
|
161
|
+
def declare(option_symbol, description: nil, short: nil, allowed: nil, default: nil, on_set: nil, shorthand: nil, convert: nil, deprecation: nil, schema: nil, complete: nil, security: nil, &block)
|
|
153
162
|
Aspera.assert_type(option_symbol, Symbol)
|
|
154
163
|
Aspera.assert(!@registry.declared?(option_symbol)) { "#{option_symbol} already declared" }
|
|
155
164
|
if on_set && allowed.eql?(Type::NONE)
|
|
@@ -170,8 +179,11 @@ module Aspera
|
|
|
170
179
|
allowed: allowed,
|
|
171
180
|
on_set: on_set,
|
|
172
181
|
shorthand: shorthand,
|
|
182
|
+
convert: convert,
|
|
173
183
|
deprecation: deprecation,
|
|
174
|
-
schema: schema
|
|
184
|
+
schema: schema,
|
|
185
|
+
complete: complete,
|
|
186
|
+
security: security
|
|
175
187
|
),
|
|
176
188
|
short: short
|
|
177
189
|
)
|
|
@@ -205,8 +217,9 @@ module Aspera
|
|
|
205
217
|
# @param validation [Class, Array, nil] Accepted value type(s) or list of Symbols
|
|
206
218
|
# @param aliases [Hash] map of aliases: key = alias, value = real value
|
|
207
219
|
# @param default [Object] default value
|
|
220
|
+
# @param evaluate [Symbol] `:extended`: extended value, `:smart`: also `true`, `yes`, `false`, `no` and numbers, `:none`: as typed
|
|
208
221
|
# @return [Object, Array, nil] one value, list or nil (if optional and no default)
|
|
209
|
-
def get_next_argument(descr, mandatory: true, multiple: false, accept_list: nil, validation: Type::STRING, aliases: nil, default: nil, schema: nil)
|
|
222
|
+
def get_next_argument(descr, mandatory: true, multiple: false, accept_list: nil, validation: Type::STRING, aliases: nil, default: nil, schema: nil, evaluate: :extended)
|
|
210
223
|
ensure_parsed
|
|
211
224
|
Aspera.assert_array_all(accept_list, Symbol) unless accept_list.nil?
|
|
212
225
|
Aspera.assert_hash_all(aliases, Symbol, Symbol) unless aliases.nil?
|
|
@@ -215,7 +228,7 @@ module Aspera
|
|
|
215
228
|
Aspera.assert_array_all(validation, Class) { 'validation' } unless validation.nil?
|
|
216
229
|
descr = "#{descr}#{add_types_info(validation)}"
|
|
217
230
|
result =
|
|
218
|
-
if !@command_line.pending_arguments.empty? then read_arguments(descr, multiple: multiple, validation: validation, accept_list: accept_list, aliases: aliases)
|
|
231
|
+
if !@command_line.pending_arguments.empty? then read_arguments(descr, multiple: multiple, validation: validation, accept_list: accept_list, aliases: aliases, evaluate: evaluate)
|
|
219
232
|
elsif !default.nil? then default
|
|
220
233
|
elsif mandatory then get_interactive(descr, multiple: multiple, accept_list: accept_list, aliases: aliases, schema: schema)
|
|
221
234
|
end
|
|
@@ -249,7 +262,11 @@ module Aspera
|
|
|
249
262
|
# @param command_list [Array<Symbol>] accepted command names
|
|
250
263
|
# @param aliases [Hash, nil] command aliases
|
|
251
264
|
# @return [Symbol] selected command
|
|
252
|
-
def get_next_command(command_list, aliases: nil)
|
|
265
|
+
def get_next_command(command_list, aliases: nil)
|
|
266
|
+
command = get_next_argument('command', accept_list: command_list, aliases: aliases)
|
|
267
|
+
@command_line.mark_command
|
|
268
|
+
command
|
|
269
|
+
end
|
|
253
270
|
|
|
254
271
|
# Check whether an option has already been declared in this manager
|
|
255
272
|
# @param option_symbol [Symbol] name of the option
|
|
@@ -353,9 +370,18 @@ module Aspera
|
|
|
353
370
|
values.include?(@command_line.pending_arguments.first)
|
|
354
371
|
end
|
|
355
372
|
|
|
373
|
+
# Check the next pending positional arguments, without consuming them
|
|
374
|
+
# @param values [Array<String>] values to compare with, in order
|
|
375
|
+
# @return [Boolean] true if the next pending positional arguments are values
|
|
376
|
+
def next_arguments?(values)
|
|
377
|
+
ensure_parsed
|
|
378
|
+
@command_line.pending_arguments.first(values.length).eql?(values)
|
|
379
|
+
end
|
|
380
|
+
|
|
356
381
|
# Check for unprocessed options or arguments error messages
|
|
382
|
+
# @param after_error [Boolean] `true` if an error was already reported: positional arguments are then not consumed because of this error, not reported
|
|
357
383
|
# @return [Array<String>] list of error messages for unprocessed tokens
|
|
358
|
-
def final_errors
|
|
384
|
+
def final_errors(after_error: false)
|
|
359
385
|
begin
|
|
360
386
|
ensure_parsed
|
|
361
387
|
rescue StandardError => e
|
|
@@ -364,17 +390,18 @@ module Aspera
|
|
|
364
390
|
end
|
|
365
391
|
result = []
|
|
366
392
|
result.push("unprocessed options: #{@command_line.pending_options}") unless @command_line.pending_options.empty?
|
|
367
|
-
result.push("unprocessed values: #{@command_line.pending_arguments}") unless @command_line.pending_arguments.empty?
|
|
393
|
+
result.push("unprocessed values: #{@command_line.pending_arguments}") unless after_error || @command_line.pending_arguments.empty?
|
|
368
394
|
result
|
|
369
395
|
end
|
|
370
396
|
|
|
371
|
-
# Get
|
|
397
|
+
# Get long options with a value from command line, used to generate a config in config file.
|
|
372
398
|
# They are marked as processed.
|
|
399
|
+
# @param after_command [Boolean] `true`: only options placed after the last command word
|
|
373
400
|
# @return [Hash] options with value, dotted notation expanded
|
|
374
|
-
def unprocessed_options_with_value
|
|
401
|
+
def unprocessed_options_with_value(after_command: false)
|
|
375
402
|
ensure_parsed
|
|
376
403
|
result = {}
|
|
377
|
-
@command_line.each_long_option_with_value do |tok|
|
|
404
|
+
@command_line.each_long_option_with_value(after_command: after_command) do |tok|
|
|
378
405
|
path = [tok.name, *tok.dot_path]
|
|
379
406
|
Log.log.debug { "option #{path.join(DotContainer::SEPARATOR)}=#{tok.value}" }
|
|
380
407
|
DotContainer.dotted_to_container(path, Parser.smart_convert(tok.value), result)
|
|
@@ -462,7 +489,7 @@ module Aspera
|
|
|
462
489
|
result = nil
|
|
463
490
|
@command_line.with_arguments_after_current_option do
|
|
464
491
|
get_next_argument('args', multiple: end_marker).each do |argument|
|
|
465
|
-
Aspera.assert(argument.include?(Option::VALUE_SEP)) { "
|
|
492
|
+
Aspera.assert(argument.include?(Option::VALUE_SEP), type: BadArgument) { "Argument collected by @: does not include #{Option::VALUE_SEP}: #{argument} (end marker: #{end_marker})" }
|
|
466
493
|
path, value = argument.split(Option::VALUE_SEP, 2)
|
|
467
494
|
result = DotContainer.dotted_to_container(path.split(DotContainer::SEPARATOR), Parser.smart_convert(value), result)
|
|
468
495
|
end
|
|
@@ -516,11 +543,17 @@ module Aspera
|
|
|
516
543
|
" (#{types.map(&:name).join(', ')})"
|
|
517
544
|
end
|
|
518
545
|
|
|
519
|
-
# Consume and evaluate
|
|
546
|
+
# Consume positional arguments, and evaluate them as told by `evaluate`
|
|
520
547
|
# @return [Object, Array] one value, or list if `multiple`
|
|
521
|
-
def read_arguments(descr, multiple:, validation:, accept_list:, aliases:)
|
|
548
|
+
def read_arguments(descr, multiple:, validation:, accept_list:, aliases:, evaluate:)
|
|
522
549
|
values = @command_line.shift_arguments(multiple)
|
|
523
|
-
|
|
550
|
+
context = "argument: #{descr}"
|
|
551
|
+
case evaluate
|
|
552
|
+
when :extended then values = values.map { |v| ExtendedValue.instance.evaluate(v, context: context, allowed: validation) }
|
|
553
|
+
when :smart then values = values.map { |v| Parser.smart_convert(v, context: context, allowed: validation) }
|
|
554
|
+
when :none then nil
|
|
555
|
+
else Aspera.error_unexpected_value(evaluate)
|
|
556
|
+
end
|
|
524
557
|
# If expecting list and only one arg of type array : it is the list
|
|
525
558
|
values = values.first if multiple && values.length.eql?(1) && values.first.is_a?(Array)
|
|
526
559
|
if accept_list
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../../assert'
|
|
7
|
+
require_relative '../../api/alee'
|
|
8
|
+
require_relative '../../nagios'
|
|
9
|
+
require_relative 'basic_auth'
|
|
7
10
|
|
|
8
11
|
module Aspera
|
|
9
12
|
module Cli
|
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../../schema/registry'
|
|
7
|
+
require_relative 'oauth'
|
|
8
|
+
require_relative 'node'
|
|
9
|
+
require_relative 'ats'
|
|
10
|
+
require_relative '../transfer_agent'
|
|
11
|
+
require_relative '../special_values'
|
|
12
|
+
require_relative '../../environment'
|
|
13
|
+
require_relative '../wizard'
|
|
14
|
+
require_relative '../../agent/node'
|
|
15
|
+
require_relative '../../transfer/result'
|
|
16
|
+
require_relative '../../transfer/spec'
|
|
17
|
+
require_relative '../../api/aoc'
|
|
18
|
+
require_relative '../../api/node'
|
|
19
|
+
require_relative '../../persistency_action_once'
|
|
20
|
+
require_relative '../../id_generator'
|
|
21
|
+
require_relative '../../assert'
|
|
22
|
+
require_relative '../../graphql'
|
|
23
|
+
require_relative '../../rainbow'
|
|
19
24
|
require 'securerandom'
|
|
20
25
|
require 'date'
|
|
21
|
-
require 'aspera/rainbow'
|
|
22
26
|
using Rainbow
|
|
23
27
|
|
|
24
28
|
module Aspera
|
|
@@ -103,17 +107,19 @@ module Aspera
|
|
|
103
107
|
# @param package_info [Hash] Package information
|
|
104
108
|
# @param destination_folder [String] Base folder
|
|
105
109
|
# @param fld [Array] List of fields of package
|
|
110
|
+
# @return [String] Folder path in destination folder
|
|
106
111
|
def unique_folder(package_info, destination_folder, fld: nil, seq: false, opt: false)
|
|
107
112
|
Aspera.assert_array_all(fld, String, type: BadArgument) { 'fld' }
|
|
108
113
|
Aspera.assert_values(fld.length, [1, 2]) { 'fld length' }
|
|
109
|
-
|
|
114
|
+
# Existence is checked in the destination folder
|
|
115
|
+
folder = File.join(destination_folder, Environment.instance.sanitized_filename(package_info[fld[0]].to_s))
|
|
110
116
|
if seq
|
|
111
117
|
folder = next_available_folder(folder, always: !opt)
|
|
112
118
|
elsif fld[1] && (Dir.exist?(folder) || !opt)
|
|
113
119
|
# NOTE: it might already exist
|
|
114
|
-
folder = "#{folder}.#{Environment.instance.sanitized_filename(fld[1])}"
|
|
120
|
+
folder = "#{folder}.#{Environment.instance.sanitized_filename(package_info[fld[1]].to_s)}"
|
|
115
121
|
end
|
|
116
|
-
|
|
122
|
+
folder
|
|
117
123
|
end
|
|
118
124
|
|
|
119
125
|
# @return [String] AoC REST path for an admin resource type
|
|
@@ -198,6 +204,7 @@ module Aspera
|
|
|
198
204
|
}
|
|
199
205
|
preset_value[:password] = options.get_option(:password, mandatory: true) if pub_info['password_protected']
|
|
200
206
|
return {
|
|
207
|
+
preset_ids: [],
|
|
201
208
|
preset_value: preset_value,
|
|
202
209
|
test_args: 'organization'
|
|
203
210
|
}
|
|
@@ -210,10 +217,10 @@ module Aspera
|
|
|
210
217
|
auto_set_jwt = false
|
|
211
218
|
# use browser authentication to bootstrap
|
|
212
219
|
use_browser_authentication = false
|
|
213
|
-
|
|
220
|
+
private_key = wizard.ask_private_key(
|
|
214
221
|
user: wiz_username,
|
|
215
222
|
url: app_url,
|
|
216
|
-
page: '👤
|
|
223
|
+
page: [Environment.char('👤'), 'Account Settings', 'Profile', 'Public Key']
|
|
217
224
|
)
|
|
218
225
|
client_id = options.get_option(:client_id)
|
|
219
226
|
client_secret = options.get_option(:client_secret)
|
|
@@ -227,15 +234,15 @@ module Aspera
|
|
|
227
234
|
else
|
|
228
235
|
formatter.display_status('Using organization specific client_id.')
|
|
229
236
|
formatter.display_status('Please login to your Aspera on Cloud instance.'.red)
|
|
230
|
-
|
|
237
|
+
wizard.display_navigation(Environment.char('𓃑'), 'Admin', 'Integrations', 'API Clients')
|
|
231
238
|
formatter.display_status('Check or create in integration:')
|
|
232
239
|
formatter.display_status('- name: cli')
|
|
233
240
|
formatter.display_status("- redirect uri: #{REDIRECT_LOCALHOST}")
|
|
234
241
|
formatter.display_status('- origin: localhost')
|
|
235
242
|
formatter.display_status('Use the generated client id and secret in the following prompts.'.red)
|
|
236
243
|
Environment.instance.open_uri("#{app_url}/admin/integrations/api-clients")
|
|
237
|
-
client_id = options.get_option(:client_id, mandatory:
|
|
238
|
-
client_secret = options.get_option(:client_secret, mandatory:
|
|
244
|
+
client_id = options.get_option(:client_id, mandatory: wizard.required)
|
|
245
|
+
client_secret = options.get_option(:client_secret, mandatory: wizard.required)
|
|
239
246
|
# use_browser_authentication = true
|
|
240
247
|
end
|
|
241
248
|
end
|
|
@@ -250,7 +257,7 @@ module Aspera
|
|
|
250
257
|
end
|
|
251
258
|
myself = aoc_api.read('self')
|
|
252
259
|
if auto_set_pub_key
|
|
253
|
-
Aspera.assert(myself['public_key'].empty?, 'Public key is already set in profile (use
|
|
260
|
+
Aspera.assert(myself['public_key'].empty?, 'Public key is already set in profile (use wizard key override=yes)', type: Error) unless option_override
|
|
254
261
|
formatter.display_status('Updating profile with the public key.')
|
|
255
262
|
aoc_api.update("users/#{myself['id']}", {'public_key' => pub_key_pem})
|
|
256
263
|
end
|
|
@@ -259,11 +266,12 @@ module Aspera
|
|
|
259
266
|
aoc_api.update("clients/#{options.get_option(:client_id)}", {'jwt_grant_enabled' => true, 'explicit_authorization_required' => false})
|
|
260
267
|
end
|
|
261
268
|
return {
|
|
269
|
+
preset_ids: [myself['email'], client_id].compact,
|
|
262
270
|
preset_value: {
|
|
263
271
|
url: app_url,
|
|
264
272
|
username: myself['email'],
|
|
265
273
|
auth: :jwt.to_s,
|
|
266
|
-
private_key:
|
|
274
|
+
private_key: private_key,
|
|
267
275
|
client_id: client_id,
|
|
268
276
|
client_secret: client_secret
|
|
269
277
|
}.compact,
|
|
@@ -803,9 +811,9 @@ module Aspera
|
|
|
803
811
|
)
|
|
804
812
|
command :create, description: 'Create an app membership', arguments: [{name: :membership, type: Hash}]
|
|
805
813
|
end
|
|
806
|
-
command :automation, description: 'Manage automation
|
|
814
|
+
command :automation, description: 'Manage automation'
|
|
807
815
|
command :gateway, description: 'Start AoC Faspex4 gateway',
|
|
808
|
-
arguments: [{name: :parameters, type: Hash, mandatory: false, default: {}}]
|
|
816
|
+
arguments: [{name: :parameters, type: Hash, mandatory: false, default: {}, schema: Schema::Registry::GATEWAY_OPTIONS}]
|
|
809
817
|
|
|
810
818
|
# user sub-commands
|
|
811
819
|
commands_under :user do
|
|
@@ -930,9 +938,41 @@ module Aspera
|
|
|
930
938
|
# Automation API: a workflow has ordered steps (step_order), a step has ordered actions (action_order)
|
|
931
939
|
AUTOMATION_CRUD = {api: :@automation_api, body_component: Schema::Registry::AUTOMATION}.freeze
|
|
932
940
|
private_constant :AUTOMATION_CRUD
|
|
941
|
+
AOC_AUTOMATION_GUIDE_URLS = [
|
|
942
|
+
'https://raw.githubusercontent.com/laurent-martin/aspera-orchestrator-plugins-doc/main/docs/aoc/aoc-automation-development-guide.md'
|
|
943
|
+
].freeze
|
|
933
944
|
commands_under :automation do
|
|
945
|
+
command :guide, description: 'AoC Automation Development Guide (from GitHub, no AoC connection needed)'
|
|
946
|
+
command :workflows, description: 'Manage workflows', setup: :setup_automation_api
|
|
947
|
+
command :instances, description: 'Manage workflow instances (jobs)', setup: :setup_automation_api
|
|
948
|
+
command :steps, description: 'Manage workflow steps', setup: :setup_automation_api
|
|
949
|
+
command :actions, description: 'Manage workflow actions', setup: :setup_automation_api
|
|
950
|
+
|
|
951
|
+
commands_under :guide do
|
|
952
|
+
command :toc, description: 'List sections of the AoC Automation Development Guide: level, title, anchor',
|
|
953
|
+
arguments: [{name: :level, type: Integer, mandatory: false, default: 3}],
|
|
954
|
+
action: ->(level: 3, **) { automation_guide_toc(level) }
|
|
955
|
+
command :full, description: 'Display the whole AoC Automation Development Guide',
|
|
956
|
+
action: ->(**) { Result::Text.new(automation_guide_document) }
|
|
957
|
+
command :section, description: 'Display one section of the guide (anchor given by `toc`)',
|
|
958
|
+
arguments: [{name: :anchor, type: String}],
|
|
959
|
+
action: ->(anchor:, **) { automation_guide_section(anchor) }
|
|
960
|
+
end
|
|
934
961
|
commands_under :workflows do
|
|
935
962
|
crud_commands(**AUTOMATION_CRUD, entity: 'workflows', items_key: 'workflows', query_component: Schema::Registry::AUTOMATION)
|
|
963
|
+
command :details, description: 'Get full workflow structure with all steps and actions',
|
|
964
|
+
arguments: [{name: :workflow_id, type: :identifier}],
|
|
965
|
+
action: ->(workflow_id:, **) { Result::SingleObject.new(workflow_details(workflow_id)) }
|
|
966
|
+
command :export, description: 'Export workflow definition to a portable structure',
|
|
967
|
+
arguments: [{name: :workflow_id, type: :identifier}],
|
|
968
|
+
action: ->(workflow_id:, **) { Result::SingleObject.new(workflow_export_data(workflow_id)) }
|
|
969
|
+
command :import, description: 'Import workflow definition and create steps and actions',
|
|
970
|
+
arguments: [{name: :workflow, type: Hash, description: 'Workflow structure with steps and actions'}],
|
|
971
|
+
action: ->(workflow:, **) { Result::SingleObject.new(workflow_import_data(workflow)) }
|
|
972
|
+
command :duplicate, description: 'Duplicate workflow and all its steps and actions',
|
|
973
|
+
arguments: [{name: :workflow_id, type: :identifier},
|
|
974
|
+
{name: :name, type: String, mandatory: false, default: nil, description: 'New workflow name'}],
|
|
975
|
+
action: ->(workflow_id:, name:, **) { Result::SingleObject.new(workflow_duplicate(workflow_id, new_name: name)) }
|
|
936
976
|
command :launch, description: 'Launch a workflow',
|
|
937
977
|
arguments: [{name: :workflow_id, type: :identifier}],
|
|
938
978
|
action: ->(workflow_id:, **) { Result::SingleObject.new(@automation_api.create("workflows/#{workflow_id}/launch", {})) }
|
|
@@ -991,9 +1031,12 @@ module Aspera
|
|
|
991
1031
|
end
|
|
992
1032
|
commands_under :instances do
|
|
993
1033
|
crud_commands(
|
|
994
|
-
**AUTOMATION_CRUD, entity: 'workflow_instances', name: 'workflow instance', operations: %i[list
|
|
1034
|
+
**AUTOMATION_CRUD, entity: 'workflow_instances', name: 'workflow instance', operations: %i[list delete],
|
|
995
1035
|
items_key: 'workflow_instances', query_component: Schema::Registry::AUTOMATION
|
|
996
1036
|
)
|
|
1037
|
+
command :show, description: 'Show a workflow instance (job), by identifier or by UUID',
|
|
1038
|
+
arguments: [{name: :workflow_instance_id, type: :identifier}],
|
|
1039
|
+
action: ->(workflow_instance_id:, **) { Result::SingleObject.new(workflow_instance_find(workflow_instance_id)) }
|
|
997
1040
|
command :cancel, description: 'Cancel workflow instance',
|
|
998
1041
|
arguments: [{name: :workflow_instance_id, type: :identifier}],
|
|
999
1042
|
action: ->(workflow_instance_id:, **) { Result::SingleObject.new(@automation_api.update("workflow_instances/#{workflow_instance_id}", {'status' => 'canceled'})) }
|
|
@@ -1022,7 +1065,6 @@ module Aspera
|
|
|
1022
1065
|
# Build automation API and store in @automation_api ivar.
|
|
1023
1066
|
def setup_automation_api(**)
|
|
1024
1067
|
change_api_scope(Api::AoC::Scope::ADMIN_USER)
|
|
1025
|
-
Log.log.warn('BETA: work under progress')
|
|
1026
1068
|
@automation_api = Rest::Client.new(**aoc_api.params, base_url: aoc_api.base_url.gsub('/api/', '/automation/'))
|
|
1027
1069
|
{}
|
|
1028
1070
|
end
|
|
@@ -1050,8 +1092,7 @@ module Aspera
|
|
|
1050
1092
|
end
|
|
1051
1093
|
package_data['encryption_at_rest'] = true if transfer.user_transfer_spec['content_protection'].eql?('encrypt')
|
|
1052
1094
|
created_package = aoc_api.create_package_simple(package_data, option_validate, new_user_option)
|
|
1053
|
-
Runner.
|
|
1054
|
-
return Result::SingleObject.new(created_package[:info])
|
|
1095
|
+
return Runner.result_object_transfer(created_package[:info], transfer.start(created_package[:spec], oauth_api: created_package[:node]))
|
|
1055
1096
|
end
|
|
1056
1097
|
|
|
1057
1098
|
# packages > receive — package_id: from arguments:(:identifier) (or overridden by public_link)
|
|
@@ -1077,7 +1118,8 @@ module Aspera
|
|
|
1077
1118
|
ids_to_download = all_packages[:items].map { |e| e['id'] }
|
|
1078
1119
|
formatter.display_status("Found #{ids_to_download.length} package(s).")
|
|
1079
1120
|
else
|
|
1080
|
-
ids_to_download =
|
|
1121
|
+
ids_to_download = Array(ids_to_download)
|
|
1122
|
+
Aspera.assert_array_all(ids_to_download, String) { 'Package id(s)' }
|
|
1081
1123
|
end
|
|
1082
1124
|
ts_paths = transfer.ts_source_paths(default: ['.'])
|
|
1083
1125
|
per_package_def = options.get_option(:package_folder).symbolize_keys
|
|
@@ -1099,7 +1141,7 @@ module Aspera
|
|
|
1099
1141
|
transfer.user_transfer_spec['destination_root'] = self.class.unique_folder(package_info, destination_folder, **per_package_def) unless per_package_def.empty?
|
|
1100
1142
|
dest_folder = transfer.user_transfer_spec['destination_root'] || destination_folder
|
|
1101
1143
|
formatter.display_status(%Q{Downloading package: [#{package_info['id']}] "#{package_info['name']}" to [#{dest_folder}]})
|
|
1102
|
-
statuses = transfer.start(transfer_spec,
|
|
1144
|
+
statuses = transfer.start(transfer_spec, oauth_api: package_node_api)
|
|
1103
1145
|
File.write(File.join(dest_folder, "#{package_id}.info.json"), package_info.to_json) if save_metadata
|
|
1104
1146
|
result_transfer.push({'package' => package_id, Runner::STATUS_FIELD => statuses})
|
|
1105
1147
|
if skip_ids_persistency && statuses.is_a?(Transfer::Result::Success)
|
|
@@ -1505,6 +1547,174 @@ module Aspera
|
|
|
1505
1547
|
Result::SingleObject.new(new_action)
|
|
1506
1548
|
end
|
|
1507
1549
|
|
|
1550
|
+
# automation helper methods
|
|
1551
|
+
|
|
1552
|
+
# Get one job. `GET workflow_instances/<id>` does not answer on the server (the job is searched without an index on `instance_id`),
|
|
1553
|
+
# so use the list, which does. The search string `q` matches the UUID (`instance_id`) but not the numeric identifier:
|
|
1554
|
+
# in this case, browse the list.
|
|
1555
|
+
# @param instance_id [String] Numeric identifier or UUID of the job
|
|
1556
|
+
# @return [Hash] The job
|
|
1557
|
+
def workflow_instance_find(instance_id)
|
|
1558
|
+
instance_id = instance_id.to_s
|
|
1559
|
+
is_uuid = instance_id.include?('-')
|
|
1560
|
+
limit = 1000
|
|
1561
|
+
offset = 0
|
|
1562
|
+
loop do
|
|
1563
|
+
query = {'limit' => limit, 'offset' => offset, 'sort' => '-state_change_time'}
|
|
1564
|
+
query['q'] = instance_id if is_uuid
|
|
1565
|
+
page = @automation_api.read('workflow_instances', query)
|
|
1566
|
+
found = page['workflow_instances'].find { |job| job[is_uuid ? 'instance_id' : 'id'].eql?(instance_id) }
|
|
1567
|
+
return found unless found.nil?
|
|
1568
|
+
offset += limit
|
|
1569
|
+
raise BadIdentifier.new('Workflow instance', instance_id) if is_uuid || offset >= page['total_count'].to_i
|
|
1570
|
+
end
|
|
1571
|
+
end
|
|
1572
|
+
|
|
1573
|
+
def workflow_details(workflow_id)
|
|
1574
|
+
workflow = @automation_api.read("workflows/#{workflow_id}")
|
|
1575
|
+
steps = Array(workflow['step_order']).map do |step_id|
|
|
1576
|
+
step = @automation_api.read("steps/#{step_id}")
|
|
1577
|
+
actions = Array(step['action_order']).map { |action_id| @automation_api.read("actions/#{action_id}") }
|
|
1578
|
+
step.merge('actions' => actions)
|
|
1579
|
+
end
|
|
1580
|
+
workflow.merge('steps' => steps)
|
|
1581
|
+
end
|
|
1582
|
+
|
|
1583
|
+
def workflow_export_data(workflow_id)
|
|
1584
|
+
wf = workflow_details(workflow_id)
|
|
1585
|
+
portable_steps = Array(wf['steps']).each_with_index.map do |step, step_idx|
|
|
1586
|
+
portable_actions = Array(step['actions']).each_with_index.map do |action, act_idx|
|
|
1587
|
+
action_data = action.dup
|
|
1588
|
+
orig_action_id = action_data.delete('id')
|
|
1589
|
+
action_data.delete('step_id')
|
|
1590
|
+
action_data.delete('created_at')
|
|
1591
|
+
action_data.delete('updated_at')
|
|
1592
|
+
action_data.delete('user_id')
|
|
1593
|
+
action_data.delete('organization_id')
|
|
1594
|
+
{
|
|
1595
|
+
'ref_id' => orig_action_id || "action_#{step_idx + 1}_#{act_idx + 1}",
|
|
1596
|
+
'name' => action_data['name'],
|
|
1597
|
+
'type' => action_data['type'],
|
|
1598
|
+
'data' => action_data['data']
|
|
1599
|
+
}.compact
|
|
1600
|
+
end
|
|
1601
|
+
orig_step_id = step['id']
|
|
1602
|
+
{
|
|
1603
|
+
'ref_id' => orig_step_id || "step_#{step_idx + 1}",
|
|
1604
|
+
'name' => step['name'],
|
|
1605
|
+
'actions' => portable_actions
|
|
1606
|
+
}.compact
|
|
1607
|
+
end
|
|
1608
|
+
{
|
|
1609
|
+
'name' => wf['name'],
|
|
1610
|
+
'trigger_type' => wf['trigger_type'] || 'manual',
|
|
1611
|
+
'allow_notifications' => wf['allow_notifications'] || false,
|
|
1612
|
+
'workflow_notifications' => wf['workflow_notifications'] || {},
|
|
1613
|
+
'steps' => portable_steps
|
|
1614
|
+
}
|
|
1615
|
+
end
|
|
1616
|
+
|
|
1617
|
+
def workflow_import_data(manifest)
|
|
1618
|
+
raise Cli::BadArgument, 'Manifest must be a Hash' unless manifest.is_a?(Hash)
|
|
1619
|
+
wf_params = {
|
|
1620
|
+
'name' => manifest['name'] || 'Imported Workflow',
|
|
1621
|
+
'trigger_type' => manifest['trigger_type'] || 'manual',
|
|
1622
|
+
'allow_notifications' => manifest['allow_notifications'] || false,
|
|
1623
|
+
'workflow_notifications' => manifest['workflow_notifications'] || {}
|
|
1624
|
+
}
|
|
1625
|
+
new_wf = @automation_api.create('workflows', wf_params)
|
|
1626
|
+
wf_id = new_wf['id']
|
|
1627
|
+
|
|
1628
|
+
step_id_map = {}
|
|
1629
|
+
action_id_map = {}
|
|
1630
|
+
created_step_ids = []
|
|
1631
|
+
|
|
1632
|
+
begin
|
|
1633
|
+
Array(manifest['steps']).each_with_index do |step_data, s_idx|
|
|
1634
|
+
step_name = step_data['name'] || "Step #{s_idx + 1}"
|
|
1635
|
+
old_step_ref = step_data['ref_id'] || step_data['id'] || "step_#{s_idx + 1}"
|
|
1636
|
+
new_step = @automation_api.create('steps', {'workflow_id' => wf_id, 'name' => step_name})
|
|
1637
|
+
new_step_id = new_step['id']
|
|
1638
|
+
step_id_map[old_step_ref] = new_step_id
|
|
1639
|
+
created_step_ids << new_step_id
|
|
1640
|
+
# The API refuses an action whose step is not yet in the workflow
|
|
1641
|
+
@automation_api.update("workflows/#{wf_id}", {'step_order' => created_step_ids})
|
|
1642
|
+
|
|
1643
|
+
created_action_ids = []
|
|
1644
|
+
Array(step_data['actions']).each_with_index do |action_data, a_idx|
|
|
1645
|
+
old_action_ref = action_data['ref_id'] || action_data['id'] || "action_#{s_idx + 1}_#{a_idx + 1}"
|
|
1646
|
+
action_payload = {
|
|
1647
|
+
'step_id' => new_step_id,
|
|
1648
|
+
'name' => action_data['name'] || (s_idx.zero? && a_idx.zero? ? 'Trigger' : "Action #{a_idx + 1}"),
|
|
1649
|
+
'type' => action_data['type'] || 'manual',
|
|
1650
|
+
'data' => remap_references(action_data['data'] || {}, step_id_map, action_id_map)
|
|
1651
|
+
}
|
|
1652
|
+
new_act = @automation_api.create('actions', action_payload)
|
|
1653
|
+
new_act_id = new_act['id']
|
|
1654
|
+
action_id_map[old_action_ref] = new_act_id
|
|
1655
|
+
created_action_ids << new_act_id
|
|
1656
|
+
end
|
|
1657
|
+
@automation_api.update("steps/#{new_step_id}", {'action_order' => created_action_ids})
|
|
1658
|
+
end
|
|
1659
|
+
rescue StandardError
|
|
1660
|
+
# do not leave a partial workflow behind
|
|
1661
|
+
begin
|
|
1662
|
+
@automation_api.delete("workflows/#{wf_id}")
|
|
1663
|
+
rescue StandardError => e
|
|
1664
|
+
Log.log.warn { "Could not delete partial workflow #{wf_id}: #{e.message}" }
|
|
1665
|
+
end
|
|
1666
|
+
raise
|
|
1667
|
+
end
|
|
1668
|
+
|
|
1669
|
+
workflow_details(wf_id)
|
|
1670
|
+
end
|
|
1671
|
+
|
|
1672
|
+
# The copy is made by the server: the API does not return secrets (tokens, passwords), so an export/import would lose them.
|
|
1673
|
+
def workflow_duplicate(workflow_id, new_name: nil)
|
|
1674
|
+
new_name ||= @automation_api.read("workflows/#{workflow_id}/default_copy_name")['default_copy_name']
|
|
1675
|
+
@automation_api.create("workflows/#{workflow_id}/copy", {'name' => new_name})
|
|
1676
|
+
end
|
|
1677
|
+
|
|
1678
|
+
# Reference to an action output in a string: step_id_<STEP>.action_id_<ACTION>
|
|
1679
|
+
ACTION_OUTPUT_REFERENCE = /step_id_((?>[^.\s{}"']{1,256}))\.action_id_((?>[^.\s{}"']{1,256}))/
|
|
1680
|
+
private_constant :ACTION_OUTPUT_REFERENCE
|
|
1681
|
+
|
|
1682
|
+
# Replace the step and action identifiers of the manifest by the new ones, in all strings of `data`
|
|
1683
|
+
# (action fields as well as `substitutions[].template`).
|
|
1684
|
+
# One pass only: an identifier that was just replaced must not be replaced again.
|
|
1685
|
+
# @param data [Object] Hash, Array, or scalar to copy
|
|
1686
|
+
# @param step_map [Hash] manifest step reference => new step id
|
|
1687
|
+
# @param action_map [Hash] manifest action reference => new action id
|
|
1688
|
+
# @return [Object] copy of `data`
|
|
1689
|
+
def remap_references(data, step_map, action_map)
|
|
1690
|
+
case data
|
|
1691
|
+
when Hash then data.transform_values { |v| remap_references(v, step_map, action_map) }
|
|
1692
|
+
when Array then data.map { |v| remap_references(v, step_map, action_map) }
|
|
1693
|
+
when String
|
|
1694
|
+
data.gsub(ACTION_OUTPUT_REFERENCE) { "step_id_#{step_map.fetch(Regexp.last_match(1), Regexp.last_match(1))}.action_id_#{action_map.fetch(Regexp.last_match(2), Regexp.last_match(2))}" }
|
|
1695
|
+
else data
|
|
1696
|
+
end
|
|
1697
|
+
end
|
|
1698
|
+
|
|
1699
|
+
# automation guide methods
|
|
1700
|
+
|
|
1701
|
+
def automation_guide_document
|
|
1702
|
+
require_relative '../../uri_reader'
|
|
1703
|
+
UriReader.read_first(AOC_AUTOMATION_GUIDE_URLS, what: 'AoC Automation Development Guide')
|
|
1704
|
+
end
|
|
1705
|
+
|
|
1706
|
+
def automation_guide_toc(level)
|
|
1707
|
+
require_relative '../../markdown'
|
|
1708
|
+
Result::ObjectList.new(Markdown.toc(automation_guide_document, max_level: level || 3), fields: %w[level title anchor])
|
|
1709
|
+
end
|
|
1710
|
+
|
|
1711
|
+
def automation_guide_section(anchor)
|
|
1712
|
+
require_relative '../../markdown'
|
|
1713
|
+
text = Markdown.extract_section(automation_guide_document, anchor)
|
|
1714
|
+
Aspera.assert(!text.nil?, type: Cli::Error) { "Section not found: #{anchor}, use `toc` to list anchors" }
|
|
1715
|
+
Result::Text.new(text)
|
|
1716
|
+
end
|
|
1717
|
+
|
|
1508
1718
|
# admin > client > set_pub_key
|
|
1509
1719
|
def action_admin_client_set_pub_key(private_key_pem:, client_id:, **)
|
|
1510
1720
|
c = aoc_res_cfg(:client)
|
|
@@ -1583,9 +1793,10 @@ module Aspera
|
|
|
1583
1793
|
if Api::AoC.workspace_access?(item)
|
|
1584
1794
|
{'name' => '[Internal permission]'}
|
|
1585
1795
|
else
|
|
1586
|
-
aoc_api.read("admin/#{item['access_type']}s/#{item['access_id']}")
|
|
1796
|
+
aoc_api.read("admin/#{item['access_type']}s/#{item['access_id']}")
|
|
1587
1797
|
end
|
|
1588
|
-
rescue => e
|
|
1798
|
+
rescue StandardError => e
|
|
1799
|
+
# e.g. member deleted: the error is shown instead of the name
|
|
1589
1800
|
{'name' => e.to_s}
|
|
1590
1801
|
end
|
|
1591
1802
|
end
|
|
@@ -1607,13 +1818,8 @@ module Aspera
|
|
|
1607
1818
|
end
|
|
1608
1819
|
|
|
1609
1820
|
def action_gateway(parameters: {}, **)
|
|
1610
|
-
|
|
1611
|
-
parameters
|
|
1612
|
-
uri = URI.parse(parameters.delete(:url) { WebServerSimple::DEFAULT_URL })
|
|
1613
|
-
server = WebServerSimple.new(uri, **parameters.slice(*WebServerSimple::PARAMS))
|
|
1614
|
-
Aspera.assert(parameters.except(*WebServerSimple::PARAMS).empty?) { "unexpected parameters: #{parameters.except(*WebServerSimple::PARAMS).keys}" }
|
|
1615
|
-
server.mount(uri.path, Faspex4GWServlet, aoc_api, aoc_api.workspace_info[:id])
|
|
1616
|
-
server.start
|
|
1821
|
+
require_relative '../../faspex_gw'
|
|
1822
|
+
Faspex4GWServlet.serve(parameters.symbolize_keys, type: Cli::BadArgument) { [aoc_api, aoc_api.workspace_info[:id]] }
|
|
1617
1823
|
return Result::Status.new('Gateway terminated')
|
|
1618
1824
|
end
|
|
1619
1825
|
end
|