aspera-cli 4.28.0 → 4.29.1
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 +217 -2
- data/CODE_OF_CONDUCT.md +18 -0
- data/CONTRIBUTING.md +135 -56
- data/GOVERNANCE.md +30 -0
- data/LICENSE +201 -0
- data/README.md +122 -26
- data/SECURITY.md +84 -0
- data/bin/ascli +8 -5
- data/bin/asession +9 -6
- data/docs/README.md +1895 -632
- data/docs/test-mcp-with-ai.md +8 -8
- 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 +20 -19
- data/lib/aspera/agent/factory.rb +6 -3
- 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 +7 -4
- data/lib/aspera/api/faspex.rb +16 -9
- data/lib/aspera/api/httpgw.rb +9 -6
- data/lib/aspera/api/node.rb +29 -22
- data/lib/aspera/ascmd.rb +8 -5
- data/lib/aspera/ascp/installation.rb +95 -67
- 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 +370 -0
- data/lib/aspera/ascp/log_locations.rb +163 -0
- data/lib/aspera/ascp/management.rb +16 -8
- data/lib/aspera/ascp/session_errors.rb +217 -0
- data/lib/aspera/assert.rb +4 -0
- data/lib/aspera/cli/ascp_actions.rb +12 -19
- data/lib/aspera/cli/ascp_logs_actions.rb +188 -0
- data/lib/aspera/cli/async_transfer_store.rb +7 -4
- data/lib/aspera/cli/bootstrapper.rb +38 -33
- data/lib/aspera/cli/command_line.rb +63 -8
- data/lib/aspera/cli/command_registry.rb +9 -1
- data/lib/aspera/cli/command_spec.rb +47 -7
- data/lib/aspera/cli/completion/ascli.bash +19 -5
- data/lib/aspera/cli/completion/ascli.fish +13 -2
- data/lib/aspera/cli/completion/ascli.ps1 +31 -9
- data/lib/aspera/cli/completion/ascli.zsh +22 -6
- data/lib/aspera/cli/completion_actions.rb +303 -69
- data/lib/aspera/cli/context.rb +9 -4
- data/lib/aspera/cli/deprecation.rb +5 -2
- data/lib/aspera/cli/error.rb +6 -0
- data/lib/aspera/cli/extended_value.rb +66 -31
- data/lib/aspera/cli/formatter.rb +43 -30
- data/lib/aspera/cli/gem_checker.rb +9 -6
- data/lib/aspera/cli/hints.rb +22 -10
- data/lib/aspera/cli/http.rb +38 -10
- data/lib/aspera/cli/info.rb +12 -7
- data/lib/aspera/cli/mailer.rb +6 -3
- data/lib/aspera/cli/mcp/http_servlet.rb +7 -8
- data/lib/aspera/cli/mcp/secrets.rb +8 -5
- data/lib/aspera/cli/mcp/tool.rb +20 -17
- 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 +77 -18
- data/lib/aspera/cli/options.schema.yaml +641 -80
- data/lib/aspera/cli/parser.rb +71 -35
- data/lib/aspera/cli/plugins/alee.rb +7 -4
- data/lib/aspera/cli/plugins/aoc.rb +248 -37
- data/lib/aspera/cli/plugins/ats.rb +10 -9
- data/lib/aspera/cli/plugins/base.rb +50 -18
- data/lib/aspera/cli/plugins/basic_auth.rb +5 -2
- data/lib/aspera/cli/plugins/config.rb +210 -104
- data/lib/aspera/cli/plugins/console.rb +6 -3
- data/lib/aspera/cli/plugins/cos.rb +8 -4
- data/lib/aspera/cli/plugins/factory.rb +21 -7
- data/lib/aspera/cli/plugins/faspex5.rb +31 -26
- data/lib/aspera/cli/plugins/faspio.rb +7 -5
- data/lib/aspera/cli/plugins/httpgw.rb +7 -4
- data/lib/aspera/cli/plugins/mcp.rb +42 -22
- data/lib/aspera/cli/plugins/node.rb +39 -38
- data/lib/aspera/cli/plugins/oauth.rb +23 -6
- data/lib/aspera/cli/plugins/orchestrator.rb +287 -83
- data/lib/aspera/cli/plugins/preview.rb +72 -45
- data/lib/aspera/cli/plugins/server.rb +66 -14
- data/lib/aspera/cli/plugins/shares.rb +87 -18
- data/lib/aspera/cli/plugins/transferd.rb +228 -0
- data/lib/aspera/cli/poll.rb +236 -0
- data/lib/aspera/cli/preset_actions.rb +144 -30
- data/lib/aspera/cli/preset_manager.rb +113 -35
- data/lib/aspera/cli/prompt.rb +157 -9
- data/lib/aspera/cli/result.rb +12 -8
- data/lib/aspera/cli/runner.rb +89 -48
- data/lib/aspera/cli/secret_finder.rb +4 -1
- data/lib/aspera/cli/security.rb +89 -9
- data/lib/aspera/cli/special_values.rb +4 -1
- data/lib/aspera/cli/sync_actions.rb +15 -10
- data/lib/aspera/cli/table_fitter.rb +3 -0
- data/lib/aspera/cli/terminal_formatter.rb +9 -6
- data/lib/aspera/cli/transfer_actions.rb +11 -8
- data/lib/aspera/cli/transfer_agent.rb +43 -20
- data/lib/aspera/cli/transfer_progress.rb +14 -45
- data/lib/aspera/cli/vault_actions.rb +45 -0
- data/lib/aspera/cli/vault_manager.rb +188 -42
- data/lib/aspera/cli/version.rb +4 -1
- data/lib/aspera/cli/web_secret.rb +12 -10
- data/lib/aspera/cli/wizard.rb +42 -39
- data/lib/aspera/command_line_builder.rb +9 -5
- data/lib/aspera/command_line_converter.rb +4 -1
- data/lib/aspera/coverage.rb +103 -33
- data/lib/aspera/data_repository.rb +4 -1
- data/lib/aspera/dot_container.rb +4 -1
- data/lib/aspera/environment.rb +23 -12
- data/lib/aspera/exec_spec.rb +3 -0
- data/lib/aspera/faspex_gw.rb +13 -9
- data/lib/aspera/faspex_postproc.rb +15 -12
- data/lib/aspera/formatter_interface.rb +4 -1
- data/lib/aspera/graphql.rb +5 -1
- data/lib/aspera/hash_ext.rb +3 -0
- data/lib/aspera/id_generator.rb +20 -5
- data/lib/aspera/inflate.rb +43 -0
- data/lib/aspera/json_rpc/client.rb +6 -5
- data/lib/aspera/json_rpc/version.rb +3 -0
- data/lib/aspera/line_logger.rb +4 -1
- data/lib/aspera/link_header.rb +4 -1
- data/lib/aspera/log.rb +18 -5
- data/lib/aspera/markdown.rb +5 -2
- data/lib/aspera/mime.rb +3 -0
- data/lib/aspera/nagios.rb +6 -4
- data/lib/aspera/node_emulator.rb +15 -13
- data/lib/aspera/oauth/client/base.rb +124 -73
- data/lib/aspera/oauth/client/boot.rb +7 -4
- data/lib/aspera/oauth/client/factory.rb +41 -18
- data/lib/aspera/oauth/client/generic.rb +5 -1
- data/lib/aspera/oauth/client/json_credentials.rb +7 -3
- data/lib/aspera/oauth/client/jwt.rb +6 -3
- data/lib/aspera/oauth/client/shares_web.rb +94 -0
- data/lib/aspera/oauth/client/url_json.rb +7 -3
- data/lib/aspera/oauth/client/web.rb +40 -13
- data/lib/aspera/oauth/server/pkce.rb +6 -5
- data/lib/aspera/orchestrator_workflow_checker.rb +129 -2
- 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 +16 -6
- data/lib/aspera/preview/utils.rb +6 -4
- data/lib/aspera/products/connect.rb +5 -2
- data/lib/aspera/products/desktop.rb +17 -2
- 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 +3 -0
- data/lib/aspera/rest/aspera_errors.rb +4 -1
- data/lib/aspera/rest/call_error.rb +3 -0
- data/lib/aspera/rest/client.rb +45 -34
- data/lib/aspera/rest/error_analyzer.rb +5 -2
- data/lib/aspera/rest/list.rb +8 -4
- data/lib/aspera/rest/parameters.rb +3 -0
- data/lib/aspera/rest/util.rb +8 -5
- data/lib/aspera/rest.rb +9 -6
- data/lib/aspera/schema/IBM Aspera Faspex API-5.0-enhanced.yaml +9 -9
- data/lib/aspera/schema/IBM Aspera Orchestrator API-v1-enhanced.yaml +118 -30
- 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/async_tables.yaml +11 -10
- data/lib/aspera/schema/documentation.rb +8 -2
- data/lib/aspera/schema/reader.rb +7 -0
- data/lib/aspera/schema/registry.rb +44 -28
- data/lib/aspera/schema/transferd-config.schema.json +333 -0
- data/lib/aspera/schema/validator.rb +4 -1
- data/lib/aspera/sealed_hash.rb +150 -0
- data/lib/aspera/secret/hider.rb +213 -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 +112 -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 +5 -2
- 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 +3 -0
- data/lib/aspera/sync/conf.schema.yaml +9 -4
- data/lib/aspera/sync/database.rb +3 -0
- data/lib/aspera/sync/operations.rb +17 -15
- data/lib/aspera/temp_file_manager.rb +8 -4
- 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 +17 -14
- data/lib/aspera/transfer/result.rb +23 -0
- data/lib/aspera/transfer/resumer.rb +6 -4
- data/lib/aspera/transfer/spec.rb +9 -22
- data/lib/aspera/units/decimal.rb +67 -0
- data/lib/aspera/units/duration.rb +109 -0
- data/lib/aspera/uri_reader.rb +64 -9
- data/lib/aspera/web_auth/index.html.erb +6 -2
- 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 +47 -10
- data/lib/aspera/web_page.rb +7 -2
- data/lib/aspera/web_server_simple.rb +6 -3
- data/lib/aspera/yaml.rb +5 -1
- data/llms-install.md +88 -0
- data/llms.txt +87 -0
- data/skills/ascli/SKILL.md +94 -0
- data.tar.gz.sig +0 -0
- metadata +77 -20
- metadata.gz.sig +0 -0
- data/lib/aspera/duration.rb +0 -42
- data/lib/aspera/keychain/base.rb +0 -30
- data/lib/aspera/keychain/encrypted_hash.rb +0 -192
- data/lib/aspera/keychain/factory.rb +0 -58
- data/lib/aspera/keychain/hashicorp_vault.rb +0 -77
- data/lib/aspera/keychain/macos_security.rb +0 -277
- data/lib/aspera/keychain/one_password_api.rb +0 -91
- data/lib/aspera/keychain/one_password_base.rb +0 -39
- data/lib/aspera/keychain/one_password_cli.rb +0 -100
- data/lib/aspera/secret_hider.rb +0 -196
- data/lib/aspera/secret_strength.rb +0 -114
|
@@ -1,25 +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
|
-
|
|
19
|
-
|
|
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'
|
|
20
24
|
require 'securerandom'
|
|
21
25
|
require 'date'
|
|
22
|
-
require 'aspera/rainbow'
|
|
23
26
|
using Rainbow
|
|
24
27
|
|
|
25
28
|
module Aspera
|
|
@@ -104,17 +107,19 @@ module Aspera
|
|
|
104
107
|
# @param package_info [Hash] Package information
|
|
105
108
|
# @param destination_folder [String] Base folder
|
|
106
109
|
# @param fld [Array] List of fields of package
|
|
110
|
+
# @return [String] Folder path in destination folder
|
|
107
111
|
def unique_folder(package_info, destination_folder, fld: nil, seq: false, opt: false)
|
|
108
112
|
Aspera.assert_array_all(fld, String, type: BadArgument) { 'fld' }
|
|
109
113
|
Aspera.assert_values(fld.length, [1, 2]) { 'fld length' }
|
|
110
|
-
|
|
114
|
+
# Existence is checked in the destination folder
|
|
115
|
+
folder = File.join(destination_folder, Environment.instance.sanitized_filename(package_info[fld[0]].to_s))
|
|
111
116
|
if seq
|
|
112
117
|
folder = next_available_folder(folder, always: !opt)
|
|
113
118
|
elsif fld[1] && (Dir.exist?(folder) || !opt)
|
|
114
119
|
# NOTE: it might already exist
|
|
115
|
-
folder = "#{folder}.#{Environment.instance.sanitized_filename(fld[1])}"
|
|
120
|
+
folder = "#{folder}.#{Environment.instance.sanitized_filename(package_info[fld[1]].to_s)}"
|
|
116
121
|
end
|
|
117
|
-
|
|
122
|
+
folder
|
|
118
123
|
end
|
|
119
124
|
|
|
120
125
|
# @return [String] AoC REST path for an admin resource type
|
|
@@ -212,7 +217,7 @@ module Aspera
|
|
|
212
217
|
auto_set_jwt = false
|
|
213
218
|
# use browser authentication to bootstrap
|
|
214
219
|
use_browser_authentication = false
|
|
215
|
-
|
|
220
|
+
private_key = wizard.ask_private_key(
|
|
216
221
|
user: wiz_username,
|
|
217
222
|
url: app_url,
|
|
218
223
|
page: [Environment.char('👤'), 'Account Settings', 'Profile', 'Public Key']
|
|
@@ -236,8 +241,8 @@ module Aspera
|
|
|
236
241
|
formatter.display_status('- origin: localhost')
|
|
237
242
|
formatter.display_status('Use the generated client id and secret in the following prompts.'.red)
|
|
238
243
|
Environment.instance.open_uri("#{app_url}/admin/integrations/api-clients")
|
|
239
|
-
client_id = options.get_option(:client_id, mandatory:
|
|
240
|
-
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)
|
|
241
246
|
# use_browser_authentication = true
|
|
242
247
|
end
|
|
243
248
|
end
|
|
@@ -252,7 +257,7 @@ module Aspera
|
|
|
252
257
|
end
|
|
253
258
|
myself = aoc_api.read('self')
|
|
254
259
|
if auto_set_pub_key
|
|
255
|
-
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
|
|
256
261
|
formatter.display_status('Updating profile with the public key.')
|
|
257
262
|
aoc_api.update("users/#{myself['id']}", {'public_key' => pub_key_pem})
|
|
258
263
|
end
|
|
@@ -266,7 +271,7 @@ module Aspera
|
|
|
266
271
|
url: app_url,
|
|
267
272
|
username: myself['email'],
|
|
268
273
|
auth: :jwt.to_s,
|
|
269
|
-
private_key:
|
|
274
|
+
private_key: private_key,
|
|
270
275
|
client_id: client_id,
|
|
271
276
|
client_secret: client_secret
|
|
272
277
|
}.compact,
|
|
@@ -741,7 +746,7 @@ module Aspera
|
|
|
741
746
|
Result::ObjectList.new(events)
|
|
742
747
|
end
|
|
743
748
|
)
|
|
744
|
-
command :transfers, description: 'List transfer events',
|
|
749
|
+
command :transfers, read_only: true, description: 'List transfer events',
|
|
745
750
|
arguments: [
|
|
746
751
|
EVENT_RESOURCE_TYPE_ARG,
|
|
747
752
|
EVENT_RESOURCE_ID_ARG.merge(mandatory: false, default: nil)
|
|
@@ -806,7 +811,7 @@ module Aspera
|
|
|
806
811
|
)
|
|
807
812
|
command :create, description: 'Create an app membership', arguments: [{name: :membership, type: Hash}]
|
|
808
813
|
end
|
|
809
|
-
command :automation, description: 'Manage automation
|
|
814
|
+
command :automation, description: 'Manage automation'
|
|
810
815
|
command :gateway, description: 'Start AoC Faspex4 gateway',
|
|
811
816
|
arguments: [{name: :parameters, type: Hash, mandatory: false, default: {}, schema: Schema::Registry::GATEWAY_OPTIONS}]
|
|
812
817
|
|
|
@@ -933,9 +938,41 @@ module Aspera
|
|
|
933
938
|
# Automation API: a workflow has ordered steps (step_order), a step has ordered actions (action_order)
|
|
934
939
|
AUTOMATION_CRUD = {api: :@automation_api, body_component: Schema::Registry::AUTOMATION}.freeze
|
|
935
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
|
|
936
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
|
|
937
961
|
commands_under :workflows do
|
|
938
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)) }
|
|
939
976
|
command :launch, description: 'Launch a workflow',
|
|
940
977
|
arguments: [{name: :workflow_id, type: :identifier}],
|
|
941
978
|
action: ->(workflow_id:, **) { Result::SingleObject.new(@automation_api.create("workflows/#{workflow_id}/launch", {})) }
|
|
@@ -994,9 +1031,12 @@ module Aspera
|
|
|
994
1031
|
end
|
|
995
1032
|
commands_under :instances do
|
|
996
1033
|
crud_commands(
|
|
997
|
-
**AUTOMATION_CRUD, entity: 'workflow_instances', name: 'workflow instance', operations: %i[list
|
|
1034
|
+
**AUTOMATION_CRUD, entity: 'workflow_instances', name: 'workflow instance', operations: %i[list delete],
|
|
998
1035
|
items_key: 'workflow_instances', query_component: Schema::Registry::AUTOMATION
|
|
999
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)) }
|
|
1000
1040
|
command :cancel, description: 'Cancel workflow instance',
|
|
1001
1041
|
arguments: [{name: :workflow_instance_id, type: :identifier}],
|
|
1002
1042
|
action: ->(workflow_instance_id:, **) { Result::SingleObject.new(@automation_api.update("workflow_instances/#{workflow_instance_id}", {'status' => 'canceled'})) }
|
|
@@ -1025,7 +1065,6 @@ module Aspera
|
|
|
1025
1065
|
# Build automation API and store in @automation_api ivar.
|
|
1026
1066
|
def setup_automation_api(**)
|
|
1027
1067
|
change_api_scope(Api::AoC::Scope::ADMIN_USER)
|
|
1028
|
-
Log.log.warn('BETA: work under progress')
|
|
1029
1068
|
@automation_api = Rest::Client.new(**aoc_api.params, base_url: aoc_api.base_url.gsub('/api/', '/automation/'))
|
|
1030
1069
|
{}
|
|
1031
1070
|
end
|
|
@@ -1041,6 +1080,8 @@ module Aspera
|
|
|
1041
1080
|
|
|
1042
1081
|
# packages > send
|
|
1043
1082
|
def action_packages_send(package:, **)
|
|
1083
|
+
# The package is created before the transfer
|
|
1084
|
+
transfer.assert_no_dry_run
|
|
1044
1085
|
package_data = package
|
|
1045
1086
|
new_user_option = options.get_option(:new_user_option)
|
|
1046
1087
|
option_validate = options.get_option(:validate_metadata)
|
|
@@ -1053,7 +1094,7 @@ module Aspera
|
|
|
1053
1094
|
end
|
|
1054
1095
|
package_data['encryption_at_rest'] = true if transfer.user_transfer_spec['content_protection'].eql?('encrypt')
|
|
1055
1096
|
created_package = aoc_api.create_package_simple(package_data, option_validate, new_user_option)
|
|
1056
|
-
return Runner.result_object_transfer(created_package[:info], transfer.start(created_package[:spec],
|
|
1097
|
+
return Runner.result_object_transfer(created_package[:info], transfer.start(created_package[:spec], oauth_api: created_package[:node]))
|
|
1057
1098
|
end
|
|
1058
1099
|
|
|
1059
1100
|
# packages > receive — package_id: from arguments:(:identifier) (or overridden by public_link)
|
|
@@ -1079,7 +1120,8 @@ module Aspera
|
|
|
1079
1120
|
ids_to_download = all_packages[:items].map { |e| e['id'] }
|
|
1080
1121
|
formatter.display_status("Found #{ids_to_download.length} package(s).")
|
|
1081
1122
|
else
|
|
1082
|
-
ids_to_download =
|
|
1123
|
+
ids_to_download = Array(ids_to_download)
|
|
1124
|
+
Aspera.assert_array_all(ids_to_download, String) { 'Package id(s)' }
|
|
1083
1125
|
end
|
|
1084
1126
|
ts_paths = transfer.ts_source_paths(default: ['.'])
|
|
1085
1127
|
per_package_def = options.get_option(:package_folder).symbolize_keys
|
|
@@ -1101,8 +1143,8 @@ module Aspera
|
|
|
1101
1143
|
transfer.user_transfer_spec['destination_root'] = self.class.unique_folder(package_info, destination_folder, **per_package_def) unless per_package_def.empty?
|
|
1102
1144
|
dest_folder = transfer.user_transfer_spec['destination_root'] || destination_folder
|
|
1103
1145
|
formatter.display_status(%Q{Downloading package: [#{package_info['id']}] "#{package_info['name']}" to [#{dest_folder}]})
|
|
1104
|
-
statuses = transfer.start(transfer_spec,
|
|
1105
|
-
File.write(File.join(dest_folder, "#{package_id}.info.json"), package_info.to_json) if save_metadata
|
|
1146
|
+
statuses = transfer.start(transfer_spec, oauth_api: package_node_api)
|
|
1147
|
+
File.write(File.join(dest_folder, "#{package_id}.info.json"), package_info.to_json) if save_metadata && !statuses.is_a?(Transfer::Result::DryRun)
|
|
1106
1148
|
result_transfer.push({'package' => package_id, Runner::STATUS_FIELD => statuses})
|
|
1107
1149
|
if skip_ids_persistency && statuses.is_a?(Transfer::Result::Success)
|
|
1108
1150
|
skip_ids_persistency.data.push(package_id)
|
|
@@ -1507,6 +1549,174 @@ module Aspera
|
|
|
1507
1549
|
Result::SingleObject.new(new_action)
|
|
1508
1550
|
end
|
|
1509
1551
|
|
|
1552
|
+
# automation helper methods
|
|
1553
|
+
|
|
1554
|
+
# Get one job. `GET workflow_instances/<id>` does not answer on the server (the job is searched without an index on `instance_id`),
|
|
1555
|
+
# so use the list, which does. The search string `q` matches the UUID (`instance_id`) but not the numeric identifier:
|
|
1556
|
+
# in this case, browse the list.
|
|
1557
|
+
# @param instance_id [String] Numeric identifier or UUID of the job
|
|
1558
|
+
# @return [Hash] The job
|
|
1559
|
+
def workflow_instance_find(instance_id)
|
|
1560
|
+
instance_id = instance_id.to_s
|
|
1561
|
+
is_uuid = instance_id.include?('-')
|
|
1562
|
+
limit = 1000
|
|
1563
|
+
offset = 0
|
|
1564
|
+
loop do
|
|
1565
|
+
query = {'limit' => limit, 'offset' => offset, 'sort' => '-state_change_time'}
|
|
1566
|
+
query['q'] = instance_id if is_uuid
|
|
1567
|
+
page = @automation_api.read('workflow_instances', query)
|
|
1568
|
+
found = page['workflow_instances'].find { |job| job[is_uuid ? 'instance_id' : 'id'].eql?(instance_id) }
|
|
1569
|
+
return found unless found.nil?
|
|
1570
|
+
offset += limit
|
|
1571
|
+
raise BadIdentifier.new('Workflow instance', instance_id) if is_uuid || offset >= page['total_count'].to_i
|
|
1572
|
+
end
|
|
1573
|
+
end
|
|
1574
|
+
|
|
1575
|
+
def workflow_details(workflow_id)
|
|
1576
|
+
workflow = @automation_api.read("workflows/#{workflow_id}")
|
|
1577
|
+
steps = Array(workflow['step_order']).map do |step_id|
|
|
1578
|
+
step = @automation_api.read("steps/#{step_id}")
|
|
1579
|
+
actions = Array(step['action_order']).map { |action_id| @automation_api.read("actions/#{action_id}") }
|
|
1580
|
+
step.merge('actions' => actions)
|
|
1581
|
+
end
|
|
1582
|
+
workflow.merge('steps' => steps)
|
|
1583
|
+
end
|
|
1584
|
+
|
|
1585
|
+
def workflow_export_data(workflow_id)
|
|
1586
|
+
wf = workflow_details(workflow_id)
|
|
1587
|
+
portable_steps = Array(wf['steps']).each_with_index.map do |step, step_idx|
|
|
1588
|
+
portable_actions = Array(step['actions']).each_with_index.map do |action, act_idx|
|
|
1589
|
+
action_data = action.dup
|
|
1590
|
+
orig_action_id = action_data.delete('id')
|
|
1591
|
+
action_data.delete('step_id')
|
|
1592
|
+
action_data.delete('created_at')
|
|
1593
|
+
action_data.delete('updated_at')
|
|
1594
|
+
action_data.delete('user_id')
|
|
1595
|
+
action_data.delete('organization_id')
|
|
1596
|
+
{
|
|
1597
|
+
'ref_id' => orig_action_id || "action_#{step_idx + 1}_#{act_idx + 1}",
|
|
1598
|
+
'name' => action_data['name'],
|
|
1599
|
+
'type' => action_data['type'],
|
|
1600
|
+
'data' => action_data['data']
|
|
1601
|
+
}.compact
|
|
1602
|
+
end
|
|
1603
|
+
orig_step_id = step['id']
|
|
1604
|
+
{
|
|
1605
|
+
'ref_id' => orig_step_id || "step_#{step_idx + 1}",
|
|
1606
|
+
'name' => step['name'],
|
|
1607
|
+
'actions' => portable_actions
|
|
1608
|
+
}.compact
|
|
1609
|
+
end
|
|
1610
|
+
{
|
|
1611
|
+
'name' => wf['name'],
|
|
1612
|
+
'trigger_type' => wf['trigger_type'] || 'manual',
|
|
1613
|
+
'allow_notifications' => wf['allow_notifications'] || false,
|
|
1614
|
+
'workflow_notifications' => wf['workflow_notifications'] || {},
|
|
1615
|
+
'steps' => portable_steps
|
|
1616
|
+
}
|
|
1617
|
+
end
|
|
1618
|
+
|
|
1619
|
+
def workflow_import_data(manifest)
|
|
1620
|
+
raise Cli::BadArgument, 'Manifest must be a Hash' unless manifest.is_a?(Hash)
|
|
1621
|
+
wf_params = {
|
|
1622
|
+
'name' => manifest['name'] || 'Imported Workflow',
|
|
1623
|
+
'trigger_type' => manifest['trigger_type'] || 'manual',
|
|
1624
|
+
'allow_notifications' => manifest['allow_notifications'] || false,
|
|
1625
|
+
'workflow_notifications' => manifest['workflow_notifications'] || {}
|
|
1626
|
+
}
|
|
1627
|
+
new_wf = @automation_api.create('workflows', wf_params)
|
|
1628
|
+
wf_id = new_wf['id']
|
|
1629
|
+
|
|
1630
|
+
step_id_map = {}
|
|
1631
|
+
action_id_map = {}
|
|
1632
|
+
created_step_ids = []
|
|
1633
|
+
|
|
1634
|
+
begin
|
|
1635
|
+
Array(manifest['steps']).each_with_index do |step_data, s_idx|
|
|
1636
|
+
step_name = step_data['name'] || "Step #{s_idx + 1}"
|
|
1637
|
+
old_step_ref = step_data['ref_id'] || step_data['id'] || "step_#{s_idx + 1}"
|
|
1638
|
+
new_step = @automation_api.create('steps', {'workflow_id' => wf_id, 'name' => step_name})
|
|
1639
|
+
new_step_id = new_step['id']
|
|
1640
|
+
step_id_map[old_step_ref] = new_step_id
|
|
1641
|
+
created_step_ids << new_step_id
|
|
1642
|
+
# The API refuses an action whose step is not yet in the workflow
|
|
1643
|
+
@automation_api.update("workflows/#{wf_id}", {'step_order' => created_step_ids})
|
|
1644
|
+
|
|
1645
|
+
created_action_ids = []
|
|
1646
|
+
Array(step_data['actions']).each_with_index do |action_data, a_idx|
|
|
1647
|
+
old_action_ref = action_data['ref_id'] || action_data['id'] || "action_#{s_idx + 1}_#{a_idx + 1}"
|
|
1648
|
+
action_payload = {
|
|
1649
|
+
'step_id' => new_step_id,
|
|
1650
|
+
'name' => action_data['name'] || (s_idx.zero? && a_idx.zero? ? 'Trigger' : "Action #{a_idx + 1}"),
|
|
1651
|
+
'type' => action_data['type'] || 'manual',
|
|
1652
|
+
'data' => remap_references(action_data['data'] || {}, step_id_map, action_id_map)
|
|
1653
|
+
}
|
|
1654
|
+
new_act = @automation_api.create('actions', action_payload)
|
|
1655
|
+
new_act_id = new_act['id']
|
|
1656
|
+
action_id_map[old_action_ref] = new_act_id
|
|
1657
|
+
created_action_ids << new_act_id
|
|
1658
|
+
end
|
|
1659
|
+
@automation_api.update("steps/#{new_step_id}", {'action_order' => created_action_ids})
|
|
1660
|
+
end
|
|
1661
|
+
rescue StandardError
|
|
1662
|
+
# do not leave a partial workflow behind
|
|
1663
|
+
begin
|
|
1664
|
+
@automation_api.delete("workflows/#{wf_id}")
|
|
1665
|
+
rescue StandardError => e
|
|
1666
|
+
Log.log.warn { "Could not delete partial workflow #{wf_id}: #{e.message}" }
|
|
1667
|
+
end
|
|
1668
|
+
raise
|
|
1669
|
+
end
|
|
1670
|
+
|
|
1671
|
+
workflow_details(wf_id)
|
|
1672
|
+
end
|
|
1673
|
+
|
|
1674
|
+
# The copy is made by the server: the API does not return secrets (tokens, passwords), so an export/import would lose them.
|
|
1675
|
+
def workflow_duplicate(workflow_id, new_name: nil)
|
|
1676
|
+
new_name ||= @automation_api.read("workflows/#{workflow_id}/default_copy_name")['default_copy_name']
|
|
1677
|
+
@automation_api.create("workflows/#{workflow_id}/copy", {'name' => new_name})
|
|
1678
|
+
end
|
|
1679
|
+
|
|
1680
|
+
# Reference to an action output in a string: step_id_<STEP>.action_id_<ACTION>
|
|
1681
|
+
ACTION_OUTPUT_REFERENCE = /step_id_((?>[^.\s{}"']{1,256}))\.action_id_((?>[^.\s{}"']{1,256}))/
|
|
1682
|
+
private_constant :ACTION_OUTPUT_REFERENCE
|
|
1683
|
+
|
|
1684
|
+
# Replace the step and action identifiers of the manifest by the new ones, in all strings of `data`
|
|
1685
|
+
# (action fields as well as `substitutions[].template`).
|
|
1686
|
+
# One pass only: an identifier that was just replaced must not be replaced again.
|
|
1687
|
+
# @param data [Object] Hash, Array, or scalar to copy
|
|
1688
|
+
# @param step_map [Hash] manifest step reference => new step id
|
|
1689
|
+
# @param action_map [Hash] manifest action reference => new action id
|
|
1690
|
+
# @return [Object] copy of `data`
|
|
1691
|
+
def remap_references(data, step_map, action_map)
|
|
1692
|
+
case data
|
|
1693
|
+
when Hash then data.transform_values { |v| remap_references(v, step_map, action_map) }
|
|
1694
|
+
when Array then data.map { |v| remap_references(v, step_map, action_map) }
|
|
1695
|
+
when String
|
|
1696
|
+
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))}" }
|
|
1697
|
+
else data
|
|
1698
|
+
end
|
|
1699
|
+
end
|
|
1700
|
+
|
|
1701
|
+
# automation guide methods
|
|
1702
|
+
|
|
1703
|
+
def automation_guide_document
|
|
1704
|
+
require_relative '../../uri_reader'
|
|
1705
|
+
UriReader.read_first(AOC_AUTOMATION_GUIDE_URLS, what: 'AoC Automation Development Guide')
|
|
1706
|
+
end
|
|
1707
|
+
|
|
1708
|
+
def automation_guide_toc(level)
|
|
1709
|
+
require_relative '../../markdown'
|
|
1710
|
+
Result::ObjectList.new(Markdown.toc(automation_guide_document, max_level: level || 3), fields: %w[level title anchor])
|
|
1711
|
+
end
|
|
1712
|
+
|
|
1713
|
+
def automation_guide_section(anchor)
|
|
1714
|
+
require_relative '../../markdown'
|
|
1715
|
+
text = Markdown.extract_section(automation_guide_document, anchor)
|
|
1716
|
+
Aspera.assert(!text.nil?, type: Cli::Error) { "Section not found: #{anchor}, use `toc` to list anchors" }
|
|
1717
|
+
Result::Text.new(text)
|
|
1718
|
+
end
|
|
1719
|
+
|
|
1510
1720
|
# admin > client > set_pub_key
|
|
1511
1721
|
def action_admin_client_set_pub_key(private_key_pem:, client_id:, **)
|
|
1512
1722
|
c = aoc_res_cfg(:client)
|
|
@@ -1585,9 +1795,10 @@ module Aspera
|
|
|
1585
1795
|
if Api::AoC.workspace_access?(item)
|
|
1586
1796
|
{'name' => '[Internal permission]'}
|
|
1587
1797
|
else
|
|
1588
|
-
aoc_api.read("admin/#{item['access_type']}s/#{item['access_id']}")
|
|
1798
|
+
aoc_api.read("admin/#{item['access_type']}s/#{item['access_id']}")
|
|
1589
1799
|
end
|
|
1590
|
-
rescue => e
|
|
1800
|
+
rescue StandardError => e
|
|
1801
|
+
# e.g. member deleted: the error is shown instead of the name
|
|
1591
1802
|
{'name' => e.to_s}
|
|
1592
1803
|
end
|
|
1593
1804
|
end
|
|
@@ -1609,7 +1820,7 @@ module Aspera
|
|
|
1609
1820
|
end
|
|
1610
1821
|
|
|
1611
1822
|
def action_gateway(parameters: {}, **)
|
|
1612
|
-
|
|
1823
|
+
require_relative '../../faspex_gw'
|
|
1613
1824
|
Faspex4GWServlet.serve(parameters.symbolize_keys, type: Cli::BadArgument) { [aoc_api, aoc_api.workspace_info[:id]] }
|
|
1614
1825
|
return Result::Status.new('Gateway terminated')
|
|
1615
1826
|
end
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
require_relative 'base'
|
|
7
|
+
require_relative 'node'
|
|
8
|
+
require_relative '../../api/ats'
|
|
9
|
+
require_relative '../../api/aoc'
|
|
10
|
+
require_relative '../../api/alee'
|
|
11
|
+
require_relative '../../assert'
|
|
12
|
+
require_relative '../../rainbow'
|
|
12
13
|
using Rainbow
|
|
13
14
|
|
|
14
15
|
module Aspera
|
|
@@ -45,7 +46,7 @@ module Aspera
|
|
|
45
46
|
command :aws_trust_policy, description: 'Show AWS trust policy', action: ->(**) { Result::SingleObject.new(ats_api.read('aws/trustpolicy', {region: options.get_option(:region, mandatory: true)})) }
|
|
46
47
|
|
|
47
48
|
commands_under :cluster do
|
|
48
|
-
command :clouds, description: 'List cloud providers', action: ->(**) { Result::ObjectList.new(@ats_api_open.cloud_names.map { |k, v| CLOUD_TABLE.zip([k, v]).to_h }) }
|
|
49
|
+
command :clouds, read_only: true, description: 'List cloud providers', action: ->(**) { Result::ObjectList.new(@ats_api_open.cloud_names.map { |k, v| CLOUD_TABLE.zip([k, v]).to_h }) }
|
|
49
50
|
command :list, description: 'List ATS servers', action: ->(**) { Result::ObjectList.new(@ats_api_open.all_servers, fields: %w[id cloud region]) }
|
|
50
51
|
command :show, description: 'Show a specific server (or use options cloud and region)',
|
|
51
52
|
arguments: [{name: :server_id, mandatory: false, default: nil}]
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../extended_value'
|
|
7
|
+
require_relative '../parser'
|
|
8
|
+
require_relative '../../assert'
|
|
9
|
+
require_relative '../result'
|
|
10
|
+
require_relative '../poll'
|
|
11
|
+
require_relative '../command_registry'
|
|
12
|
+
require_relative '../option_declarator'
|
|
13
|
+
require_relative '../special_values'
|
|
14
|
+
require_relative '../../rest/list'
|
|
15
|
+
require_relative '../../schema/registry'
|
|
12
16
|
|
|
13
17
|
module Aspera
|
|
14
18
|
module Cli
|
|
@@ -81,7 +85,7 @@ module Aspera
|
|
|
81
85
|
return "#{verb.capitalize} #{noun}" unless verb.eql?(:list)
|
|
82
86
|
plural =
|
|
83
87
|
case noun
|
|
84
|
-
when /[^aeiou]y\z/ then noun.sub(/y\z/, 'ies')
|
|
88
|
+
when /[^aeiou]y\z/ then noun.sub(/y\z/, 'ies') # cspell:disable-line
|
|
85
89
|
when /(s|x|sh|ch)\z/ then "#{noun}es"
|
|
86
90
|
else "#{noun}s"
|
|
87
91
|
end
|
|
@@ -286,6 +290,7 @@ module Aspera
|
|
|
286
290
|
option :query, description: 'Additional filter for for some commands (list/delete)', allowed: [Hash, Array, NilClass]
|
|
287
291
|
option :bulk, description: 'Bulk operation (only some)', allowed: Type::BOOLEAN, default: false
|
|
288
292
|
option :bfail, description: 'Bulk operation error handling', allowed: Type::BOOLEAN, default: true
|
|
293
|
+
option :poll, description: 'Repeat a read-only command (dot-notation: interval, max, timeout, until, show, errors)', schema: Schema::Registry::POLL_OPTIONS
|
|
289
294
|
|
|
290
295
|
def initialize(context:)
|
|
291
296
|
Aspera.assert_type(context, Context) { 'context' }
|
|
@@ -350,6 +355,9 @@ module Aspera
|
|
|
350
355
|
end
|
|
351
356
|
end
|
|
352
357
|
else
|
|
358
|
+
Security.instance.check_level(spec.security, "command #{current_path.join(' ')}") if spec
|
|
359
|
+
# Before anything is executed (setup, arguments, action)
|
|
360
|
+
poll = poll_result(current_path, spec) if is_leaf
|
|
353
361
|
# Phase A - for intermediate nodes only: resolve all ArgumentSpec declared on this node
|
|
354
362
|
# before dispatching to children (leaf nodes resolve their arguments inside execute_leaf).
|
|
355
363
|
ctx = resolve_arguments(spec.arguments, ctx) if !is_leaf && spec&.arguments
|
|
@@ -358,7 +366,7 @@ module Aspera
|
|
|
358
366
|
|
|
359
367
|
# Phase B - leaf fast-path or child dispatch
|
|
360
368
|
if is_leaf
|
|
361
|
-
dispatch_leaf(current_path, spec, ctx)
|
|
369
|
+
dispatch_leaf(current_path, spec, ctx, poll: poll)
|
|
362
370
|
else
|
|
363
371
|
dispatch_child(current_path, registry, ctx)
|
|
364
372
|
end
|
|
@@ -369,13 +377,32 @@ module Aspera
|
|
|
369
377
|
# @param current_path [Array<Symbol>]
|
|
370
378
|
# @param spec [CommandSpec]
|
|
371
379
|
# @param ctx [Hash]
|
|
380
|
+
# @param poll [Result::Poll, nil] With option `poll`: result that executes the action when displayed
|
|
372
381
|
# @return [Object]
|
|
373
|
-
def dispatch_leaf(current_path, spec, ctx)
|
|
382
|
+
def dispatch_leaf(current_path, spec, ctx, poll: nil)
|
|
374
383
|
if @context.help_requested
|
|
375
384
|
@help_path = current_path
|
|
376
385
|
raise Cli::HelpRequest, self
|
|
377
386
|
end
|
|
378
|
-
execute_leaf(spec, ctx)
|
|
387
|
+
execute_leaf(spec, ctx, poll: poll)
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
# With option `poll`, check that the command is read-only, and the parameters of `poll`
|
|
391
|
+
# @param current_path [Array<Symbol>] path of the leaf command
|
|
392
|
+
# @param spec [CommandSpec] leaf command
|
|
393
|
+
# @return [Result::Poll, nil] `nil` if option `poll` is not set
|
|
394
|
+
# @raise [Cli::BadArgument] if the command is not read-only, or a parameter is invalid
|
|
395
|
+
def poll_result(current_path, spec)
|
|
396
|
+
parameters = options.get_option(:poll)
|
|
397
|
+
return if parameters.nil? || parameters.empty?
|
|
398
|
+
command = [self.class.name.split('::').last.downcase, *current_path].join(' ')
|
|
399
|
+
Aspera.assert(spec.read_only?, type: Cli::BadArgument) do
|
|
400
|
+
"Option poll: refused on `#{command}`: only a read-only command can be repeated (e.g. list, show, status)"
|
|
401
|
+
end
|
|
402
|
+
# Options that make a read-only command change state at each run
|
|
403
|
+
Aspera.assert(!options.get_option(:once_only), type: Cli::BadArgument) { 'Option poll: refused with option once_only: it saves state at each run' }
|
|
404
|
+
Aspera.assert(options.get_option(:notify_to).nil?, type: Cli::BadArgument) { 'Option poll: refused with option notify_to: it sends emails at each run' }
|
|
405
|
+
Result::Poll.new(parameters, format: formatter&.format_type)
|
|
379
406
|
end
|
|
380
407
|
|
|
381
408
|
# Phase B, child branch: consume the next command argument, then either continue
|
|
@@ -482,13 +509,17 @@ module Aspera
|
|
|
482
509
|
# they are not read again from the command line.
|
|
483
510
|
# @param spec [CommandSpec] a leaf node (no children)
|
|
484
511
|
# @param ctx [Hash] accumulated context (pre-resolved keys are not re-consumed)
|
|
512
|
+
# @param poll [Result::Poll, nil] With option `poll`: the action is executed when this result is displayed
|
|
485
513
|
# @return [Object]
|
|
486
|
-
def execute_leaf(spec, ctx)
|
|
514
|
+
def execute_leaf(spec, ctx, poll: nil)
|
|
487
515
|
a = action_for(spec)
|
|
488
516
|
# Always resolve declared arguments (even when transfer_paths is set — those arguments
|
|
489
517
|
# are consumed first; ts_source_paths then reads whatever remains in the queue).
|
|
490
518
|
ctx = resolve_arguments(spec.arguments, ctx) if spec.arguments
|
|
491
|
-
invoke_action(a, [], ctx)
|
|
519
|
+
return invoke_action(a, [], ctx) if poll.nil?
|
|
520
|
+
# Arguments are resolved once, the action is executed at each run
|
|
521
|
+
poll.action = -> { invoke_action(a, [], ctx) }
|
|
522
|
+
poll
|
|
492
523
|
end
|
|
493
524
|
|
|
494
525
|
# Resolve positional arguments from the CLI argument stream, in order.
|
|
@@ -505,6 +536,8 @@ module Aspera
|
|
|
505
536
|
options.get_next_argument(arg_spec.name.to_s, mandatory: false) if options.next_argument_in?([ctx[arg_spec.name].to_s, SpecialValues::ALL])
|
|
506
537
|
next
|
|
507
538
|
end
|
|
539
|
+
# Not given: not passed to the action, which uses its own default
|
|
540
|
+
next if arg_spec.omit_absent && options.command_or_arg_empty?
|
|
508
541
|
lookup_cb = arg_spec.lookup if arg_spec.type.eql?(:identifier)
|
|
509
542
|
current = ctx
|
|
510
543
|
block =
|
|
@@ -549,7 +582,7 @@ module Aspera
|
|
|
549
582
|
else
|
|
550
583
|
case arg_spec.type
|
|
551
584
|
when :identifier
|
|
552
|
-
options.instance_identifier(description: arg_spec.name.to_s, &block)
|
|
585
|
+
options.instance_identifier(description: arg_spec.name.to_s, mandatory: arg_spec.mandatory, default: arg_spec.default, &block)
|
|
553
586
|
else
|
|
554
587
|
# Class or Array<Class> -> pass as validation type
|
|
555
588
|
# When interactive: true, prompt for this argument only when no CLI argument is provided
|
|
@@ -563,7 +596,7 @@ module Aspera
|
|
|
563
596
|
accept_list: arg_spec.allowed,
|
|
564
597
|
default: arg_spec.interactive ? nil : arg_spec.default,
|
|
565
598
|
schema: arg_spec.schema,
|
|
566
|
-
|
|
599
|
+
evaluate: arg_spec.evaluate
|
|
567
600
|
)
|
|
568
601
|
end
|
|
569
602
|
end
|
|
@@ -676,7 +709,6 @@ module Aspera
|
|
|
676
709
|
# @param data [Hash, Array<Hash>] Entity data (Array with bulk), from the command's declared `data` argument
|
|
677
710
|
# @param display_fields [Array, nil] Fields to display
|
|
678
711
|
def entity_create(api:, entity:, data:, display_fields: nil, **)
|
|
679
|
-
data = [data] unless data.is_a?(Array)
|
|
680
712
|
bulk_result(data, command: :create, fields: display_fields) do |params|
|
|
681
713
|
api.create(entity, params)
|
|
682
714
|
end
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../../rest'
|
|
7
|
+
require_relative 'base'
|
|
5
8
|
|
|
6
9
|
module Aspera
|
|
7
10
|
module Cli
|