aspera-cli 4.29.1 → 4.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +4 -4
- data/CHANGELOG.md +119 -0
- data/CONTRIBUTING.md +8 -1
- data/README.md +2 -0
- data/TODO.md +4 -5
- data/bin/asession +2 -2
- data/docs/README.md +616 -86
- data/docs/test-mcp-with-ai.md +4 -0
- data/lib/aspera/agent/base.rb +62 -6
- data/lib/aspera/agent/factory.rb +127 -20
- data/lib/aspera/ascp/data_repository.rb +71 -0
- data/lib/aspera/ascp/installation.rb +16 -11
- data/lib/aspera/ascp/log_analyzer/lines.rb +4 -4
- data/lib/aspera/ascp/log_analyzer/log_file.rb +5 -3
- data/lib/aspera/ascp/log_analyzer/records.rb +11 -6
- data/lib/aspera/ascp/log_analyzer.rb +43 -18
- data/lib/aspera/ascp/log_locations.rb +2 -2
- data/lib/aspera/assert.rb +8 -0
- data/lib/aspera/bundle_registry.rb +528 -0
- data/lib/aspera/cli/argument.rb +110 -0
- data/lib/aspera/cli/bool_value.rb +41 -0
- data/lib/aspera/cli/bootstrapper.rb +31 -24
- data/lib/aspera/cli/command/mount.rb +53 -0
- data/lib/aspera/cli/command/registry.rb +434 -0
- data/lib/aspera/cli/command.rb +95 -0
- data/lib/aspera/cli/command_line.rb +91 -91
- data/lib/aspera/cli/complete.rb +22 -0
- data/lib/aspera/cli/completion_actions.rb +28 -26
- data/lib/aspera/cli/context.rb +29 -6
- data/lib/aspera/cli/error.rb +39 -0
- data/lib/aspera/cli/extended_value.rb +25 -4
- data/lib/aspera/cli/formatter.rb +8 -8
- data/lib/aspera/cli/hints.rb +17 -52
- data/lib/aspera/cli/http.rb +17 -12
- data/lib/aspera/cli/mailer.rb +7 -24
- data/lib/aspera/cli/mcp/tool.rb +10 -2
- data/lib/aspera/cli/option/declarator.rb +80 -0
- data/lib/aspera/cli/option/registry.rb +74 -0
- data/lib/aspera/cli/option/source.rb +38 -0
- data/lib/aspera/cli/option/type.rb +37 -0
- data/lib/aspera/cli/option/value.rb +376 -0
- data/lib/aspera/cli/option.rb +78 -0
- data/lib/aspera/cli/options.schema.yaml +28 -783
- data/lib/aspera/cli/parser.rb +73 -41
- data/lib/aspera/cli/plugins/base.rb +122 -42
- data/lib/aspera/cli/plugins/basic_auth.rb +13 -2
- data/lib/aspera/cli/plugins/config.rb +101 -167
- data/lib/aspera/cli/plugins/factory.rb +139 -43
- data/lib/aspera/cli/plugins/mcp.rb +61 -54
- data/lib/aspera/cli/plugins/oauth.rb +19 -6
- data/lib/aspera/cli/poll.rb +14 -20
- data/lib/aspera/cli/preset_actions.rb +11 -3
- data/lib/aspera/cli/preset_manager.rb +16 -6
- data/lib/aspera/cli/result.rb +2 -2
- data/lib/aspera/cli/runner.rb +71 -99
- data/lib/aspera/cli/secret_finder.rb +1 -1
- data/lib/aspera/cli/security.rb +102 -4
- data/lib/aspera/{preview/terminal.rb → cli/terminal_image.rb} +93 -94
- data/lib/aspera/cli/vault_manager.rb +3 -3
- data/lib/aspera/cli/version.rb +1 -1
- data/lib/aspera/cli/wizard.rb +9 -3
- data/lib/aspera/coverage.rb +1 -2
- data/lib/aspera/line_logger.rb +35 -6
- data/lib/aspera/log.rb +3 -2
- data/lib/aspera/oauth/client/base.rb +19 -1
- data/lib/aspera/oauth/client/factory.rb +1 -7
- data/lib/aspera/plugin.schema.yaml +178 -0
- data/lib/aspera/plugins/alee/api.rb +25 -0
- data/lib/aspera/{cli/plugins/alee.rb → plugins/alee/commands.rb} +10 -8
- data/lib/aspera/plugins/alee/plugin.yaml +3 -0
- data/lib/aspera/plugins/aoc/admin_resources.rb +148 -0
- data/lib/aspera/plugins/aoc/api.rb +783 -0
- data/lib/aspera/{cli/plugins/aoc.rb → plugins/aoc/commands.rb} +404 -330
- data/lib/aspera/plugins/aoc/graphql.rb +45 -0
- data/lib/aspera/plugins/aoc/plugin.yaml +31 -0
- data/lib/aspera/{schema → plugins/aoc/schemas}/IBM Aspera on Cloud API-0.2.6-enhanced.yaml +15042 -7076
- data/lib/aspera/plugins/aoc/schemas/options.yaml +47 -0
- data/lib/aspera/plugins/ats/api.rb +51 -0
- data/lib/aspera/{cli/plugins/ats.rb → plugins/ats/commands.rb} +33 -33
- data/lib/aspera/plugins/ats/plugin.yaml +6 -0
- data/lib/aspera/plugins/connect/agent.rb +199 -0
- data/lib/aspera/plugins/connect/plugin.yaml +11 -0
- data/lib/aspera/plugins/connect/schemas/agent_options.yaml +6 -0
- data/lib/aspera/{cli/plugins/console.rb → plugins/console/commands.rb} +41 -33
- data/lib/aspera/plugins/console/plugin.yaml +8 -0
- data/lib/aspera/plugins/cos/api.rb +114 -0
- data/lib/aspera/{cli/plugins/cos.rb → plugins/cos/commands.rb} +19 -16
- data/lib/aspera/plugins/cos/plugin.yaml +9 -0
- data/lib/aspera/plugins/cos/schemas/options.yaml +30 -0
- data/lib/aspera/plugins/desktop/agent.rb +165 -0
- data/lib/aspera/plugins/desktop/plugin.yaml +11 -0
- data/lib/aspera/plugins/desktop/schemas/agent_options.yaml +6 -0
- data/lib/aspera/plugins/direct/agent.rb +518 -0
- data/lib/aspera/plugins/direct/plugin.yaml +11 -0
- data/lib/aspera/plugins/direct/schemas/agent_options.yaml +86 -0
- data/lib/aspera/plugins/faspex4/gateway_options.rb +18 -0
- data/lib/aspera/plugins/faspex4/gw_servlet.rb +122 -0
- data/lib/aspera/plugins/faspex4/plugin.yaml +7 -0
- data/lib/aspera/plugins/faspex4/schemas/options.yaml +57 -0
- data/lib/aspera/plugins/faspex5/api.rb +269 -0
- data/lib/aspera/{cli/plugins/faspex5.rb → plugins/faspex5/commands.rb} +152 -114
- data/lib/aspera/plugins/faspex5/faspex4_post_proc_servlet.rb +241 -0
- data/lib/aspera/plugins/faspex5/plugin.yaml +14 -0
- data/lib/aspera/{schema → plugins/faspex5/schemas}/IBM Aspera Faspex API-5.0-enhanced.yaml +279 -76
- data/lib/aspera/plugins/faspex5/schemas/options.yaml +87 -0
- data/lib/aspera/{cli/plugins/faspio.rb → plugins/faspio/commands.rb} +11 -7
- data/lib/aspera/plugins/faspio/plugin.yaml +8 -0
- data/lib/aspera/{schema → plugins/faspio/schemas}/IBM Aspera faspio Gateway API-1.0.0-enhanced.yaml +4 -2
- data/lib/aspera/plugins/httpgw/agent.rb +126 -0
- data/lib/aspera/plugins/httpgw/api.rb +411 -0
- data/lib/aspera/{cli/plugins/httpgw.rb → plugins/httpgw/commands.rb} +9 -9
- data/lib/aspera/plugins/httpgw/plugin.yaml +12 -0
- data/lib/aspera/plugins/httpgw/schemas/agent_options.yaml +24 -0
- data/lib/aspera/plugins/node/agent.rb +184 -0
- data/lib/aspera/plugins/node/api.rb +699 -0
- data/lib/aspera/{cli/plugins/node.rb → plugins/node/commands.rb} +166 -141
- data/lib/aspera/plugins/node/emulator.rb +774 -0
- data/lib/aspera/plugins/node/plugin.yaml +20 -0
- data/lib/aspera/plugins/node/schemas/agent_options.yaml +20 -0
- data/lib/aspera/plugins/node/schemas/options.yaml +190 -0
- data/lib/aspera/{cli/plugins/orchestrator.rb → plugins/orchestrator/commands.rb} +139 -110
- data/lib/aspera/plugins/orchestrator/plugin.yaml +34 -0
- data/lib/aspera/{schema → plugins/orchestrator/schemas}/IBM Aspera Orchestrator API-v1-enhanced.yaml +486 -16
- data/lib/aspera/plugins/orchestrator/schemas/options.yaml +143 -0
- data/lib/aspera/plugins/orchestrator/workflow_checker.rb +692 -0
- data/lib/aspera/{cli/plugins/preview.rb → plugins/preview/commands.rb} +53 -51
- data/lib/aspera/plugins/preview/file_types.rb +121 -0
- data/lib/aspera/plugins/preview/generator.rb +350 -0
- data/lib/aspera/plugins/preview/plugin.yaml +12 -0
- data/lib/aspera/{preview/options.schema.yaml → plugins/preview/schemas/options.yaml} +1 -1
- data/lib/aspera/plugins/preview/utils.rb +213 -0
- data/lib/aspera/plugins/server/ascmd.rb +374 -0
- data/lib/aspera/{cli/plugins/server.rb → plugins/server/commands.rb} +48 -32
- data/lib/aspera/plugins/server/plugin.yaml +9 -0
- data/lib/aspera/plugins/server/schemas/options.yaml +30 -0
- data/lib/aspera/{cli/plugins/shares.rb → plugins/shares/commands.rb} +29 -21
- data/lib/aspera/plugins/shares/plugin.yaml +10 -0
- data/lib/aspera/plugins/shares/shares_web.rb +97 -0
- data/lib/aspera/plugins/transferd/agent.rb +258 -0
- data/lib/aspera/plugins/transferd/api.rb +180 -0
- data/lib/aspera/plugins/transferd/client.rb +67 -0
- data/lib/aspera/{cli/plugins/transferd.rb → plugins/transferd/commands.rb} +43 -42
- data/lib/aspera/plugins/transferd/config_commands.rb +38 -0
- data/lib/aspera/plugins/transferd/plugin.yaml +27 -0
- data/lib/aspera/plugins/transferd/product.rb +146 -0
- data/lib/aspera/plugins/transferd/schemas/agent_options.yaml +31 -0
- data/lib/aspera/plugins/transferd/schemas/options.yaml +80 -0
- data/lib/aspera/plugins/transferd/service.rb +617 -0
- data/lib/aspera/plugins/xfer/ascp_actions.rb +131 -0
- data/lib/aspera/plugins/xfer/ascp_logs_actions.rb +198 -0
- data/lib/aspera/plugins/xfer/async_transfer_store.rb +131 -0
- data/lib/aspera/plugins/xfer/config_commands.rb +119 -0
- data/lib/aspera/plugins/xfer/helper.rb +19 -0
- data/lib/aspera/plugins/xfer/plugin.yaml +42 -0
- data/lib/aspera/plugins/xfer/schemas/agent_extension.schema.yaml +26 -0
- data/lib/aspera/plugins/xfer/schemas/options.yaml +125 -0
- data/lib/aspera/plugins/xfer/sync_actions.rb +253 -0
- data/lib/aspera/plugins/xfer/transfer_actions.rb +176 -0
- data/lib/aspera/plugins/xfer/transfer_agent.rb +505 -0
- data/lib/aspera/products/cli_v3.rb +34 -0
- data/lib/aspera/products/connect.rb +1 -1
- data/lib/aspera/products/drive.rb +29 -0
- data/lib/aspera/products/hsts.rb +34 -0
- data/lib/aspera/products/transferd.rb +25 -3
- data/lib/aspera/products.rb +54 -0
- data/lib/aspera/prompt.rb +184 -0
- data/lib/aspera/proxy_auto_config.rb +3 -3
- data/lib/aspera/rest/aspera_errors.rb +4 -38
- data/lib/aspera/rest/error_analyzer.rb +6 -2
- data/lib/aspera/rest/list.rb +4 -5
- data/lib/aspera/schema/reader.rb +15 -0
- data/lib/aspera/schema/registry.rb +239 -45
- data/lib/aspera/schema/validator.rb +63 -17
- data/lib/aspera/sealed_hash.rb +4 -0
- data/lib/aspera/secret/hider.rb +159 -24
- data/lib/aspera/secret/reference.rb +8 -0
- data/lib/aspera/secret/resolver.rb +8 -4
- data/lib/aspera/secret/store/base.rb +10 -9
- data/lib/aspera/secret/store/encrypted_hash.rb +6 -6
- data/lib/aspera/secret/store/hashicorp_vault.rb +3 -3
- data/lib/aspera/secret/store/keeper.rb +2 -2
- data/lib/aspera/secret/store/macos_security.rb +2 -3
- data/lib/aspera/secret/store/one_password_api.rb +2 -2
- data/lib/aspera/secret/store/one_password_cli.rb +3 -3
- data/lib/aspera/secret/store/secret_service.rb +2 -2
- data/lib/aspera/ssl.rb +3 -3
- data/lib/aspera/standard_input.rb +20 -0
- data/lib/aspera/{schema → sync}/async_tables.yaml +1 -1
- data/lib/aspera/sync/database.rb +7 -0
- data/lib/aspera/sync/log_parser.rb +138 -0
- data/lib/aspera/sync/operations.rb +59 -34
- data/lib/aspera/transfer/command_line_builder.rb +248 -0
- data/lib/aspera/transfer/command_line_converter.rb +37 -0
- data/lib/aspera/transfer/faux_file.rb +2 -2
- data/lib/aspera/transfer/parameters.rb +9 -10
- data/lib/aspera/transfer/spec.rb +28 -1
- data/lib/aspera/transfer/spec.schema.yaml +30 -5
- data/lib/aspera/units/decimal.rb +1 -1
- data/lib/aspera/units/timestamp.rb +84 -0
- data/lib/aspera/uri_reader.rb +2 -2
- data/lib/aspera/web_auth/paste.rb +2 -2
- data/lib/aspera/web_server_simple.rb +10 -4
- data.tar.gz.sig +0 -0
- metadata +137 -80
- metadata.gz.sig +0 -0
- data/lib/aspera/agent/connect.rb +0 -188
- data/lib/aspera/agent/desktop.rb +0 -154
- data/lib/aspera/agent/direct.rb +0 -496
- data/lib/aspera/agent/httpgw.rb +0 -100
- data/lib/aspera/agent/node.rb +0 -166
- data/lib/aspera/agent/transferd.rb +0 -341
- data/lib/aspera/api/alee.rb +0 -19
- data/lib/aspera/api/aoc.rb +0 -776
- data/lib/aspera/api/ats.rb +0 -49
- data/lib/aspera/api/cos_node.rb +0 -107
- data/lib/aspera/api/faspex.rb +0 -258
- data/lib/aspera/api/httpgw.rb +0 -409
- data/lib/aspera/api/node.rb +0 -684
- data/lib/aspera/ascmd.rb +0 -248
- data/lib/aspera/cli/ascp_actions.rb +0 -113
- data/lib/aspera/cli/ascp_logs_actions.rb +0 -188
- data/lib/aspera/cli/async_transfer_store.rb +0 -129
- data/lib/aspera/cli/command_registry.rb +0 -371
- data/lib/aspera/cli/command_spec.rb +0 -273
- data/lib/aspera/cli/option_declarator.rb +0 -74
- data/lib/aspera/cli/option_registry.rb +0 -72
- data/lib/aspera/cli/option_types.rb +0 -120
- data/lib/aspera/cli/option_value.rb +0 -345
- data/lib/aspera/cli/prompt.rb +0 -186
- data/lib/aspera/cli/sync_actions.rb +0 -181
- data/lib/aspera/cli/transfer_actions.rb +0 -98
- data/lib/aspera/cli/transfer_agent.rb +0 -348
- data/lib/aspera/command_line_builder.rb +0 -244
- data/lib/aspera/command_line_converter.rb +0 -35
- data/lib/aspera/data_repository.rb +0 -69
- data/lib/aspera/faspex_gw.rb +0 -172
- data/lib/aspera/faspex_postproc.rb +0 -237
- data/lib/aspera/graphql.rb +0 -41
- data/lib/aspera/node_emulator.rb +0 -758
- data/lib/aspera/oauth/client/shares_web.rb +0 -94
- data/lib/aspera/orchestrator_workflow_checker.rb +0 -688
- data/lib/aspera/preview/file_types.rb +0 -119
- data/lib/aspera/preview/generator.rb +0 -345
- data/lib/aspera/preview/utils.rb +0 -211
- data/lib/aspera/products/other.rb +0 -92
- data/lib/aspera/products/transferd_service.rb +0 -610
- /data/lib/aspera/{data → ascp/data}/1 +0 -0
- /data/lib/aspera/{data → ascp/data}/2 +0 -0
- /data/lib/aspera/{data → ascp/data}/3 +0 -0
- /data/lib/aspera/{data → ascp/data}/4 +0 -0
- /data/lib/aspera/{data → ascp/data}/5 +0 -0
- /data/lib/aspera/{data → ascp/data}/6 +0 -0
- /data/lib/aspera/{api → plugins/aoc}/queries/bss_subscription_account.graphql +0 -0
- /data/lib/aspera/{api → plugins/aoc}/queries/bss_subscription_usage.graphql +0 -0
- /data/lib/aspera/{schema → plugins/aoc/schemas}/IBM Aspera on Cloud Automation API-1.0.5-enhanced.yaml +0 -0
- /data/lib/aspera/{schema → plugins/console/schemas}/IBM Aspera Console-enhanced.yaml +0 -0
- /data/lib/aspera/{schema → plugins/node/schemas}/IBM Aspera Node API-4.4.6.yaml +0 -0
- /data/lib/aspera/{preview → plugins/preview}/image_error.png +0 -0
- /data/lib/aspera/{preview → plugins/preview}/video_error.png +0 -0
- /data/lib/aspera/{schema → plugins/shares/schemas}/IBM_Aspera_Shares.yaml +0 -0
- /data/lib/{transferd_pb.rb → aspera/plugins/transferd/grpc/transferd_pb.rb} +0 -0
- /data/lib/{transferd_services_pb.rb → aspera/plugins/transferd/grpc/transferd_services_pb.rb} +0 -0
- /data/lib/aspera/{schema → plugins/transferd/schemas}/transferd-config.schema.json +0 -0
|
@@ -0,0 +1,783 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../../log'
|
|
7
|
+
require_relative '../../assert'
|
|
8
|
+
require_relative '../../rest'
|
|
9
|
+
require_relative '../../hash_ext'
|
|
10
|
+
require_relative '../../ascp/data_repository'
|
|
11
|
+
require_relative '../../transfer/spec'
|
|
12
|
+
require_relative '../node/api'
|
|
13
|
+
require_relative '../../rest/list'
|
|
14
|
+
require_relative '../../oauth/client/boot'
|
|
15
|
+
require_relative '../../oauth/client/jwt'
|
|
16
|
+
require_relative '../../oauth/client/url_json'
|
|
17
|
+
require_relative '../../oauth/client/web'
|
|
18
|
+
require_relative '../../rainbow'
|
|
19
|
+
require 'base64'
|
|
20
|
+
using Rainbow
|
|
21
|
+
|
|
22
|
+
module Aspera
|
|
23
|
+
module Plugins
|
|
24
|
+
module Aoc
|
|
25
|
+
# Aspera on Cloud API client
|
|
26
|
+
class Api < Rest::Client
|
|
27
|
+
include Rest::List
|
|
28
|
+
|
|
29
|
+
module AppType
|
|
30
|
+
FILES = 'files'
|
|
31
|
+
PACKAGES = 'packages'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class AppInfo
|
|
35
|
+
# @return [Aspera::Plugins::Aoc::Api] Rest Api object
|
|
36
|
+
attr_reader :api
|
|
37
|
+
# @return [Hash, nil] Package information, `"files"` or `"packages"`
|
|
38
|
+
attr_reader :package
|
|
39
|
+
# @return [Hash] Result of GET /nodes/:id
|
|
40
|
+
attr_reader :node_info
|
|
41
|
+
# @return [String] Workspace id
|
|
42
|
+
attr_reader :workspace_id
|
|
43
|
+
# @return [String] Workspace name
|
|
44
|
+
attr_reader :workspace_name
|
|
45
|
+
# @return [String, nil] "Share as" link name
|
|
46
|
+
attr_accessor :opt_link_name
|
|
47
|
+
|
|
48
|
+
# @param api [Aoc::Api] Rest Api object
|
|
49
|
+
# @param package [Hash,nil] package information or nil
|
|
50
|
+
# @param node_info [Hash] Result of GET /nodes/:id
|
|
51
|
+
# @param workspace_id [String] Workspace identifier
|
|
52
|
+
# @param workspace_name [String] Workspace name
|
|
53
|
+
def initialize(api, package, node_info, workspace_id, workspace_name)
|
|
54
|
+
@api = api
|
|
55
|
+
@package = package
|
|
56
|
+
@node_info = node_info
|
|
57
|
+
@workspace_id = workspace_id
|
|
58
|
+
@workspace_name = workspace_name
|
|
59
|
+
@opt_link_name = nil
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# @return ["files", "packages"] Type of application
|
|
63
|
+
def app
|
|
64
|
+
package.nil? ? AppType::FILES : AppType::PACKAGES
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
PRODUCT_NAME = 'Aspera on Cloud'
|
|
68
|
+
# `''` Use default workspace if it is set, else none
|
|
69
|
+
DEFAULT_WORKSPACE = ''
|
|
70
|
+
# Production domain of AoC
|
|
71
|
+
SAAS_DOMAIN_PROD = 'ibmaspera.com'
|
|
72
|
+
# To avoid infinite loop in pub link redirection
|
|
73
|
+
MAX_AOC_URL_REDIRECT = 10
|
|
74
|
+
CLIENT_ID_PREFIX = 'aspera.'
|
|
75
|
+
# Well-known AoC global client apps
|
|
76
|
+
GLOBAL_CLIENT_APPS = Ascp::DataRepository::ELEMENTS.select { |i| i.to_s.start_with?(CLIENT_ID_PREFIX) }.freeze
|
|
77
|
+
# cookie prefix so that console can decode identity
|
|
78
|
+
COOKIE_PREFIX_CONSOLE_AOC = 'aspera.aoc'
|
|
79
|
+
# path in URL of public links (warning if not in list)
|
|
80
|
+
PUBLIC_LINK_PATHS = %w[/packages/public/receive /packages/public/send /files/public /public/files /public/files/ /public/package /public/send /public/send/package].freeze
|
|
81
|
+
JWT_AUDIENCE = 'https://api.asperafiles.com/api/v1/oauth2/token'
|
|
82
|
+
OAUTH_API_SUBPATH = 'api/v1/oauth2'
|
|
83
|
+
# minimum fields for user info if retrieval fails
|
|
84
|
+
USER_INFO_FIELDS_MIN = %w[name email id default_workspace_id organization_id].freeze
|
|
85
|
+
# types of events for shared folder creation
|
|
86
|
+
# Node events: permission.created permission.modified permission.deleted
|
|
87
|
+
PERMISSIONS_CREATED = ['permission.created'].freeze
|
|
88
|
+
# Special user identifier when creating workspace shared folders
|
|
89
|
+
ID_AK_ADMIN = 'ASPERA_ACCESS_KEY_ADMIN'
|
|
90
|
+
HEADER_X_TOTAL_COUNT = 'X-Total-Count'
|
|
91
|
+
|
|
92
|
+
private_constant :MAX_AOC_URL_REDIRECT,
|
|
93
|
+
:CLIENT_ID_PREFIX,
|
|
94
|
+
:GLOBAL_CLIENT_APPS,
|
|
95
|
+
:COOKIE_PREFIX_CONSOLE_AOC,
|
|
96
|
+
:PUBLIC_LINK_PATHS,
|
|
97
|
+
:JWT_AUDIENCE,
|
|
98
|
+
:OAUTH_API_SUBPATH,
|
|
99
|
+
:USER_INFO_FIELDS_MIN,
|
|
100
|
+
:PERMISSIONS_CREATED,
|
|
101
|
+
:ID_AK_ADMIN,
|
|
102
|
+
:HEADER_X_TOTAL_COUNT
|
|
103
|
+
|
|
104
|
+
# Various API scopes supported
|
|
105
|
+
module Scope
|
|
106
|
+
SELF = 'self'
|
|
107
|
+
# Scope `user:all`
|
|
108
|
+
USER = 'user:all'
|
|
109
|
+
# Scope `admin:all`
|
|
110
|
+
ADMIN = 'admin:all'
|
|
111
|
+
ADMIN_USER = 'admin-user:all'
|
|
112
|
+
ADMIN_USER_USER = "#{ADMIN_USER}+#{USER}".freeze
|
|
113
|
+
end
|
|
114
|
+
API_V1 = 'api/v1'
|
|
115
|
+
|
|
116
|
+
# class static methods
|
|
117
|
+
class << self
|
|
118
|
+
# strings /Applications/Aspera\ Drive.app/Contents/MacOS/AsperaDrive|grep -E '.{100}==$'|base64 --decode
|
|
119
|
+
def get_client_info(client_name = nil)
|
|
120
|
+
client_key = client_name.nil? ? GLOBAL_CLIENT_APPS.first : client_name.to_sym
|
|
121
|
+
return client_key, Ascp::DataRepository.instance.item(client_key)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Base API url depends on domain, which could be "qa.xxx" or self-managed domain
|
|
125
|
+
# @param api_domain [String] the AoC domain (e.g. "ibmaspera.com" (SAAS_DOMAIN_PROD) or a self-managed domain)
|
|
126
|
+
# @return [String] the base URL for the AoC API
|
|
127
|
+
def api_base_url(api_domain)
|
|
128
|
+
return "https://api.#{api_domain}"
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# split host of URL into organization and domain
|
|
132
|
+
def split_org_domain(uri)
|
|
133
|
+
Aspera.assert_type(uri, URI)
|
|
134
|
+
Aspera.assert(!uri.host.nil?) { "No host found in URL. Please check URL format: https://myorg.#{SAAS_DOMAIN_PROD}" }
|
|
135
|
+
parts = uri.host.split('.', 2)
|
|
136
|
+
Aspera.assert(parts.length == 2) { "expecting a public FQDN for #{PRODUCT_NAME}" }
|
|
137
|
+
parts[0] = nil if parts[0].eql?('api')
|
|
138
|
+
return %i{organization domain}.zip(parts).to_h
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def saas_url?(url)
|
|
142
|
+
URI.parse(url).host&.end_with?(".#{SAAS_DOMAIN_PROD}")
|
|
143
|
+
rescue URI::InvalidURIError
|
|
144
|
+
false
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Get information from link
|
|
148
|
+
# @param url [String] URL of AoC public link
|
|
149
|
+
# @return [Hash{Symbol => String, Hash}] Information about public link, or nil if not a public link
|
|
150
|
+
def link_info(url)
|
|
151
|
+
final_uri = Rest::Client.new(base_url: url, redirect_max: MAX_AOC_URL_REDIRECT).call(operation: 'GET', ret: :resp).uri
|
|
152
|
+
Log.dump(:final_uri, final_uri, level: :trace1)
|
|
153
|
+
org_domain = split_org_domain(final_uri)
|
|
154
|
+
if (m = final_uri.path.match(%r{/oauth2/([^/]+)/login$}))
|
|
155
|
+
org_domain[:organization] = m[1] if org_domain[:organization].nil?
|
|
156
|
+
else
|
|
157
|
+
Log.log.debug { "path=#{final_uri.path} does not end with /login" }
|
|
158
|
+
end
|
|
159
|
+
Aspera.assert(!final_uri.query.nil?, 'AoC shall redirect to login page with a query', type: Error)
|
|
160
|
+
query = Rest.query_to_h(final_uri.query)
|
|
161
|
+
Log.dump(:query, query, level: :trace1)
|
|
162
|
+
# is that a public link ?
|
|
163
|
+
if query.key?('token')
|
|
164
|
+
Log.log.warn { "Unknown pub link path: #{final_uri.path}" } unless PUBLIC_LINK_PATHS.include?(final_uri.path)
|
|
165
|
+
# ok we get it !
|
|
166
|
+
return {
|
|
167
|
+
instance_domain: org_domain[:domain],
|
|
168
|
+
url: "https://#{final_uri.host}",
|
|
169
|
+
token: query['token']
|
|
170
|
+
}
|
|
171
|
+
end
|
|
172
|
+
if query.key?('state')
|
|
173
|
+
# can be a private link
|
|
174
|
+
state_uri = URI.parse(query['state'])
|
|
175
|
+
if state_uri.query && query['redirect_uri']
|
|
176
|
+
decoded_state = Rest.query_to_h(state_uri.query)
|
|
177
|
+
if decoded_state.key?('short_link_url')
|
|
178
|
+
if (m = state_uri.path.match(%r{/files/workspaces/([0-9]+)/all/([0-9]+):([0-9]+)}))
|
|
179
|
+
redirect_uri = URI.parse(query['redirect_uri'])
|
|
180
|
+
org_domain = split_org_domain(redirect_uri)
|
|
181
|
+
return {
|
|
182
|
+
instance_domain: org_domain[:domain],
|
|
183
|
+
organization: org_domain[:organization],
|
|
184
|
+
url: "https://#{redirect_uri.host}",
|
|
185
|
+
private_link: {
|
|
186
|
+
workspace_id: m[1],
|
|
187
|
+
node_id: m[2],
|
|
188
|
+
file_id: m[3]
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
Log.dump(:org_domain, org_domain)
|
|
196
|
+
return {
|
|
197
|
+
instance_domain: org_domain[:domain],
|
|
198
|
+
organization: org_domain[:organization]
|
|
199
|
+
}
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# Call `block` with same query using paging and response information.
|
|
203
|
+
# Block must return a 2 element `Array` with data and http response
|
|
204
|
+
# @param query [Hash] Additional query parameters
|
|
205
|
+
# @return [Hash] Items and total number of items
|
|
206
|
+
# @option return [Array<Hash>] :items The list of items
|
|
207
|
+
# @option return [Integer] :total The total number of items
|
|
208
|
+
def call_paging(query: {})
|
|
209
|
+
Aspera.assert_type(query, Hash) { 'query' }
|
|
210
|
+
Aspera.assert(block_given?, 'block required for call_paging')
|
|
211
|
+
# set default large page if user does not specify own parameters. AoC Caps to 1000 anyway
|
|
212
|
+
query['per_page'] = 1000 unless query.key?('per_page')
|
|
213
|
+
max_items = query.delete(Rest::List::MAX_ITEMS)
|
|
214
|
+
max_pages = query.delete(Rest::List::MAX_PAGES)
|
|
215
|
+
item_list = []
|
|
216
|
+
total_count = nil
|
|
217
|
+
current_page = query['page']
|
|
218
|
+
current_page = 1 if current_page.nil?
|
|
219
|
+
page_count = 0
|
|
220
|
+
loop do
|
|
221
|
+
new_query = query.clone
|
|
222
|
+
new_query['page'] = current_page
|
|
223
|
+
result_data, result_http = yield(new_query)
|
|
224
|
+
Aspera.assert(result_http, 'expected HTTP result from paging block')
|
|
225
|
+
total_count = result_http[HEADER_X_TOTAL_COUNT]&.to_i
|
|
226
|
+
page_count += 1
|
|
227
|
+
current_page += 1
|
|
228
|
+
add_items = result_data
|
|
229
|
+
break if add_items.nil?
|
|
230
|
+
break if add_items.empty?
|
|
231
|
+
# append new items to full list
|
|
232
|
+
item_list += add_items
|
|
233
|
+
break if !max_items.nil? && item_list.count >= max_items
|
|
234
|
+
break if !max_pages.nil? && page_count >= max_pages
|
|
235
|
+
break if total_count&.<=(item_list.count)
|
|
236
|
+
Rest::Parameters.instance.spinner_cb.call("#{item_list.count} / #{total_count}") unless total_count.eql?(item_list.count.to_s)
|
|
237
|
+
end
|
|
238
|
+
Rest::Parameters.instance.spinner_cb.call(action: :success)
|
|
239
|
+
item_list = item_list[0..max_items - 1] if !max_items.nil? && item_list.count > max_items
|
|
240
|
+
return {items: item_list, total: total_count}
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
# @param id [String] Identifier or workspace
|
|
244
|
+
# @return [Hash] suitable for permission filtering
|
|
245
|
+
def workspace_access(id)
|
|
246
|
+
{
|
|
247
|
+
'access_type' => 'user',
|
|
248
|
+
'access_id' => "#{ID_AK_ADMIN}_WS_#{id}"
|
|
249
|
+
}
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
# @param permission [Hash] Shared folder information
|
|
253
|
+
# @return [Boolean] `true` if internal access
|
|
254
|
+
def workspace_access?(permission)
|
|
255
|
+
permission['access_id'].start_with?("#{ID_AK_ADMIN}_WS_")
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
# Expand access levels to full list of levels.
|
|
259
|
+
# @param levels [nil, String, Array] Access levels
|
|
260
|
+
# @return [Array] Expanded access levels
|
|
261
|
+
def expand_access_levels(levels)
|
|
262
|
+
case levels
|
|
263
|
+
when nil, 'edit' then Node::Api::ACCESS_LEVELS
|
|
264
|
+
when 'preview' then %w[list preview]
|
|
265
|
+
when 'download' then %w[list preview read]
|
|
266
|
+
when 'upload' then %w[mkdir write]
|
|
267
|
+
when Array
|
|
268
|
+
Aspera.assert_array_all(levels, String) { 'access_levels' }
|
|
269
|
+
levels.each { |level| Aspera.assert_values(level, Node::Api::ACCESS_LEVELS) { 'access_level' } }
|
|
270
|
+
levels
|
|
271
|
+
else Aspera.error_unexpected_value(levels) { "access_levels must be a list of #{Node::Api::ACCESS_LEVELS.join(', ')} or one of edit, preview, download, upload" }
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
attr_reader :private_link
|
|
277
|
+
attr_accessor :ws_ids
|
|
278
|
+
|
|
279
|
+
# By default: no workspace
|
|
280
|
+
def initialize(
|
|
281
|
+
scope: nil,
|
|
282
|
+
subpath: API_V1,
|
|
283
|
+
secret_finder: nil,
|
|
284
|
+
# parameters below: OAuth::AUTH_OPTIONS
|
|
285
|
+
url:,
|
|
286
|
+
auth:,
|
|
287
|
+
client_id: nil,
|
|
288
|
+
client_secret: nil,
|
|
289
|
+
redirect_uri: nil,
|
|
290
|
+
private_key: nil,
|
|
291
|
+
passphrase: nil,
|
|
292
|
+
username: nil,
|
|
293
|
+
password: nil
|
|
294
|
+
)
|
|
295
|
+
# Test here because link may set url
|
|
296
|
+
Aspera.assert(url, 'Missing mandatory option: url', type: ParameterError)
|
|
297
|
+
# analyze type of url
|
|
298
|
+
url_info = self.class.link_info(url)
|
|
299
|
+
Log.dump(:url_info, url_info)
|
|
300
|
+
@private_link = url_info[:private_link]
|
|
301
|
+
Aspera.assert(auth, 'Missing mandatory option: auth', type: ParameterError) unless url_info.key?(:token)
|
|
302
|
+
# this is the base API url
|
|
303
|
+
api_url_base = self.class.api_base_url(url_info[:instance_domain])
|
|
304
|
+
Aspera.assert(scope, 'Missing mandatory option: scope', type: ParameterError) unless auth.eql?(:none)
|
|
305
|
+
# default values for client id
|
|
306
|
+
global_client = client_id.nil?
|
|
307
|
+
client_id, client_secret = self.class.get_client_info if global_client
|
|
308
|
+
# access key secrets are provided out of band to get node api access
|
|
309
|
+
# maps access key (String) to its associated secret (String)
|
|
310
|
+
@secret_finder = secret_finder
|
|
311
|
+
@cache_user_info = nil
|
|
312
|
+
@cache_url_token_info = nil
|
|
313
|
+
# @type [Hash]
|
|
314
|
+
@workspace_info = nil
|
|
315
|
+
# Used only for init: provided by user
|
|
316
|
+
@ws_ids = {id: nil, name: nil}
|
|
317
|
+
@home_info = nil
|
|
318
|
+
base_args = {
|
|
319
|
+
base_url: "#{api_url_base}/#{subpath}",
|
|
320
|
+
auth: {
|
|
321
|
+
type: :oauth2,
|
|
322
|
+
grant_method: url_info.key?(:token) ? :url_json : auth,
|
|
323
|
+
base_url: "#{api_url_base}/#{OAUTH_API_SUBPATH}/#{url_info[:organization]}",
|
|
324
|
+
params: {
|
|
325
|
+
client_id: client_id,
|
|
326
|
+
client_secret: client_secret,
|
|
327
|
+
scope: scope
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
# shortcut alias
|
|
332
|
+
auth_params = base_args[:auth]
|
|
333
|
+
# fill other auth parameters based on OAuth method
|
|
334
|
+
case auth_params[:grant_method]
|
|
335
|
+
when :web
|
|
336
|
+
# AoC accepts only the redirect URIs registered in the API client: the global client has none for loopback
|
|
337
|
+
Aspera.assert(!global_client, 'auth=web requires an API client of the organization: set options client_id and client_secret (the global client supports only auth=jwt)', type: ParameterError)
|
|
338
|
+
Aspera.assert(redirect_uri, 'Missing mandatory option: redirect_uri', type: ParameterError)
|
|
339
|
+
auth_params[:redirect_uri] = redirect_uri
|
|
340
|
+
when :jwt
|
|
341
|
+
Aspera.assert(private_key, 'Missing mandatory option: private_key', type: ParameterError)
|
|
342
|
+
Aspera.assert(username, 'Missing mandatory option: username', type: ParameterError)
|
|
343
|
+
auth_params[:private_key_obj] = OpenSSL::PKey::RSA.new(private_key, passphrase)
|
|
344
|
+
auth_params[:payload] = {
|
|
345
|
+
iss: client_id, # issuer
|
|
346
|
+
sub: username, # subject
|
|
347
|
+
aud: JWT_AUDIENCE
|
|
348
|
+
}
|
|
349
|
+
# add jwt payload for global client id
|
|
350
|
+
auth_params[:payload][:org] = url_info[:organization] if GLOBAL_CLIENT_APPS.include?(client_id)
|
|
351
|
+
auth_params[:cache_ids] = [url_info[:organization]]
|
|
352
|
+
when :url_json
|
|
353
|
+
auth_params[:url] = {grant_type: 'url_token'} # Query arguments
|
|
354
|
+
auth_params[:json] = {url_token: url_info[:token]} # JSON body
|
|
355
|
+
# password protection of link
|
|
356
|
+
auth_params[:json][:password] = password unless password.nil?
|
|
357
|
+
# basic auth required for /token
|
|
358
|
+
auth_params[:auth] = {type: :basic, username: client_id, password: client_secret}
|
|
359
|
+
when :boot
|
|
360
|
+
# cookie is optional: if absent, existing cache is used
|
|
361
|
+
auth_params[:cookie] = password unless password.nil?
|
|
362
|
+
auth_params[:username] = username unless username.nil?
|
|
363
|
+
when :none
|
|
364
|
+
auth_params.clear
|
|
365
|
+
auth_params[:type] = :none
|
|
366
|
+
else Aspera.error_unexpected_value(auth_params[:grant_method]) { 'auth, use one of: web, jwt, boot' }
|
|
367
|
+
end
|
|
368
|
+
super(**base_args)
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
# Read using the query and paging
|
|
372
|
+
# @param subpath [String] Entity path
|
|
373
|
+
# @param query [nil, Hash] Additional query
|
|
374
|
+
# @return [Hash] {items: , total: }
|
|
375
|
+
def read_with_paging(subpath, query = nil)
|
|
376
|
+
return self.class.call_paging(query: query) do |paged_query|
|
|
377
|
+
read(subpath, query: paged_query, ret: :both)
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
# @param expected [Array<String>] Link types
|
|
382
|
+
def assert_public_link_types(expected)
|
|
383
|
+
Aspera.assert_values(public_link['purpose'], expected) { 'public link type' }
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
def additional_persistence_ids
|
|
387
|
+
return [current_user_info['id']] if public_link.nil?
|
|
388
|
+
return [] # TODO : public_link['id'] ?
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
# Cached public link information
|
|
392
|
+
# @return [Hash, nil] token info if public link or nil
|
|
393
|
+
def public_link
|
|
394
|
+
return unless auth_params[:grant_method].eql?(:url_json)
|
|
395
|
+
return @cache_url_token_info unless @cache_url_token_info.nil?
|
|
396
|
+
# TODO: can there be several in list ?
|
|
397
|
+
@cache_url_token_info = read('url_tokens').first
|
|
398
|
+
return @cache_url_token_info
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
# Cached user information
|
|
402
|
+
def current_user_info(exception: false)
|
|
403
|
+
return @cache_user_info unless @cache_user_info.nil?
|
|
404
|
+
# get our user's default information
|
|
405
|
+
@cache_user_info =
|
|
406
|
+
begin
|
|
407
|
+
read('self')
|
|
408
|
+
rescue Aspera::Rest::CallError => e
|
|
409
|
+
raise if exception || e.message.include?('invalid_grant')
|
|
410
|
+
Log.log.debug { "Ignoring error: (#{e.class}) #{e}" }
|
|
411
|
+
{}
|
|
412
|
+
end
|
|
413
|
+
USER_INFO_FIELDS_MIN.each { |f| @cache_user_info[f] = nil if @cache_user_info[f].nil? }
|
|
414
|
+
return @cache_user_info
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
def default_workspace?
|
|
418
|
+
@ws_ids[:name].eql?(DEFAULT_WORKSPACE)
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
# Cached workspace information.
|
|
422
|
+
# Always with `:name`.
|
|
423
|
+
# If no workspace, then no `:id`
|
|
424
|
+
# @return [Hash{Symbol=>String}] Workspace info.
|
|
425
|
+
def workspace_info
|
|
426
|
+
return @workspace_info unless @workspace_info.nil?
|
|
427
|
+
if !public_link.nil?
|
|
428
|
+
Log.log.debug('Using workspace of public link')
|
|
429
|
+
@ws_ids[:id] = public_link['data']['workspace_id']
|
|
430
|
+
elsif !private_link.nil?
|
|
431
|
+
Log.log.debug('Using workspace of private link')
|
|
432
|
+
@ws_ids[:id] = private_link[:workspace_id]
|
|
433
|
+
elsif @ws_ids[:id]
|
|
434
|
+
Log.log.debug("Using workspace id: #{@ws_ids[:id]}")
|
|
435
|
+
elsif default_workspace?
|
|
436
|
+
if current_user_info['default_workspace_id'].nil?
|
|
437
|
+
@ws_ids[:name] = nil
|
|
438
|
+
Log.log.warn('No default workspace')
|
|
439
|
+
else
|
|
440
|
+
Log.log.debug('Using default workspace'.green)
|
|
441
|
+
@ws_ids[:id] = current_user_info['default_workspace_id']
|
|
442
|
+
end
|
|
443
|
+
elsif !@ws_ids[:name].nil?
|
|
444
|
+
@workspace_info = lookup_with_q('workspaces', value: @ws_ids[:name])
|
|
445
|
+
end
|
|
446
|
+
@workspace_info = read("workspaces/#{@ws_ids[:id]}") unless @ws_ids[:id].nil?
|
|
447
|
+
@workspace_info ||= {name: 'Shared (no workspace)'}
|
|
448
|
+
@workspace_info = @workspace_info.slice('name', 'id', 'home_node_id', 'home_file_id').symbolize_keys
|
|
449
|
+
Log.dump(:workspace_info, @workspace_info)
|
|
450
|
+
@workspace_info
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
# Cached Home information for current user in Files app
|
|
454
|
+
def home
|
|
455
|
+
return @home_info unless @home_info.nil?
|
|
456
|
+
@home_info =
|
|
457
|
+
if !public_link.nil?
|
|
458
|
+
assert_public_link_types(['view_shared_file'])
|
|
459
|
+
{
|
|
460
|
+
node_id: public_link['data']['node_id'],
|
|
461
|
+
file_id: public_link['data']['file_id']
|
|
462
|
+
}
|
|
463
|
+
elsif !private_link.nil?
|
|
464
|
+
{
|
|
465
|
+
node_id: private_link[:node_id],
|
|
466
|
+
file_id: private_link[:file_id]
|
|
467
|
+
}
|
|
468
|
+
elsif workspace_info[:home_node_id] && workspace_info[:home_file_id]
|
|
469
|
+
{
|
|
470
|
+
node_id: workspace_info[:home_node_id],
|
|
471
|
+
file_id: workspace_info[:home_file_id]
|
|
472
|
+
}
|
|
473
|
+
else
|
|
474
|
+
# not part of any workspace, but has some folder shared
|
|
475
|
+
user_info = current_user_info(exception: true) rescue {'read_only_home_node_id' => nil, 'read_only_home_file_id' => nil}
|
|
476
|
+
{
|
|
477
|
+
node_id: user_info['read_only_home_node_id'],
|
|
478
|
+
file_id: user_info['read_only_home_file_id']
|
|
479
|
+
}
|
|
480
|
+
end
|
|
481
|
+
Aspera.assert(!@home_info[:node_id].to_s.empty?, "Cannot get user's home node id, check your default workspace or specify one", type: ParameterError)
|
|
482
|
+
Log.dump(:context, @home_info)
|
|
483
|
+
@home_info
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
# Return a Node API for given node id, in a given context (files, packages), for the given scope.
|
|
487
|
+
# @param node_id [String] identifier of node in AoC
|
|
488
|
+
# @param workspace_id [String,nil] workspace identifier
|
|
489
|
+
# @param workspace_name [String,nil] workspace name
|
|
490
|
+
# @param scope [String,nil] e.g. Plugins::Node::Api::Scope::USER, or Plugins::Node::Api::Scope::ADMIN, or nil (requires secret)
|
|
491
|
+
# @param package_info [Hash,nil] created package information
|
|
492
|
+
# @return [Node] a node API for access key
|
|
493
|
+
def node_api_from(node_id:, workspace_id: nil, workspace_name: nil, scope: Node::Api::Scope::USER, package_info: nil)
|
|
494
|
+
Aspera.assert_type(node_id, String)
|
|
495
|
+
node_info = read("nodes/#{node_id}")
|
|
496
|
+
workspace_name = read("workspaces/#{workspace_id}")['name'] if workspace_name.nil? && !workspace_id.nil?
|
|
497
|
+
app_info = AppInfo.new(self, package_info, node_info, workspace_id, workspace_name)
|
|
498
|
+
node_params = {base_url: node_info['url']}
|
|
499
|
+
ak_secret = @secret_finder&.lookup(url: node_info['url'], username: node_info['access_key'])
|
|
500
|
+
# If secret is available, or no scope, use basic auth
|
|
501
|
+
if scope.nil? || ak_secret
|
|
502
|
+
Aspera.assert(ak_secret, type: ParameterError) { "Secret not found for access key #{node_info['access_key']}@#{node_info['url']}" }
|
|
503
|
+
node_params[:auth] = {
|
|
504
|
+
type: :basic,
|
|
505
|
+
username: node_info['access_key'],
|
|
506
|
+
password: ak_secret
|
|
507
|
+
}
|
|
508
|
+
else
|
|
509
|
+
# OAuth bearer token
|
|
510
|
+
# copy nested params, so that auth params of this API are not modified
|
|
511
|
+
node_params[:auth] = auth_params.merge(params: auth_params[:params]&.dup || {})
|
|
512
|
+
node_params[:auth][:params][:scope] = Node::Api::Scope.join(access_key: node_info['access_key'], scope: scope)
|
|
513
|
+
node_params[:auth][:params][:owner_access] = true if scope.eql?(Node::Api::Scope::ADMIN)
|
|
514
|
+
# Special header required for bearer token only
|
|
515
|
+
node_params[:headers] = {Node::Api::HEADER_X_ASPERA_ACCESS_KEY => node_info['access_key']}
|
|
516
|
+
end
|
|
517
|
+
node_params[:app_info] = app_info
|
|
518
|
+
return Node::Api.new(**node_params)
|
|
519
|
+
end
|
|
520
|
+
|
|
521
|
+
# Check metadata: remove when validation is done server side
|
|
522
|
+
def validate_metadata(pkg_data)
|
|
523
|
+
# validate only for shared inboxes
|
|
524
|
+
return unless pkg_data['recipients'].is_a?(Array) &&
|
|
525
|
+
pkg_data['recipients'].first.is_a?(Hash) &&
|
|
526
|
+
pkg_data['recipients'].first.key?('type') &&
|
|
527
|
+
pkg_data['recipients'].first['type'].eql?('dropbox')
|
|
528
|
+
meta_schema = read("dropboxes/#{pkg_data['recipients'].first['id']}")['metadata_schema']
|
|
529
|
+
if meta_schema.nil? || meta_schema.empty?
|
|
530
|
+
Log.log.debug('no metadata in shared inbox')
|
|
531
|
+
return
|
|
532
|
+
end
|
|
533
|
+
Aspera.assert(pkg_data.key?('metadata')) { "package requires metadata: #{meta_schema}" }
|
|
534
|
+
pkg_meta = pkg_data['metadata']
|
|
535
|
+
Aspera.assert_type(pkg_meta, Array) { 'metadata' }
|
|
536
|
+
Log.dump(:metadata, pkg_meta)
|
|
537
|
+
pkg_meta.each do |field|
|
|
538
|
+
Aspera.assert_type(field, Hash) { 'metadata field' }
|
|
539
|
+
Aspera.assert(field.key?('name'), 'metadata field must have name')
|
|
540
|
+
Aspera.assert(field.key?('values'), 'metadata field must have values')
|
|
541
|
+
Aspera.assert_type(field['values'], Array) { 'metadata field values' }
|
|
542
|
+
Aspera.assert(meta_schema.any? { |i| i['name'].eql?(field['name']) }) { "unknown metadata field: #{field['name']}" }
|
|
543
|
+
end
|
|
544
|
+
meta_schema.each do |field|
|
|
545
|
+
provided = pkg_meta.select { |i| i['name'].eql?(field['name']) }
|
|
546
|
+
Aspera.assert(provided.count <= 1, type: ParameterError) { "only one field with name #{field['name']} allowed" }
|
|
547
|
+
Aspera.assert(!provided.empty?, type: ParameterError) { "missing mandatory field: #{field['name']}" } if field['required']
|
|
548
|
+
end
|
|
549
|
+
end
|
|
550
|
+
|
|
551
|
+
# Normalize package creation recipient lists as expected by AoC API
|
|
552
|
+
# AoC expects {type: , id: }, but ascli allows providing either the native values or just a name
|
|
553
|
+
# in that case, the name is resolved and replaced with {type: , id: }
|
|
554
|
+
# @param package_data [Hash] The whole package creation payload
|
|
555
|
+
# @param rcpt_lst_field [String] The field in structure, i.e. recipients or bcc_recipients
|
|
556
|
+
# @param new_user_option [Hash] Additional fields for contact creation
|
|
557
|
+
# @return [nil] `package_data` is modified in place
|
|
558
|
+
def resolve_package_recipients(package_data, rcpt_lst_field, new_user_option)
|
|
559
|
+
return unless package_data.key?(rcpt_lst_field)
|
|
560
|
+
Aspera.assert_type(package_data[rcpt_lst_field], Array) { rcpt_lst_field }
|
|
561
|
+
new_user_option = {'package_contact' => true} if new_user_option.nil?
|
|
562
|
+
Aspera.assert_type(new_user_option, Hash) { 'new_user_option' }
|
|
563
|
+
ws_id = package_data['workspace_id']
|
|
564
|
+
# list with resolved elements
|
|
565
|
+
resolved_list = []
|
|
566
|
+
package_data[rcpt_lst_field].each do |short_recipient_info|
|
|
567
|
+
case short_recipient_info
|
|
568
|
+
when Hash # native API information, check keys
|
|
569
|
+
Aspera.assert(short_recipient_info.keys.sort.eql?(%w[id type])) { "#{rcpt_lst_field} element shall have fields: id and type" }
|
|
570
|
+
when String # CLI helper: need to resolve provided name to type/id
|
|
571
|
+
# email: user, else dropbox
|
|
572
|
+
entity_type = short_recipient_info.include?('@') ? 'contacts' : 'dropboxes'
|
|
573
|
+
begin
|
|
574
|
+
full_recipient_info = lookup_with_q(entity_type, value: short_recipient_info, query: {'workspace_id' => ws_id})
|
|
575
|
+
rescue EntityNotFound
|
|
576
|
+
# dropboxes cannot be created on the fly
|
|
577
|
+
Aspera.assert_values(entity_type, %w[contacts], type: EntityNotFound) { "No such shared inbox in workspace #{ws_id}" }
|
|
578
|
+
# unknown user: create it as external user
|
|
579
|
+
full_recipient_info = create('contacts', {
|
|
580
|
+
'current_workspace_id' => ws_id,
|
|
581
|
+
'email' => short_recipient_info
|
|
582
|
+
}.merge(new_user_option))
|
|
583
|
+
end
|
|
584
|
+
short_recipient_info = if entity_type.eql?('dropboxes')
|
|
585
|
+
{'id' => full_recipient_info['id'], 'type' => 'dropbox'}
|
|
586
|
+
else
|
|
587
|
+
{'id' => full_recipient_info['source_id'], 'type' => full_recipient_info['source_type']}
|
|
588
|
+
end
|
|
589
|
+
else Aspera.error_unexpected_value(short_recipient_info.class.name) { "#{rcpt_lst_field} item must be a String (email, shared inbox) or Hash (id,type)" }
|
|
590
|
+
end
|
|
591
|
+
# add original or resolved recipient info
|
|
592
|
+
resolved_list.push(short_recipient_info)
|
|
593
|
+
end
|
|
594
|
+
# replace with resolved elements
|
|
595
|
+
package_data[rcpt_lst_field] = resolved_list
|
|
596
|
+
return
|
|
597
|
+
end
|
|
598
|
+
|
|
599
|
+
# CLI allows simplified format for metadata: transform if necessary for API
|
|
600
|
+
def update_package_metadata_for_api(pkg_data)
|
|
601
|
+
case pkg_data['metadata']
|
|
602
|
+
when Array, NilClass # no action
|
|
603
|
+
when Hash
|
|
604
|
+
api_meta = pkg_data['metadata'].map do |k, v|
|
|
605
|
+
{
|
|
606
|
+
# 'input_type' => 'single-dropdown',
|
|
607
|
+
'name' => k,
|
|
608
|
+
'values' => v.is_a?(Array) ? v : [v]
|
|
609
|
+
}
|
|
610
|
+
end
|
|
611
|
+
pkg_data['metadata'] = api_meta
|
|
612
|
+
else Aspera.error_unexpected_value(pkg_meta.class)
|
|
613
|
+
end
|
|
614
|
+
return
|
|
615
|
+
end
|
|
616
|
+
|
|
617
|
+
# create a package
|
|
618
|
+
# @param package_data [Hash] package creation (with extensions...)
|
|
619
|
+
# @param validate_meta [TrueClass,FalseClass] true to validate parameters locally
|
|
620
|
+
# @param new_user_option [Hash,NilClass] options if an unknown user is specified
|
|
621
|
+
# @return [Array] transfer spec, node api and package information
|
|
622
|
+
def create_package_simple(package_data, validate_meta, new_user_option)
|
|
623
|
+
update_package_metadata_for_api(package_data)
|
|
624
|
+
# list of files to include in package, optional
|
|
625
|
+
# package_data['file_names']||=[..list of filenames to transfer...]
|
|
626
|
+
|
|
627
|
+
# lookup users
|
|
628
|
+
resolve_package_recipients(package_data, 'recipients', new_user_option)
|
|
629
|
+
resolve_package_recipients(package_data, 'bcc_recipients', new_user_option)
|
|
630
|
+
|
|
631
|
+
validate_metadata(package_data) if validate_meta
|
|
632
|
+
|
|
633
|
+
# tell AoC what to expect in package: 1 transfer (can also be done after transfer)
|
|
634
|
+
# TODO: if multi session was used we should probably tell
|
|
635
|
+
# also, currently no "multi-source" , i.e. only from client-side files, unless "node" agent is used
|
|
636
|
+
# `single_source` is required to allow web UI to ask for CSEAR password on download, see API doc
|
|
637
|
+
package_data.merge!({
|
|
638
|
+
'single_source' => true,
|
|
639
|
+
'sent' => true,
|
|
640
|
+
'transfers_expected' => 1
|
|
641
|
+
})
|
|
642
|
+
|
|
643
|
+
# create a new package container
|
|
644
|
+
created_package = create('packages', package_data)
|
|
645
|
+
|
|
646
|
+
package_node_api = node_api_from(
|
|
647
|
+
node_id: created_package['node_id'],
|
|
648
|
+
workspace_id: created_package['workspace_id'],
|
|
649
|
+
package_info: created_package
|
|
650
|
+
)
|
|
651
|
+
|
|
652
|
+
return {
|
|
653
|
+
spec: package_node_api.transfer_spec_gen4(created_package['contents_file_id'], Aspera::Transfer::Spec::DIRECTION_SEND),
|
|
654
|
+
node: package_node_api,
|
|
655
|
+
info: created_package
|
|
656
|
+
}
|
|
657
|
+
end
|
|
658
|
+
|
|
659
|
+
# Add transfer spec
|
|
660
|
+
# callback in Node (transfer_spec_gen4)
|
|
661
|
+
def add_ts_tags(transfer_spec:, app_info:)
|
|
662
|
+
# translate transfer direction to upload/download
|
|
663
|
+
transfer_type = Aspera::Transfer::Spec.direction_to_transfer_type(transfer_spec['direction'])
|
|
664
|
+
# Analytics tags
|
|
665
|
+
################
|
|
666
|
+
transfer_spec.deep_merge!({
|
|
667
|
+
'tags' => {
|
|
668
|
+
Aspera::Transfer::Spec::TAG_RESERVED => {
|
|
669
|
+
'app' => app_info.app,
|
|
670
|
+
'usage_id' => "aspera.files.workspace.#{app_info.workspace_id}", # activity tracking
|
|
671
|
+
'files' => {
|
|
672
|
+
'node_id' => app_info.node_info['id'],
|
|
673
|
+
'files_transfer_action' => "#{transfer_type}_#{app_info.app.gsub(/s$/, '')}",
|
|
674
|
+
'workspace_name' => app_info.workspace_name, # activity tracking
|
|
675
|
+
'workspace_id' => app_info.workspace_id
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
})
|
|
680
|
+
# Console cookie
|
|
681
|
+
################
|
|
682
|
+
# we are sure that fields are not nil
|
|
683
|
+
cookie_elements = [app_info.app, current_user_info['name'] || 'public link', current_user_info['email'] || 'none'].map { |e| Base64.strict_encode64(e) }
|
|
684
|
+
cookie_elements.unshift(COOKIE_PREFIX_CONSOLE_AOC)
|
|
685
|
+
transfer_spec['cookie'] = cookie_elements.join(':')
|
|
686
|
+
# Application tags
|
|
687
|
+
##################
|
|
688
|
+
case app_info.app
|
|
689
|
+
when AppType::FILES
|
|
690
|
+
file_id = transfer_spec['tags'][Aspera::Transfer::Spec::TAG_RESERVED]['node']['file_id']
|
|
691
|
+
transfer_spec.deep_merge!({
|
|
692
|
+
'tags' => {
|
|
693
|
+
Aspera::Transfer::Spec::TAG_RESERVED => {
|
|
694
|
+
'files' => {
|
|
695
|
+
'parentCwd' => "#{app_info.node_info['id']}:#{file_id}"
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}) unless transfer_spec.key?('remote_access_key')
|
|
700
|
+
when AppType::PACKAGES
|
|
701
|
+
transfer_spec.deep_merge!({
|
|
702
|
+
'tags' => {
|
|
703
|
+
Aspera::Transfer::Spec::TAG_RESERVED => {
|
|
704
|
+
'files' => {
|
|
705
|
+
'package_id' => app_info.package['id'],
|
|
706
|
+
'package_name' => app_info.package['name'],
|
|
707
|
+
'package_operation' => transfer_type
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
})
|
|
712
|
+
end
|
|
713
|
+
end
|
|
714
|
+
|
|
715
|
+
# Callback from Plugins::Node
|
|
716
|
+
# add application specific tags to permissions creation
|
|
717
|
+
# @param perm_data [Hash] parameters for creating permissions
|
|
718
|
+
# @param app_info [AppInfo] application information
|
|
719
|
+
def permissions_set_create_params(perm_data:, app_info:)
|
|
720
|
+
defaults = {
|
|
721
|
+
'tags' => {
|
|
722
|
+
Aspera::Transfer::Spec::TAG_RESERVED => {
|
|
723
|
+
'files' => {
|
|
724
|
+
'workspace' => {
|
|
725
|
+
'id' => app_info.workspace_id,
|
|
726
|
+
'workspace_name' => app_info.workspace_name,
|
|
727
|
+
'user_name' => current_user_info['name'],
|
|
728
|
+
'shared_by_user_id' => current_user_info['id'],
|
|
729
|
+
'shared_by_name' => current_user_info['name'],
|
|
730
|
+
'shared_by_email' => current_user_info['email'],
|
|
731
|
+
'access_key' => app_info.node_info['access_key'],
|
|
732
|
+
'node' => app_info.node_info['name']
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
perm_data.deep_merge!(defaults)
|
|
739
|
+
tag_workspace = perm_data['tags'][Aspera::Transfer::Spec::TAG_RESERVED]['files']['workspace']
|
|
740
|
+
shared_with = perm_data.delete('with')
|
|
741
|
+
case shared_with
|
|
742
|
+
when NilClass
|
|
743
|
+
when ''
|
|
744
|
+
# workspace shared folder
|
|
745
|
+
perm_data.merge!(self.class.workspace_access(app_info.workspace_id))
|
|
746
|
+
tag_workspace['shared_with_name'] = perm_data['access_id']
|
|
747
|
+
else
|
|
748
|
+
entity_info = lookup_with_q('contacts', value: shared_with, query: {'current_workspace_id' => app_info.workspace_id})
|
|
749
|
+
perm_data['access_type'] = entity_info['source_type']
|
|
750
|
+
perm_data['access_id'] = entity_info['source_id']
|
|
751
|
+
tag_workspace['shared_with_name'] = entity_info['email'] # TODO: check that ???
|
|
752
|
+
end
|
|
753
|
+
if perm_data.key?('as')
|
|
754
|
+
tag_workspace['share_as'] = perm_data['as']
|
|
755
|
+
perm_data.delete('as')
|
|
756
|
+
end
|
|
757
|
+
# optional
|
|
758
|
+
app_info.opt_link_name = perm_data.delete('link_name')
|
|
759
|
+
end
|
|
760
|
+
|
|
761
|
+
# Callback from Plugins::Node
|
|
762
|
+
# send shared folder event to AoC
|
|
763
|
+
# @param event_data [Hash] response from permission creation
|
|
764
|
+
# @param app_info [AppInfo] hash with app info
|
|
765
|
+
# @param types [Array] event types
|
|
766
|
+
def permissions_send_event(event_data:, app_info:, types: PERMISSIONS_CREATED)
|
|
767
|
+
Aspera.assert_type(types, Array)
|
|
768
|
+
Aspera.assert(!types.empty?, 'types must not be empty')
|
|
769
|
+
event_creation = {
|
|
770
|
+
'types' => types,
|
|
771
|
+
'node_id' => app_info.node_info['id'],
|
|
772
|
+
'workspace_id' => app_info.workspace_id,
|
|
773
|
+
'data' => event_data
|
|
774
|
+
}
|
|
775
|
+
# (optional). The name of the folder to be displayed to the destination user.
|
|
776
|
+
# Use it if its value is different from the "share_as" field.
|
|
777
|
+
event_creation['link_name'] = app_info.opt_link_name unless app_info.opt_link_name.nil?
|
|
778
|
+
create('events', event_creation, query: {admin: true})
|
|
779
|
+
end
|
|
780
|
+
end
|
|
781
|
+
end
|
|
782
|
+
end
|
|
783
|
+
end
|