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
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
-
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
|
|
6
|
-
require_relative 'assert'
|
|
7
|
-
require 'singleton'
|
|
8
|
-
require 'openssl'
|
|
9
|
-
require 'zlib'
|
|
10
|
-
require 'base64'
|
|
11
|
-
|
|
12
|
-
module Aspera
|
|
13
|
-
# a simple binary data repository
|
|
14
|
-
#
|
|
15
|
-
# @!method self.instance
|
|
16
|
-
# Returns the singleton instance of DataRepository
|
|
17
|
-
# @return [DataRepository] the singleton instance
|
|
18
|
-
class DataRepository
|
|
19
|
-
include Singleton
|
|
20
|
-
|
|
21
|
-
# name of data item => name of its file in data folder
|
|
22
|
-
FILES = {
|
|
23
|
-
dsa: '1',
|
|
24
|
-
rsa: '2',
|
|
25
|
-
uuid: '3',
|
|
26
|
-
'aspera.global-cli-client': '4',
|
|
27
|
-
'aspera.drive': '5',
|
|
28
|
-
license: '6'
|
|
29
|
-
}.freeze
|
|
30
|
-
# names of data items
|
|
31
|
-
ELEMENTS = FILES.keys.freeze
|
|
32
|
-
DATA_FOLDER_NAME = 'data'
|
|
33
|
-
|
|
34
|
-
# Get a data item, decoded to its usable form
|
|
35
|
-
# @param name [Symbol] name of the data item, one of ELEMENTS
|
|
36
|
-
# @return [String] PEM private key (dsa, rsa), UUID (uuid), base64url secret (client apps), or text (license)
|
|
37
|
-
def item(name)
|
|
38
|
-
Aspera.assert_values(name, ELEMENTS, type: ParameterError) { 'data item' }
|
|
39
|
-
raw_data = data(name)
|
|
40
|
-
value =
|
|
41
|
-
case name
|
|
42
|
-
when :dsa, :rsa
|
|
43
|
-
# generate PEM from DER
|
|
44
|
-
# Class of key, not `OpenSSL::PKey.read`: on JRuby (jruby-openssl 0.16), it fails on these keys (DER, traditional format)
|
|
45
|
-
{dsa: OpenSSL::PKey::DSA, rsa: OpenSSL::PKey::RSA}[name].new(raw_data).to_pem
|
|
46
|
-
when :license
|
|
47
|
-
Zlib::Inflate.inflate(raw_data)
|
|
48
|
-
when :uuid
|
|
49
|
-
format('%08x-%04x-%04x-%04x-%04x%08x', *raw_data.unpack('NnnnnN'))
|
|
50
|
-
when :'aspera.global-cli-client', :'aspera.drive'
|
|
51
|
-
Base64.urlsafe_encode64(raw_data)
|
|
52
|
-
else Aspera.error_unexpected_value(name)
|
|
53
|
-
end
|
|
54
|
-
# all items are text
|
|
55
|
-
return value.force_encoding(Encoding::UTF_8)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
private
|
|
59
|
-
|
|
60
|
-
private_constant :FILES, :DATA_FOLDER_NAME
|
|
61
|
-
|
|
62
|
-
# get binary value from data repository
|
|
63
|
-
# @param name [Symbol] name of the data item
|
|
64
|
-
# @return [String] raw binary data
|
|
65
|
-
def data(name)
|
|
66
|
-
File.binread(File.join(__dir__, DATA_FOLDER_NAME, FILES[name]))
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
data/lib/aspera/faspex_gw.rb
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
-
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
|
|
6
|
-
require_relative 'api/faspex'
|
|
7
|
-
require_relative 'log'
|
|
8
|
-
require_relative 'assert'
|
|
9
|
-
require_relative 'hash_ext'
|
|
10
|
-
require_relative 'mime'
|
|
11
|
-
require_relative 'secret/strength'
|
|
12
|
-
require_relative 'servlet_helpers'
|
|
13
|
-
require_relative 'web_server_simple'
|
|
14
|
-
require 'webrick'
|
|
15
|
-
require 'json'
|
|
16
|
-
|
|
17
|
-
module Aspera
|
|
18
|
-
# Simulate the Faspex 4 /send API and creates a package on Aspera on Cloud or Faspex 5
|
|
19
|
-
#
|
|
20
|
-
# Security notes:
|
|
21
|
-
# - Packages are created as the user of the application, to any recipient, and the caller receives an upload transfer spec.
|
|
22
|
-
# - Clients authenticate with HTTP Basic, as on Faspex 4, when `username` and `password` are set:
|
|
23
|
-
# they are required when the server listens on an address that is not loopback (checked by `serve`).
|
|
24
|
-
# - Requests that a web page could send are refused (see ServletHelpers#check_request): the body shall be `application/json`.
|
|
25
|
-
class Faspex4GWServlet < WEBrick::HTTPServlet::AbstractServlet
|
|
26
|
-
include ServletHelpers
|
|
27
|
-
|
|
28
|
-
AOC_API = 'Aspera::Api::AoC'
|
|
29
|
-
FX_API = 'Aspera::Api::Faspex'
|
|
30
|
-
ALLOWED_PARAMETERS = %i[username password password_min_bits].freeze
|
|
31
|
-
REALM = 'Faspex 4 Gateway'
|
|
32
|
-
private_constant :REALM
|
|
33
|
-
|
|
34
|
-
class << self
|
|
35
|
-
# Check parameters and set defaults
|
|
36
|
-
# Called at startup, so that errors are reported before the first request
|
|
37
|
-
# @param parameters [Hash] Parameters of the servlet
|
|
38
|
-
# @return [Hash] Parameters with defaults
|
|
39
|
-
def normalize_parameters(parameters)
|
|
40
|
-
Aspera.assert_type(parameters, Hash)
|
|
41
|
-
parameters = parameters.symbolize_keys
|
|
42
|
-
not_allowed = parameters.keys - ALLOWED_PARAMETERS
|
|
43
|
-
Aspera.assert(not_allowed.empty?, type: ParameterError) { "unsupported parameters: #{not_allowed.join(', ')}" }
|
|
44
|
-
Aspera.assert(parameters[:username].nil? == parameters[:password].nil?, type: ParameterError) { 'Parameters username and password must be set together' }
|
|
45
|
-
parameters[:password_min_bits] ||= Secret::Strength::DEFAULT_MIN_BITS
|
|
46
|
-
Secret::Strength.assert_strong(parameters[:password], name: 'password', min_bits: parameters[:password_min_bits]) unless parameters[:password].nil?
|
|
47
|
-
parameters
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
# Start the gateway, until signal INT or TERM
|
|
51
|
-
# @param parameters [Hash] Parameters of the server (see `WebServerSimple.url`) and of the servlet (see `normalize_parameters`)
|
|
52
|
-
# @param type [Exception] Exception raised when the server is not protected
|
|
53
|
-
# @yieldreturn [Array] API of the application, and workspace id (AoC only), see `initialize`: called once parameters are checked
|
|
54
|
-
def serve(parameters, type: ParameterError)
|
|
55
|
-
servlet_parameters = normalize_parameters(WebServerSimple.servlet_parameters(parameters))
|
|
56
|
-
# Packages can be sent to anyone by anyone who can reach the server
|
|
57
|
-
WebServerSimple.serve(parameters, self, protected: !servlet_parameters[:username].nil?, what: 'username and password', type: type) { [servlet_parameters, *yield] }
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# @param server [WEBrick::HTTPServer] Server
|
|
62
|
-
# @param parameters [Hash] Parameters from `normalize_parameters`
|
|
63
|
-
# @param app_api [Rest::Client] API object
|
|
64
|
-
# @param app_context [String] workspace id (aoc only)
|
|
65
|
-
def initialize(server, parameters, app_api, app_context)
|
|
66
|
-
Aspera.assert_values(app_api.class.name, [AOC_API, FX_API])
|
|
67
|
-
super(server)
|
|
68
|
-
@expected_auth = "#{parameters[:username]}:#{parameters[:password]}" unless parameters[:username].nil?
|
|
69
|
-
@app_api = app_api
|
|
70
|
-
@app_context = app_context
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# Map Faspex 4 /send API to AoC package create
|
|
74
|
-
# parameters from user to Faspex API call
|
|
75
|
-
# https://developer.ibm.com/apis/catalog/aspera--aspera-faspex-client-sdk/Sending%20Packages%20(API%20v.3)
|
|
76
|
-
def faspex4_send_to_aoc(faspex_pkg_parameters)
|
|
77
|
-
faspex_pkg_delivery = faspex_pkg_parameters['delivery']
|
|
78
|
-
package_data = {
|
|
79
|
-
# 'file_names' => faspex_pkg_delivery['sources'][0]['paths'],
|
|
80
|
-
'name' => faspex_pkg_delivery['title'],
|
|
81
|
-
'note' => faspex_pkg_delivery['note'],
|
|
82
|
-
'recipients' => faspex_pkg_delivery['recipients'],
|
|
83
|
-
'workspace_id' => @app_context
|
|
84
|
-
}
|
|
85
|
-
created_package = @app_api.create_package_simple(package_data, true, nil)
|
|
86
|
-
# but we place it in a Faspex package creation response
|
|
87
|
-
return {
|
|
88
|
-
'links' => {'status' => 'unused'},
|
|
89
|
-
'xfer_sessions' => [created_package[:spec]]
|
|
90
|
-
}
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def faspex4_send_to_faspex5(faspex_pkg_parameters)
|
|
94
|
-
faspex_pkg_delivery = faspex_pkg_parameters['delivery']
|
|
95
|
-
package_data = {
|
|
96
|
-
'title' => faspex_pkg_delivery['title'],
|
|
97
|
-
'note' => faspex_pkg_delivery['note'],
|
|
98
|
-
'recipients' => faspex_pkg_delivery['recipients'].map { |name| {'name'=>name} }
|
|
99
|
-
}
|
|
100
|
-
package = @app_api.create('packages', package_data)
|
|
101
|
-
# TODO: option to send from remote source or httpgw
|
|
102
|
-
transfer_spec = @app_api.call(
|
|
103
|
-
operation: 'POST',
|
|
104
|
-
subpath: "packages/#{package['id']}/transfer_spec/upload",
|
|
105
|
-
query: {transfer_type: Api::Faspex::TRANSFER_CONNECT},
|
|
106
|
-
content_type: Mime::JSON,
|
|
107
|
-
body: {paths: [{'destination'=>'/'}]},
|
|
108
|
-
headers: {'Accept' => Mime::JSON}
|
|
109
|
-
)
|
|
110
|
-
transfer_spec.delete('authentication')
|
|
111
|
-
# but we place it in a Faspex package creation response
|
|
112
|
-
return {
|
|
113
|
-
'links' => {'status' => 'unused'},
|
|
114
|
-
'xfer_sessions' => [transfer_spec]
|
|
115
|
-
}
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def do_POST(request, response)
|
|
119
|
-
# Refuse requests of web pages
|
|
120
|
-
check_request(request, json: true)
|
|
121
|
-
return json_error(response, 401, 'Invalid or missing credentials', headers: {'WWW-Authenticate' => %Q(Basic realm="#{REALM}")}) unless authorized?(request)
|
|
122
|
-
return json_error(response, 400, 'Unsupported endpoint') unless request.path.eql?('/aspera/faspex/send')
|
|
123
|
-
faspex_pkg_parameters = package_parameters(request.body)
|
|
124
|
-
Log.dump(:faspex_pkg_parameters, faspex_pkg_parameters)
|
|
125
|
-
# compare string, as class is not yet known here
|
|
126
|
-
faspex_package_create_result =
|
|
127
|
-
case @app_api.class.name
|
|
128
|
-
when AOC_API
|
|
129
|
-
faspex4_send_to_aoc(faspex_pkg_parameters)
|
|
130
|
-
when FX_API
|
|
131
|
-
faspex4_send_to_faspex5(faspex_pkg_parameters)
|
|
132
|
-
else Aspera.error_unexpected_value(@app_api.class.name)
|
|
133
|
-
end
|
|
134
|
-
Log.dump(:faspex_package_create_result, faspex_package_create_result)
|
|
135
|
-
json_response(response, 200, faspex_package_create_result)
|
|
136
|
-
rescue WEBrick::HTTPStatus::Error => e
|
|
137
|
-
Log.log.warn { "Rejected request: #{e.message}" }
|
|
138
|
-
json_error(response, e.code, e.message)
|
|
139
|
-
rescue StandardError => e
|
|
140
|
-
# The stack trace is logged only: it is not for the caller
|
|
141
|
-
Log.log.error(e.message)
|
|
142
|
-
Log.log.debug { e.backtrace.join("\n") }
|
|
143
|
-
json_error(response, 500, e.message)
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
private
|
|
147
|
-
|
|
148
|
-
# @param request [WEBrick::HTTPRequest]
|
|
149
|
-
# @return [Boolean] `true` if the request has the expected Basic credentials, or if none are expected
|
|
150
|
-
def authorized?(request)
|
|
151
|
-
@expected_auth.nil? || basic_authorized?(request, @expected_auth)
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
# @param body [String, nil] Body of the request
|
|
155
|
-
# @return [Hash] Parameters of Faspex 4 package creation, with `delivery` and its `recipients`
|
|
156
|
-
# @raise [WEBrick::HTTPStatus::BadRequest] if the body is not a valid package creation request
|
|
157
|
-
def package_parameters(body)
|
|
158
|
-
raise WEBrick::HTTPStatus::BadRequest, 'Empty request' if body.nil?
|
|
159
|
-
parameters =
|
|
160
|
-
begin
|
|
161
|
-
JSON.parse(body)
|
|
162
|
-
rescue JSON::ParserError
|
|
163
|
-
nil
|
|
164
|
-
end
|
|
165
|
-
raise WEBrick::HTTPStatus::BadRequest, 'Request body shall be a JSON object' unless parameters.is_a?(Hash)
|
|
166
|
-
raise WEBrick::HTTPStatus::BadRequest, 'Missing object: delivery' unless parameters['delivery'].is_a?(Hash)
|
|
167
|
-
recipients = parameters['delivery']['recipients']
|
|
168
|
-
raise WEBrick::HTTPStatus::BadRequest, 'delivery.recipients shall be a non-empty list of names' unless recipients.is_a?(Array) && !recipients.empty? && recipients.all?(String)
|
|
169
|
-
parameters
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
end
|
|
@@ -1,237 +0,0 @@
|
|
|
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 'environment'
|
|
9
|
-
require_relative 'hash_ext'
|
|
10
|
-
require_relative 'secret/strength'
|
|
11
|
-
require_relative 'servlet_helpers'
|
|
12
|
-
require_relative 'web_server_simple'
|
|
13
|
-
require 'json'
|
|
14
|
-
require 'timeout'
|
|
15
|
-
require 'English'
|
|
16
|
-
require 'ipaddr'
|
|
17
|
-
require 'openssl'
|
|
18
|
-
require 'webrick'
|
|
19
|
-
|
|
20
|
-
module Aspera
|
|
21
|
-
# Start a Faspex-4 style post-processing script using Faspex-5 webhook
|
|
22
|
-
#
|
|
23
|
-
# Security notes:
|
|
24
|
-
# - By default the listener binds to loopback only (url defaults to http://localhost:...).
|
|
25
|
-
# Use a routable address only when the Faspex containers must reach this host:
|
|
26
|
-
# then `secret_token` or `allowed_ips` is required (checked by `serve`).
|
|
27
|
-
# - Use `secret_token` so the token must be present as a `token` query parameter on every
|
|
28
|
-
# incoming request (configure the webhook URL in Faspex as http://host:port/path?token=VALUE).
|
|
29
|
-
# - Use `allowed_ips` to restrict which source IPs or networks may call the listener.
|
|
30
|
-
# - Requests that a web page could send are refused (see ServletHelpers#check_request): the body shall be `application/json`.
|
|
31
|
-
# - Only webhook values with a key starting with `faspex_` are passed to the script.
|
|
32
|
-
# - With `lambda` in the URL query, a Ruby script (`.rb`) is evaluated in this process:
|
|
33
|
-
# it shall return a lambda, called with the webhook values.
|
|
34
|
-
class Faspex4PostProcServlet < WEBrick::HTTPServlet::AbstractServlet
|
|
35
|
-
include ServletHelpers
|
|
36
|
-
|
|
37
|
-
ALLOWED_PARAMETERS = %i[root script_folder fail_on_error timeout_seconds secret_token secret_token_min_bits allowed_ips].freeze
|
|
38
|
-
# Prefix of keys of webhook values passed as environment variables: Faspex 4 post-processing variables
|
|
39
|
-
ENV_KEY_PREFIX = 'faspex_'
|
|
40
|
-
private_constant :ENV_KEY_PREFIX
|
|
41
|
-
|
|
42
|
-
class << self
|
|
43
|
-
# Check parameters and set defaults
|
|
44
|
-
# Called at startup, so that errors are reported before the first request
|
|
45
|
-
# @param parameters [Hash] Parameters of the servlet
|
|
46
|
-
# @return [Hash] Parameters with defaults, and `allowed_ips` as `IPAddr`
|
|
47
|
-
def normalize_parameters(parameters)
|
|
48
|
-
Aspera.assert_type(parameters, Hash)
|
|
49
|
-
parameters = parameters.symbolize_keys
|
|
50
|
-
not_allowed = parameters.keys - ALLOWED_PARAMETERS
|
|
51
|
-
Aspera.assert(not_allowed.empty?) { "unsupported parameters: #{not_allowed.join(', ')}" }
|
|
52
|
-
parameters[:script_folder] ||= '.'
|
|
53
|
-
parameters[:fail_on_error] ||= false
|
|
54
|
-
parameters[:timeout_seconds] ||= 60
|
|
55
|
-
parameters[:secret_token_min_bits] ||= Secret::Strength::DEFAULT_MIN_BITS
|
|
56
|
-
Aspera.assert(File.directory?(parameters[:script_folder])) { "script_folder not found: #{parameters[:script_folder]}" }
|
|
57
|
-
Secret::Strength.assert_strong(parameters[:secret_token], name: 'secret_token', min_bits: parameters[:secret_token_min_bits]) if parameters.key?(:secret_token)
|
|
58
|
-
# allowed_ips: optional IP addresses or networks (CIDR); nil means no restriction
|
|
59
|
-
parameters[:allowed_ips] = Array(parameters[:allowed_ips]).map { |ip| ip_address(ip) } if parameters.key?(:allowed_ips)
|
|
60
|
-
parameters
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# Start the server, until signal INT or TERM
|
|
64
|
-
# Parameters are checked before: the servlet is created on each request
|
|
65
|
-
# @param parameters [Hash] Parameters of the server (see `WebServerSimple.url`) and of the servlet (see `normalize_parameters`)
|
|
66
|
-
# @param type [Exception] Exception raised when the server is not protected
|
|
67
|
-
def serve(parameters, type: ParameterError)
|
|
68
|
-
servlet_parameters = normalize_parameters(WebServerSimple.servlet_parameters(parameters).merge(root: WebServerSimple.url(parameters).path))
|
|
69
|
-
# Scripts can be started by anyone who can reach the server
|
|
70
|
-
WebServerSimple.serve(
|
|
71
|
-
parameters,
|
|
72
|
-
self,
|
|
73
|
-
protected: servlet_parameters.key?(:secret_token) || servlet_parameters.key?(:allowed_ips),
|
|
74
|
-
what: 'secret_token or allowed_ips',
|
|
75
|
-
type: type
|
|
76
|
-
) { [servlet_parameters] }
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
private
|
|
80
|
-
|
|
81
|
-
# @param ip [String, IPAddr] IP address or network (CIDR)
|
|
82
|
-
# @return [IPAddr] Parsed address
|
|
83
|
-
def ip_address(ip)
|
|
84
|
-
return ip if ip.is_a?(IPAddr)
|
|
85
|
-
IPAddr.new(ip)
|
|
86
|
-
rescue IPAddr::Error
|
|
87
|
-
raise ArgumentError, "allowed_ips: invalid IP address or network: #{ip}"
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
# @param server [WEBrick::HTTPServer] Server
|
|
92
|
-
# @param parameters [Hash] Parameters from `normalize_parameters`: the servlet is created on each request
|
|
93
|
-
def initialize(server, parameters)
|
|
94
|
-
@parameters = parameters
|
|
95
|
-
Log.dump(:post_proc_parameters, @parameters)
|
|
96
|
-
super(server)
|
|
97
|
-
Log.log.debug { 'Faspex4PostProcServlet initialized' }
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
# :reek:UncommunicativeMethodName
|
|
101
|
-
def do_POST(request, response)
|
|
102
|
-
Log.log.debug { "request=#{request.path}" }
|
|
103
|
-
# `request.query` only parses a form body for POST: parameters in the URL come from the query string
|
|
104
|
-
url_query = WEBrick::HTTPUtils.parse_query(request.query_string)
|
|
105
|
-
Log.dump(:query, url_query)
|
|
106
|
-
post_proc_pid = nil
|
|
107
|
-
script_path = nil
|
|
108
|
-
begin
|
|
109
|
-
# Refuse requests of web pages (also on localhost without protection)
|
|
110
|
-
check_request(request, json: true)
|
|
111
|
-
# Check source IP against allowlist when configured
|
|
112
|
-
if @parameters[:allowed_ips]
|
|
113
|
-
client_ip = request.peeraddr[3]
|
|
114
|
-
unless allowed_ip?(client_ip)
|
|
115
|
-
Log.log.warn { "Rejected request from disallowed IP: #{client_ip}" }
|
|
116
|
-
return error_response(response, 403, 'Forbidden')
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
# Verify shared secret when configured (expected as ?token=VALUE in the URL)
|
|
120
|
-
if @parameters[:secret_token] && !OpenSSL.secure_compare(url_query['token'].to_s, @parameters[:secret_token].to_s)
|
|
121
|
-
Log.log.warn { 'Rejected request with invalid or missing token' }
|
|
122
|
-
return error_response(response, 401, 'Unauthorized')
|
|
123
|
-
end
|
|
124
|
-
# Only accept requests on the root
|
|
125
|
-
return error_response(response, 400, 'Request outside domain') unless request.path.start_with?(@parameters[:root])
|
|
126
|
-
return error_response(response, 400, 'Empty request') if request.body.nil?
|
|
127
|
-
webhook_parameters =
|
|
128
|
-
begin
|
|
129
|
-
JSON.parse(request.body)
|
|
130
|
-
rescue JSON::ParserError
|
|
131
|
-
nil
|
|
132
|
-
end
|
|
133
|
-
return error_response(response, 400, 'Request body shall be a JSON object') unless webhook_parameters.is_a?(Hash)
|
|
134
|
-
Log.dump(:webhook_parameters, webhook_parameters)
|
|
135
|
-
# build script path by removing domain and adding script folder
|
|
136
|
-
script_file = request.path[@parameters[:root].size..]
|
|
137
|
-
Log.log.debug { "script file=#{script_file}" }
|
|
138
|
-
# Resolve the real path and ensure it stays within script_folder (prevents path traversal)
|
|
139
|
-
resolved_script_folder = File.realpath(@parameters[:script_folder])
|
|
140
|
-
begin
|
|
141
|
-
script_path = File.realpath(File.join(@parameters[:script_folder], script_file))
|
|
142
|
-
rescue Errno::ENOENT, Errno::ENOTDIR
|
|
143
|
-
return error_response(response, 404, 'Script not found')
|
|
144
|
-
end
|
|
145
|
-
unless script_path.start_with?("#{resolved_script_folder}/")
|
|
146
|
-
Log.log.warn { "Rejected script outside script_folder: #{script_path}" }
|
|
147
|
-
return error_response(response, 403, 'Script path traversal attempt detected')
|
|
148
|
-
end
|
|
149
|
-
return error_response(response, 404, 'Script not found') unless File.file?(script_path)
|
|
150
|
-
Log.log.debug { "script=#{script_path}" }
|
|
151
|
-
process_status = nil
|
|
152
|
-
if url_query.key?('lambda')
|
|
153
|
-
return error_response(response, 400, 'lambda requires a Ruby script (.rb)') unless File.extname(script_path).eql?('.rb')
|
|
154
|
-
run_lambda(script_path, webhook_parameters)
|
|
155
|
-
else
|
|
156
|
-
post_proc_pid = Environment.secure_execute(script_path, mode: :background, env: script_environment(webhook_parameters))
|
|
157
|
-
Timeout.timeout(@parameters[:timeout_seconds]) do
|
|
158
|
-
# "wait" for process to avoid zombie
|
|
159
|
-
::Process.wait(post_proc_pid)
|
|
160
|
-
post_proc_pid = nil
|
|
161
|
-
end
|
|
162
|
-
process_status = $CHILD_STATUS
|
|
163
|
-
Aspera.assert(process_status.success? || !@parameters[:fail_on_error]) { "script #{script_path} failed with code #{process_status.exitstatus}" }
|
|
164
|
-
end
|
|
165
|
-
json_response(response, 200, {status: 'success', script: script_path, exit_code: process_status&.exitstatus})
|
|
166
|
-
Log.log.debug { 'Script executed successfully' }
|
|
167
|
-
rescue WEBrick::HTTPStatus::Error => e
|
|
168
|
-
Log.log.warn { "Rejected request: #{e.message}" }
|
|
169
|
-
error_response(response, e.code, e.message)
|
|
170
|
-
rescue StandardError, ScriptError => e
|
|
171
|
-
# ScriptError: syntax error in lambda script
|
|
172
|
-
Log.log.error("Script failed: #{e.class}:#{e.message}")
|
|
173
|
-
kill_script(post_proc_pid) unless post_proc_pid.nil?
|
|
174
|
-
error_response(response, 500, e.message, script: script_path)
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
private
|
|
179
|
-
|
|
180
|
-
# Set an error in the response
|
|
181
|
-
# @param response [WEBrick::HTTPResponse] Response to set
|
|
182
|
-
# @param status [Integer] HTTP status code
|
|
183
|
-
# @param message [String] Error message
|
|
184
|
-
# @param info [Hash] Additional fields in body
|
|
185
|
-
# @return nil
|
|
186
|
-
def error_response(response, status, message, **info)
|
|
187
|
-
json_response(response, status, {status: 'error', **info, message: message})
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
# @param client_ip [String] Source IP address of the request
|
|
191
|
-
# @return [Boolean] `true` if the address is in one of `allowed_ips`
|
|
192
|
-
def allowed_ip?(client_ip)
|
|
193
|
-
# IPv4 clients of a dual-stack listener appear as IPv4-mapped IPv6 addresses
|
|
194
|
-
address = IPAddr.new(client_ip).native
|
|
195
|
-
@parameters[:allowed_ips].any? { |allowed| allowed.include?(address) }
|
|
196
|
-
rescue IPAddr::Error
|
|
197
|
-
false
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
# Environment variables of the script: same as Faspex 4 post-processing
|
|
201
|
-
# Other keys are ignored: they could change the behavior of the script (e.g. `PATH`, `LD_PRELOAD`)
|
|
202
|
-
# @param webhook_parameters [Hash] Values received in webhook
|
|
203
|
-
# @return [Hash] Environment variables, values are `String`
|
|
204
|
-
def script_environment(webhook_parameters)
|
|
205
|
-
webhook_parameters.each_with_object({}) do |(key, value), env|
|
|
206
|
-
unless key.start_with?(ENV_KEY_PREFIX)
|
|
207
|
-
Log.log.warn { "Ignoring webhook value with key not starting with #{ENV_KEY_PREFIX}: #{key.inspect}" }
|
|
208
|
-
next
|
|
209
|
-
end
|
|
210
|
-
# Structured values are given as JSON
|
|
211
|
-
env[key] = value.is_a?(Hash) || value.is_a?(Array) ? JSON.generate(value) : value.to_s
|
|
212
|
-
end
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
# Evaluate a Ruby script in this process, and call the lambda it returns
|
|
216
|
-
# @param script_path [String] Path of Ruby script
|
|
217
|
-
# @param webhook_parameters [Hash] Values received in webhook
|
|
218
|
-
def run_lambda(script_path, webhook_parameters)
|
|
219
|
-
Timeout.timeout(@parameters[:timeout_seconds]) do
|
|
220
|
-
code = Environment.secure_eval(File.read(script_path), script_path, 1)
|
|
221
|
-
Aspera.assert(code.respond_to?(:call)) { "script #{script_path} shall return a lambda" }
|
|
222
|
-
code.call(webhook_parameters)
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
# Kill the script after a timeout or an error
|
|
227
|
-
# @param pid [Integer] Process id of the script
|
|
228
|
-
def kill_script(pid)
|
|
229
|
-
::Process.kill('SIGKILL', pid)
|
|
230
|
-
::Process.wait(pid)
|
|
231
|
-
Log.log.error("Killed process: #{pid}")
|
|
232
|
-
rescue SystemCallError
|
|
233
|
-
# already terminated
|
|
234
|
-
nil
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
end
|
data/lib/aspera/graphql.rb
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
-
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
|
|
6
|
-
require_relative 'rest/call_error'
|
|
7
|
-
require_relative 'assert'
|
|
8
|
-
|
|
9
|
-
module Aspera
|
|
10
|
-
# Helper to execute GraphQL queries via a Rest::Client object.
|
|
11
|
-
# Follows the GraphQL-over-HTTP convention: POST {query, variables} to endpoint,
|
|
12
|
-
# parse top-level `data` key, raise on top-level `errors` array.
|
|
13
|
-
module GraphQL
|
|
14
|
-
QUERIES_FOLDER = File.join(__dir__, 'api', 'queries')
|
|
15
|
-
private_constant :QUERIES_FOLDER
|
|
16
|
-
|
|
17
|
-
class << self
|
|
18
|
-
# Execute a GraphQL query loaded from a .graphql file in lib/aspera/api/queries/
|
|
19
|
-
# @param rest [Rest::Client] API object pointing at the GraphQL endpoint
|
|
20
|
-
# @param name [String] Base filename without extension (e.g. 'my_query')
|
|
21
|
-
# @param variables [Hash] GraphQL variables
|
|
22
|
-
# @return [Hash] The `data` object from the response
|
|
23
|
-
# @raise [Rest::CallError] if the response contains GraphQL errors
|
|
24
|
-
def execute(rest, name, variables = {})
|
|
25
|
-
query = load_query(name)
|
|
26
|
-
response = rest.create(nil, {query: query, variables: variables})
|
|
27
|
-
errors = response['errors']
|
|
28
|
-
raise Rest::CallError, errors.map { |e| e['message'] }.join("\n") if errors.is_a?(Array) && !errors.empty?
|
|
29
|
-
response['data']
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
private
|
|
33
|
-
|
|
34
|
-
def load_query(name)
|
|
35
|
-
candidate = File.realpath(File.join(QUERIES_FOLDER, "#{name}.graphql"))
|
|
36
|
-
Aspera.assert(candidate.start_with?("#{QUERIES_FOLDER}/")) { "Invalid GraphQL query name: #{name}" }
|
|
37
|
-
File.read(candidate)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|