aspera-cli 4.29.1 → 4.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +4 -4
- data/CHANGELOG.md +119 -0
- data/CONTRIBUTING.md +8 -1
- data/README.md +2 -0
- data/TODO.md +4 -5
- data/bin/asession +2 -2
- data/docs/README.md +616 -86
- data/docs/test-mcp-with-ai.md +4 -0
- data/lib/aspera/agent/base.rb +62 -6
- data/lib/aspera/agent/factory.rb +127 -20
- data/lib/aspera/ascp/data_repository.rb +71 -0
- data/lib/aspera/ascp/installation.rb +16 -11
- data/lib/aspera/ascp/log_analyzer/lines.rb +4 -4
- data/lib/aspera/ascp/log_analyzer/log_file.rb +5 -3
- data/lib/aspera/ascp/log_analyzer/records.rb +11 -6
- data/lib/aspera/ascp/log_analyzer.rb +43 -18
- data/lib/aspera/ascp/log_locations.rb +2 -2
- data/lib/aspera/assert.rb +8 -0
- data/lib/aspera/bundle_registry.rb +528 -0
- data/lib/aspera/cli/argument.rb +110 -0
- data/lib/aspera/cli/bool_value.rb +41 -0
- data/lib/aspera/cli/bootstrapper.rb +31 -24
- data/lib/aspera/cli/command/mount.rb +53 -0
- data/lib/aspera/cli/command/registry.rb +434 -0
- data/lib/aspera/cli/command.rb +95 -0
- data/lib/aspera/cli/command_line.rb +91 -91
- data/lib/aspera/cli/complete.rb +22 -0
- data/lib/aspera/cli/completion_actions.rb +28 -26
- data/lib/aspera/cli/context.rb +29 -6
- data/lib/aspera/cli/error.rb +39 -0
- data/lib/aspera/cli/extended_value.rb +25 -4
- data/lib/aspera/cli/formatter.rb +8 -8
- data/lib/aspera/cli/hints.rb +17 -52
- data/lib/aspera/cli/http.rb +17 -12
- data/lib/aspera/cli/mailer.rb +7 -24
- data/lib/aspera/cli/mcp/tool.rb +10 -2
- data/lib/aspera/cli/option/declarator.rb +80 -0
- data/lib/aspera/cli/option/registry.rb +74 -0
- data/lib/aspera/cli/option/source.rb +38 -0
- data/lib/aspera/cli/option/type.rb +37 -0
- data/lib/aspera/cli/option/value.rb +376 -0
- data/lib/aspera/cli/option.rb +78 -0
- data/lib/aspera/cli/options.schema.yaml +28 -783
- data/lib/aspera/cli/parser.rb +73 -41
- data/lib/aspera/cli/plugins/base.rb +122 -42
- data/lib/aspera/cli/plugins/basic_auth.rb +13 -2
- data/lib/aspera/cli/plugins/config.rb +101 -167
- data/lib/aspera/cli/plugins/factory.rb +139 -43
- data/lib/aspera/cli/plugins/mcp.rb +61 -54
- data/lib/aspera/cli/plugins/oauth.rb +19 -6
- data/lib/aspera/cli/poll.rb +14 -20
- data/lib/aspera/cli/preset_actions.rb +11 -3
- data/lib/aspera/cli/preset_manager.rb +16 -6
- data/lib/aspera/cli/result.rb +2 -2
- data/lib/aspera/cli/runner.rb +71 -99
- data/lib/aspera/cli/secret_finder.rb +1 -1
- data/lib/aspera/cli/security.rb +102 -4
- data/lib/aspera/{preview/terminal.rb → cli/terminal_image.rb} +93 -94
- data/lib/aspera/cli/vault_manager.rb +3 -3
- data/lib/aspera/cli/version.rb +1 -1
- data/lib/aspera/cli/wizard.rb +9 -3
- data/lib/aspera/coverage.rb +1 -2
- data/lib/aspera/line_logger.rb +35 -6
- data/lib/aspera/log.rb +3 -2
- data/lib/aspera/oauth/client/base.rb +19 -1
- data/lib/aspera/oauth/client/factory.rb +1 -7
- data/lib/aspera/plugin.schema.yaml +178 -0
- data/lib/aspera/plugins/alee/api.rb +25 -0
- data/lib/aspera/{cli/plugins/alee.rb → plugins/alee/commands.rb} +10 -8
- data/lib/aspera/plugins/alee/plugin.yaml +3 -0
- data/lib/aspera/plugins/aoc/admin_resources.rb +148 -0
- data/lib/aspera/plugins/aoc/api.rb +783 -0
- data/lib/aspera/{cli/plugins/aoc.rb → plugins/aoc/commands.rb} +404 -330
- data/lib/aspera/plugins/aoc/graphql.rb +45 -0
- data/lib/aspera/plugins/aoc/plugin.yaml +31 -0
- data/lib/aspera/{schema → plugins/aoc/schemas}/IBM Aspera on Cloud API-0.2.6-enhanced.yaml +15042 -7076
- data/lib/aspera/plugins/aoc/schemas/options.yaml +47 -0
- data/lib/aspera/plugins/ats/api.rb +51 -0
- data/lib/aspera/{cli/plugins/ats.rb → plugins/ats/commands.rb} +33 -33
- data/lib/aspera/plugins/ats/plugin.yaml +6 -0
- data/lib/aspera/plugins/connect/agent.rb +199 -0
- data/lib/aspera/plugins/connect/plugin.yaml +11 -0
- data/lib/aspera/plugins/connect/schemas/agent_options.yaml +6 -0
- data/lib/aspera/{cli/plugins/console.rb → plugins/console/commands.rb} +41 -33
- data/lib/aspera/plugins/console/plugin.yaml +8 -0
- data/lib/aspera/plugins/cos/api.rb +114 -0
- data/lib/aspera/{cli/plugins/cos.rb → plugins/cos/commands.rb} +19 -16
- data/lib/aspera/plugins/cos/plugin.yaml +9 -0
- data/lib/aspera/plugins/cos/schemas/options.yaml +30 -0
- data/lib/aspera/plugins/desktop/agent.rb +165 -0
- data/lib/aspera/plugins/desktop/plugin.yaml +11 -0
- data/lib/aspera/plugins/desktop/schemas/agent_options.yaml +6 -0
- data/lib/aspera/plugins/direct/agent.rb +518 -0
- data/lib/aspera/plugins/direct/plugin.yaml +11 -0
- data/lib/aspera/plugins/direct/schemas/agent_options.yaml +86 -0
- data/lib/aspera/plugins/faspex4/gateway_options.rb +18 -0
- data/lib/aspera/plugins/faspex4/gw_servlet.rb +122 -0
- data/lib/aspera/plugins/faspex4/plugin.yaml +7 -0
- data/lib/aspera/plugins/faspex4/schemas/options.yaml +57 -0
- data/lib/aspera/plugins/faspex5/api.rb +269 -0
- data/lib/aspera/{cli/plugins/faspex5.rb → plugins/faspex5/commands.rb} +152 -114
- data/lib/aspera/plugins/faspex5/faspex4_post_proc_servlet.rb +241 -0
- data/lib/aspera/plugins/faspex5/plugin.yaml +14 -0
- data/lib/aspera/{schema → plugins/faspex5/schemas}/IBM Aspera Faspex API-5.0-enhanced.yaml +279 -76
- data/lib/aspera/plugins/faspex5/schemas/options.yaml +87 -0
- data/lib/aspera/{cli/plugins/faspio.rb → plugins/faspio/commands.rb} +11 -7
- data/lib/aspera/plugins/faspio/plugin.yaml +8 -0
- data/lib/aspera/{schema → plugins/faspio/schemas}/IBM Aspera faspio Gateway API-1.0.0-enhanced.yaml +4 -2
- data/lib/aspera/plugins/httpgw/agent.rb +126 -0
- data/lib/aspera/plugins/httpgw/api.rb +411 -0
- data/lib/aspera/{cli/plugins/httpgw.rb → plugins/httpgw/commands.rb} +9 -9
- data/lib/aspera/plugins/httpgw/plugin.yaml +12 -0
- data/lib/aspera/plugins/httpgw/schemas/agent_options.yaml +24 -0
- data/lib/aspera/plugins/node/agent.rb +184 -0
- data/lib/aspera/plugins/node/api.rb +699 -0
- data/lib/aspera/{cli/plugins/node.rb → plugins/node/commands.rb} +166 -141
- data/lib/aspera/plugins/node/emulator.rb +774 -0
- data/lib/aspera/plugins/node/plugin.yaml +20 -0
- data/lib/aspera/plugins/node/schemas/agent_options.yaml +20 -0
- data/lib/aspera/plugins/node/schemas/options.yaml +190 -0
- data/lib/aspera/{cli/plugins/orchestrator.rb → plugins/orchestrator/commands.rb} +139 -110
- data/lib/aspera/plugins/orchestrator/plugin.yaml +34 -0
- data/lib/aspera/{schema → plugins/orchestrator/schemas}/IBM Aspera Orchestrator API-v1-enhanced.yaml +486 -16
- data/lib/aspera/plugins/orchestrator/schemas/options.yaml +143 -0
- data/lib/aspera/plugins/orchestrator/workflow_checker.rb +692 -0
- data/lib/aspera/{cli/plugins/preview.rb → plugins/preview/commands.rb} +53 -51
- data/lib/aspera/plugins/preview/file_types.rb +121 -0
- data/lib/aspera/plugins/preview/generator.rb +350 -0
- data/lib/aspera/plugins/preview/plugin.yaml +12 -0
- data/lib/aspera/{preview/options.schema.yaml → plugins/preview/schemas/options.yaml} +1 -1
- data/lib/aspera/plugins/preview/utils.rb +213 -0
- data/lib/aspera/plugins/server/ascmd.rb +374 -0
- data/lib/aspera/{cli/plugins/server.rb → plugins/server/commands.rb} +48 -32
- data/lib/aspera/plugins/server/plugin.yaml +9 -0
- data/lib/aspera/plugins/server/schemas/options.yaml +30 -0
- data/lib/aspera/{cli/plugins/shares.rb → plugins/shares/commands.rb} +29 -21
- data/lib/aspera/plugins/shares/plugin.yaml +10 -0
- data/lib/aspera/plugins/shares/shares_web.rb +97 -0
- data/lib/aspera/plugins/transferd/agent.rb +258 -0
- data/lib/aspera/plugins/transferd/api.rb +180 -0
- data/lib/aspera/plugins/transferd/client.rb +67 -0
- data/lib/aspera/{cli/plugins/transferd.rb → plugins/transferd/commands.rb} +43 -42
- data/lib/aspera/plugins/transferd/config_commands.rb +38 -0
- data/lib/aspera/plugins/transferd/plugin.yaml +27 -0
- data/lib/aspera/plugins/transferd/product.rb +146 -0
- data/lib/aspera/plugins/transferd/schemas/agent_options.yaml +31 -0
- data/lib/aspera/plugins/transferd/schemas/options.yaml +80 -0
- data/lib/aspera/plugins/transferd/service.rb +617 -0
- data/lib/aspera/plugins/xfer/ascp_actions.rb +131 -0
- data/lib/aspera/plugins/xfer/ascp_logs_actions.rb +198 -0
- data/lib/aspera/plugins/xfer/async_transfer_store.rb +131 -0
- data/lib/aspera/plugins/xfer/config_commands.rb +119 -0
- data/lib/aspera/plugins/xfer/helper.rb +19 -0
- data/lib/aspera/plugins/xfer/plugin.yaml +42 -0
- data/lib/aspera/plugins/xfer/schemas/agent_extension.schema.yaml +26 -0
- data/lib/aspera/plugins/xfer/schemas/options.yaml +125 -0
- data/lib/aspera/plugins/xfer/sync_actions.rb +253 -0
- data/lib/aspera/plugins/xfer/transfer_actions.rb +176 -0
- data/lib/aspera/plugins/xfer/transfer_agent.rb +505 -0
- data/lib/aspera/products/cli_v3.rb +34 -0
- data/lib/aspera/products/connect.rb +1 -1
- data/lib/aspera/products/drive.rb +29 -0
- data/lib/aspera/products/hsts.rb +34 -0
- data/lib/aspera/products/transferd.rb +25 -3
- data/lib/aspera/products.rb +54 -0
- data/lib/aspera/prompt.rb +184 -0
- data/lib/aspera/proxy_auto_config.rb +3 -3
- data/lib/aspera/rest/aspera_errors.rb +4 -38
- data/lib/aspera/rest/error_analyzer.rb +6 -2
- data/lib/aspera/rest/list.rb +4 -5
- data/lib/aspera/schema/reader.rb +15 -0
- data/lib/aspera/schema/registry.rb +239 -45
- data/lib/aspera/schema/validator.rb +63 -17
- data/lib/aspera/sealed_hash.rb +4 -0
- data/lib/aspera/secret/hider.rb +159 -24
- data/lib/aspera/secret/reference.rb +8 -0
- data/lib/aspera/secret/resolver.rb +8 -4
- data/lib/aspera/secret/store/base.rb +10 -9
- data/lib/aspera/secret/store/encrypted_hash.rb +6 -6
- data/lib/aspera/secret/store/hashicorp_vault.rb +3 -3
- data/lib/aspera/secret/store/keeper.rb +2 -2
- data/lib/aspera/secret/store/macos_security.rb +2 -3
- data/lib/aspera/secret/store/one_password_api.rb +2 -2
- data/lib/aspera/secret/store/one_password_cli.rb +3 -3
- data/lib/aspera/secret/store/secret_service.rb +2 -2
- data/lib/aspera/ssl.rb +3 -3
- data/lib/aspera/standard_input.rb +20 -0
- data/lib/aspera/{schema → sync}/async_tables.yaml +1 -1
- data/lib/aspera/sync/database.rb +7 -0
- data/lib/aspera/sync/log_parser.rb +138 -0
- data/lib/aspera/sync/operations.rb +59 -34
- data/lib/aspera/transfer/command_line_builder.rb +248 -0
- data/lib/aspera/transfer/command_line_converter.rb +37 -0
- data/lib/aspera/transfer/faux_file.rb +2 -2
- data/lib/aspera/transfer/parameters.rb +9 -10
- data/lib/aspera/transfer/spec.rb +28 -1
- data/lib/aspera/transfer/spec.schema.yaml +30 -5
- data/lib/aspera/units/decimal.rb +1 -1
- data/lib/aspera/units/timestamp.rb +84 -0
- data/lib/aspera/uri_reader.rb +2 -2
- data/lib/aspera/web_auth/paste.rb +2 -2
- data/lib/aspera/web_server_simple.rb +10 -4
- data.tar.gz.sig +0 -0
- metadata +137 -80
- metadata.gz.sig +0 -0
- data/lib/aspera/agent/connect.rb +0 -188
- data/lib/aspera/agent/desktop.rb +0 -154
- data/lib/aspera/agent/direct.rb +0 -496
- data/lib/aspera/agent/httpgw.rb +0 -100
- data/lib/aspera/agent/node.rb +0 -166
- data/lib/aspera/agent/transferd.rb +0 -341
- data/lib/aspera/api/alee.rb +0 -19
- data/lib/aspera/api/aoc.rb +0 -776
- data/lib/aspera/api/ats.rb +0 -49
- data/lib/aspera/api/cos_node.rb +0 -107
- data/lib/aspera/api/faspex.rb +0 -258
- data/lib/aspera/api/httpgw.rb +0 -409
- data/lib/aspera/api/node.rb +0 -684
- data/lib/aspera/ascmd.rb +0 -248
- data/lib/aspera/cli/ascp_actions.rb +0 -113
- data/lib/aspera/cli/ascp_logs_actions.rb +0 -188
- data/lib/aspera/cli/async_transfer_store.rb +0 -129
- data/lib/aspera/cli/command_registry.rb +0 -371
- data/lib/aspera/cli/command_spec.rb +0 -273
- data/lib/aspera/cli/option_declarator.rb +0 -74
- data/lib/aspera/cli/option_registry.rb +0 -72
- data/lib/aspera/cli/option_types.rb +0 -120
- data/lib/aspera/cli/option_value.rb +0 -345
- data/lib/aspera/cli/prompt.rb +0 -186
- data/lib/aspera/cli/sync_actions.rb +0 -181
- data/lib/aspera/cli/transfer_actions.rb +0 -98
- data/lib/aspera/cli/transfer_agent.rb +0 -348
- data/lib/aspera/command_line_builder.rb +0 -244
- data/lib/aspera/command_line_converter.rb +0 -35
- data/lib/aspera/data_repository.rb +0 -69
- data/lib/aspera/faspex_gw.rb +0 -172
- data/lib/aspera/faspex_postproc.rb +0 -237
- data/lib/aspera/graphql.rb +0 -41
- data/lib/aspera/node_emulator.rb +0 -758
- data/lib/aspera/oauth/client/shares_web.rb +0 -94
- data/lib/aspera/orchestrator_workflow_checker.rb +0 -688
- data/lib/aspera/preview/file_types.rb +0 -119
- data/lib/aspera/preview/generator.rb +0 -345
- data/lib/aspera/preview/utils.rb +0 -211
- data/lib/aspera/products/other.rb +0 -92
- data/lib/aspera/products/transferd_service.rb +0 -610
- /data/lib/aspera/{data → ascp/data}/1 +0 -0
- /data/lib/aspera/{data → ascp/data}/2 +0 -0
- /data/lib/aspera/{data → ascp/data}/3 +0 -0
- /data/lib/aspera/{data → ascp/data}/4 +0 -0
- /data/lib/aspera/{data → ascp/data}/5 +0 -0
- /data/lib/aspera/{data → ascp/data}/6 +0 -0
- /data/lib/aspera/{api → plugins/aoc}/queries/bss_subscription_account.graphql +0 -0
- /data/lib/aspera/{api → plugins/aoc}/queries/bss_subscription_usage.graphql +0 -0
- /data/lib/aspera/{schema → plugins/aoc/schemas}/IBM Aspera on Cloud Automation API-1.0.5-enhanced.yaml +0 -0
- /data/lib/aspera/{schema → plugins/console/schemas}/IBM Aspera Console-enhanced.yaml +0 -0
- /data/lib/aspera/{schema → plugins/node/schemas}/IBM Aspera Node API-4.4.6.yaml +0 -0
- /data/lib/aspera/{preview → plugins/preview}/image_error.png +0 -0
- /data/lib/aspera/{preview → plugins/preview}/video_error.png +0 -0
- /data/lib/aspera/{schema → plugins/shares/schemas}/IBM_Aspera_Shares.yaml +0 -0
- /data/lib/{transferd_pb.rb → aspera/plugins/transferd/grpc/transferd_pb.rb} +0 -0
- /data/lib/{transferd_services_pb.rb → aspera/plugins/transferd/grpc/transferd_services_pb.rb} +0 -0
- /data/lib/aspera/{schema → plugins/transferd/schemas}/transferd-config.schema.json +0 -0
data/docs/test-mcp-with-ai.md
CHANGED
|
@@ -127,6 +127,10 @@ environment is available.
|
|
|
127
127
|
|
|
128
128
|
### 4.2 Demo server — download a file
|
|
129
129
|
|
|
130
|
+
At the default security level `high` of the server, a transfer with the local agent `direct` (the default) is refused.
|
|
131
|
+
For this test, start the server with level `medium` and `/tmp` in `writable_paths`:
|
|
132
|
+
add `--security.level=medium --security.writable_paths.0=/tmp` after `mcp server` (in `args` of the MCP configuration).
|
|
133
|
+
|
|
130
134
|
> "Download the file `/aspera-test-dir-small/10KB.1` from the demo server
|
|
131
135
|
> (same credentials as above) to `/tmp`."
|
|
132
136
|
|
data/lib/aspera/agent/base.rb
CHANGED
|
@@ -14,6 +14,8 @@ module Aspera
|
|
|
14
14
|
# - `notify_progress` : called back by transfer agent to notify transfer progress
|
|
15
15
|
# - `self.transfer_status` : (optional) re-query a previously started transfer by id
|
|
16
16
|
# - `self.transfer_cancel` : (optional) stop a previously started transfer by id
|
|
17
|
+
# Every agent receives the same base options (see `initialize`): plain values and callable objects (Proc), never objects of the CLI.
|
|
18
|
+
# Each agent uses those it needs.
|
|
17
19
|
class Base
|
|
18
20
|
class << self
|
|
19
21
|
# Re-query the status of a transfer that was started asynchronously.
|
|
@@ -34,6 +36,16 @@ module Aspera
|
|
|
34
36
|
def transfer_cancel(_transfer_id, _agent_params)
|
|
35
37
|
nil
|
|
36
38
|
end
|
|
39
|
+
|
|
40
|
+
# Most restrictive security level (see `Cli::Security`) at which this agent may be used, given its parameters.
|
|
41
|
+
# An agent that runs on the local host (executes a local program, reads or writes local files, starts a local daemon)
|
|
42
|
+
# returns `:medium`, so that it is refused at level `high`: at `high`, transfers use a remote agent that the user controls.
|
|
43
|
+
# An agent that only talks to a remote system (e.g. `node`, or `transferd` attached to a remote daemon) returns `nil` (any level).
|
|
44
|
+
# @param options [Hash] parameters passed to the agent constructor (keys as symbols)
|
|
45
|
+
# @return [Symbol, nil] `nil`, `:low`, `:medium` or `:high`
|
|
46
|
+
def required_security_level(options)
|
|
47
|
+
nil
|
|
48
|
+
end
|
|
37
49
|
end
|
|
38
50
|
|
|
39
51
|
# Where received files are written (direction `receive`).
|
|
@@ -67,6 +79,23 @@ module Aspera
|
|
|
67
79
|
nil
|
|
68
80
|
end
|
|
69
81
|
|
|
82
|
+
# Identifier of the last transfer started, for class methods `transfer_status` and `transfer_cancel`.
|
|
83
|
+
# In-process agents (direct, httpgw): the job id (`last_job_id`).
|
|
84
|
+
# @return [String, nil] `nil` if no transfer was started
|
|
85
|
+
attr_reader :transfer_id
|
|
86
|
+
|
|
87
|
+
# Connection details resolved when the agent runs (e.g. the port of a daemon started by the agent),
|
|
88
|
+
# added to the agent parameters given to `transfer_status` and `transfer_cancel`.
|
|
89
|
+
# @return [Hash] JSON-compatible values, String keys
|
|
90
|
+
def async_params
|
|
91
|
+
{}
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# @return [Boolean] `true` if transfers run in this process (threads): their status is known only while it runs
|
|
95
|
+
def in_process?
|
|
96
|
+
false
|
|
97
|
+
end
|
|
98
|
+
|
|
70
99
|
private
|
|
71
100
|
|
|
72
101
|
Aspera.require_method!(:start_transfer)
|
|
@@ -76,22 +105,49 @@ module Aspera
|
|
|
76
105
|
nil
|
|
77
106
|
end
|
|
78
107
|
|
|
79
|
-
attr_reader :config_dir
|
|
108
|
+
attr_reader :config_dir, :check_ignore_cb, :trusted_certs, :url_provider
|
|
80
109
|
|
|
81
|
-
# Base transfer agent object
|
|
82
|
-
#
|
|
83
|
-
# @param
|
|
110
|
+
# Base transfer agent object.
|
|
111
|
+
# Base options: given to every agent by the application, each agent uses those it needs.
|
|
112
|
+
# @param progress [#event, nil] Receives progress events: `event(type, session_id:, info:)`
|
|
113
|
+
# @param progress_default [Boolean] `true` if `progress` is a default choice, not requested by the user: an agent that displays its own progress does not use it
|
|
114
|
+
# @param config_dir [String, nil] Configuration folder of the application
|
|
115
|
+
# @param check_ignore_cb [Proc, nil] Called with host and port: `true` if the certificate of that server is not checked
|
|
116
|
+
# @param trusted_certs [Array<String>, nil] Files of trusted certificates
|
|
117
|
+
# @param preset_lookup [Proc, nil] Called with a plugin name (Symbol): values of the default preset of that plugin (Hash)
|
|
118
|
+
# @param url_provider [Proc, nil] Returns the URL of the server of the agent given by the application (e.g. HTTP Gateway of AoC)
|
|
84
119
|
def initialize(
|
|
85
|
-
progress:
|
|
86
|
-
|
|
120
|
+
progress: nil,
|
|
121
|
+
progress_default: false,
|
|
122
|
+
config_dir: nil,
|
|
123
|
+
check_ignore_cb: nil,
|
|
124
|
+
trusted_certs: nil,
|
|
125
|
+
preset_lookup: nil,
|
|
126
|
+
url_provider: nil
|
|
87
127
|
)
|
|
88
128
|
@progress = progress
|
|
129
|
+
@progress_default = progress_default
|
|
89
130
|
@config_dir = config_dir
|
|
131
|
+
@check_ignore_cb = check_ignore_cb
|
|
132
|
+
@trusted_certs = trusted_certs
|
|
133
|
+
@preset_lookup = preset_lookup
|
|
134
|
+
@url_provider = url_provider
|
|
90
135
|
end
|
|
91
136
|
|
|
92
137
|
def notify_progress(*pos_args, **kw_args)
|
|
93
138
|
@progress&.event(*pos_args, **kw_args)
|
|
94
139
|
end
|
|
140
|
+
|
|
141
|
+
# The agent displays its own progress: no notification to `progress` if it is a default choice
|
|
142
|
+
def own_progress_display
|
|
143
|
+
@progress = nil if @progress_default
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# @param plugin [Symbol] Plugin name
|
|
147
|
+
# @return [Hash, nil] Values of the default preset of the plugin (String keys), `nil` if no preset lookup was given
|
|
148
|
+
def preset_values(plugin)
|
|
149
|
+
@preset_lookup&.call(plugin)
|
|
150
|
+
end
|
|
95
151
|
end
|
|
96
152
|
end
|
|
97
153
|
end
|
data/lib/aspera/agent/factory.rb
CHANGED
|
@@ -4,11 +4,15 @@
|
|
|
4
4
|
# SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
|
|
6
6
|
require_relative '../log'
|
|
7
|
-
require_relative '../
|
|
7
|
+
require_relative '../assert'
|
|
8
|
+
require_relative '../bundle_registry'
|
|
8
9
|
require 'singleton'
|
|
9
10
|
module Aspera
|
|
10
11
|
module Agent
|
|
11
|
-
# Factory for Agents
|
|
12
|
+
# Factory for Agents: the entries of the extension point `agent` of bundles.
|
|
13
|
+
#
|
|
14
|
+
# `ALL` [Hash{Symbol => Hash}]: available agents, sorted by name: `long` capitalized name string, `short` single character symbol.
|
|
15
|
+
# Computed on access (`instance.all`): bundles of folders added after this file is loaded are included.
|
|
12
16
|
#
|
|
13
17
|
# @!method self.instance
|
|
14
18
|
# Returns the singleton instance of Factory
|
|
@@ -16,27 +20,130 @@ module Aspera
|
|
|
16
20
|
class Factory
|
|
17
21
|
include Singleton
|
|
18
22
|
|
|
23
|
+
# Extension point of the agents of bundles
|
|
24
|
+
POINT = :agent
|
|
25
|
+
|
|
26
|
+
class << self
|
|
27
|
+
# `ALL`: available agents, see `#all`
|
|
28
|
+
def const_missing(name)
|
|
29
|
+
return instance.all if name.eql?(:ALL)
|
|
30
|
+
super
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @param registry [BundleRegistry] Registry of the bundles that provide agents (loaded on use: the factory works without the CLI)
|
|
35
|
+
def initialize(registry: BundleRegistry.instance)
|
|
36
|
+
@registry = registry
|
|
37
|
+
# Entries of the extension point used to build `@all`
|
|
38
|
+
@entries = nil
|
|
39
|
+
# Available agents, see `all`
|
|
40
|
+
@all = nil
|
|
41
|
+
# Entry of each agent provided by a bundle, by name
|
|
42
|
+
@provided = {}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Available agents: entries of the extension point `agent`.
|
|
46
|
+
# An entry whose name is provided by an earlier entry, or whose letter is taken, is left out with a warning.
|
|
47
|
+
# Recomputed when the entries change.
|
|
48
|
+
# @return [Hash{Symbol => Hash}] By name, sorted: `long` capitalized name string, `short` single character symbol
|
|
49
|
+
def all
|
|
50
|
+
entries = @registry.extensions(POINT)
|
|
51
|
+
unless entries.eql?(@entries)
|
|
52
|
+
@entries = entries
|
|
53
|
+
@provided = provided_agents(entries)
|
|
54
|
+
@all = @provided.sort.to_h { |name, entry| [name, {long: name.to_s.capitalize, short: entry.fields['short'].to_sym}.freeze] }.freeze
|
|
55
|
+
end
|
|
56
|
+
@all
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Load the class of an agent: the file of the entry of its bundle, with the checks of the registry: security level, availability, gems
|
|
60
|
+
# @param agent [Symbol, String] Name of an agent of `all`
|
|
61
|
+
# @return [Class] The class of the agent
|
|
62
|
+
# @raise [BundleRegistry::Unavailable] If the bundle of the agent is unavailable or a gem is missing
|
|
63
|
+
def agent_class(agent)
|
|
64
|
+
name = agent.to_sym
|
|
65
|
+
reason = unavailable_reason(name)
|
|
66
|
+
raise BundleRegistry::Unavailable, reason unless reason.nil?
|
|
67
|
+
Aspera.assert(@provided.key?(name)) { "unknown agent: #{name}" }
|
|
68
|
+
@registry.load_entry(@provided[name])
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# @param agent [Symbol, String] Name of an agent
|
|
72
|
+
# @return [Boolean] `true` if the agent is provided by an entry of a bundle
|
|
73
|
+
def provided?(agent)
|
|
74
|
+
all
|
|
75
|
+
@provided.key?(agent.to_sym)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# @param agent [Symbol, String] Name of an agent
|
|
79
|
+
# @return [String, nil] Why the agent is not in `all`: its bundle is unavailable (a bundle that declares it, or, if its manifest is invalid, a bundle of this name); `nil` if it is in `all` or unknown
|
|
80
|
+
def unavailable_reason(agent)
|
|
81
|
+
name = agent.to_sym
|
|
82
|
+
all
|
|
83
|
+
return if @provided.key?(name)
|
|
84
|
+
@registry.names.each do |bundle_name|
|
|
85
|
+
bundle = @registry[bundle_name]
|
|
86
|
+
next unless bundle.bundle?
|
|
87
|
+
reason = @registry.unavailable_reason(bundle_name)
|
|
88
|
+
next if reason.nil?
|
|
89
|
+
return "plugin #{bundle_name} is unavailable: #{reason}" if declares_agent?(bundle, name) || (bundle_name.eql?(name) && !bundle.error.nil?)
|
|
90
|
+
end
|
|
91
|
+
nil
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Found by the name of the class: no code is loaded (a bundle that cannot be loaded does not hide the others).
|
|
95
|
+
# @param instance [Base] An agent
|
|
96
|
+
# @return [Symbol, nil] Name of the agent of `all` this is an instance of, `nil` if none
|
|
97
|
+
def agent_name(instance)
|
|
98
|
+
class_name = instance.class.name
|
|
99
|
+
all
|
|
100
|
+
@provided.each { |name, entry| return name if @registry.constant_name(entry.bundle, entry.constant).eql?(class_name) }
|
|
101
|
+
nil
|
|
102
|
+
end
|
|
103
|
+
|
|
19
104
|
# Create new agent
|
|
105
|
+
# @param agent [Symbol, String] Name of an agent of `all`
|
|
106
|
+
# @param options [Hash] Keyword arguments of the constructor of the agent
|
|
107
|
+
# @return [Base] The agent
|
|
20
108
|
def create(agent, options)
|
|
21
109
|
Log.dump(:options, options)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
#
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
110
|
+
agent_class(agent).new(**options)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
private
|
|
114
|
+
|
|
115
|
+
# @param bundle [BundleRegistry::Plugin] A bundle with a valid manifest
|
|
116
|
+
# @param name [Symbol] Name of an agent
|
|
117
|
+
# @return [Boolean] `true` if the manifest of the bundle declares an agent of this name
|
|
118
|
+
def declares_agent?(bundle, name)
|
|
119
|
+
bundle.extensions.any? { |entry| entry.point.eql?(POINT) && entry.fields['name'].to_s.eql?(name.to_s) }
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# @param entries [Array<BundleRegistry::Extension>] Entries of the extension point, in the order of the registry
|
|
123
|
+
# @return [Hash{Symbol => BundleRegistry::Extension}] Entries kept, by name of agent
|
|
124
|
+
def provided_agents(entries)
|
|
125
|
+
provided = {}
|
|
126
|
+
entries.each do |entry|
|
|
127
|
+
name, short = entry.fields.values_at('name', 'short')
|
|
128
|
+
if !name.is_a?(String) || !short.is_a?(String) || !short.length.eql?(1)
|
|
129
|
+
Log.log.warn { "Agent of bundle #{entry.bundle} is left out: invalid name #{name.inspect} or letter #{short.inspect}" }
|
|
130
|
+
next
|
|
131
|
+
end
|
|
132
|
+
name = name.to_sym
|
|
133
|
+
short = short.to_sym
|
|
134
|
+
if provided.key?(name)
|
|
135
|
+
Log.log.warn { "Agent #{name} of bundle #{entry.bundle} is left out: provided by bundle #{provided[name].bundle}" }
|
|
136
|
+
next
|
|
137
|
+
end
|
|
138
|
+
owner = provided.find { |_, other| other.fields['short'].eql?(short.to_s) }&.first
|
|
139
|
+
unless owner.nil?
|
|
140
|
+
Log.log.warn { "Agent #{name} of bundle #{entry.bundle} is left out: letter #{short} is taken by agent #{owner}" }
|
|
141
|
+
next
|
|
142
|
+
end
|
|
143
|
+
provided[name] = entry
|
|
144
|
+
end
|
|
145
|
+
provided
|
|
146
|
+
end
|
|
40
147
|
end
|
|
41
148
|
end
|
|
42
149
|
end
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
module Ascp
|
|
14
|
+
# a simple binary data repository
|
|
15
|
+
#
|
|
16
|
+
# @!method self.instance
|
|
17
|
+
# Returns the singleton instance of DataRepository
|
|
18
|
+
# @return [DataRepository] the singleton instance
|
|
19
|
+
class DataRepository
|
|
20
|
+
include Singleton
|
|
21
|
+
|
|
22
|
+
# name of data item => name of its file in data folder
|
|
23
|
+
FILES = {
|
|
24
|
+
dsa: '1',
|
|
25
|
+
rsa: '2',
|
|
26
|
+
uuid: '3',
|
|
27
|
+
'aspera.global-cli-client': '4',
|
|
28
|
+
'aspera.drive': '5',
|
|
29
|
+
license: '6'
|
|
30
|
+
}.freeze
|
|
31
|
+
# names of data items
|
|
32
|
+
ELEMENTS = FILES.keys.freeze
|
|
33
|
+
DATA_FOLDER_NAME = 'data'
|
|
34
|
+
|
|
35
|
+
# Get a data item, decoded to its usable form
|
|
36
|
+
# @param name [Symbol] name of the data item, one of ELEMENTS
|
|
37
|
+
# @return [String] PEM private key (dsa, rsa), UUID (uuid), base64url secret (client apps), or text (license)
|
|
38
|
+
def item(name)
|
|
39
|
+
Aspera.assert_values(name, ELEMENTS, type: ParameterError) { 'data item' }
|
|
40
|
+
raw_data = data(name)
|
|
41
|
+
value =
|
|
42
|
+
case name
|
|
43
|
+
when :dsa, :rsa
|
|
44
|
+
# generate PEM from DER
|
|
45
|
+
# Class of key, not `OpenSSL::PKey.read`: on JRuby (jruby-openssl 0.16), it fails on these keys (DER, traditional format)
|
|
46
|
+
{dsa: OpenSSL::PKey::DSA, rsa: OpenSSL::PKey::RSA}[name].new(raw_data).to_pem
|
|
47
|
+
when :license
|
|
48
|
+
Zlib::Inflate.inflate(raw_data)
|
|
49
|
+
when :uuid
|
|
50
|
+
format('%08x-%04x-%04x-%04x-%04x%08x', *raw_data.unpack('NnnnnN'))
|
|
51
|
+
when :'aspera.global-cli-client', :'aspera.drive'
|
|
52
|
+
Base64.urlsafe_encode64(raw_data)
|
|
53
|
+
else Aspera.error_unexpected_value(name)
|
|
54
|
+
end
|
|
55
|
+
# all items are text
|
|
56
|
+
return value.force_encoding(Encoding::UTF_8)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
private_constant :FILES, :DATA_FOLDER_NAME
|
|
62
|
+
|
|
63
|
+
# get binary value from data repository
|
|
64
|
+
# @param name [Symbol] name of the data item
|
|
65
|
+
# @return [String] raw binary data
|
|
66
|
+
def data(name)
|
|
67
|
+
File.binread(File.join(__dir__, DATA_FOLDER_NAME, FILES[name]))
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
# cspell:ignore ckpt
|
|
7
7
|
require_relative '../yaml'
|
|
8
8
|
require_relative '../environment'
|
|
9
|
-
require_relative '
|
|
9
|
+
require_relative 'data_repository'
|
|
10
10
|
require_relative '../log'
|
|
11
11
|
require_relative '../rest'
|
|
12
12
|
require_relative '../uri_reader'
|
|
@@ -16,7 +16,10 @@ require_relative '../hash_ext'
|
|
|
16
16
|
require_relative '../products/desktop'
|
|
17
17
|
require_relative '../products/connect'
|
|
18
18
|
require_relative '../products/transferd'
|
|
19
|
-
require_relative '../products
|
|
19
|
+
require_relative '../products'
|
|
20
|
+
require_relative '../products/cli_v3'
|
|
21
|
+
require_relative '../products/hsts'
|
|
22
|
+
require_relative '../products/drive'
|
|
20
23
|
require 'fileutils'
|
|
21
24
|
require 'openssl'
|
|
22
25
|
require 'singleton'
|
|
@@ -75,7 +78,7 @@ module Aspera
|
|
|
75
78
|
# @return [nil]
|
|
76
79
|
def sdk_folder=(ascp_location)
|
|
77
80
|
Aspera.assert_type(ascp_location, String) { 'ascp_location' }
|
|
78
|
-
Aspera.assert(!ascp_location.empty?, 'ascp location cannot be empty: check your config file')
|
|
81
|
+
Aspera.assert(!ascp_location.empty?, 'ascp location cannot be empty: check your config file', type: ParameterError)
|
|
79
82
|
@ascp_folder = nil
|
|
80
83
|
if self.class.product_selector?(ascp_location)
|
|
81
84
|
# Resolved on first use: product scan requires the SDK folder, which is set later
|
|
@@ -252,10 +255,10 @@ module Aspera
|
|
|
252
255
|
platform = Environment.instance.architecture if platform.nil?
|
|
253
256
|
all_locations = sdk_locations(download: {sdk: version || LATEST_VERSION, platform: platform})
|
|
254
257
|
locations = all_locations.select { |l| l['platform'].eql?(platform) }
|
|
255
|
-
Aspera.assert(!locations.empty
|
|
258
|
+
Aspera.assert(!locations.empty?, type: ParameterError) { "No SDK for platform: #{platform}, available: #{all_locations.map { |i| i['platform'] }.uniq}" }
|
|
256
259
|
version = locations.max_by { |entry| Gem::Version.new(entry['version']) }['version'] if version.nil?
|
|
257
260
|
info = locations.select { |entry| entry['version'].eql?(version) }
|
|
258
|
-
Aspera.assert(!info.empty
|
|
261
|
+
Aspera.assert(!info.empty?, type: ParameterError) { "No such version: #{version} for #{platform}" }
|
|
259
262
|
return info.first
|
|
260
263
|
end
|
|
261
264
|
|
|
@@ -267,7 +270,7 @@ module Aspera
|
|
|
267
270
|
# @return [String, nil] Version of the SDK installed in the SDK folder (from its meta data file), or nil if not installed
|
|
268
271
|
def installed_sdk_version
|
|
269
272
|
return unless File.exist?(sdk_exe_path(:transferd))
|
|
270
|
-
meta_data_file = File.join(Products::Transferd.sdk_directory, Products::
|
|
273
|
+
meta_data_file = File.join(Products::Transferd.sdk_directory, Products::INFO_META_FILE)
|
|
271
274
|
return unless File.exist?(meta_data_file)
|
|
272
275
|
return File.read(meta_data_file).scan(%r{<version>(.*?)</version>}).flatten.first
|
|
273
276
|
end
|
|
@@ -424,7 +427,7 @@ module Aspera
|
|
|
424
427
|
end
|
|
425
428
|
end
|
|
426
429
|
# Generate meta data XML file in SDK if needed, based on actual binaries versions
|
|
427
|
-
meta_data_file = File.join(folder, Products::
|
|
430
|
+
meta_data_file = File.join(folder, Products::INFO_META_FILE)
|
|
428
431
|
if File.exist?(meta_data_file)
|
|
429
432
|
# file is there, read values:
|
|
430
433
|
meta_data = File.read(meta_data_file)
|
|
@@ -525,10 +528,10 @@ module Aspera
|
|
|
525
528
|
if @ascp_folder.nil?
|
|
526
529
|
if @ascp_product.eql?(FIRST_FOUND)
|
|
527
530
|
pl = installed_products.first
|
|
528
|
-
Aspera.assert(!pl.nil
|
|
531
|
+
Aspera.assert(!pl.nil?, type: EnvironmentError) { "No Aspera transfer module or SDK found.\nRefer to the manual or install SDK with command:\nascli config ascp install" }
|
|
529
532
|
else
|
|
530
533
|
pl = installed_products.find { |i| i[:name].eql?(@ascp_product) }
|
|
531
|
-
Aspera.assert(!pl.nil
|
|
534
|
+
Aspera.assert(!pl.nil?, type: ParameterError) { "No such product installed: #{@ascp_product}" }
|
|
532
535
|
end
|
|
533
536
|
@ascp_folder = File.dirname(pl[:ascp_path])
|
|
534
537
|
Log.log.debug { "ascp_folder=#{@ascp_folder}" }
|
|
@@ -549,9 +552,11 @@ module Aspera
|
|
|
549
552
|
scan_locations = Products::Transferd.locations +
|
|
550
553
|
Products::Desktop.locations +
|
|
551
554
|
Products::Connect.locations +
|
|
552
|
-
Products::
|
|
555
|
+
Products::CliV3.locations +
|
|
556
|
+
Products::Hsts.locations +
|
|
557
|
+
Products::Drive.locations
|
|
553
558
|
# search installed products: with ascp
|
|
554
|
-
@found_products = Products
|
|
559
|
+
@found_products = Products.find(scan_locations)
|
|
555
560
|
end
|
|
556
561
|
end
|
|
557
562
|
end
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
# SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
|
|
6
6
|
# cspell:words getlocal MSGID PROCID rsyslog
|
|
7
|
+
require_relative '../../standard_input'
|
|
8
|
+
|
|
7
9
|
module Aspera
|
|
8
10
|
module Ascp
|
|
9
11
|
class LogAnalyzer
|
|
10
|
-
#
|
|
11
|
-
STDIN_PATH = '-'
|
|
12
|
-
# Formats and timestamps of log lines: shared by LogFile and Records, which define `@path` and `@timezone` (nil: time zone of the analyst)
|
|
12
|
+
# Formats and timestamps of log lines: shared by LogFile and Records, which define `@source` (file or standard input), `@path` (its name) and `@timezone` (nil: time zone of the analyst)
|
|
13
13
|
module Lines
|
|
14
14
|
MONTHS = %w[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec].freeze
|
|
15
15
|
# Line of ascp: FASP message, or syslog line of process `ascp`
|
|
@@ -66,7 +66,7 @@ module Aspera
|
|
|
66
66
|
# (a log from December to January analyzed in March: December is of the previous year).
|
|
67
67
|
# @return [Integer] year of the line
|
|
68
68
|
def syslog_year(month, day)
|
|
69
|
-
@reference ||= (@
|
|
69
|
+
@reference ||= (@source.is_a?(StandardInput) ? Time.now : File.mtime(@source)).getlocal(@timezone)
|
|
70
70
|
month > @reference.month || (month == @reference.month && day > @reference.day) ? @reference.year - 1 : @reference.year
|
|
71
71
|
end
|
|
72
72
|
end
|
|
@@ -44,14 +44,16 @@ module Aspera
|
|
|
44
44
|
|
|
45
45
|
attr_reader :path, :stats, :licenses, :first_time, :last_time, :thresholds
|
|
46
46
|
|
|
47
|
-
# @param path [String]
|
|
47
|
+
# @param path [String, StandardInput] Log file, or standard input
|
|
48
48
|
# @param period [Integer] Snapshot period in seconds
|
|
49
49
|
# @param zero_bytes [Boolean] Include sessions without transferred bytes
|
|
50
50
|
# @param mtu [Integer, nil] MTU to use when not found in logs
|
|
51
51
|
# @param thresholds [Hash] Diagnostic thresholds
|
|
52
52
|
# @param timezone [String, nil] Time zone of the log lines: `UTC` or `+HH:MM`. Time zone of the analyst if nil.
|
|
53
53
|
def initialize(path, period: 60, zero_bytes: false, mtu: nil, thresholds: {}, timezone: nil)
|
|
54
|
-
@
|
|
54
|
+
@source = path
|
|
55
|
+
# Name in results: `-` for the standard input
|
|
56
|
+
@path = path.to_s
|
|
55
57
|
@timezone = timezone
|
|
56
58
|
@period = period
|
|
57
59
|
@zero_bytes = zero_bytes
|
|
@@ -80,7 +82,7 @@ module Aspera
|
|
|
80
82
|
# Read and analyze the log file
|
|
81
83
|
# @return [self]
|
|
82
84
|
def analyze
|
|
83
|
-
LogAnalyzer.read_lines(@
|
|
85
|
+
LogAnalyzer.read_lines(@source, Encoding::BINARY) { |line| parse_line(normalize(line)) }
|
|
84
86
|
@sessions.each(&:evaluate_atm)
|
|
85
87
|
@periods.sort.each { |time, period| end_of_period(time, period) }
|
|
86
88
|
compute_statistics
|
|
@@ -23,6 +23,8 @@ module Aspera
|
|
|
23
23
|
class Records
|
|
24
24
|
include Lines
|
|
25
25
|
|
|
26
|
+
# Fields of the records: schema `ascp_log` of the files of `ascp`
|
|
27
|
+
Schema::Registry.register(Schema::Registry::ASCP_LOG, File.expand_path('../log.schema.yaml', __dir__))
|
|
26
28
|
# Kind of record => schema
|
|
27
29
|
SCHEMAS = {
|
|
28
30
|
samples: "#{Schema::Registry::ASCP_LOG}:components.schemas.Sample",
|
|
@@ -67,13 +69,14 @@ module Aspera
|
|
|
67
69
|
|
|
68
70
|
class << self
|
|
69
71
|
# @param kind [Symbol] One of the keys of SCHEMAS
|
|
70
|
-
# @param paths [Array<String>] Log files,
|
|
72
|
+
# @param paths [Array<String, StandardInput>] Log files, standard input or folders
|
|
71
73
|
# @param timezone [String, nil] Time zone of the log lines: `UTC` or `+HH:MM`. Time zone of the analyst if nil.
|
|
74
|
+
# @param readable [#call, nil] For a folder: tells if a file or folder found in it can be read, see `LogAnalyzer.log_paths`
|
|
72
75
|
# @return [Array<Hash>] records of all log files, with field `log_file` when there are several log files
|
|
73
|
-
def list(kind, paths, timezone: nil)
|
|
76
|
+
def list(kind, paths, timezone: nil, readable: nil)
|
|
74
77
|
Aspera.assert_values(kind, SCHEMAS.keys)
|
|
75
78
|
LogAnalyzer.check_timezone(timezone)
|
|
76
|
-
logs = paths.flat_map { |path| LogAnalyzer.load_logs(path) { |file| new(file, timezone: timezone).parse } }
|
|
79
|
+
logs = paths.flat_map { |path| LogAnalyzer.load_logs(path, readable: readable) { |file| new(file, timezone: timezone).parse } }
|
|
77
80
|
logs.flat_map do |log|
|
|
78
81
|
rows = log.public_send(kind)
|
|
79
82
|
logs.size > 1 ? rows.map { |row| {'log_file' => log.path}.merge(row) } : rows
|
|
@@ -223,10 +226,12 @@ module Aspera
|
|
|
223
226
|
# @return [Array<Hash>] one record per sample of a session
|
|
224
227
|
attr_reader :samples
|
|
225
228
|
|
|
226
|
-
# @param path [String]
|
|
229
|
+
# @param path [String, StandardInput] Log file, or standard input
|
|
227
230
|
# @param timezone [String, nil] Time zone of the log lines: `UTC` or `+HH:MM`. Time zone of the analyst if nil.
|
|
228
231
|
def initialize(path, timezone: nil)
|
|
229
|
-
@
|
|
232
|
+
@source = path
|
|
233
|
+
# Name in results: `-` for the standard input
|
|
234
|
+
@path = path.to_s
|
|
230
235
|
@timezone = timezone
|
|
231
236
|
@samples = []
|
|
232
237
|
# uuid => session record
|
|
@@ -245,7 +250,7 @@ module Aspera
|
|
|
245
250
|
# Read and parse the log file
|
|
246
251
|
# @return [self]
|
|
247
252
|
def parse
|
|
248
|
-
LogAnalyzer.read_lines(@
|
|
253
|
+
LogAnalyzer.read_lines(@source, Encoding::UTF_8) do |line|
|
|
249
254
|
line = line.scrub unless line.valid_encoding?
|
|
250
255
|
parse_line(normalize(line))
|
|
251
256
|
end
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
# cspell:ignore asperascp asws getname lastlog lsass pcap tokengen trapd userdata winuser wtmp
|
|
7
7
|
require_relative '../assert'
|
|
8
8
|
require_relative '../log'
|
|
9
|
+
require_relative '../standard_input'
|
|
9
10
|
require_relative 'log_analyzer/log_file'
|
|
10
11
|
require_relative 'log_analyzer/records'
|
|
11
12
|
require 'resolv'
|
|
@@ -86,19 +87,30 @@ module Aspera
|
|
|
86
87
|
raise ParameterError, "Invalid time zone: #{timezone.inspect}, expected `UTC` or `+HH:MM`"
|
|
87
88
|
end
|
|
88
89
|
|
|
89
|
-
# @param path [String] log file,
|
|
90
|
-
# @return [
|
|
91
|
-
def
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
# @param path [String, StandardInput] log file, standard input, or folder
|
|
91
|
+
# @return [Boolean] true if it is a folder
|
|
92
|
+
def folder?(path) = path.is_a?(String) && File.directory?(path)
|
|
93
|
+
|
|
94
|
+
# @param path [String, StandardInput] log file, standard input, or folder
|
|
95
|
+
# @param readable [#call, nil] For a folder: tells if a file or folder found in it can be read (e.g. it is in the allowed paths
|
|
96
|
+
# of the caller, also through a symbolic link), else it is skipped. `nil`: all are read.
|
|
97
|
+
# @return [Array<String, StandardInput>] the log file (or standard input), or the log files in the folder (recursively)
|
|
98
|
+
def log_paths(path, readable: nil)
|
|
99
|
+
return [path] unless folder?(path)
|
|
100
|
+
without_links(scan_folder(path, path, [], readable))
|
|
94
101
|
end
|
|
95
102
|
|
|
96
103
|
# Read the lines of a log file: plain, or compressed with gzip (detected with its first bytes)
|
|
97
|
-
# @param path [String]
|
|
104
|
+
# @param path [String, StandardInput] Log file, or the standard input
|
|
98
105
|
# @param encoding [Encoding] Encoding of lines
|
|
99
106
|
# @yieldparam line [String]
|
|
100
107
|
def read_lines(path, encoding, &block)
|
|
101
|
-
io =
|
|
108
|
+
io =
|
|
109
|
+
case path
|
|
110
|
+
when StandardInput then StringIO.new(path.read)
|
|
111
|
+
when String then File.open(path, 'rb')
|
|
112
|
+
else Aspera.error_unexpected_value(path.class) { 'log file' }
|
|
113
|
+
end
|
|
102
114
|
gzip = io.read(2) == GZIP_MAGIC
|
|
103
115
|
io.rewind
|
|
104
116
|
io = Zlib::GzipReader.new(io, external_encoding: encoding) if gzip
|
|
@@ -110,13 +122,14 @@ module Aspera
|
|
|
110
122
|
|
|
111
123
|
# Load the log files of a path
|
|
112
124
|
# In a folder, a file that is not an ascp log is ignored. A file given explicitly must be an ascp log.
|
|
113
|
-
# @param path
|
|
114
|
-
# @
|
|
125
|
+
# @param path [String, StandardInput] log file, standard input, or folder
|
|
126
|
+
# @param readable [#call, nil] see `log_paths`
|
|
127
|
+
# @yieldparam file [String, StandardInput] log file, or standard input
|
|
115
128
|
# @yieldreturn [#ascp?] the loaded log
|
|
116
129
|
# @return [Array] the loaded logs that are ascp logs
|
|
117
|
-
def load_logs(path)
|
|
118
|
-
explicit = !
|
|
119
|
-
log_paths(path).filter_map do |file|
|
|
130
|
+
def load_logs(path, readable: nil)
|
|
131
|
+
explicit = !folder?(path)
|
|
132
|
+
log_paths(path, readable: readable).filter_map do |file|
|
|
120
133
|
log = yield(file)
|
|
121
134
|
next log if log.ascp?
|
|
122
135
|
Aspera.assert(!explicit, type: ParameterError) { "Not an ascp log: #{file}" }
|
|
@@ -153,8 +166,10 @@ module Aspera
|
|
|
153
166
|
end
|
|
154
167
|
end
|
|
155
168
|
|
|
169
|
+
# A file or sub-folder that `readable` refuses is skipped before it is read or listed: a symbolic link does not lead outside of what the caller may read.
|
|
170
|
+
# @param readable [#call, nil] see `log_paths`
|
|
156
171
|
# @return [Array<String>] files, with the log files of folder added
|
|
157
|
-
def scan_folder(root, folder, files)
|
|
172
|
+
def scan_folder(root, folder, files, readable)
|
|
158
173
|
children = begin
|
|
159
174
|
Dir.children(folder)
|
|
160
175
|
rescue SystemCallError => e
|
|
@@ -167,20 +182,30 @@ module Aspera
|
|
|
167
182
|
next if name.start_with?('.')
|
|
168
183
|
path = File.join(folder, name)
|
|
169
184
|
if File.directory?(path)
|
|
170
|
-
scan_folder(root, path, files)
|
|
171
|
-
elsif name.match?(INCLUDED_FILES) && !path.delete_prefix(root).match?(EXCLUDED_FILES)
|
|
185
|
+
scan_folder(root, path, files, readable) if !name.match?(EXCLUDED_FOLDERS) && accepted?(path, readable)
|
|
186
|
+
elsif name.match?(INCLUDED_FILES) && !path.delete_prefix(root).match?(EXCLUDED_FILES) && accepted?(path, readable)
|
|
172
187
|
files.push(path)
|
|
173
188
|
end
|
|
174
189
|
end
|
|
175
190
|
files
|
|
176
191
|
end
|
|
192
|
+
|
|
193
|
+
# @param path [String] file or folder found in a folder
|
|
194
|
+
# @param readable [#call, nil] see `log_paths`
|
|
195
|
+
# @return [Boolean] `true` if it can be read, else it is skipped
|
|
196
|
+
def accepted?(path, readable)
|
|
197
|
+
return true if readable.nil? || readable.call(path)
|
|
198
|
+
Log.log.debug { "Ignored, not readable: #{path}" }
|
|
199
|
+
false
|
|
200
|
+
end
|
|
177
201
|
end
|
|
178
202
|
|
|
179
203
|
# Analyze a log file, or the log files in a folder (recursively)
|
|
180
|
-
# @param path
|
|
204
|
+
# @param path [String, StandardInput] file, standard input or folder
|
|
205
|
+
# @param readable [#call, nil] see `log_paths`
|
|
181
206
|
# @return [self]
|
|
182
|
-
def add(path)
|
|
183
|
-
@log_files.concat(self.class.load_logs(path) { |file| LogFile.new(file, **@options).analyze })
|
|
207
|
+
def add(path, readable: nil)
|
|
208
|
+
@log_files.concat(self.class.load_logs(path, readable: readable) { |file| LogFile.new(file, **@options).analyze })
|
|
184
209
|
self
|
|
185
210
|
end
|
|
186
211
|
|