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
data/lib/aspera/api/node.rb
DELETED
|
@@ -1,684 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
-
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
|
|
6
|
-
require_relative '../link_header'
|
|
7
|
-
require_relative '../transfer/spec'
|
|
8
|
-
require_relative '../rest'
|
|
9
|
-
require_relative '../oauth/client/factory'
|
|
10
|
-
require_relative '../log'
|
|
11
|
-
require_relative '../assert'
|
|
12
|
-
require_relative '../inflate'
|
|
13
|
-
require_relative '../secret/hider'
|
|
14
|
-
require_relative '../environment'
|
|
15
|
-
require_relative '../rainbow'
|
|
16
|
-
require 'base64'
|
|
17
|
-
require 'openssl'
|
|
18
|
-
require 'pathname'
|
|
19
|
-
require 'zlib'
|
|
20
|
-
require 'net/ssh/buffer'
|
|
21
|
-
using Rainbow
|
|
22
|
-
|
|
23
|
-
module Aspera
|
|
24
|
-
module Api
|
|
25
|
-
# Combination of Node API with access key and file identifier on that node
|
|
26
|
-
class NodeFileId
|
|
27
|
-
# @param api [Aspera::Api::Node] API client
|
|
28
|
-
attr_reader :node_api
|
|
29
|
-
# @param id [String] File identifier
|
|
30
|
-
attr_reader :file_id
|
|
31
|
-
|
|
32
|
-
# Initialize a new instance of NodeFileId
|
|
33
|
-
# @param api [Aspera::Api::Node] API client
|
|
34
|
-
# @param id [String] File identifier in access key
|
|
35
|
-
def initialize(api, id)
|
|
36
|
-
@node_api = api
|
|
37
|
-
@file_id = id
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# Aspera Node API client
|
|
42
|
-
# with gen4 extensions (access keys)
|
|
43
|
-
class Node < Rest::Client
|
|
44
|
-
# Format of node scope : node.<access key>:<scope>
|
|
45
|
-
module Scope
|
|
46
|
-
# Node sub-scopes
|
|
47
|
-
USER = 'user:all'
|
|
48
|
-
ADMIN = 'admin:all'
|
|
49
|
-
# Separator between node.AK and user:all
|
|
50
|
-
SEPARATOR = ':'
|
|
51
|
-
NODE_PREFIX = 'node.'
|
|
52
|
-
|
|
53
|
-
extend self
|
|
54
|
-
|
|
55
|
-
# Encode node API scope
|
|
56
|
-
# @param access_key [String] Access Key
|
|
57
|
-
# @param scope [String] internal scope
|
|
58
|
-
# @return [String] full node scope
|
|
59
|
-
def join(access_key:, scope:)
|
|
60
|
-
["#{NODE_PREFIX}#{access_key}", scope].join(SEPARATOR)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# Decode node scope into access key and scope
|
|
64
|
-
# @param scope [String] scope string to split
|
|
65
|
-
# @return [Hash] decoded scope with access key and scope parts
|
|
66
|
-
def split(scope)
|
|
67
|
-
items = scope.split(Scope::SEPARATOR, 2)
|
|
68
|
-
Aspera.assert(items.length.eql?(2)) { "invalid scope: #{scope}" }
|
|
69
|
-
Aspera.assert(items[0].start_with?(NODE_PREFIX)) { "invalid scope: #{scope}" }
|
|
70
|
-
{access_key: items[0].delete_prefix(NODE_PREFIX), scope: items[1]}
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
# Delimiter in decoded node token
|
|
74
|
-
SIGNATURE_DELIMITER = '==SIGNATURE=='
|
|
75
|
-
# Default validity when generating a bearer token "manually"
|
|
76
|
-
BEARER_TOKEN_VALIDITY_DEFAULT = 86400
|
|
77
|
-
# Maximum size of a decoded bearer token (a few kB): it is given by the user, a client, or a server
|
|
78
|
-
BEARER_TOKEN_MAX_INFLATED_SIZE = 65_536
|
|
79
|
-
private_constant :SIGNATURE_DELIMITER, :BEARER_TOKEN_VALIDITY_DEFAULT, :BEARER_TOKEN_MAX_INFLATED_SIZE
|
|
80
|
-
# Node API permissions: delete list mkdir preview read rename write
|
|
81
|
-
ACCESS_LEVELS = %w[delete list mkdir preview read rename write].freeze
|
|
82
|
-
# Special HTTP Headers
|
|
83
|
-
HEADER_X_ASPERA_ACCESS_KEY = 'X-Aspera-AccessKey'
|
|
84
|
-
HEADER_X_CACHE_CONTROL = 'X-Aspera-Cache-Control'
|
|
85
|
-
HEADER_X_NEXT_ITER_TOKEN = 'X-Aspera-Next-Iteration-Token'
|
|
86
|
-
HEADER_X_TOTAL_COUNT = 'X-Total-Count'
|
|
87
|
-
HEADER_ACCEPT_VERSION = 'Accept-Version'
|
|
88
|
-
# / in cloud
|
|
89
|
-
PATH_SEPARATOR = '/'
|
|
90
|
-
|
|
91
|
-
# Register node special token decoder
|
|
92
|
-
OAuth::Factory.instance.register_decoder(lambda { |token| Node.decode_bearer_token(token) })
|
|
93
|
-
|
|
94
|
-
# Class instance variable, access with accessors on class
|
|
95
|
-
@api_options = {
|
|
96
|
-
# Set to false to read transfer parameters from download_setup
|
|
97
|
-
standard_ports: true,
|
|
98
|
-
# Set to false to bypass cache in redis
|
|
99
|
-
cache: true,
|
|
100
|
-
accept_v4: true
|
|
101
|
-
}
|
|
102
|
-
OPTIONS = @api_options.keys.freeze
|
|
103
|
-
|
|
104
|
-
class << self
|
|
105
|
-
attr_reader :api_options
|
|
106
|
-
attr_reader :use_dynamic_key
|
|
107
|
-
|
|
108
|
-
def api_options=(options_hash)
|
|
109
|
-
Aspera.assert_type(options_hash, Hash)
|
|
110
|
-
options_hash.each do |key, val|
|
|
111
|
-
Aspera.assert(@api_options.key?(key.to_sym)) { "unknown api option: #{key} (#{OPTIONS.join(', ')})" }
|
|
112
|
-
Aspera.assert_type(val, TrueClass, FalseClass) { "api options value for #{key} should be boolean" }
|
|
113
|
-
@api_options[key.to_sym] = val
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
# Adds cache control header for node API /files/:id
|
|
118
|
-
# as globally specified to read request
|
|
119
|
-
# Use like this: read(..., headers: add_cache_control)
|
|
120
|
-
# @param headers [Hash] optional initial headers to add to
|
|
121
|
-
# @return [Hash] headers with cache control header added if needed
|
|
122
|
-
def add_cache_control(headers = {})
|
|
123
|
-
headers[HEADER_X_CACHE_CONTROL] = 'no-cache' unless api_options[:cache]
|
|
124
|
-
headers
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
# Set private key to be used
|
|
128
|
-
# @param pem_content [String] PEM encoded private key
|
|
129
|
-
def use_dynamic_key=(pem_content)
|
|
130
|
-
Aspera.assert_type(pem_content, String)
|
|
131
|
-
@dynamic_key = OpenSSL::PKey.read(pem_content)
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
# Adds fields `public_keys` in provided Hash, if dynamic key is set.
|
|
135
|
-
# @param parameters [Hash] Hash to add public key to
|
|
136
|
-
# @return [Hash] Hash with public key added
|
|
137
|
-
def add_public_key(parameters)
|
|
138
|
-
if @dynamic_key
|
|
139
|
-
ssh_key = Net::SSH::Buffer.from(:key, @dynamic_key)
|
|
140
|
-
# Get pub key in OpenSSH public key format (authorized_keys)
|
|
141
|
-
parameters['public_keys'] = [
|
|
142
|
-
ssh_key.read_string,
|
|
143
|
-
Base64.strict_encode64(ssh_key.to_s)
|
|
144
|
-
].join(' ')
|
|
145
|
-
end
|
|
146
|
-
return parameters
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
# Adds fields `ssh_private_key` in provided Hash, if dynamic key is set.
|
|
150
|
-
# @param parameters [Hash] Hash to add private key to
|
|
151
|
-
def add_private_key(parameters)
|
|
152
|
-
parameters['ssh_private_key'] = @dynamic_key.to_pem if @dynamic_key
|
|
153
|
-
return parameters
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
# Split path into folder + filename
|
|
157
|
-
# @param path [String] file path to split
|
|
158
|
-
# @return [Array(String, String)] containing folder + inside folder/file
|
|
159
|
-
def split_folder(path)
|
|
160
|
-
folder = path.split(PATH_SEPARATOR)
|
|
161
|
-
inside = folder.pop
|
|
162
|
-
[folder.join(PATH_SEPARATOR), inside]
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
# Create an Aspera Node bearer token
|
|
166
|
-
# @param access_key [String] Access key identifier
|
|
167
|
-
# @param payload [String] JSON payload to be included in the token
|
|
168
|
-
# @param private_key [OpenSSL::PKey::RSA] Private key to sign the token
|
|
169
|
-
def bearer_token(access_key:, payload:, private_key:)
|
|
170
|
-
Aspera.assert_type(payload, Hash)
|
|
171
|
-
Aspera.assert(payload.key?('user_id'), 'payload must have user_id')
|
|
172
|
-
Aspera.assert_type(payload['user_id'], String)
|
|
173
|
-
Aspera.assert(!payload['user_id'].empty?, 'user_id must not be empty')
|
|
174
|
-
Aspera.assert_type(private_key, OpenSSL::PKey::RSA)
|
|
175
|
-
# Manage convenience parameters
|
|
176
|
-
expiration_sec = payload['_validity'] || BEARER_TOKEN_VALIDITY_DEFAULT
|
|
177
|
-
payload.delete('_validity')
|
|
178
|
-
scope = payload.delete('_scope') || Scope::USER
|
|
179
|
-
payload['scope'] ||= Scope.join(access_key: access_key, scope: scope)
|
|
180
|
-
payload['auth_type'] ||= 'access_key'
|
|
181
|
-
payload['expires_at'] ||= (Time.now + expiration_sec).utc.strftime('%FT%TZ')
|
|
182
|
-
payload_json = JSON.generate(payload)
|
|
183
|
-
token = Base64.strict_encode64(Zlib::Deflate.deflate([
|
|
184
|
-
payload_json,
|
|
185
|
-
SIGNATURE_DELIMITER,
|
|
186
|
-
Base64.strict_encode64(private_key.sign(OpenSSL::Digest.new('sha512'), payload_json)).scan(/.{1,60}/).join("\n"),
|
|
187
|
-
''
|
|
188
|
-
].join("\n")))
|
|
189
|
-
# Hidden wherever it appears (logs, results)
|
|
190
|
-
Secret::Hider.instance.add_secret_values(token)
|
|
191
|
-
return token
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
# Decode an Aspera Node bearer token
|
|
195
|
-
# @param token [String] Base64 of deflated payload and signature
|
|
196
|
-
# @return [Hash] Payload
|
|
197
|
-
# @raise [ParameterError] If the decoded token is too large
|
|
198
|
-
def decode_bearer_token(token)
|
|
199
|
-
inflated = Inflate.limited(Base64.decode64(token), max_size: BEARER_TOKEN_MAX_INFLATED_SIZE, what: 'Node bearer token')
|
|
200
|
-
return JSON.parse(inflated.partition(SIGNATURE_DELIMITER).first)
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
# @return [Hash] Headers to call node API with access key and auth
|
|
204
|
-
def bearer_headers(bearer_auth, access_key: nil)
|
|
205
|
-
# If username is not provided, use the access key from the token
|
|
206
|
-
if access_key.nil?
|
|
207
|
-
access_key = Node::Scope.split(Node.decode_bearer_token(OAuth::Factory.bearer_token(bearer_auth))['scope'])[:access_key]
|
|
208
|
-
Aspera.assert(!access_key.nil?, 'access_key could not be determined from token')
|
|
209
|
-
end
|
|
210
|
-
return {
|
|
211
|
-
HEADER_X_ASPERA_ACCESS_KEY => access_key,
|
|
212
|
-
'Authorization' => bearer_auth
|
|
213
|
-
}
|
|
214
|
-
end
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
# @return [Api::AoC::AppInfo,nil] set for AoC
|
|
218
|
-
attr_reader :app_info
|
|
219
|
-
|
|
220
|
-
# @param app_info [Api::AoC::AppInfo,nil] App information, typically AoC
|
|
221
|
-
# @param add_tspec [Hash,nil] Additional transfer spec
|
|
222
|
-
# @param base_url [String] Rest parameters
|
|
223
|
-
# @param auth [String,nil] Rest parameters
|
|
224
|
-
# @param headers [String,nil] Rest parameters
|
|
225
|
-
def initialize(app_info: nil, add_tspec: nil, **rest_args)
|
|
226
|
-
# Init Rest
|
|
227
|
-
super(**rest_args)
|
|
228
|
-
@dynamic_key = nil
|
|
229
|
-
@app_info = app_info
|
|
230
|
-
# This is added to transfer spec, for instance to add tags (COS)
|
|
231
|
-
@add_tspec = add_tspec
|
|
232
|
-
@std_t_spec_cache = nil
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
# Update transfer spec with special additional tags
|
|
236
|
-
# @param tspec [Hash] Transfer spec to be modified
|
|
237
|
-
# @return [Hash] initial modified tspec
|
|
238
|
-
def add_tspec_info(tspec)
|
|
239
|
-
tspec.deep_merge!(@add_tspec) unless @add_tspec.nil?
|
|
240
|
-
return tspec
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
# @return [Node, nil] a Node Api object or nil if no App defined
|
|
244
|
-
def node_id_to_node(node_id)
|
|
245
|
-
if !@app_info.nil?
|
|
246
|
-
return self if node_id.eql?(@app_info.node_info['id'])
|
|
247
|
-
return @app_info.api.node_api_from(
|
|
248
|
-
node_id: node_id,
|
|
249
|
-
workspace_id: @app_info.workspace_id,
|
|
250
|
-
workspace_name: @app_info.workspace_name
|
|
251
|
-
)
|
|
252
|
-
end
|
|
253
|
-
Log.log.warn { "Cannot resolve link with node id #{node_id}, no resolver" }
|
|
254
|
-
return
|
|
255
|
-
rescue Rest::CallError => e
|
|
256
|
-
Log.log.warn { "Cannot resolve link with node id #{node_id}: #{e.message}" }
|
|
257
|
-
return
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
# Check if a link entry in folder has target information
|
|
261
|
-
# @param entry [Hash] entry in folder
|
|
262
|
-
# @return [Boolean] true if target information is available
|
|
263
|
-
def entry_has_link_information(entry)
|
|
264
|
-
# If target information is missing in folder, try to get it on entry
|
|
265
|
-
if entry['target_node_id'].nil? || entry['target_id'].nil?
|
|
266
|
-
link_entry = read("files/#{entry['id']}")
|
|
267
|
-
entry['target_node_id'] = link_entry['target_node_id']
|
|
268
|
-
entry['target_id'] = link_entry['target_id']
|
|
269
|
-
end
|
|
270
|
-
return true unless entry['target_node_id'].nil? || entry['target_id'].nil?
|
|
271
|
-
Log.log.warn { "Missing target information for link: #{entry['name']}" }
|
|
272
|
-
return false
|
|
273
|
-
end
|
|
274
|
-
|
|
275
|
-
# Read folder content with pagination management for gen4 (non-recursive)
|
|
276
|
-
#
|
|
277
|
-
# Behavior WITHOUT `Accept-Version: 4.0`:
|
|
278
|
-
# - Without `page` and `per_page`: all entries are returned
|
|
279
|
-
# - With `page` or `per_page`: both parameters are required, otherwise returns 400 error
|
|
280
|
-
#
|
|
281
|
-
# Behavior WITH `Accept-Version: 4.0`:
|
|
282
|
-
# - Unavailable query parameters (ignored or return 400 error):
|
|
283
|
-
# page, sort, min_size, max_size, min_modified_time, max_modified_time,
|
|
284
|
-
# target_id, target_node_id, files_prefetch_count, name_iglob
|
|
285
|
-
# - Query parameter `include`: accepted but has no effect (access_levels and recursive_counts already included)
|
|
286
|
-
# - Query parameter `iteration_token`: enables pagination
|
|
287
|
-
# * Response header `X-Aspera-Next-Iteration-Token`: token for next page
|
|
288
|
-
# * Response header `X-Aspera-Total-Count`: total count of entries
|
|
289
|
-
#
|
|
290
|
-
# @param file_id [String] The folder file identifier
|
|
291
|
-
# @param query [Hash, nil] Optional query parameters for the API request
|
|
292
|
-
# @param exception [Boolean] If true, raises exceptions on errors; if false, logs warnings
|
|
293
|
-
# @param path [String, nil] Optional path for logging purposes
|
|
294
|
-
# @return [Array<Hash>] List of folder entries (files, folders, links)
|
|
295
|
-
def read_folder_content(file_id, query = nil, exception: true, path: nil)
|
|
296
|
-
folder_items = []
|
|
297
|
-
begin
|
|
298
|
-
query ||= {}
|
|
299
|
-
headers = self.class.add_cache_control
|
|
300
|
-
use_v4 = self.class.api_options[:accept_v4]
|
|
301
|
-
return read("files/#{file_id}/files", query, headers: headers) unless use_v4 || query.key?('page') || query.key?('per_page')
|
|
302
|
-
if use_v4
|
|
303
|
-
headers[HEADER_ACCEPT_VERSION] = '4.0'
|
|
304
|
-
query['per_page'] = 1000 unless query.key?('per_page')
|
|
305
|
-
else
|
|
306
|
-
# API v3 requires both `page` (first is 1) and `per_page`
|
|
307
|
-
query['page'] = 1 unless query.key?('page')
|
|
308
|
-
query['per_page'] = 1000 unless query.key?('per_page')
|
|
309
|
-
end
|
|
310
|
-
loop do
|
|
311
|
-
Rest::Parameters.instance.spinner_cb.call(folder_items.count)
|
|
312
|
-
data, http = read("files/#{file_id}/files", query, headers: headers, ret: :both)
|
|
313
|
-
folder_items.concat(data)
|
|
314
|
-
if use_v4
|
|
315
|
-
iteration_token = http[HEADER_X_NEXT_ITER_TOKEN]
|
|
316
|
-
break if iteration_token.nil? || iteration_token.empty?
|
|
317
|
-
query['iteration_token'] = iteration_token
|
|
318
|
-
else
|
|
319
|
-
# Last page: empty, or shorter than requested
|
|
320
|
-
break if data.empty? || (query.key?('per_page') && data.length < query['per_page'].to_i)
|
|
321
|
-
query['page'] = query['page'].to_i + 1
|
|
322
|
-
end
|
|
323
|
-
end
|
|
324
|
-
rescue StandardError => e
|
|
325
|
-
raise e if exception
|
|
326
|
-
Log.log.warn { "#{path || file_id}: #{e.class} #{e.message}" }
|
|
327
|
-
Log.log.debug { (['Backtrace:'] + e.backtrace).join("\n") }
|
|
328
|
-
ensure
|
|
329
|
-
Rest::Parameters.instance.spinner_cb.call(folder_items.count, action: :success)
|
|
330
|
-
end
|
|
331
|
-
folder_items
|
|
332
|
-
end
|
|
333
|
-
|
|
334
|
-
# Recursively browse in a folder (with non-recursive method)
|
|
335
|
-
# Entries of folders are processed if the processing method returns true
|
|
336
|
-
# Links are processed on the respective node
|
|
337
|
-
# @param method_sym [Symbol] processing method, arguments: entry, path, state
|
|
338
|
-
# @param state [Object] state object sent to processing method
|
|
339
|
-
# @param top_file_id [String] file id to start at (default = access key root file id)
|
|
340
|
-
# @param top_file_path [String] path of top folder (default = /)
|
|
341
|
-
# @para query [Hash, nil] optional query for `read`
|
|
342
|
-
def process_folder_tree(method_sym:, state:, top_file_id:, top_file_path: '/', query: nil)
|
|
343
|
-
Aspera.assert(!top_file_path.nil?, 'top_file_path not set')
|
|
344
|
-
Log.log.debug { "process_folder_tree: node=#{@app_info ? @app_info.node_info['id'] : 'nil'}, file id=#{top_file_id}, path=#{top_file_path}" }
|
|
345
|
-
# Start at top folder
|
|
346
|
-
folders_to_explore = [{id: top_file_id, path: top_file_path}]
|
|
347
|
-
Log.dump(:folders_to_explore, folders_to_explore)
|
|
348
|
-
until folders_to_explore.empty?
|
|
349
|
-
# Consume first in job list
|
|
350
|
-
current_item = folders_to_explore.shift
|
|
351
|
-
Log.log.debug { "Exploring #{current_item[:path]}".bg(:green) }
|
|
352
|
-
# Get folder content
|
|
353
|
-
folder_contents = read_folder_content(current_item[:id], query, exception: false, path: current_item[:path])
|
|
354
|
-
Log.dump(:folder_contents, folder_contents)
|
|
355
|
-
folder_contents.each do |entry|
|
|
356
|
-
if entry.key?('error')
|
|
357
|
-
Log.log.error(entry['error']['user_message']) if entry['error'].is_a?(Hash) && entry['error'].key?('user_message')
|
|
358
|
-
next
|
|
359
|
-
end
|
|
360
|
-
current_path = File.join(current_item[:path], entry['name'])
|
|
361
|
-
Log.log.debug { "process_folder_tree: checking #{current_path}" }
|
|
362
|
-
# Call block, continue only if method returns true
|
|
363
|
-
next unless send(method_sym, entry, current_path, state)
|
|
364
|
-
# Entry type is file, folder or link
|
|
365
|
-
case entry['type']
|
|
366
|
-
when 'folder'
|
|
367
|
-
folders_to_explore.push({id: entry['id'], path: current_path})
|
|
368
|
-
when 'link'
|
|
369
|
-
if entry_has_link_information(entry)
|
|
370
|
-
node_id_to_node(entry['target_node_id'])&.process_folder_tree(
|
|
371
|
-
method_sym: method_sym,
|
|
372
|
-
state: state,
|
|
373
|
-
top_file_id: entry['target_id'],
|
|
374
|
-
top_file_path: current_path
|
|
375
|
-
)
|
|
376
|
-
end
|
|
377
|
-
end
|
|
378
|
-
end
|
|
379
|
-
end
|
|
380
|
-
end
|
|
381
|
-
|
|
382
|
-
# Navigate the path from given file id on current node, and return the node and file id of target.
|
|
383
|
-
# If the path ends with a "/" or process_last_link is true then if the last item in path is a link, it is followed.
|
|
384
|
-
# @param top_file_id [String] id initial file id
|
|
385
|
-
# @param path [String] file or folder path (end with "/" is like setting process_last_link)
|
|
386
|
-
# @param process_last_link [Boolean] if true, follow the last link
|
|
387
|
-
# @return [NodeFileId] Full reference to file on node
|
|
388
|
-
def resolve_api_fid(top_file_id, path, process_last_link = false)
|
|
389
|
-
Aspera.assert_type(top_file_id, String)
|
|
390
|
-
Aspera.assert_type(path, String)
|
|
391
|
-
process_last_link ||= path.end_with?(PATH_SEPARATOR)
|
|
392
|
-
path_elements = path.split(PATH_SEPARATOR).reject(&:empty?)
|
|
393
|
-
return NodeFileId.new(self, top_file_id) if path_elements.empty?
|
|
394
|
-
resolve_state = {path: path_elements, consumed: [], result: nil, process_last_link: process_last_link}
|
|
395
|
-
process_folder_tree(method_sym: :process_api_fid, state: resolve_state, top_file_id: top_file_id)
|
|
396
|
-
Aspera.assert(!resolve_state[:result].nil?, type: ParameterError) { "Entry not found: #{resolve_state[:path].first} in /#{resolve_state[:consumed].join(PATH_SEPARATOR)}" }
|
|
397
|
-
Log.log.debug { "resolve_api_fid: #{path} -> #{resolve_state[:result].node_api.base_url} #{resolve_state[:result].file_id}" }
|
|
398
|
-
return resolve_state[:result]
|
|
399
|
-
end
|
|
400
|
-
|
|
401
|
-
# Given a list of paths, finds a common root and list of sub-paths
|
|
402
|
-
# @param top_file_id [String] Root file id
|
|
403
|
-
# @param paths [Array(Hash)] List of paths
|
|
404
|
-
# @return [Array<(NodeFileId, Array<Hash>)>] Tuple containing the file identifier and paths
|
|
405
|
-
# - [0] NodeFileId: Reference to the file on the node
|
|
406
|
-
# - [1] Array<Hash>: Transfer paths, each Hash having:
|
|
407
|
-
# - 'source' [String]: Source path
|
|
408
|
-
# - 'destination' [String]: Destination path (optional)
|
|
409
|
-
def resolve_api_fid_paths(top_file_id, paths)
|
|
410
|
-
Aspera.assert_type(paths, Array)
|
|
411
|
-
Aspera.assert(paths.size.positive?, 'paths must not be empty')
|
|
412
|
-
split_sources = paths.map { |p| Pathname(p['source']).each_filename.to_a }
|
|
413
|
-
root = []
|
|
414
|
-
split_sources.map(&:size).min.times do |i|
|
|
415
|
-
parts = split_sources.map { |s| s[i] }
|
|
416
|
-
break unless parts.uniq.size == 1
|
|
417
|
-
root << parts.first
|
|
418
|
-
end
|
|
419
|
-
source_folder = File.join(root)
|
|
420
|
-
source_paths = paths.each_with_index.map do |p, i|
|
|
421
|
-
m = {'source' => File.join(split_sources[i][root.size..])}
|
|
422
|
-
m['destination'] = p['destination'] if p.key?('destination')
|
|
423
|
-
m
|
|
424
|
-
end
|
|
425
|
-
apifid = resolve_api_fid(top_file_id, source_folder, true)
|
|
426
|
-
# If a single item
|
|
427
|
-
if source_paths.size.eql?(1)
|
|
428
|
-
# Get precise info in this element
|
|
429
|
-
file_info = apifid.node_api.read("files/#{apifid.file_id}")
|
|
430
|
-
source_paths =
|
|
431
|
-
case file_info['type']
|
|
432
|
-
when 'file'
|
|
433
|
-
# If the single source is a file, we need to split into folder path and filename
|
|
434
|
-
src_dir_elements = source_folder.split(Api::Node::PATH_SEPARATOR)
|
|
435
|
-
filename = src_dir_elements.pop
|
|
436
|
-
apifid = resolve_api_fid(top_file_id, src_dir_elements.join(Api::Node::PATH_SEPARATOR), true)
|
|
437
|
-
# Filename is the last one, source folder is what remains
|
|
438
|
-
[{'source' => filename}]
|
|
439
|
-
when 'link', 'folder'
|
|
440
|
-
# Single source is 'folder' or 'link'
|
|
441
|
-
# TODO: add this ? , 'destination'=>file_info['name']
|
|
442
|
-
[{'source' => '.'}]
|
|
443
|
-
else Aspera.error_unexpected_value(file_info['type']) { 'source type' }
|
|
444
|
-
end
|
|
445
|
-
end
|
|
446
|
-
[apifid, source_paths]
|
|
447
|
-
end
|
|
448
|
-
|
|
449
|
-
# Recursively find files matching lambda
|
|
450
|
-
# @param top_file_id [String] Search root
|
|
451
|
-
# @param test_lambda [Proc] Test function
|
|
452
|
-
def find_files(top_file_id, test_lambda)
|
|
453
|
-
Log.log.debug { "find_files: file id=#{top_file_id}" }
|
|
454
|
-
find_state = {found: [], test_lambda: test_lambda}
|
|
455
|
-
process_folder_tree(method_sym: :process_find_files, state: find_state, top_file_id: top_file_id)
|
|
456
|
-
return find_state[:found]
|
|
457
|
-
end
|
|
458
|
-
|
|
459
|
-
# Recursively list all files and folders
|
|
460
|
-
def list_files(top_file_id, query: nil)
|
|
461
|
-
find_state = {found: []}
|
|
462
|
-
process_folder_tree(method_sym: :process_list_files, state: find_state, top_file_id: top_file_id, query: query)
|
|
463
|
-
return find_state[:found]
|
|
464
|
-
end
|
|
465
|
-
|
|
466
|
-
# Get a base download transfer spec (gen3)
|
|
467
|
-
# @return [Hash] Base transfer spec
|
|
468
|
-
def base_spec
|
|
469
|
-
create(
|
|
470
|
-
'files/download_setup',
|
|
471
|
-
{transfer_requests: [{transfer_request: {paths: [{source: '/'}]}}]}
|
|
472
|
-
)['transfer_specs'].first&.fetch('transfer_spec')
|
|
473
|
-
end
|
|
474
|
-
|
|
475
|
-
# Get generic part of transfer spec with transport parameters only
|
|
476
|
-
# @return [Hash] Base transfer spec
|
|
477
|
-
def transport_params
|
|
478
|
-
@std_t_spec_cache ||= base_spec.slice(*Transfer::Spec::TRANSPORT_FIELDS).freeze
|
|
479
|
-
end
|
|
480
|
-
|
|
481
|
-
# Create transfer spec for gen4
|
|
482
|
-
# @param file_id [String] Destination or source folder (id)
|
|
483
|
-
# @param direction [Symbol] One of Transfer::Spec::DIRECTION_SEND, Transfer::Spec::DIRECTION_RECEIVE
|
|
484
|
-
# @param ts_merge [Hash,nil] Additional transfer spec to merge
|
|
485
|
-
def transfer_spec_gen4(file_id, direction, ts_merge = nil)
|
|
486
|
-
ak_name = nil
|
|
487
|
-
ak_token = nil
|
|
488
|
-
case auth_params[:type]
|
|
489
|
-
when :basic
|
|
490
|
-
ak_name = auth_params[:username]
|
|
491
|
-
Aspera.assert(auth_params[:password], 'no secret in node object')
|
|
492
|
-
ak_token = Rest.basic_authorization(auth_params[:username], auth_params[:password])
|
|
493
|
-
when :oauth2
|
|
494
|
-
ak_name = params[:headers][HEADER_X_ASPERA_ACCESS_KEY]
|
|
495
|
-
# Get bearer token, possibly use cache
|
|
496
|
-
ak_token = oauth.authorization
|
|
497
|
-
when :none
|
|
498
|
-
ak_name = params[:headers][HEADER_X_ASPERA_ACCESS_KEY]
|
|
499
|
-
ak_token = params[:headers]['Authorization']
|
|
500
|
-
else Aspera.error_unexpected_value(auth_params[:type])
|
|
501
|
-
end
|
|
502
|
-
transfer_spec = {
|
|
503
|
-
'direction' => direction,
|
|
504
|
-
'token' => ak_token,
|
|
505
|
-
'tags' => {
|
|
506
|
-
Transfer::Spec::TAG_RESERVED => {
|
|
507
|
-
'node' => {
|
|
508
|
-
'access_key' => ak_name,
|
|
509
|
-
'file_id' => file_id
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
# Add specials tags (cos)
|
|
515
|
-
add_tspec_info(transfer_spec)
|
|
516
|
-
transfer_spec.deep_merge!(ts_merge) unless ts_merge.nil?
|
|
517
|
-
# Add application specific tags (AoC)
|
|
518
|
-
@app_info&.api&.add_ts_tags(transfer_spec: transfer_spec, app_info: @app_info)
|
|
519
|
-
# Add remote host info
|
|
520
|
-
if self.class.api_options[:standard_ports]
|
|
521
|
-
# Get default TCP/UDP ports and transfer user
|
|
522
|
-
transfer_spec.merge!(Transfer::Spec::AK_TSPEC_BASE)
|
|
523
|
-
# By default: same address as node API
|
|
524
|
-
transfer_spec['remote_host'] = URI.parse(base_url).host
|
|
525
|
-
# AoC allows specification of other url (in UI: `Transfer endpoint (optional)`)
|
|
526
|
-
transfer_url = @app_info&.node_info&.[]('transfer_url').to_s
|
|
527
|
-
transfer_spec['remote_host'] = transfer_url unless transfer_url.empty?
|
|
528
|
-
info = read('info')
|
|
529
|
-
# Get the transfer user from info on access key
|
|
530
|
-
transfer_spec['remote_user'] = info['transfer_user'] if info['transfer_user']
|
|
531
|
-
# Get settings from name.value array to hash key.value
|
|
532
|
-
settings = info['settings']&.to_h { |i| [i['name'], i['value']] }
|
|
533
|
-
# Check WSS ports
|
|
534
|
-
Transfer::Spec::WSS_FIELDS.each do |i|
|
|
535
|
-
transfer_spec[i] = settings[i] if settings.key?(i)
|
|
536
|
-
end if settings.is_a?(Hash)
|
|
537
|
-
else
|
|
538
|
-
transfer_spec.merge!(transport_params)
|
|
539
|
-
end
|
|
540
|
-
Aspera.assert_values(transfer_spec['remote_user'], [Transfer::Spec::ACCESS_KEY_TRANSFER_USER], type: :warn) { 'transfer user' }
|
|
541
|
-
return transfer_spec
|
|
542
|
-
end
|
|
543
|
-
|
|
544
|
-
# Executes `GET` call in loop using `iteration_token` (`/ops/transfers`)
|
|
545
|
-
# @param iteration [Array] a single element array with the iteration token or nil
|
|
546
|
-
# @param call_args [Hash] additional arguments to pass to `Rest::Client#call`
|
|
547
|
-
# @return [Array] list of items returned by the API call
|
|
548
|
-
def read_with_paging(subpath, query = nil, iteration: nil, **call_args)
|
|
549
|
-
Aspera.assert_type(iteration, Array, NilClass) { 'iteration' }
|
|
550
|
-
Aspera.assert_type(query, Hash, NilClass) { 'query' }
|
|
551
|
-
Aspera.assert(!call_args.key?(:query), ':query must not be in call_args (use query parameter)')
|
|
552
|
-
query = {} if query.nil?
|
|
553
|
-
query[:iteration_token] = iteration[0] unless iteration.nil? || iteration[0].nil?
|
|
554
|
-
max = query.delete(Rest::List::MAX_ITEMS)
|
|
555
|
-
# Return empty list immediately if max is 0
|
|
556
|
-
return [] if max&.zero?
|
|
557
|
-
item_list = []
|
|
558
|
-
loop do
|
|
559
|
-
data, http = read(subpath, query, **call_args, ret: :both)
|
|
560
|
-
Aspera.assert_type(data, Array) { "Expected data to be an Array, got: #{data.class}" }
|
|
561
|
-
# no data
|
|
562
|
-
break if data.empty?
|
|
563
|
-
item_list.concat(data)
|
|
564
|
-
# Check if we reached the max limit
|
|
565
|
-
if max&.<=(item_list.length)
|
|
566
|
-
item_list = item_list.slice(0, max)
|
|
567
|
-
break
|
|
568
|
-
end
|
|
569
|
-
# Update progress spinner
|
|
570
|
-
Rest::Parameters.instance.spinner_cb.call(item_list.length)
|
|
571
|
-
# Parse Link header according to RFC 8288 to extract next iteration token
|
|
572
|
-
next_url = LinkHeader.parse(http['Link']).find_href(rel: 'next')
|
|
573
|
-
next_iteration_token = nil
|
|
574
|
-
if next_url
|
|
575
|
-
begin
|
|
576
|
-
parsed_uri = URI.parse(next_url)
|
|
577
|
-
query_params = Rest.query_to_h(parsed_uri.query) if parsed_uri.query
|
|
578
|
-
next_iteration_token = query_params['iteration_token'] if query_params
|
|
579
|
-
rescue URI::InvalidURIError => e
|
|
580
|
-
Log.log.warn { "Invalid URI in Link header: #{next_url} - #{e.message}" }
|
|
581
|
-
end
|
|
582
|
-
end
|
|
583
|
-
# Stop if no next token
|
|
584
|
-
break if next_iteration_token.nil?
|
|
585
|
-
# Stop if same token as current (infinite loop protection)
|
|
586
|
-
break if next_iteration_token.eql?(query[:iteration_token])
|
|
587
|
-
# Update token for next iteration
|
|
588
|
-
query[:iteration_token] = next_iteration_token
|
|
589
|
-
end
|
|
590
|
-
# Signal completion
|
|
591
|
-
Rest::Parameters.instance.spinner_cb.call(action: :success)
|
|
592
|
-
# save iteration token if needed
|
|
593
|
-
iteration[0] = query[:iteration_token] unless iteration.nil?
|
|
594
|
-
item_list
|
|
595
|
-
end
|
|
596
|
-
|
|
597
|
-
# Read resource content with pagination (page, per_page)
|
|
598
|
-
#
|
|
599
|
-
# @param subpath [String] API Path
|
|
600
|
-
# @param query [Hash, nil] Optional query parameters for the API request
|
|
601
|
-
# @param kwargs [Hash] Other parameters for Rest::Client#read
|
|
602
|
-
#
|
|
603
|
-
# @return [Array<Hash>] List of folder entries (files, folders, links)
|
|
604
|
-
def read_with_pages(subpath, query = nil, **kwargs)
|
|
605
|
-
items = []
|
|
606
|
-
query ||= {}
|
|
607
|
-
query['per_page'] ||= 500
|
|
608
|
-
query['page'] ||= 1
|
|
609
|
-
suffix = nil
|
|
610
|
-
loop do
|
|
611
|
-
Rest::Parameters.instance.spinner_cb.call("#{items.count}#{suffix}")
|
|
612
|
-
data, http = read(subpath, query, **kwargs, ret: :both)
|
|
613
|
-
items.concat(data)
|
|
614
|
-
break if data.length < query['per_page']
|
|
615
|
-
suffix ||= "/#{http[HEADER_X_TOTAL_COUNT]}" if http[HEADER_X_TOTAL_COUNT]
|
|
616
|
-
query['page'] += 1
|
|
617
|
-
end
|
|
618
|
-
rescue StandardError => e
|
|
619
|
-
Log.log.warn { "#{e.class} #{e.message}" }
|
|
620
|
-
Log.log.debug { (['Backtrace:'] + e.backtrace).join("\n") }
|
|
621
|
-
ensure
|
|
622
|
-
Rest::Parameters.instance.spinner_cb.call(items.count, action: :success)
|
|
623
|
-
return items # rubocop:disable Lint/EnsureReturn
|
|
624
|
-
end
|
|
625
|
-
|
|
626
|
-
private
|
|
627
|
-
|
|
628
|
-
# Method called in loop for each entry for `resolve_api_fid`
|
|
629
|
-
# @return [Boolean] `true` to continue digging, `false` to stop processing: set state[:result] if found
|
|
630
|
-
def process_api_fid(entry, path, state)
|
|
631
|
-
# Stop digging here if already found, or if not the next path element directly under the consumed path (not a sibling)
|
|
632
|
-
return false if state[:path].empty? || !path.eql?(File.join(PATH_SEPARATOR, *state[:consumed], state[:path].first))
|
|
633
|
-
# Ok it matches, so we remove the match, and continue digging
|
|
634
|
-
state[:consumed].push(state[:path].shift)
|
|
635
|
-
path_fully_consumed = state[:path].empty?
|
|
636
|
-
case entry['type']
|
|
637
|
-
when 'file'
|
|
638
|
-
# File must be terminal
|
|
639
|
-
raise "#{entry['name']} is a file, expecting folder to find: #{state[:path]}" unless path_fully_consumed
|
|
640
|
-
# It's terminal, we found it
|
|
641
|
-
Log.log.debug { "process_api_fid: found #{path} -> #{entry['id']}" }
|
|
642
|
-
state[:result] = NodeFileId.new(self, entry['id'])
|
|
643
|
-
return false
|
|
644
|
-
when 'folder'
|
|
645
|
-
if path_fully_consumed
|
|
646
|
-
# We found it
|
|
647
|
-
state[:result] = NodeFileId.new(self, entry['id'])
|
|
648
|
-
return false
|
|
649
|
-
end
|
|
650
|
-
when 'link'
|
|
651
|
-
if path_fully_consumed
|
|
652
|
-
if state[:process_last_link]
|
|
653
|
-
# We found it
|
|
654
|
-
other_node = nil
|
|
655
|
-
other_node = node_id_to_node(entry['target_node_id']) if entry_has_link_information(entry)
|
|
656
|
-
Aspera.assert(!other_node.nil?, type: Error) { 'Cannot resolve link' }
|
|
657
|
-
state[:result] = NodeFileId.new(other_node, entry['target_id'])
|
|
658
|
-
else
|
|
659
|
-
# We found it but we do not process the link
|
|
660
|
-
state[:result] = NodeFileId.new(self, entry['id'])
|
|
661
|
-
end
|
|
662
|
-
return false
|
|
663
|
-
end
|
|
664
|
-
else Aspera.error_unexpected_value(entry['type'], type: :warn) { 'folder entry type' }
|
|
665
|
-
end
|
|
666
|
-
# Continue to dig folder
|
|
667
|
-
return true
|
|
668
|
-
end
|
|
669
|
-
|
|
670
|
-
# Method called in loop for each entry for `find_files`
|
|
671
|
-
def process_find_files(entry, path, state)
|
|
672
|
-
state[:found].push(entry.merge({'path' => path})) if state[:test_lambda].call(entry)
|
|
673
|
-
# Test all files deeply
|
|
674
|
-
return true
|
|
675
|
-
end
|
|
676
|
-
|
|
677
|
-
# Method called in loop for each entry for `list_files`
|
|
678
|
-
def process_list_files(entry, path, state)
|
|
679
|
-
state[:found].push(entry.merge({'path' => path}))
|
|
680
|
-
return false
|
|
681
|
-
end
|
|
682
|
-
end
|
|
683
|
-
end
|
|
684
|
-
end
|