aspera-cli 4.27.5 → 4.29.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 +0 -0
- data/BUGS.md +5 -10
- data/CHANGELOG.md +301 -4
- data/CODE_OF_CONDUCT.md +18 -0
- data/CONTRIBUTING.md +139 -58
- data/GOVERNANCE.md +30 -0
- data/LICENSE +201 -0
- data/README.md +103 -26
- data/SECURITY.md +70 -0
- data/bin/ascli +8 -5
- data/bin/asession +10 -7
- data/docs/README.md +2551 -772
- data/docs/test-mcp-with-ai.md +13 -11
- data/lib/aspera/agent/base.rb +23 -2
- data/lib/aspera/agent/connect.rb +16 -12
- data/lib/aspera/agent/desktop.rb +10 -7
- data/lib/aspera/agent/direct.rb +34 -22
- data/lib/aspera/agent/factory.rb +8 -4
- data/lib/aspera/agent/httpgw.rb +7 -5
- data/lib/aspera/agent/node.rb +15 -7
- data/lib/aspera/agent/transferd.rb +167 -43
- data/lib/aspera/api/alee.rb +4 -1
- data/lib/aspera/api/aoc.rb +14 -11
- data/lib/aspera/api/ats.rb +4 -2
- data/lib/aspera/api/cos_node.rb +8 -5
- data/lib/aspera/api/faspex.rb +16 -9
- data/lib/aspera/api/httpgw.rb +9 -6
- data/lib/aspera/api/node.rb +23 -19
- data/lib/aspera/ascmd.rb +8 -5
- data/lib/aspera/ascp/installation.rb +84 -42
- data/lib/aspera/ascp/log.schema.yaml +1084 -0
- data/lib/aspera/ascp/log_analyzer/advice.rb +97 -0
- data/lib/aspera/ascp/log_analyzer/diagnostics.rb +344 -0
- data/lib/aspera/ascp/log_analyzer/lines.rb +75 -0
- data/lib/aspera/ascp/log_analyzer/log_file.rb +593 -0
- data/lib/aspera/ascp/log_analyzer/records.rb +379 -0
- data/lib/aspera/ascp/log_analyzer/rules.rb +172 -0
- data/lib/aspera/ascp/log_analyzer/session.rb +782 -0
- data/lib/aspera/ascp/log_analyzer.rb +354 -0
- data/lib/aspera/ascp/management.rb +102 -48
- data/lib/aspera/ascp/session_errors.rb +217 -0
- data/lib/aspera/assert.rb +4 -0
- data/lib/aspera/cli/ascp_actions.rb +16 -37
- data/lib/aspera/cli/ascp_logs_actions.rb +176 -0
- data/lib/aspera/cli/async_transfer_store.rb +7 -4
- data/lib/aspera/cli/bootstrapper.rb +37 -34
- data/lib/aspera/cli/command_line.rb +24 -6
- data/lib/aspera/cli/command_registry.rb +49 -4
- data/lib/aspera/cli/command_spec.rb +34 -4
- data/lib/aspera/cli/completion/ascli.bash +53 -5
- data/lib/aspera/cli/completion/ascli.fish +27 -8
- data/lib/aspera/cli/completion/ascli.ps1 +63 -0
- data/lib/aspera/cli/completion/ascli.zsh +36 -4
- data/lib/aspera/cli/completion_actions.rb +594 -0
- data/lib/aspera/cli/context.rb +9 -4
- data/lib/aspera/cli/deprecation.rb +5 -2
- data/lib/aspera/cli/error.rb +45 -0
- data/lib/aspera/cli/extended_value.rb +83 -24
- data/lib/aspera/cli/formatter.rb +142 -73
- data/lib/aspera/cli/gem_checker.rb +9 -6
- data/lib/aspera/cli/hints.rb +22 -11
- data/lib/aspera/cli/http.rb +17 -13
- data/lib/aspera/cli/info.rb +17 -6
- data/lib/aspera/cli/mailer.rb +7 -4
- data/lib/aspera/cli/mcp/http_servlet.rb +155 -0
- data/lib/aspera/cli/mcp/secrets.rb +146 -0
- data/lib/aspera/cli/mcp/tool.rb +232 -0
- data/lib/aspera/cli/option_declarator.rb +10 -4
- data/lib/aspera/cli/option_registry.rb +6 -3
- data/lib/aspera/cli/option_types.rb +17 -2
- data/lib/aspera/cli/option_value.rb +72 -11
- data/lib/aspera/cli/options.schema.yaml +856 -81
- data/lib/aspera/cli/parser.rb +64 -31
- data/lib/aspera/cli/plugins/alee.rb +7 -4
- data/lib/aspera/cli/plugins/aoc.rb +250 -44
- data/lib/aspera/cli/plugins/ats.rb +9 -8
- data/lib/aspera/cli/plugins/base.rb +51 -25
- data/lib/aspera/cli/plugins/basic_auth.rb +5 -2
- data/lib/aspera/cli/plugins/config.rb +207 -141
- data/lib/aspera/cli/plugins/console.rb +9 -4
- data/lib/aspera/cli/plugins/cos.rb +8 -4
- data/lib/aspera/cli/plugins/factory.rb +22 -8
- data/lib/aspera/cli/plugins/faspex5.rb +37 -44
- data/lib/aspera/cli/plugins/faspio.rb +41 -8
- data/lib/aspera/cli/plugins/httpgw.rb +8 -4
- data/lib/aspera/cli/plugins/mcp.rb +186 -121
- data/lib/aspera/cli/plugins/node.rb +41 -34
- data/lib/aspera/cli/plugins/oauth.rb +5 -1
- data/lib/aspera/cli/plugins/orchestrator.rb +572 -59
- data/lib/aspera/cli/plugins/preview.rb +69 -44
- data/lib/aspera/cli/plugins/server.rb +66 -12
- data/lib/aspera/cli/plugins/shares.rb +288 -48
- data/lib/aspera/cli/plugins/transferd.rb +223 -0
- data/lib/aspera/cli/preset_actions.rb +155 -33
- data/lib/aspera/cli/preset_manager.rb +72 -16
- data/lib/aspera/cli/prompt.rb +7 -2
- data/lib/aspera/cli/result.rb +28 -11
- data/lib/aspera/cli/runner.rb +193 -80
- data/lib/aspera/cli/secret_finder.rb +4 -1
- data/lib/aspera/cli/security.rb +204 -0
- data/lib/aspera/cli/special_values.rb +4 -1
- data/lib/aspera/cli/sync_actions.rb +13 -10
- data/lib/aspera/cli/table_fitter.rb +119 -0
- data/lib/aspera/cli/terminal_formatter.rb +32 -40
- data/lib/aspera/cli/transfer_actions.rb +11 -8
- data/lib/aspera/cli/transfer_agent.rb +31 -19
- data/lib/aspera/cli/transfer_progress.rb +13 -45
- data/lib/aspera/cli/vault_actions.rb +45 -0
- data/lib/aspera/cli/vault_manager.rb +197 -50
- data/lib/aspera/cli/version.rb +4 -1
- data/lib/aspera/cli/web_secret.html.erb +61 -0
- data/lib/aspera/cli/web_secret.rb +222 -0
- data/lib/aspera/cli/wizard.rb +58 -45
- data/lib/aspera/command_line_builder.rb +35 -5
- data/lib/aspera/command_line_converter.rb +4 -1
- data/lib/aspera/coverage.rb +103 -33
- data/lib/aspera/data_repository.rb +42 -25
- data/lib/aspera/dot_container.rb +4 -1
- data/lib/aspera/duration.rb +45 -0
- data/lib/aspera/environment.rb +106 -33
- data/lib/aspera/exec_spec.rb +9 -5
- data/lib/aspera/faspex_gw.rb +105 -35
- data/lib/aspera/faspex_postproc.rb +193 -47
- data/lib/aspera/formatter_interface.rb +4 -2
- data/lib/aspera/graphql.rb +5 -1
- data/lib/aspera/hash_ext.rb +3 -0
- data/lib/aspera/id_generator.rb +6 -3
- data/lib/aspera/json_rpc/client.rb +55 -35
- data/lib/aspera/json_rpc/version.rb +4 -0
- data/lib/aspera/line_logger.rb +4 -1
- data/lib/aspera/link_header.rb +4 -1
- data/lib/aspera/log.rb +20 -10
- data/lib/aspera/markdown.rb +155 -115
- data/lib/aspera/mime.rb +9 -0
- data/lib/aspera/nagios.rb +9 -5
- data/lib/aspera/node_emulator.rb +111 -112
- data/lib/aspera/oauth/client/base.rb +163 -0
- data/lib/aspera/oauth/{boot.rb → client/boot.rb} +8 -4
- data/lib/aspera/oauth/{factory.rb → client/factory.rb} +13 -3
- data/lib/aspera/oauth/{generic.rb → client/generic.rb} +5 -1
- data/lib/aspera/oauth/{json_credentials.rb → client/json_credentials.rb} +4 -1
- data/lib/aspera/oauth/{jwt.rb → client/jwt.rb} +6 -3
- data/lib/aspera/oauth/client/shares_web.rb +85 -0
- data/lib/aspera/oauth/{url_json.rb → client/url_json.rb} +4 -1
- data/lib/aspera/oauth/client/web.rb +84 -0
- data/lib/aspera/oauth/server/authorize.html.erb +34 -0
- data/lib/aspera/oauth/server/pkce.rb +427 -0
- data/lib/aspera/orchestrator_workflow_checker.rb +679 -0
- data/lib/aspera/persistency_action_once.rb +5 -3
- data/lib/aspera/persistency_folder.rb +6 -3
- data/lib/aspera/preview/file_types.rb +6 -3
- data/lib/aspera/preview/generator.rb +9 -5
- data/lib/aspera/preview/options.schema.yaml +3 -3
- data/lib/aspera/preview/terminal.rb +11 -6
- data/lib/aspera/preview/utils.rb +6 -4
- data/lib/aspera/products/connect.rb +5 -2
- data/lib/aspera/products/desktop.rb +4 -1
- data/lib/aspera/products/other.rb +4 -2
- data/lib/aspera/products/transferd.rb +6 -2
- data/lib/aspera/products/transferd_service.rb +610 -0
- data/lib/aspera/proxy_auto_config.js +2 -2
- data/lib/aspera/proxy_auto_config.rb +5 -2
- data/lib/aspera/rainbow.rb +30 -1
- data/lib/aspera/rest/aspera_errors.rb +55 -60
- data/lib/aspera/rest/call_error.rb +3 -0
- data/lib/aspera/rest/client.rb +42 -42
- data/lib/aspera/rest/error_analyzer.rb +14 -2
- data/lib/aspera/rest/list.rb +14 -10
- data/lib/aspera/rest/parameters.rb +3 -0
- data/lib/aspera/rest/util.rb +13 -4
- data/lib/aspera/rest.rb +9 -7
- data/lib/aspera/schema/IBM Aspera Faspex API-5.0-enhanced.yaml +9 -11
- data/lib/aspera/schema/IBM Aspera Orchestrator API-v1-enhanced.yaml +4089 -0
- data/lib/aspera/schema/IBM Aspera faspio Gateway API-1.0.0-enhanced.yaml +1097 -0
- data/lib/aspera/schema/IBM Aspera on Cloud API-0.2.6-enhanced.yaml +11 -11
- data/lib/aspera/schema/IBM Aspera on Cloud Automation API-1.0.5-enhanced.yaml +2437 -1437
- data/lib/aspera/schema/IBM_Aspera_Shares.yaml +819 -7
- data/lib/aspera/schema/async_tables.yaml +11 -10
- data/lib/aspera/schema/documentation.rb +56 -78
- data/lib/aspera/schema/reader.rb +46 -11
- data/lib/aspera/schema/registry.rb +45 -24
- data/lib/aspera/schema/transferd-config.schema.json +333 -0
- data/lib/aspera/schema/validator.rb +4 -1
- data/lib/aspera/sealed_hash.rb +166 -0
- data/lib/aspera/secret/hider.rb +201 -0
- data/lib/aspera/secret/reference.rb +150 -0
- data/lib/aspera/secret/resolver.rb +212 -0
- data/lib/aspera/secret/store/base.rb +153 -0
- data/lib/aspera/secret/store/encrypted_hash.rb +329 -0
- data/lib/aspera/secret/store/factory.rb +103 -0
- data/lib/aspera/secret/store/hashicorp_vault.rb +390 -0
- data/lib/aspera/secret/store/keeper.rb +141 -0
- data/lib/aspera/secret/store/macos_security.rb +284 -0
- data/lib/aspera/secret/store/one_password_api.rb +99 -0
- data/lib/aspera/secret/store/one_password_base.rb +42 -0
- data/lib/aspera/secret/store/one_password_cli.rb +110 -0
- data/lib/aspera/secret/store/secret_service.rb +125 -0
- data/lib/aspera/secret/strength.rb +119 -0
- data/lib/aspera/servlet_helpers.rb +114 -0
- data/lib/aspera/ssh.rb +10 -7
- data/lib/aspera/ssl.rb +5 -2
- data/lib/aspera/string_ext.rb +3 -0
- data/lib/aspera/sync/args.schema.yaml +6 -1
- data/lib/aspera/sync/conf.schema.yaml +25 -10
- data/lib/aspera/sync/database.rb +3 -0
- data/lib/aspera/sync/operations.rb +34 -12
- data/lib/aspera/temp_file_manager.rb +85 -22
- data/lib/aspera/timer_limiter.rb +3 -0
- data/lib/aspera/transfer/error.rb +4 -1
- data/lib/aspera/transfer/faux_file.rb +4 -1
- data/lib/aspera/transfer/parameters.rb +22 -14
- data/lib/aspera/transfer/result.rb +3 -0
- data/lib/aspera/transfer/resumer.rb +6 -4
- data/lib/aspera/transfer/spec.rb +45 -18
- data/lib/aspera/transfer/spec.schema.yaml +8 -5
- data/lib/aspera/transfer/units.rb +75 -0
- data/lib/aspera/uri_reader.rb +57 -7
- data/lib/aspera/web_auth/index.html.erb +20 -0
- data/lib/aspera/web_auth/paste.rb +109 -0
- data/lib/aspera/web_auth/receiver.rb +50 -0
- data/lib/aspera/web_auth/relay.rb +76 -0
- data/lib/aspera/web_auth/reply.html.erb +150 -0
- data/lib/aspera/web_auth/server.rb +59 -14
- data/lib/aspera/web_page.html.erb +262 -0
- data/lib/aspera/web_page.rb +66 -0
- data/lib/aspera/web_server_simple.rb +82 -13
- data/lib/aspera/yaml.rb +5 -1
- data/llms.txt +81 -0
- data/skills/ascli/SKILL.md +88 -0
- data.tar.gz.sig +0 -0
- metadata +116 -48
- metadata.gz.sig +0 -0
- data/lib/aspera/cli/mcp_tool.rb +0 -189
- data/lib/aspera/keychain/base.rb +0 -25
- data/lib/aspera/keychain/encrypted_hash.rb +0 -188
- data/lib/aspera/keychain/factory.rb +0 -59
- data/lib/aspera/keychain/hashicorp_vault.rb +0 -74
- data/lib/aspera/keychain/macos_security.rb +0 -171
- data/lib/aspera/keychain/one_password_api.rb +0 -86
- data/lib/aspera/keychain/one_password_base.rb +0 -34
- data/lib/aspera/keychain/one_password_cli.rb +0 -98
- data/lib/aspera/oauth/base.rb +0 -141
- data/lib/aspera/oauth/web.rb +0 -57
- data/lib/aspera/oauth.rb +0 -9
- data/lib/aspera/schema/IBM Aspera Orchestrator API-v1.yaml +0 -1784
- data/lib/aspera/schema/IBM Aspera faspio Gateway API-1.0.0.yaml +0 -249
- data/lib/aspera/secret_hider.rb +0 -117
- data/lib/aspera/web_auth/index.html +0 -147
|
@@ -0,0 +1,222 @@
|
|
|
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 '../web_page'
|
|
10
|
+
require_relative '../servlet_helpers'
|
|
11
|
+
require_relative 'error'
|
|
12
|
+
require_relative 'info'
|
|
13
|
+
require 'openssl'
|
|
14
|
+
require 'securerandom'
|
|
15
|
+
require 'uri'
|
|
16
|
+
|
|
17
|
+
module Aspera
|
|
18
|
+
module Cli
|
|
19
|
+
# Secrets entered by the user on a web page, instead of the terminal.
|
|
20
|
+
# Used by extended value `@secret:` when option `ui` is `graphical`, and in MCP server mode (see Mcp::Secrets).
|
|
21
|
+
#
|
|
22
|
+
# Requests are kept in memory, identified by a random value in the URL of the page, and expire after TTL seconds.
|
|
23
|
+
# Pages are served by a local web server, started on first request, or by the web server of the caller (see #handle).
|
|
24
|
+
class WebSecret
|
|
25
|
+
# Lifetime of a request in seconds: the user shall enter the secret within this time
|
|
26
|
+
TTL = 600
|
|
27
|
+
# Path of the page, followed by the request identifier
|
|
28
|
+
PATH_PREFIX = '/secret/'
|
|
29
|
+
# Interval in seconds between calls to the block while waiting for the user
|
|
30
|
+
WAIT_SLICE = 10
|
|
31
|
+
# Address of the local web server
|
|
32
|
+
LOCAL_ADDRESS = '127.0.0.1'
|
|
33
|
+
# Maximum time in seconds to wait for the local web server to send the last page on shutdown
|
|
34
|
+
SHUTDOWN_TIMEOUT = 5
|
|
35
|
+
# ERB template of the page
|
|
36
|
+
HTML_TEMPLATE_PATH = File.join(__dir__, 'web_secret.html.erb')
|
|
37
|
+
# A request for a secret, status is one of: :pending, :received, :cancelled
|
|
38
|
+
Request = Struct.new(:prompt, :status, :value, :expires_at, keyword_init: true)
|
|
39
|
+
private_constant :WAIT_SLICE, :LOCAL_ADDRESS, :SHUTDOWN_TIMEOUT, :HTML_TEMPLATE_PATH, :Request
|
|
40
|
+
|
|
41
|
+
class << self
|
|
42
|
+
# Ask for a secret on a web page, opened in the browser
|
|
43
|
+
# @param prompt [String] Name of the secret
|
|
44
|
+
# @return [String] The secret
|
|
45
|
+
def ask(prompt)
|
|
46
|
+
web_secret = new
|
|
47
|
+
id = web_secret.create(prompt)
|
|
48
|
+
Environment.instance.open_uri(web_secret.url(id))
|
|
49
|
+
web_secret.wait_value(id)
|
|
50
|
+
ensure
|
|
51
|
+
web_secret&.shutdown
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# @param base_url [String, nil] URL of the web server serving the pages (see #handle), `nil` to start a local web server on first request
|
|
56
|
+
# @param access_code [String, nil] If set, the user must also enter it on the page
|
|
57
|
+
# @param name [String] Name of the application needing the secret, shown on the page
|
|
58
|
+
# @param requester [String, nil] Who requested the command, shown on the page, e.g. `AI assistant`, `nil` for the user on terminal
|
|
59
|
+
def initialize(base_url: nil, access_code: nil, name: Info::CMD_NAME, requester: nil)
|
|
60
|
+
Aspera.assert(access_code.nil? || !access_code.to_s.empty?) { 'access_code must not be empty' }
|
|
61
|
+
@base_url = base_url
|
|
62
|
+
@access_code = access_code&.to_s
|
|
63
|
+
@name = name
|
|
64
|
+
@requester = requester
|
|
65
|
+
@mutex = Mutex.new
|
|
66
|
+
@cond = ConditionVariable.new
|
|
67
|
+
# id => Request
|
|
68
|
+
@requests = {}
|
|
69
|
+
@local_server = nil
|
|
70
|
+
@local_thread = nil
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# @param prompt [String] Name of the secret, shown to the user
|
|
74
|
+
# @return [String] Identifier of the new request
|
|
75
|
+
def create(prompt)
|
|
76
|
+
id = SecureRandom.urlsafe_base64(24)
|
|
77
|
+
@mutex.synchronize do
|
|
78
|
+
purge_expired
|
|
79
|
+
@requests[id] = Request.new(prompt: prompt, status: :pending, expires_at: Time.now + TTL)
|
|
80
|
+
end
|
|
81
|
+
id
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# @param id [String] Identifier of the request
|
|
85
|
+
# @return [String] URL of the page where the user enters the secret
|
|
86
|
+
def url(id)
|
|
87
|
+
"#{base_url}#{PATH_PREFIX}#{id}"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# @param id [String] Identifier of the request
|
|
91
|
+
# @return [String, nil] Prompt of the request, `nil` if unknown or expired
|
|
92
|
+
def prompt(id)
|
|
93
|
+
@mutex.synchronize { live_request(id)&.prompt }
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Wait until the user enters the secret, or cancels, on the page
|
|
97
|
+
# @param id [String] Identifier of the request
|
|
98
|
+
# @yield [elapsed] Called periodically while waiting, with elapsed seconds
|
|
99
|
+
# @return [String] The secret
|
|
100
|
+
# @raise [Cli::Error] if the request is unknown, expired, or cancelled by the user
|
|
101
|
+
def wait_value(id)
|
|
102
|
+
start = Time.now
|
|
103
|
+
loop do
|
|
104
|
+
@mutex.synchronize do
|
|
105
|
+
request = live_request(id)
|
|
106
|
+
raise Error, 'Secret request expired: execute the command again' if request.nil?
|
|
107
|
+
raise Error, 'Secret entry cancelled by user' if request.status.eql?(:cancelled)
|
|
108
|
+
return request.value if request.status.eql?(:received)
|
|
109
|
+
@cond.wait(@mutex, (request.expires_at - Time.now).clamp(0, WAIT_SLICE))
|
|
110
|
+
end
|
|
111
|
+
yield(Time.now - start) if block_given?
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Forget requests, and their secrets
|
|
116
|
+
# @param ids [Array<String>] Identifiers of requests
|
|
117
|
+
def delete(ids)
|
|
118
|
+
@mutex.synchronize { ids.each { |id| @requests.delete(id) } }
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Stop the local web server, if started, after it sends the last page to the browser
|
|
122
|
+
def shutdown
|
|
123
|
+
return if @local_server.nil?
|
|
124
|
+
@local_server.shutdown
|
|
125
|
+
@local_thread.join(SHUTDOWN_TIMEOUT)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Serve the page: GET shows the form, POST receives the secret or the cancellation
|
|
129
|
+
# @param req [WEBrick::HTTPRequest]
|
|
130
|
+
# @param res [WEBrick::HTTPResponse]
|
|
131
|
+
def handle(req, res)
|
|
132
|
+
require 'webrick'
|
|
133
|
+
id = req.path.delete_prefix(PATH_PREFIX)
|
|
134
|
+
status, page = @mutex.synchronize do
|
|
135
|
+
request = live_request(id)
|
|
136
|
+
if request.nil? || !request.status.eql?(:pending)
|
|
137
|
+
[404, {state: :unknown}]
|
|
138
|
+
elsif req.request_method.eql?('GET')
|
|
139
|
+
[200, {state: :form, prompt: request.prompt}]
|
|
140
|
+
elsif req.request_method.eql?('POST')
|
|
141
|
+
answer(request, WEBrick::HTTPUtils.parse_query(req.body.to_s))
|
|
142
|
+
else
|
|
143
|
+
[405, {state: :unknown}]
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
res.status = status
|
|
147
|
+
WebPage.secure_headers(res)
|
|
148
|
+
# Variables of the template, state is one of: :form, :received, :cancelled, :unknown
|
|
149
|
+
res.body = WebPage.render(
|
|
150
|
+
HTML_TEMPLATE_PATH,
|
|
151
|
+
title: 'Secret request',
|
|
152
|
+
name: @name,
|
|
153
|
+
requester: @requester,
|
|
154
|
+
action_url: "#{PATH_PREFIX}#{id}",
|
|
155
|
+
access_code_required: !@access_code.nil?,
|
|
156
|
+
prompt: nil,
|
|
157
|
+
error: nil,
|
|
158
|
+
**page
|
|
159
|
+
)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
private
|
|
163
|
+
|
|
164
|
+
# Record the answer of the user, called with the mutex locked
|
|
165
|
+
# @param request [Request] The pending request
|
|
166
|
+
# @param params [Hash] Fields of the form
|
|
167
|
+
# @return [Array] HTTP status and attributes of the page
|
|
168
|
+
def answer(request, params)
|
|
169
|
+
if params['decision'].eql?('cancel')
|
|
170
|
+
request.status = :cancelled
|
|
171
|
+
elsif @access_code && !OpenSSL.secure_compare(params['access_code'].to_s, @access_code)
|
|
172
|
+
Log.log.warn('Secret page: wrong access code')
|
|
173
|
+
return [401, {state: :form, prompt: request.prompt, error: 'Invalid access code'}]
|
|
174
|
+
else
|
|
175
|
+
# Form data is binary, the page is UTF-8
|
|
176
|
+
request.value = params['secret'].to_s.dup.force_encoding(Encoding::UTF_8)
|
|
177
|
+
request.status = :received
|
|
178
|
+
end
|
|
179
|
+
@cond.broadcast
|
|
180
|
+
[200, {state: request.status}]
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# Called with the mutex locked
|
|
184
|
+
# @return [Request, nil] The request, `nil` if unknown or expired
|
|
185
|
+
def live_request(id)
|
|
186
|
+
request = @requests[id]
|
|
187
|
+
request unless request.nil? || request.expires_at < Time.now
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def purge_expired
|
|
191
|
+
now = Time.now
|
|
192
|
+
@requests.delete_if { |_, request| request.expires_at < now }
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# @return [String] URL of the server, for the browser
|
|
196
|
+
def base_url
|
|
197
|
+
@mutex.synchronize { @base_url ||= start_local_server }
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# Start a local web server for the pages
|
|
201
|
+
# @return [String] URL of the local server
|
|
202
|
+
def start_local_server
|
|
203
|
+
require_relative '../web_server_simple'
|
|
204
|
+
servlet = Class.new(WEBrick::HTTPServlet::AbstractServlet) do
|
|
205
|
+
include ServletHelpers
|
|
206
|
+
|
|
207
|
+
# Refuse requests of other web pages, the WebSecret instance is the option of the servlet
|
|
208
|
+
def service(req, res)
|
|
209
|
+
check_request(req)
|
|
210
|
+
@options.first.handle(req, res)
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
# Port 0: any free port
|
|
214
|
+
@local_server = WebServerSimple.new(URI::HTTP.build(host: LOCAL_ADDRESS, port: 0))
|
|
215
|
+
@local_server.mount(PATH_PREFIX, servlet, self)
|
|
216
|
+
# In a thread: signals are not trapped by the server
|
|
217
|
+
@local_thread = Thread.new { @local_server.start }
|
|
218
|
+
@local_server.uri.to_s
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
end
|
data/lib/aspera/cli/wizard.rb
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../oauth/client/jwt'
|
|
7
|
+
require_relative '../assert'
|
|
8
|
+
require_relative '../environment'
|
|
9
|
+
require_relative '../id_generator'
|
|
10
|
+
require_relative 'plugins/factory'
|
|
11
|
+
require_relative '../rainbow'
|
|
8
12
|
using Rainbow
|
|
9
13
|
|
|
10
14
|
module Aspera
|
|
11
15
|
module Cli
|
|
12
16
|
# The wizard detects applications and generates a config
|
|
13
17
|
class Wizard
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
WIZARD_RESULT_KEYS = %i[preset_value test_args].freeze
|
|
18
|
+
WIZARD_RESULT_KEYS = %i[preset_ids preset_value test_args].freeze
|
|
17
19
|
DEFAULT_PRIV_KEY_FILENAME = 'my_private_key.pem' # pragma: allowlist secret
|
|
18
20
|
private_constant :WIZARD_RESULT_KEYS, :DEFAULT_PRIV_KEY_FILENAME
|
|
19
21
|
|
|
20
|
-
# Declared by the `config` plugin (`use_options Wizard`)
|
|
21
|
-
option :override, description: 'Wizard: override existing value', allowed: Type::BOOLEAN, default: false
|
|
22
|
-
option :default, description: 'Wizard: set as default configuration for specified plugin (also: update)', allowed: Type::BOOLEAN, default: true
|
|
23
|
-
option :key_path, description: 'Wizard: path to private key for JWT'
|
|
24
|
-
|
|
25
22
|
def initialize(parent, main_folder)
|
|
26
23
|
@parent = parent
|
|
27
24
|
@main_folder = main_folder
|
|
@@ -84,51 +81,68 @@ module Aspera
|
|
|
84
81
|
return found_apps
|
|
85
82
|
end
|
|
86
83
|
|
|
87
|
-
#
|
|
84
|
+
# Display the path to a page of the web UI
|
|
85
|
+
# @param steps [Array<String>] Menus and pages, from the top (e.g. `Environment.char('👤')` for the user menu)
|
|
86
|
+
# @return [nil]
|
|
87
|
+
def display_navigation(*steps)
|
|
88
|
+
formatter.display_status("Navigate to: #{steps.join(" #{Environment.char('→')} ")}")
|
|
89
|
+
nil
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# To be called in public wizard method to get private key.
|
|
93
|
+
# The key is the value of option `private_key` (e.g. `@file:<path>`): if empty or not provided, the default key is used, or generated.
|
|
88
94
|
# @param user [String] User's email
|
|
89
95
|
# @param url [String] Instance URL
|
|
90
|
-
# @param page [String]
|
|
91
|
-
# @return [String]
|
|
96
|
+
# @param page [Array<String>] Navigation steps to the page to enter the public key (see `display_navigation`)
|
|
97
|
+
# @return [String] Value of `private_key` for the preset: the key as provided, or a reference to the generated file
|
|
92
98
|
def ask_private_key(user:, url:, page:)
|
|
93
|
-
# Lets see if
|
|
94
|
-
|
|
99
|
+
# Lets see if the private key is provided
|
|
100
|
+
private_key_pem = options.get_option(:private_key)
|
|
95
101
|
# Give a chance to provide
|
|
96
|
-
if
|
|
97
|
-
formatter.display_status('
|
|
98
|
-
|
|
102
|
+
if private_key_pem.nil?
|
|
103
|
+
formatter.display_status('Private RSA key, e.g. @file:<path> (leave empty to generate):')
|
|
104
|
+
private_key_pem = options.get_option(:private_key, mandatory: true).to_s
|
|
99
105
|
end
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
106
|
+
if private_key_pem.empty?
|
|
107
|
+
private_key_path = File.join(@main_folder, DEFAULT_PRIV_KEY_FILENAME)
|
|
108
|
+
if File.exist?(File.expand_path(private_key_path))
|
|
109
|
+
formatter.display_status('Using existing key:')
|
|
110
|
+
else
|
|
111
|
+
formatter.display_status("Generating #{OAuth::Jwt::DEFAULT_PRIV_KEY_LENGTH} bit RSA key...")
|
|
112
|
+
OAuth::Jwt.generate_rsa_private_key(path: private_key_path)
|
|
113
|
+
formatter.display_status('Created key:')
|
|
114
|
+
end
|
|
115
|
+
formatter.display_status(private_key_path)
|
|
116
|
+
private_key_pem = File.read(File.expand_path(private_key_path))
|
|
117
|
+
options.set_option(:private_key, private_key_pem)
|
|
118
|
+
private_key_preset_value = "@file:#{private_key_path}"
|
|
104
119
|
else
|
|
105
|
-
|
|
106
|
-
OAuth::Jwt.generate_rsa_private_key(path: private_key_path)
|
|
107
|
-
formatter.display_status('Created key:')
|
|
120
|
+
private_key_preset_value = private_key_pem
|
|
108
121
|
end
|
|
109
|
-
formatter.display_status(private_key_path)
|
|
110
|
-
private_key_pem = File.read(File.expand_path(private_key_path))
|
|
111
122
|
pub_key_pem = OpenSSL::PKey::RSA.new(private_key_pem).public_key.to_s
|
|
112
|
-
options.set_option(:private_key, private_key_pem)
|
|
113
123
|
formatter.display_status("Please Log in as user #{user.red} at: #{url.red}")
|
|
114
|
-
|
|
124
|
+
display_navigation(*page)
|
|
115
125
|
formatter.display_status("Check or update the value to (#{'including BEGIN/END lines'.red}):".blink)
|
|
116
126
|
formatter.display_status(pub_key_pem, hide_secrets: false)
|
|
117
127
|
formatter.display_status('Once updated or validated, press [Enter].')
|
|
118
128
|
Environment.instance.open_uri(url)
|
|
119
129
|
$stdin.gets if required
|
|
120
|
-
|
|
130
|
+
private_key_preset_value
|
|
121
131
|
end
|
|
122
132
|
|
|
123
133
|
# Wizard function, creates configuration
|
|
124
|
-
#
|
|
125
|
-
|
|
134
|
+
# Options of the plugin (e.g. `--username`, `--password`, `--private-key`) are read from the command line, once the plugin has declared them.
|
|
135
|
+
# @param apps [Array] list of detected apps
|
|
136
|
+
# @param preset_name [String] name of the preset to create (default: generated)
|
|
137
|
+
# @param override [Boolean] override the existing default preset of the plugin, if it exists
|
|
138
|
+
# @param default [Boolean] set the preset as default configuration for the plugin
|
|
139
|
+
def find(apps, preset_name: '', override: false, default: true)
|
|
126
140
|
identification = if apps.length.eql?(1)
|
|
127
141
|
Log.log.debug { "Detected: #{identification}" }
|
|
128
142
|
apps.first
|
|
129
143
|
else
|
|
130
144
|
formatter.display_status('Multiple applications detected, please select from:')
|
|
131
|
-
|
|
145
|
+
require_relative 'result'
|
|
132
146
|
formatter.display_results(Result::ObjectList.new(apps, fields: %w[product url version]))
|
|
133
147
|
answer = options.prompt_user_input_in_list('product', apps.map { |a| a[:product] })
|
|
134
148
|
apps.find { |a| a[:product].eql?(answer) }
|
|
@@ -146,23 +160,22 @@ module Aspera
|
|
|
146
160
|
wizard_result = plugin_instance.wizard(self, wiz_url)
|
|
147
161
|
Log.log.debug { "wizard result: #{wizard_result}" }
|
|
148
162
|
Aspera.assert(WIZARD_RESULT_KEYS.eql?(wizard_result.keys.sort)) { "missing or extra keys in wizard result: #{wizard_result.keys}" }
|
|
163
|
+
Aspera.assert_array_all(wizard_result[:preset_ids], String) { 'preset_ids' }
|
|
149
164
|
# Get preset name from user or default
|
|
150
165
|
if wiz_preset_name.empty?
|
|
151
|
-
|
|
166
|
+
wiz_preset_name = IdGenerator.from_list(
|
|
152
167
|
identification[:product],
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
wiz_preset_name = elements.join('_').strip.downcase.gsub(/[^a-z0-9]/, '_').squeeze('_')
|
|
168
|
+
wiz_url,
|
|
169
|
+
*wizard_result[:preset_ids]
|
|
170
|
+
)
|
|
157
171
|
end
|
|
158
172
|
# Write configuration file
|
|
159
173
|
formatter.display_status("Preparing preset: #{wiz_preset_name}")
|
|
160
174
|
# Init defaults if necessary
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
@parent.context.presets.defaults_set(identification[:product], wiz_preset_name, wizard_result[:preset_value].stringify_keys, option_default, option_override)
|
|
175
|
+
preset_value = {PresetManager::Key::COMMENT => "wizard: #{identification[:name]}"}.merge(wizard_result[:preset_value].stringify_keys)
|
|
176
|
+
@parent.context.presets.defaults_set(identification[:product], wiz_preset_name, preset_value, default, override)
|
|
164
177
|
test_args = wizard_result[:test_args]
|
|
165
|
-
test_args = "-P#{wiz_preset_name} #{test_args}" unless
|
|
178
|
+
test_args = "-P#{wiz_preset_name} #{test_args}" unless default
|
|
166
179
|
# TODO: actually test the command
|
|
167
180
|
test_cmd = "#{Info::CMD_NAME} #{identification[:product]} #{test_args}"
|
|
168
181
|
return Result::Status.new("You can test with:\n#{test_cmd.red}")
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'log'
|
|
7
|
+
require_relative 'assert'
|
|
8
|
+
require_relative 'schema/registry'
|
|
9
|
+
require_relative 'exec_spec'
|
|
7
10
|
require 'yaml'
|
|
8
11
|
module Aspera
|
|
9
12
|
# Helper class to build command line from a parameter list (key-value hash)
|
|
@@ -28,9 +31,11 @@ module Aspera
|
|
|
28
31
|
'x-cli-switch', # [Boolean] `true` if option has no arg, else by default option has a value
|
|
29
32
|
'x-cli-special', # [Boolean] `true` if special handling (deferred)
|
|
30
33
|
'x-cli-convert', # [String,Hash] Method name for Convert object or Conversion for enum ts to arg
|
|
34
|
+
'x-cli-complete', # [String] Values proposed by shell completion: `file`, `folder` (see `Cli::Complete::KINDS`)
|
|
31
35
|
'x-agents', # [Array] Supported agents (for doc only), if not specified: all
|
|
32
36
|
'x-ts-name', # [Boolean,String] (async) true if same name in transfer spec, else real name in transfer spec, else ignored
|
|
33
37
|
'x-ts-convert', # [String] (async) Name of methods to convert value from transfer spec to `conf` API.
|
|
38
|
+
'x-unit', # [String] (async) Time unit of the integer value in `conf` (e.g. `ms`), command line option is a DURATION
|
|
34
39
|
'x-deprecation' # [String] Deprecation message for doc
|
|
35
40
|
].freeze
|
|
36
41
|
|
|
@@ -52,6 +57,30 @@ module Aspera
|
|
|
52
57
|
!properties.key?('x-agents') || properties['x-agents'].include?(agent.to_s)
|
|
53
58
|
end
|
|
54
59
|
|
|
60
|
+
# Documentation of the command line option of a property: `annotate` of `Schema::Documentation`
|
|
61
|
+
# @param node [Hash] Schema of the property
|
|
62
|
+
# @param formatter [FormatterInterface] Formatter of the documentation
|
|
63
|
+
# @return [Array<String>] Lines added to the description, empty if no option
|
|
64
|
+
def doc_lines(node, formatter)
|
|
65
|
+
envvar_prefix = ''
|
|
66
|
+
cli_option =
|
|
67
|
+
if node.key?('x-cli-envvar')
|
|
68
|
+
envvar_prefix = 'env:'
|
|
69
|
+
node['x-cli-envvar']
|
|
70
|
+
elsif node['x-cli-switch']
|
|
71
|
+
false_part = node.key?('x-cli-false') ? " / #{node['x-cli-false']}" : ''
|
|
72
|
+
"#{node['x-cli-option']}#{false_part}"
|
|
73
|
+
elsif node['x-cli-option']
|
|
74
|
+
arg_type = node.key?('enum') ? '{enum}' : "{#{[node['type']].flatten.join('|')}}"
|
|
75
|
+
conversion_tag = node.key?('x-cli-convert') ? 'conversion' : nil
|
|
76
|
+
sep = node['x-cli-option'].start_with?('--') ? '=' : ' '
|
|
77
|
+
"#{node['x-cli-option']}#{sep}#{"(#{conversion_tag})" if conversion_tag}#{arg_type}"
|
|
78
|
+
end
|
|
79
|
+
return [] unless cli_option
|
|
80
|
+
short = node.key?('x-cli-short') ? "(#{node['x-cli-short']})" : nil
|
|
81
|
+
["(#{'special:' if node['x-cli-special']}#{envvar_prefix}#{formatter.markdown_text("`#{cli_option}`")})#{short}"]
|
|
82
|
+
end
|
|
83
|
+
|
|
55
84
|
private
|
|
56
85
|
|
|
57
86
|
# `ascp`: mandatory type
|
|
@@ -72,6 +101,7 @@ module Aspera
|
|
|
72
101
|
Aspera.assert(node['type'].eql?('boolean')) { "switch must be bool: #{name}" } if node['x-cli-switch'] && !node['x-cli-special']
|
|
73
102
|
Aspera.assert(node['x-cli-switch']) { "boolean direct option must have x-cli-switch: #{name}" } if node['type'].eql?('boolean') && node.key?('x-cli-option') && supported_by_agent(:direct, node) && !node['x-cli-special']
|
|
74
103
|
node['x-cli-option'] = "--#{name.to_s.tr('_', '-')}" if node['x-cli-option'].eql?(true) || (node['x-cli-switch'].eql?(true) && !node.key?('x-cli-option'))
|
|
104
|
+
Aspera.assert(supported_by_agent(:direct, node)) { "#{name}: x-cli-option requires agent direct (or nil)" } if node['x-cli-option']
|
|
75
105
|
Aspera.assert(DIRECT_PROPERTIES.any? { |i| node.key?(i) }, name, type: :warn) if ascp && supported_by_agent(:direct, node)
|
|
76
106
|
node.freeze
|
|
77
107
|
end
|
|
@@ -205,7 +235,7 @@ module Aspera
|
|
|
205
235
|
else
|
|
206
236
|
# transform into command line option with value
|
|
207
237
|
# parameter_value=parameter_value.to_s if parameter_value.is_a?(Integer)
|
|
208
|
-
parameter_value =
|
|
238
|
+
parameter_value = Array(parameter_value)
|
|
209
239
|
# if transfer_spec value is an array, applies option many times
|
|
210
240
|
parameter_value.each { |v| add_command_line_options(properties['x-cli-option'], v) }
|
|
211
241
|
end
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'assert'
|
|
4
7
|
module Aspera
|
|
5
8
|
# conversion class for transfer spec values to CLI values (ascp)
|
|
6
9
|
class CommandLineConverter
|
data/lib/aspera/coverage.rb
CHANGED
|
@@ -1,39 +1,109 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
#
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
module Aspera
|
|
7
|
+
# Test coverage with SimpleCov, enabled with env var `ENABLE_COVERAGE`.
|
|
8
|
+
# Each tested process stores only its own result in `parts/<uuid>`: merging all results at each process exit is slow when there are many processes.
|
|
9
|
+
# The report is generated by `report`, which merges all parts (called by the test Rake tasks).
|
|
10
|
+
module Coverage
|
|
11
|
+
# Development top folder, computed from this source location
|
|
12
|
+
ROOT = File.dirname(File.realpath(__FILE__), 3)
|
|
13
|
+
# Report folder, relative to `ROOT`
|
|
14
|
+
DIR = 'tmp/coverage'
|
|
15
|
+
# One sub-folder per process, each with its own `.resultset.json`
|
|
16
|
+
PARTS = File.join(DIR, 'parts')
|
|
17
|
+
# Coverage badge (shields.io endpoint), relative to `ROOT`
|
|
18
|
+
BADGE = 'docs/coverage.json'
|
|
19
|
+
# Badge color: first one whose lower limit is reached
|
|
20
|
+
BADGE_COLORS = {90 => 'brightgreen', 80 => 'green', 70 => 'yellowgreen', 60 => 'yellow', 50 => 'orange'}.freeze
|
|
21
|
+
# Results are kept for 1 day (must be longer than time to run the whole test suite, possibly in several runs)
|
|
22
|
+
MERGE_TIMEOUT = 86_400
|
|
23
|
+
# Lines with those words are ignored from coverage (assertions usually do not trigger)
|
|
24
|
+
NO_COV_FUNCTIONS = %w[error_unreachable_line error_unexpected_value Log.log.trace].freeze
|
|
25
|
+
# No coverage in these files or folders
|
|
26
|
+
NO_COV_PATHS = %w[
|
|
27
|
+
build/
|
|
28
|
+
tmp/
|
|
29
|
+
lib/transferd_pb.rb
|
|
30
|
+
lib/transferd_services_pb.rb
|
|
31
|
+
lib/aspera/secret/store/macos_security.rb
|
|
32
|
+
lib/aspera/assert.rb
|
|
33
|
+
].freeze
|
|
34
|
+
private_constant :BADGE_COLORS, :MERGE_TIMEOUT, :NO_COV_FUNCTIONS, :NO_COV_PATHS
|
|
35
|
+
|
|
36
|
+
class << self
|
|
37
|
+
# Start coverage of current process.
|
|
38
|
+
# Must be called before any library is loaded.
|
|
39
|
+
def start
|
|
40
|
+
require 'simplecov'
|
|
41
|
+
require 'securerandom'
|
|
42
|
+
name = SecureRandom.uuid
|
|
43
|
+
SimpleCov.root(ROOT)
|
|
44
|
+
SimpleCov.coverage_dir(File.join(PARTS, name))
|
|
45
|
+
SimpleCov.command_name(name)
|
|
46
|
+
SimpleCov.merge_subprocesses(true)
|
|
47
|
+
SimpleCov.merge_timeout(MERGE_TIMEOUT)
|
|
48
|
+
# The trend of a single process is meaningless
|
|
49
|
+
SimpleCov.history_limit(0)
|
|
50
|
+
# Only store this process result (in its own folder): no report
|
|
51
|
+
SimpleCov.at_exit { SimpleCov.result }
|
|
52
|
+
SimpleCov.start { Aspera::Coverage.filters(self) }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Merge the results of all processes and generate the report in `DIR`.
|
|
56
|
+
# Results older than `MERGE_TIMEOUT` are deleted.
|
|
57
|
+
# @return [Float, nil] Percentage of covered lines, or `nil` if there is no result
|
|
58
|
+
def report
|
|
59
|
+
require 'simplecov'
|
|
60
|
+
require 'fileutils'
|
|
61
|
+
require 'etc'
|
|
62
|
+
parts = Dir.glob(File.join(ROOT, PARTS, '*'))
|
|
63
|
+
old, parts = parts.partition { |dir| Time.now - File.mtime(dir) > MERGE_TIMEOUT }
|
|
64
|
+
FileUtils.rm_rf(old)
|
|
65
|
+
results = parts.map { |dir| File.join(dir, '.resultset.json') }.select { |file| File.exist?(file) }
|
|
66
|
+
return if results.empty?
|
|
67
|
+
# Else the merged result would be added to the previous one
|
|
68
|
+
FileUtils.rm_f(File.join(ROOT, DIR, '.resultset.json'))
|
|
69
|
+
SimpleCov.root(ROOT)
|
|
70
|
+
SimpleCov.coverage_dir(DIR)
|
|
71
|
+
percent = nil
|
|
72
|
+
# The merged command name lists all process UUIDs: show their number instead
|
|
73
|
+
SimpleCov.at_exit do
|
|
74
|
+
result = SimpleCov.result
|
|
75
|
+
result.command_name = "#{result.command_names.size} processes"
|
|
76
|
+
result.format!
|
|
77
|
+
percent = result.covered_percent
|
|
78
|
+
end
|
|
79
|
+
SimpleCov.collate(results, processes: Etc.nprocessors) { Aspera::Coverage.filters(self) }
|
|
80
|
+
percent
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Write the coverage badge: a shields.io endpoint file, shown in the top `README.md`
|
|
84
|
+
# @param percent [Float] Percentage of covered lines
|
|
85
|
+
def write_badge(percent)
|
|
86
|
+
require 'json'
|
|
87
|
+
color = BADGE_COLORS.find { |limit, _| percent >= limit }&.last || 'red'
|
|
88
|
+
File.write(File.join(ROOT, BADGE), "#{JSON.pretty_generate(schemaVersion: 1, label: 'coverage', message: format('%.1f%%', percent), color: color)}\n")
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Configure coverage criteria and filters (in `SimpleCov.start` or `SimpleCov.collate` block)
|
|
92
|
+
# Branch coverage is measured in addition to line coverage (shown in the report, the badge shows lines).
|
|
93
|
+
# @param config [SimpleCov] Receiver of the configuration block
|
|
94
|
+
def filters(config)
|
|
95
|
+
config.enable_coverage(:branch)
|
|
96
|
+
config.skip do |source_file|
|
|
97
|
+
source_file.lines.each do |line|
|
|
98
|
+
line.skipped! if NO_COV_FUNCTIONS.any? { |i| line.src.include?(i) }
|
|
99
|
+
end
|
|
100
|
+
false
|
|
101
|
+
end
|
|
102
|
+
NO_COV_PATHS.each { |path| config.skip(path) }
|
|
32
103
|
end
|
|
33
|
-
false
|
|
34
104
|
end
|
|
35
|
-
# no coverage in these files
|
|
36
|
-
add_filter 'lib/aspera/keychain/macos_security.rb'
|
|
37
|
-
add_filter 'lib/aspera/assert.rb'
|
|
38
105
|
end
|
|
39
106
|
end
|
|
107
|
+
|
|
108
|
+
# Start coverage when this file is loaded, if enabled: must be required before any other library
|
|
109
|
+
Aspera::Coverage.start if ENV.key?('ENABLE_COVERAGE')
|