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
|
@@ -3,16 +3,15 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
4
|
# SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
|
|
6
|
-
require_relative 'basic_auth'
|
|
7
|
-
require_relative '
|
|
8
|
-
require_relative '
|
|
9
|
-
require_relative '
|
|
10
|
-
require_relative '../../preview/terminal'
|
|
6
|
+
require_relative '../../cli/plugins/basic_auth'
|
|
7
|
+
require_relative 'generator'
|
|
8
|
+
require_relative 'utils'
|
|
9
|
+
require_relative 'file_types'
|
|
11
10
|
require_relative '../../transfer/spec'
|
|
12
11
|
require_relative '../../schema/registry'
|
|
13
12
|
require_relative '../../persistency_action_once'
|
|
14
13
|
require_relative '../../temp_file_manager'
|
|
15
|
-
require_relative '
|
|
14
|
+
require_relative '../node/api'
|
|
16
15
|
require_relative '../../hash_ext'
|
|
17
16
|
require_relative '../../timer_limiter'
|
|
18
17
|
require_relative '../../id_generator'
|
|
@@ -20,13 +19,16 @@ require_relative '../../uri_reader'
|
|
|
20
19
|
require_relative '../../log'
|
|
21
20
|
require_relative '../../assert'
|
|
22
21
|
require_relative '../../rainbow'
|
|
22
|
+
require_relative '../xfer/transfer_agent'
|
|
23
23
|
require 'securerandom'
|
|
24
24
|
using Rainbow
|
|
25
25
|
|
|
26
26
|
module Aspera
|
|
27
|
-
module
|
|
28
|
-
module
|
|
29
|
-
class
|
|
27
|
+
module Plugins
|
|
28
|
+
module Preview
|
|
29
|
+
class Commands < Cli::Plugins::Base
|
|
30
|
+
include Cli::Plugins::BasicAuth
|
|
31
|
+
|
|
30
32
|
# Reserved transfer tag used to identify preview-generation transfers.
|
|
31
33
|
PREV_GEN_TAG = 'preview_generator'
|
|
32
34
|
# Node API suffix for the per-file preview folder.
|
|
@@ -51,35 +53,35 @@ module Aspera
|
|
|
51
53
|
:REMOTE_ACCESS
|
|
52
54
|
|
|
53
55
|
# DSL option declarations
|
|
54
|
-
option :skip_format, description: 'Skip this preview format', allowed:
|
|
56
|
+
option :skip_format, description: 'Skip this preview format', allowed: Generator::PREVIEW_FORMATS
|
|
55
57
|
# TODO: use the same option as in `node` plugin
|
|
56
58
|
option :folder_reset_cache, description: 'Force detection of generated preview by refresh cache', allowed: %i[no header read], default: :no
|
|
57
|
-
option :skip_types, description: 'Skip generation for those types of files', allowed: Type::SYMBOL_ARRAY +
|
|
59
|
+
option :skip_types, description: 'Skip generation for those types of files', allowed: Cli::Option::Type::SYMBOL_ARRAY + FileTypes::CONVERSION_TYPES
|
|
58
60
|
option :previews_folder, description: 'Preview folder in storage root', default: DEFAULT_PREVIEWS_FOLDER
|
|
59
|
-
option :skip_folders, description: 'List of folder to skip', allowed: Type::STRING_ARRAY
|
|
61
|
+
option :skip_folders, description: 'List of folder to skip', allowed: Cli::Option::Type::STRING_ARRAY
|
|
60
62
|
option :base, description: 'Basename of output for for test'
|
|
61
63
|
option :filter, description: 'File name filter: String (glob), Regexp, or Proc', allowed: [String, Regexp, Proc, NilClass]
|
|
62
|
-
option :detect_mime, description: 'Detect Mime type by analyzing file', allowed: Type::BOOLEAN, default: false
|
|
64
|
+
option :detect_mime, description: 'Detect Mime type by analyzing file', allowed: Cli::Option::Type::BOOLEAN, default: false
|
|
63
65
|
option :overwrite, description: 'When to overwrite result file', allowed: %i[always never mtime], default: :mtime
|
|
64
66
|
option :root_url, description: "How to read and write files on storage (#{REMOTE_ACCESS}, or #{UriReader.file_url('<folder>')})", default: REMOTE_ACCESS
|
|
65
67
|
# Generator options, defined in schema: values set in @gen_options
|
|
66
|
-
Schema::Registry.instance.reader(
|
|
68
|
+
Schema::Registry.instance.reader(Generator::OPTIONS_SCHEMA).current['properties'].each do |name, property|
|
|
67
69
|
key = name.to_sym
|
|
68
70
|
option(
|
|
69
71
|
key,
|
|
70
72
|
description: property['description'].lines.first.strip.delete_suffix('.'),
|
|
71
|
-
allowed: property.key?('enum') ? property['enum'].map(&:to_sym) : {'integer' => Type::INTEGER, 'number' => Type::FLOAT, 'boolean' => Type::BOOLEAN}[property['type']],
|
|
73
|
+
allowed: property.key?('enum') ? property['enum'].map(&:to_sym) : {'integer' => Cli::Option::Type::INTEGER, 'number' => Cli::Option::Type::FLOAT, 'boolean' => Cli::Option::Type::BOOLEAN}[property['type']],
|
|
72
74
|
default: property['default'],
|
|
73
75
|
# `Hash` value: validated with schema
|
|
74
|
-
schema: ("#{
|
|
76
|
+
schema: ("#{Generator::OPTIONS_SCHEMA}:properties.#{name}" if property['type'].eql?('object')),
|
|
75
77
|
on_set: ->(value) { @gen_options[key] = value }
|
|
76
78
|
)
|
|
77
79
|
end
|
|
78
80
|
|
|
79
81
|
def initialize(**_)
|
|
80
|
-
# Generator options, see `options.
|
|
82
|
+
# Generator options, see `schemas/options.yaml`
|
|
81
83
|
# Created before `super`, which declares options: values are set through `on_set`.
|
|
82
|
-
@gen_options =
|
|
84
|
+
@gen_options = Generator::Options.new
|
|
83
85
|
super
|
|
84
86
|
# Used to rate-limit periodic progress logging and checkpoint persistence.
|
|
85
87
|
@periodic = TimerLimiter.new(LOG_LIMITER_SEC)
|
|
@@ -95,10 +97,10 @@ module Aspera
|
|
|
95
97
|
@option_skip_folders = options.get_option(:skip_folders).dup
|
|
96
98
|
@option_overwrite = options.get_option(:overwrite)
|
|
97
99
|
# Tell which tool we will use for office docs
|
|
98
|
-
|
|
99
|
-
Api
|
|
100
|
+
Utils.office_tool = @gen_options.office_conversion
|
|
101
|
+
Node::Api.api_options[:cache] = !@option_folder_reset_cache.eql?(:header)
|
|
100
102
|
# Start from the full supported format list, then remove any skipped format.
|
|
101
|
-
@preview_formats_to_generate =
|
|
103
|
+
@preview_formats_to_generate = Generator::PREVIEW_FORMATS.dup
|
|
102
104
|
skip = options.get_option(:skip_format)
|
|
103
105
|
@preview_formats_to_generate.delete(skip) if skip
|
|
104
106
|
# Created by `tools_cleanup`, only for commands that use it
|
|
@@ -128,11 +130,11 @@ module Aspera
|
|
|
128
130
|
end
|
|
129
131
|
return if events.empty?
|
|
130
132
|
events.each do |event|
|
|
131
|
-
if event['data']['direction'].eql?(Transfer::Spec::DIRECTION_RECEIVE) &&
|
|
133
|
+
if event['data']['direction'].eql?(Aspera::Transfer::Spec::DIRECTION_RECEIVE) &&
|
|
132
134
|
event['data']['status'].eql?('completed') &&
|
|
133
135
|
event['data']['error_code'].eql?(0) &&
|
|
134
|
-
event['data'].dig('tags', Transfer::Spec::TAG_RESERVED, PREV_GEN_TAG).nil?
|
|
135
|
-
folder_id = event.dig('data', 'tags', Transfer::Spec::TAG_RESERVED, 'node', 'file_id')
|
|
136
|
+
event['data'].dig('tags', Aspera::Transfer::Spec::TAG_RESERVED, PREV_GEN_TAG).nil?
|
|
137
|
+
folder_id = event.dig('data', 'tags', Aspera::Transfer::Spec::TAG_RESERVED, 'node', 'file_id')
|
|
136
138
|
folder_id ||= event.dig('data', 'file_id')
|
|
137
139
|
if !folder_id.nil?
|
|
138
140
|
folder_entry = @api_node.read("files/#{folder_id}") rescue nil
|
|
@@ -218,23 +220,23 @@ module Aspera
|
|
|
218
220
|
|
|
219
221
|
# Transfer a file to or from the configured Node storage using a tagged transfer spec.
|
|
220
222
|
#
|
|
221
|
-
# @param direction [String] transfer direction, typically from [`Transfer::Spec`](lib/aspera/transfer/spec.rb)
|
|
223
|
+
# @param direction [String] transfer direction, typically from [`Aspera::Transfer::Spec`](lib/aspera/transfer/spec.rb)
|
|
222
224
|
# @param folder_id [String] Node API identifier of the reference folder
|
|
223
225
|
# @param source_filename [String] relative source path inside the transfer root
|
|
224
226
|
# @param destination [String, nil] local destination root for receive operations
|
|
225
|
-
# @return [Object] transfer result returned by
|
|
227
|
+
# @return [Object] transfer result returned by `Xfer::TransferAgent.result_transfer`
|
|
226
228
|
def do_transfer(direction, folder_id, source_filename, destination = '/')
|
|
227
|
-
Aspera.assert(!(destination.nil? && direction.eql?(Transfer::Spec::DIRECTION_RECEIVE)), 'destination must be set for receive direction')
|
|
229
|
+
Aspera.assert(!(destination.nil? && direction.eql?(Aspera::Transfer::Spec::DIRECTION_RECEIVE)), 'destination must be set for receive direction')
|
|
228
230
|
# Previews are generated from downloaded files, and uploaded
|
|
229
231
|
transfer.assert_no_dry_run
|
|
230
232
|
t_spec = @api_node.transfer_spec_gen4(folder_id, direction, {
|
|
231
233
|
'paths' => [{'source' => source_filename}],
|
|
232
|
-
'tags' => {Transfer::Spec::TAG_RESERVED => {PREV_GEN_TAG => true}}
|
|
234
|
+
'tags' => {Aspera::Transfer::Spec::TAG_RESERVED => {PREV_GEN_TAG => true}}
|
|
233
235
|
})
|
|
234
236
|
# Force the destination on the transfer agent object.
|
|
235
237
|
# Setting `t_spec['destination_root']` directly would later be overwritten.
|
|
236
238
|
transfer.user_transfer_spec['destination_root'] = destination
|
|
237
|
-
|
|
239
|
+
Xfer::TransferAgent.result_transfer(transfer.start(t_spec))
|
|
238
240
|
end
|
|
239
241
|
|
|
240
242
|
# Populate generation metadata for a source file available on the local filesystem.
|
|
@@ -272,7 +274,7 @@ module Aspera
|
|
|
272
274
|
# original_mtime=DateTime.parse(entry['modified_time'])
|
|
273
275
|
# Local directory where previews are generated before being uploaded back.
|
|
274
276
|
local_entry_preview_dir = File.join(@tmp_folder, entry_preview_folder_name(entry))
|
|
275
|
-
file_info = @api_node.read("files/#{entry['id']}", headers: Api
|
|
277
|
+
file_info = @api_node.read("files/#{entry['id']}", headers: Node::Api.add_cache_control)
|
|
276
278
|
# Check if preview exists either from file_info or by checking preview endpoint
|
|
277
279
|
preview_exist = file_info.key?('preview')
|
|
278
280
|
unless preview_exist
|
|
@@ -346,7 +348,7 @@ module Aspera
|
|
|
346
348
|
end
|
|
347
349
|
begin
|
|
348
350
|
# need generator for further checks
|
|
349
|
-
gen_info[:generator] =
|
|
351
|
+
gen_info[:generator] = Generator.new(gen_info[:src], gen_info[:dst], @gen_options, @tmp_folder, mime: entry['content_type'])
|
|
350
352
|
rescue
|
|
351
353
|
# no conversion supported
|
|
352
354
|
next false
|
|
@@ -362,7 +364,7 @@ module Aspera
|
|
|
362
364
|
if @access_remote
|
|
363
365
|
Aspera.assert(!entry['parent_file_id'].nil?, 'missing parent_file_id in entry')
|
|
364
366
|
# download original file to temp folder
|
|
365
|
-
do_transfer(Transfer::Spec::DIRECTION_RECEIVE, entry['parent_file_id'], entry['name'], @tmp_folder)
|
|
367
|
+
do_transfer(Aspera::Transfer::Spec::DIRECTION_RECEIVE, entry['parent_file_id'], entry['name'], @tmp_folder)
|
|
366
368
|
end
|
|
367
369
|
Log.log.debug { "source: #{entry['id']}: #{entry['path']}" }
|
|
368
370
|
gen_infos.each do |gen_info|
|
|
@@ -375,7 +377,7 @@ module Aspera
|
|
|
375
377
|
end
|
|
376
378
|
if @access_remote
|
|
377
379
|
# upload
|
|
378
|
-
do_transfer(Transfer::Spec::DIRECTION_SEND, @previews_folder_entry['id'], local_entry_preview_dir)
|
|
380
|
+
do_transfer(Aspera::Transfer::Spec::DIRECTION_SEND, @previews_folder_entry['id'], local_entry_preview_dir)
|
|
379
381
|
# cleanup after upload
|
|
380
382
|
FileUtils.rm_rf(local_entry_preview_dir)
|
|
381
383
|
File.delete(File.join(@tmp_folder, entry['name']))
|
|
@@ -441,13 +443,13 @@ module Aspera
|
|
|
441
443
|
arguments: [{name: :path, description: 'File or folder from which to start scanning', mandatory: false, default: '/'}]
|
|
442
444
|
command :events, description: 'Process file events and generate previews', setup: :setup_node_api, action: ->(**) { run_event_loop(:events) }
|
|
443
445
|
command :trevents, description: 'Process transfer events and generate previews', setup: :setup_node_api, action: ->(**) { run_event_loop(:trevents) }
|
|
444
|
-
command :check, description: 'Check required tools are installed', action: ->(**) { tools_cleanup { Result::Status.new('Tools validated') } }
|
|
446
|
+
command :check, description: 'Check required tools are installed', action: ->(**) { tools_cleanup { Cli::Result::Status.new('Tools validated') } }
|
|
445
447
|
command :show, read_only: false, description: 'Generate and display preview of a source file',
|
|
446
|
-
arguments: [{name: :source_file, description: 'Local file to preview', complete: :file}]
|
|
448
|
+
arguments: [{name: :source_file, description: 'Local file to preview', complete: :file, access: :read}]
|
|
447
449
|
command :test, description: 'Test preview generation for a source file',
|
|
448
450
|
arguments: [
|
|
449
|
-
{name: :source_file, description: 'Local file to preview', complete: :file},
|
|
450
|
-
{name: :format, description: 'Preview output format', allowed:
|
|
451
|
+
{name: :source_file, description: 'Local file to preview', complete: :file, access: :read},
|
|
452
|
+
{name: :format, description: 'Preview output format', allowed: Generator::PREVIEW_FORMATS, mandatory: false, default: :png}
|
|
451
453
|
]
|
|
452
454
|
|
|
453
455
|
# --- setup ---
|
|
@@ -455,7 +457,7 @@ module Aspera
|
|
|
455
457
|
# Build the Node API and set up storage references for scan/events/trevents.
|
|
456
458
|
# @return [Hash] empty ctx (state stored in instance variables)
|
|
457
459
|
def setup_node_api(**)
|
|
458
|
-
@api_node = Api
|
|
460
|
+
@api_node = Node::Api.new(**basic_auth_params)
|
|
459
461
|
@transfer_server_address = URI.parse(@api_node.base_url).host
|
|
460
462
|
# Get current access key information
|
|
461
463
|
@access_key_self = @api_node.read('access_keys/self')
|
|
@@ -478,7 +480,7 @@ module Aspera
|
|
|
478
480
|
else
|
|
479
481
|
@local_storage_root = UriReader.file_path(option_root_url)
|
|
480
482
|
# TODO: Windows could have "C:" ?
|
|
481
|
-
Aspera.assert(@local_storage_root.start_with?('/')) { "not local storage: #{@local_storage_root}" }
|
|
483
|
+
Aspera.assert(@local_storage_root.start_with?('/'), type: Cli::BadArgument) { "not local storage: #{@local_storage_root}" }
|
|
482
484
|
Aspera.assert(File.directory?(@local_storage_root), type: Cli::Error) { "Local storage root folder #{@local_storage_root} does not exist." }
|
|
483
485
|
@local_preview_folder = File.join(@local_storage_root, @option_previews_folder)
|
|
484
486
|
Aspera.assert(File.directory?(@local_preview_folder), type: Cli::Error) { "Folder #{@local_preview_folder} does not exist locally. Please create it, or specify an alternate name." }
|
|
@@ -500,15 +502,15 @@ module Aspera
|
|
|
500
502
|
def action_scan(path:, **)
|
|
501
503
|
tools_cleanup do
|
|
502
504
|
apifid =
|
|
503
|
-
if (selector = Parser.percent_selector(path))
|
|
504
|
-
Aspera.assert_values(selector[:field], ['id'], type: BadArgument) { 'file id' }
|
|
505
|
-
|
|
505
|
+
if (selector = Cli::Parser.percent_selector(path))
|
|
506
|
+
Aspera.assert_values(selector[:field], ['id'], type: Cli::BadArgument) { 'file id' }
|
|
507
|
+
Node::NodeFileId.new(@api_node, selector[:value].to_s.empty? ? @access_key_self['root_file_id'] : selector[:value])
|
|
506
508
|
else
|
|
507
509
|
@api_node.resolve_api_fid(@access_key_self['root_file_id'], path)
|
|
508
510
|
end
|
|
509
|
-
@filter_block = Base.file_matcher(options.get_option(:filter))
|
|
511
|
+
@filter_block = Cli::Plugins::Base.file_matcher(options.get_option(:filter))
|
|
510
512
|
scan_folder_files(@api_node.read("files/#{apifid.file_id}"))
|
|
511
|
-
Result::Status.new('scan finished')
|
|
513
|
+
Cli::Result::Status.new('scan finished')
|
|
512
514
|
end
|
|
513
515
|
end
|
|
514
516
|
|
|
@@ -518,8 +520,8 @@ module Aspera
|
|
|
518
520
|
def action_test(source_file:, format:, **)
|
|
519
521
|
tools_cleanup do
|
|
520
522
|
generated_file_path = preview_filename(format, options.get_option(:base))
|
|
521
|
-
|
|
522
|
-
Result::Status.new("#{MSG_GEN_TITLE}#{generated_file_path}")
|
|
523
|
+
Generator.new(source_file, generated_file_path, @gen_options, @tmp_folder).generate
|
|
524
|
+
Cli::Result::Status.new("#{MSG_GEN_TITLE}#{generated_file_path}")
|
|
523
525
|
end
|
|
524
526
|
end
|
|
525
527
|
|
|
@@ -527,7 +529,7 @@ module Aspera
|
|
|
527
529
|
status = action_test(source_file: source_file, format: :png)
|
|
528
530
|
formatter.display_status(status.data)
|
|
529
531
|
generated_file_path = status.data.delete_prefix(MSG_GEN_TITLE)
|
|
530
|
-
Result::Image.new(UriReader.file_url(generated_file_path))
|
|
532
|
+
Cli::Result::Image.new(UriReader.file_url(generated_file_path))
|
|
531
533
|
end
|
|
532
534
|
|
|
533
535
|
private
|
|
@@ -535,8 +537,8 @@ module Aspera
|
|
|
535
537
|
# Check tools and set option flag.
|
|
536
538
|
# Create the temporary folder for the command, and clean it up after.
|
|
537
539
|
def tools_cleanup
|
|
538
|
-
|
|
539
|
-
|
|
540
|
+
FileTypes.instance.detect_mime = options.get_option(:detect_mime, mandatory: true)
|
|
541
|
+
Utils.check_tools(@option_skip_types)
|
|
540
542
|
FileUtils.mkdir_p(@tmp_folder)
|
|
541
543
|
Log.log.debug { "tmpdir: #{@tmp_folder}" }
|
|
542
544
|
yield
|
|
@@ -551,7 +553,7 @@ module Aspera
|
|
|
551
553
|
def run_event_loop(command)
|
|
552
554
|
tools_cleanup do
|
|
553
555
|
filter = options.get_option(:filter)
|
|
554
|
-
@filter_block = Base.file_matcher(filter)
|
|
556
|
+
@filter_block = Cli::Plugins::Base.file_matcher(filter)
|
|
555
557
|
iteration_persistency = nil
|
|
556
558
|
if options.get_option(:once_only, mandatory: true)
|
|
557
559
|
iteration_persistency = PersistencyActionOnce.new(
|
|
@@ -566,7 +568,7 @@ module Aspera
|
|
|
566
568
|
)
|
|
567
569
|
end
|
|
568
570
|
send(:"process_#{command}", iteration_persistency)
|
|
569
|
-
Result::Status.new("#{command} finished")
|
|
571
|
+
Cli::Result::Status.new("#{command} finished")
|
|
570
572
|
end
|
|
571
573
|
end
|
|
572
574
|
end
|
|
@@ -0,0 +1,121 @@
|
|
|
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 'singleton'
|
|
9
|
+
require 'marcel'
|
|
10
|
+
|
|
11
|
+
module Aspera
|
|
12
|
+
module Plugins
|
|
13
|
+
module Preview
|
|
14
|
+
# function conversion_type returns one of the types: CONVERSION_TYPES
|
|
15
|
+
#
|
|
16
|
+
# @!method self.instance
|
|
17
|
+
# Returns the singleton instance of FileTypes
|
|
18
|
+
# @return [FileTypes] the singleton instance
|
|
19
|
+
class FileTypes
|
|
20
|
+
include Singleton
|
|
21
|
+
|
|
22
|
+
# values for conversion_type : input format
|
|
23
|
+
CONVERSION_TYPES = %i[image office pdf plaintext video].freeze
|
|
24
|
+
|
|
25
|
+
# Special cases for MIME types
|
|
26
|
+
# spellchecker:disable
|
|
27
|
+
SUPPORTED_MIME_TYPES = {
|
|
28
|
+
'application/json' => :plaintext,
|
|
29
|
+
'text/plain' => :plaintext,
|
|
30
|
+
'application/pdf' => :pdf,
|
|
31
|
+
'audio/ogg' => :video,
|
|
32
|
+
'application/mxf' => :video,
|
|
33
|
+
'application/mac-binhex40' => :office,
|
|
34
|
+
'application/msword' => :office,
|
|
35
|
+
'application/vnd.ms-excel' => :office,
|
|
36
|
+
'application/vnd.ms-powerpoint' => :office,
|
|
37
|
+
'application/rtf' => :office,
|
|
38
|
+
'application/x-abiword' => :office,
|
|
39
|
+
'application/x-mspublisher' => :office,
|
|
40
|
+
'image/vnd.dxf' => :office,
|
|
41
|
+
'image/x-cmx' => :office,
|
|
42
|
+
'image/x-freehand' => :office,
|
|
43
|
+
'image/x-pict' => :office,
|
|
44
|
+
'text/csv' => :office,
|
|
45
|
+
'text/html' => :office,
|
|
46
|
+
'application/dicom' => :image,
|
|
47
|
+
'application/postscript' => :image,
|
|
48
|
+
'application/vnd.3gpp.pic-bw-small' => :image,
|
|
49
|
+
'application/vnd.hp-hpgl' => :image,
|
|
50
|
+
'application/vnd.hp-pcl' => :image,
|
|
51
|
+
'application/vnd.mobius.msl' => :image,
|
|
52
|
+
'application/vnd.mophun.certificate' => :image,
|
|
53
|
+
'application/x-director' => :image,
|
|
54
|
+
'application/x-font-type1' => :image,
|
|
55
|
+
'application/x-msmetafile' => :image,
|
|
56
|
+
'application/x-xfig' => :image,
|
|
57
|
+
'font/ttf' => :image,
|
|
58
|
+
'text/troff' => :image,
|
|
59
|
+
'video/x-mng' => :image
|
|
60
|
+
}.freeze
|
|
61
|
+
|
|
62
|
+
private_constant :SUPPORTED_MIME_TYPES
|
|
63
|
+
|
|
64
|
+
# @attr detect_mime [Boolean] `true` to determine real mime type based on file content
|
|
65
|
+
attr_accessor :detect_mime
|
|
66
|
+
|
|
67
|
+
def initialize
|
|
68
|
+
@detect_mime = false
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# @param mimetype [String] mime type
|
|
72
|
+
# @return [NilClass,Symbol] file type, one of enum CONVERSION_TYPES, or nil if not found
|
|
73
|
+
def mime_to_type(mimetype)
|
|
74
|
+
Aspera.assert_type(mimetype, String)
|
|
75
|
+
return SUPPORTED_MIME_TYPES[mimetype] if SUPPORTED_MIME_TYPES.key?(mimetype)
|
|
76
|
+
return :office if mimetype.start_with?('application/vnd.ms-')
|
|
77
|
+
return :office if mimetype.start_with?('application/vnd.openxmlformats-officedocument')
|
|
78
|
+
return :video if mimetype.start_with?('video/')
|
|
79
|
+
return :image if mimetype.start_with?('image/')
|
|
80
|
+
return
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# @param filepath [String] Full path to file
|
|
84
|
+
# @param mimetype [String] MIME typre provided by node API
|
|
85
|
+
# @return [Symbol] file type, one of enum CONVERSION_TYPES
|
|
86
|
+
# @raise [RuntimeError] if no conversion type found
|
|
87
|
+
def conversion_type(filepath, mimetype)
|
|
88
|
+
Log.log.debug { "conversion_type(#{filepath},mime=#{mimetype},magic=#{@detect_mime})" }
|
|
89
|
+
# Default type or empty means no type
|
|
90
|
+
mimetype = TYPE_NOT_FOUND if mimetype.nil? || (mimetype.is_a?(String) && mimetype.empty?)
|
|
91
|
+
mimetype = Marcel::MimeType.for(Pathname.new(filepath), name: File.basename(filepath), declared_type: mimetype)
|
|
92
|
+
mimetype = 'text/plain' if mimetype.eql?(TYPE_NOT_FOUND) && ascii_text_file?(filepath)
|
|
93
|
+
Aspera.assert(!mimetype.eql?(TYPE_NOT_FOUND)) { "no MIME type found for #{File.basename(filepath)}" }
|
|
94
|
+
conversion_type = mime_to_type(mimetype)
|
|
95
|
+
Aspera.assert(!conversion_type.nil?) { "no conversion type found for #{File.basename(filepath)}" }
|
|
96
|
+
Log.log.trace1 { "conversion_type(#{File.basename(filepath)}): #{conversion_type.class.name} [#{conversion_type}]" }
|
|
97
|
+
return conversion_type
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
private
|
|
101
|
+
|
|
102
|
+
TYPE_NOT_FOUND = 'application/octet-stream'
|
|
103
|
+
ACCEPT_CTRL_CHARS = [9, 10, 13].freeze
|
|
104
|
+
|
|
105
|
+
# Returns true if the file looks like ASCII text (printable ASCII + \t, \r, \n, space).
|
|
106
|
+
# It reads only a small prefix (default: 64KB) and fails fast on the first bad byte.
|
|
107
|
+
def ascii_text_file?(path, sample_size: 64 * 1024)
|
|
108
|
+
File.open(path, 'rb') do |f|
|
|
109
|
+
sample = f.read(sample_size) || ''.b
|
|
110
|
+
sample.each_byte do |b|
|
|
111
|
+
next if b.between?(32, 126) || ACCEPT_CTRL_CHARS.include?(b)
|
|
112
|
+
# Any other control character => not ASCII text
|
|
113
|
+
return false
|
|
114
|
+
end
|
|
115
|
+
true
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|