aspera-cli 4.28.0 → 4.29.1
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 +217 -2
- data/CODE_OF_CONDUCT.md +18 -0
- data/CONTRIBUTING.md +135 -56
- data/GOVERNANCE.md +30 -0
- data/LICENSE +201 -0
- data/README.md +122 -26
- data/SECURITY.md +84 -0
- data/bin/ascli +8 -5
- data/bin/asession +9 -6
- data/docs/README.md +1895 -632
- data/docs/test-mcp-with-ai.md +8 -8
- 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 +20 -19
- data/lib/aspera/agent/factory.rb +6 -3
- 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 +7 -4
- data/lib/aspera/api/faspex.rb +16 -9
- data/lib/aspera/api/httpgw.rb +9 -6
- data/lib/aspera/api/node.rb +29 -22
- data/lib/aspera/ascmd.rb +8 -5
- data/lib/aspera/ascp/installation.rb +95 -67
- 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 +370 -0
- data/lib/aspera/ascp/log_locations.rb +163 -0
- data/lib/aspera/ascp/management.rb +16 -8
- data/lib/aspera/ascp/session_errors.rb +217 -0
- data/lib/aspera/assert.rb +4 -0
- data/lib/aspera/cli/ascp_actions.rb +12 -19
- data/lib/aspera/cli/ascp_logs_actions.rb +188 -0
- data/lib/aspera/cli/async_transfer_store.rb +7 -4
- data/lib/aspera/cli/bootstrapper.rb +38 -33
- data/lib/aspera/cli/command_line.rb +63 -8
- data/lib/aspera/cli/command_registry.rb +9 -1
- data/lib/aspera/cli/command_spec.rb +47 -7
- data/lib/aspera/cli/completion/ascli.bash +19 -5
- data/lib/aspera/cli/completion/ascli.fish +13 -2
- data/lib/aspera/cli/completion/ascli.ps1 +31 -9
- data/lib/aspera/cli/completion/ascli.zsh +22 -6
- data/lib/aspera/cli/completion_actions.rb +303 -69
- data/lib/aspera/cli/context.rb +9 -4
- data/lib/aspera/cli/deprecation.rb +5 -2
- data/lib/aspera/cli/error.rb +6 -0
- data/lib/aspera/cli/extended_value.rb +66 -31
- data/lib/aspera/cli/formatter.rb +43 -30
- data/lib/aspera/cli/gem_checker.rb +9 -6
- data/lib/aspera/cli/hints.rb +22 -10
- data/lib/aspera/cli/http.rb +38 -10
- data/lib/aspera/cli/info.rb +12 -7
- data/lib/aspera/cli/mailer.rb +6 -3
- data/lib/aspera/cli/mcp/http_servlet.rb +7 -8
- data/lib/aspera/cli/mcp/secrets.rb +8 -5
- data/lib/aspera/cli/mcp/tool.rb +20 -17
- 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 +77 -18
- data/lib/aspera/cli/options.schema.yaml +641 -80
- data/lib/aspera/cli/parser.rb +71 -35
- data/lib/aspera/cli/plugins/alee.rb +7 -4
- data/lib/aspera/cli/plugins/aoc.rb +248 -37
- data/lib/aspera/cli/plugins/ats.rb +10 -9
- data/lib/aspera/cli/plugins/base.rb +50 -18
- data/lib/aspera/cli/plugins/basic_auth.rb +5 -2
- data/lib/aspera/cli/plugins/config.rb +210 -104
- data/lib/aspera/cli/plugins/console.rb +6 -3
- data/lib/aspera/cli/plugins/cos.rb +8 -4
- data/lib/aspera/cli/plugins/factory.rb +21 -7
- data/lib/aspera/cli/plugins/faspex5.rb +31 -26
- data/lib/aspera/cli/plugins/faspio.rb +7 -5
- data/lib/aspera/cli/plugins/httpgw.rb +7 -4
- data/lib/aspera/cli/plugins/mcp.rb +42 -22
- data/lib/aspera/cli/plugins/node.rb +39 -38
- data/lib/aspera/cli/plugins/oauth.rb +23 -6
- data/lib/aspera/cli/plugins/orchestrator.rb +287 -83
- data/lib/aspera/cli/plugins/preview.rb +72 -45
- data/lib/aspera/cli/plugins/server.rb +66 -14
- data/lib/aspera/cli/plugins/shares.rb +87 -18
- data/lib/aspera/cli/plugins/transferd.rb +228 -0
- data/lib/aspera/cli/poll.rb +236 -0
- data/lib/aspera/cli/preset_actions.rb +144 -30
- data/lib/aspera/cli/preset_manager.rb +113 -35
- data/lib/aspera/cli/prompt.rb +157 -9
- data/lib/aspera/cli/result.rb +12 -8
- data/lib/aspera/cli/runner.rb +89 -48
- data/lib/aspera/cli/secret_finder.rb +4 -1
- data/lib/aspera/cli/security.rb +89 -9
- data/lib/aspera/cli/special_values.rb +4 -1
- data/lib/aspera/cli/sync_actions.rb +15 -10
- data/lib/aspera/cli/table_fitter.rb +3 -0
- data/lib/aspera/cli/terminal_formatter.rb +9 -6
- data/lib/aspera/cli/transfer_actions.rb +11 -8
- data/lib/aspera/cli/transfer_agent.rb +43 -20
- data/lib/aspera/cli/transfer_progress.rb +14 -45
- data/lib/aspera/cli/vault_actions.rb +45 -0
- data/lib/aspera/cli/vault_manager.rb +188 -42
- data/lib/aspera/cli/version.rb +4 -1
- data/lib/aspera/cli/web_secret.rb +12 -10
- data/lib/aspera/cli/wizard.rb +42 -39
- data/lib/aspera/command_line_builder.rb +9 -5
- data/lib/aspera/command_line_converter.rb +4 -1
- data/lib/aspera/coverage.rb +103 -33
- data/lib/aspera/data_repository.rb +4 -1
- data/lib/aspera/dot_container.rb +4 -1
- data/lib/aspera/environment.rb +23 -12
- data/lib/aspera/exec_spec.rb +3 -0
- data/lib/aspera/faspex_gw.rb +13 -9
- data/lib/aspera/faspex_postproc.rb +15 -12
- data/lib/aspera/formatter_interface.rb +4 -1
- data/lib/aspera/graphql.rb +5 -1
- data/lib/aspera/hash_ext.rb +3 -0
- data/lib/aspera/id_generator.rb +20 -5
- data/lib/aspera/inflate.rb +43 -0
- data/lib/aspera/json_rpc/client.rb +6 -5
- data/lib/aspera/json_rpc/version.rb +3 -0
- data/lib/aspera/line_logger.rb +4 -1
- data/lib/aspera/link_header.rb +4 -1
- data/lib/aspera/log.rb +18 -5
- data/lib/aspera/markdown.rb +5 -2
- data/lib/aspera/mime.rb +3 -0
- data/lib/aspera/nagios.rb +6 -4
- data/lib/aspera/node_emulator.rb +15 -13
- data/lib/aspera/oauth/client/base.rb +124 -73
- data/lib/aspera/oauth/client/boot.rb +7 -4
- data/lib/aspera/oauth/client/factory.rb +41 -18
- data/lib/aspera/oauth/client/generic.rb +5 -1
- data/lib/aspera/oauth/client/json_credentials.rb +7 -3
- data/lib/aspera/oauth/client/jwt.rb +6 -3
- data/lib/aspera/oauth/client/shares_web.rb +94 -0
- data/lib/aspera/oauth/client/url_json.rb +7 -3
- data/lib/aspera/oauth/client/web.rb +40 -13
- data/lib/aspera/oauth/server/pkce.rb +6 -5
- data/lib/aspera/orchestrator_workflow_checker.rb +129 -2
- 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 +16 -6
- data/lib/aspera/preview/utils.rb +6 -4
- data/lib/aspera/products/connect.rb +5 -2
- data/lib/aspera/products/desktop.rb +17 -2
- 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 +3 -0
- data/lib/aspera/rest/aspera_errors.rb +4 -1
- data/lib/aspera/rest/call_error.rb +3 -0
- data/lib/aspera/rest/client.rb +45 -34
- data/lib/aspera/rest/error_analyzer.rb +5 -2
- data/lib/aspera/rest/list.rb +8 -4
- data/lib/aspera/rest/parameters.rb +3 -0
- data/lib/aspera/rest/util.rb +8 -5
- data/lib/aspera/rest.rb +9 -6
- data/lib/aspera/schema/IBM Aspera Faspex API-5.0-enhanced.yaml +9 -9
- data/lib/aspera/schema/IBM Aspera Orchestrator API-v1-enhanced.yaml +118 -30
- 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/async_tables.yaml +11 -10
- data/lib/aspera/schema/documentation.rb +8 -2
- data/lib/aspera/schema/reader.rb +7 -0
- data/lib/aspera/schema/registry.rb +44 -28
- data/lib/aspera/schema/transferd-config.schema.json +333 -0
- data/lib/aspera/schema/validator.rb +4 -1
- data/lib/aspera/sealed_hash.rb +150 -0
- data/lib/aspera/secret/hider.rb +213 -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 +112 -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 +5 -2
- 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 +3 -0
- data/lib/aspera/sync/conf.schema.yaml +9 -4
- data/lib/aspera/sync/database.rb +3 -0
- data/lib/aspera/sync/operations.rb +17 -15
- data/lib/aspera/temp_file_manager.rb +8 -4
- 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 +17 -14
- data/lib/aspera/transfer/result.rb +23 -0
- data/lib/aspera/transfer/resumer.rb +6 -4
- data/lib/aspera/transfer/spec.rb +9 -22
- data/lib/aspera/units/decimal.rb +67 -0
- data/lib/aspera/units/duration.rb +109 -0
- data/lib/aspera/uri_reader.rb +64 -9
- data/lib/aspera/web_auth/index.html.erb +6 -2
- 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 +47 -10
- data/lib/aspera/web_page.rb +7 -2
- data/lib/aspera/web_server_simple.rb +6 -3
- data/lib/aspera/yaml.rb +5 -1
- data/llms-install.md +88 -0
- data/llms.txt +87 -0
- data/skills/ascli/SKILL.md +94 -0
- data.tar.gz.sig +0 -0
- metadata +77 -20
- metadata.gz.sig +0 -0
- data/lib/aspera/duration.rb +0 -42
- data/lib/aspera/keychain/base.rb +0 -30
- data/lib/aspera/keychain/encrypted_hash.rb +0 -192
- data/lib/aspera/keychain/factory.rb +0 -58
- data/lib/aspera/keychain/hashicorp_vault.rb +0 -77
- data/lib/aspera/keychain/macos_security.rb +0 -277
- data/lib/aspera/keychain/one_password_api.rb +0 -91
- data/lib/aspera/keychain/one_password_base.rb +0 -39
- data/lib/aspera/keychain/one_password_cli.rb +0 -100
- data/lib/aspera/secret_hider.rb +0 -196
- data/lib/aspera/secret_strength.rb +0 -114
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../assert'
|
|
7
|
+
|
|
8
|
+
module Aspera
|
|
9
|
+
module Units
|
|
10
|
+
# Rates and sizes in decimal units (prefixes `K`, `M`, `G`... x1000, like `ascp`): parsed from user input and formatted for display.
|
|
11
|
+
# Depends only on `aspera/assert`: usable without the CLI.
|
|
12
|
+
module Decimal
|
|
13
|
+
# Decimal prefixes: each one is `KILO` times the previous one
|
|
14
|
+
PREFIX = ['', 'K', 'M', 'G', 'T', 'P'].freeze
|
|
15
|
+
KILO = 1000
|
|
16
|
+
# Multiplier of each prefix, e.g. `'M' => 1_000_000`
|
|
17
|
+
MULTIPLIER = PREFIX.each_with_index.to_h { |prefix, power| [prefix, KILO**power] }.freeze
|
|
18
|
+
# Units of sizes: `B`, `KB`, `MB`...
|
|
19
|
+
BYTE_UNITS = PREFIX.map { |prefix| "#{prefix}B" }.freeze
|
|
20
|
+
# Rate typed by a user: integer with an optional prefix, case ignored
|
|
21
|
+
RATE_INPUT = /\A(\d+)([#{PREFIX.join}])?\z/i
|
|
22
|
+
BITS_PER_BYTE = 8
|
|
23
|
+
private_constant :MULTIPLIER, :BYTE_UNITS, :RATE_INPUT, :BITS_PER_BYTE
|
|
24
|
+
|
|
25
|
+
class << self
|
|
26
|
+
# Parse a human-readable rate (as accepted by async -l) into an integer bps value.
|
|
27
|
+
# Accepted: plain integer (bps), or integer + prefix of `PREFIX`, case ignored, e.g. `k` (x1000), `M` (x1000000), `g` (x1000000000).
|
|
28
|
+
# @param value [String, Integer] e.g. "100m", "500000", "1g", 500000
|
|
29
|
+
# @return [Integer] value in bps
|
|
30
|
+
def rate_string_to_bps(value)
|
|
31
|
+
m = RATE_INPUT.match(value.to_s.strip)
|
|
32
|
+
Aspera.assert(m) { "Invalid rate value: #{value.inspect}. Expected integer with optional suffix #{PREFIX.drop(1).join(', ')} (case ignored)." }
|
|
33
|
+
return m[1].to_i * MULTIPLIER.fetch(m[2].to_s.upcase)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Inverse of `rate_string_to_bps`: the shortest exact text, e.g. `100M`, `1G`, `1500K`, `999`
|
|
37
|
+
# @param bps [Integer] Rate in bits per second
|
|
38
|
+
# @return [String] Rate accepted by `rate_string_to_bps`
|
|
39
|
+
def rate_bps_to_string(bps)
|
|
40
|
+
prefix = PREFIX.reverse.find { |candidate| bps.positive? && (bps % MULTIPLIER[candidate]).zero? } || ''
|
|
41
|
+
"#{bps / MULTIPLIER[prefix]}#{prefix}"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# @param bytes [Integer] Size in bytes
|
|
45
|
+
# @return [String] Size with decimal unit, e.g. `12.3 MB`
|
|
46
|
+
def format_bytes(bytes)
|
|
47
|
+
value = bytes.to_f
|
|
48
|
+
index = 0
|
|
49
|
+
while value >= KILO && index < BYTE_UNITS.length - 1
|
|
50
|
+
value /= KILO
|
|
51
|
+
index += 1
|
|
52
|
+
end
|
|
53
|
+
return "#{bytes} B" if index.zero?
|
|
54
|
+
format('%.1f %s', value, BYTE_UNITS[index])
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# @param bytes_per_second [Float, nil] Rate, `nil` if unknown
|
|
58
|
+
# @return [String] Rate in megabits per second (decimal, like `ascp`)
|
|
59
|
+
def format_rate(bytes_per_second)
|
|
60
|
+
return '-- Mbps' if bytes_per_second.nil?
|
|
61
|
+
mbps = bytes_per_second * BITS_PER_BYTE / MULTIPLIER.fetch('M')
|
|
62
|
+
mbps < 10 ? format('%.2f Mbps', mbps) : format('%.0f Mbps', mbps)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
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 'strscan'
|
|
8
|
+
|
|
9
|
+
module Aspera
|
|
10
|
+
module Units
|
|
11
|
+
# Duration in the format of Aspera Sync (`async` DURATION): parsed from user input and formatted for display.
|
|
12
|
+
# Immutable, kept as an integer number of microseconds.
|
|
13
|
+
class Duration
|
|
14
|
+
include Comparable
|
|
15
|
+
|
|
16
|
+
# Microseconds per unit
|
|
17
|
+
UNIT_US = {'w' => 604_800_000_000, 'd' => 86_400_000_000, 'h' => 3_600_000_000, 'm' => 60_000_000, 's' => 1_000_000, 'ms' => 1_000, 'us' => 1}.freeze
|
|
18
|
+
private_constant :UNIT_US
|
|
19
|
+
|
|
20
|
+
# @param value [Numeric, String] Number of `unit`, or text parsed (a plain number in text is seconds, whatever `unit`)
|
|
21
|
+
# @param unit [String] Time unit of a `Numeric` value, e.g. `ms`
|
|
22
|
+
# @raise [ParameterError] if the text is invalid
|
|
23
|
+
def initialize(value, unit = 's')
|
|
24
|
+
@microseconds =
|
|
25
|
+
if value.is_a?(Numeric)
|
|
26
|
+
(value * unit_us(unit)).round
|
|
27
|
+
else
|
|
28
|
+
Aspera.assert_type(value, String) { 'duration' }
|
|
29
|
+
parse_us(value)
|
|
30
|
+
end
|
|
31
|
+
freeze
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @return [Integer] Duration in microseconds
|
|
35
|
+
attr_reader :microseconds
|
|
36
|
+
|
|
37
|
+
# @param unit [String] Time unit of result, e.g. `ms`
|
|
38
|
+
# @return [Integer] Duration in `unit`, rounded down
|
|
39
|
+
def to_unit(unit)
|
|
40
|
+
@microseconds / unit_us(unit)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# @return [String] Duration as `1h02m03s`, `2m03s` or `3s` (seconds rounded), accepted by {#initialize}
|
|
44
|
+
def to_s
|
|
45
|
+
seconds = rounded_seconds
|
|
46
|
+
return "#{seconds}s" if seconds < 60
|
|
47
|
+
hours, rest = seconds.divmod(3600)
|
|
48
|
+
minutes, secs = rest.divmod(60)
|
|
49
|
+
hours.positive? ? format('%dh%02dm%02ds', hours, minutes, secs) : format('%dm%02ds', minutes, secs)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# @return [String] Duration as `hh:mm:ss` (seconds rounded)
|
|
53
|
+
def to_hms
|
|
54
|
+
seconds = rounded_seconds
|
|
55
|
+
format('%02d:%02d:%02d', seconds / 3600, (seconds / 60) % 60, seconds % 60)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def <=>(other)
|
|
59
|
+
return unless other.is_a?(Duration)
|
|
60
|
+
@microseconds <=> other.microseconds
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def eql?(other)
|
|
64
|
+
other.is_a?(Duration) && @microseconds.eql?(other.microseconds)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def hash
|
|
68
|
+
@microseconds.hash
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
# @param unit [String] Time unit
|
|
74
|
+
# @return [Integer] Microseconds per unit
|
|
75
|
+
def unit_us(unit)
|
|
76
|
+
Aspera.assert_values(unit, UNIT_US.keys) { 'duration unit' }
|
|
77
|
+
UNIT_US[unit]
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# @param value [String] `DDd HH:MM:SS.mmm` or `NNw NNd NNh NNm NNs NNms NNus`, leading fields and spaces may be omitted, a plain number is seconds
|
|
81
|
+
# @return [Integer] Duration in microseconds
|
|
82
|
+
# @raise [ParameterError] if the duration is invalid
|
|
83
|
+
def parse_us(value)
|
|
84
|
+
value = value.delete(' ')
|
|
85
|
+
if (m = value.match(/\A(?:(\d+)d)?(?:(?:(\d+):)?(\d+):)?(\d+)(?:\.(\d{1,3}))?\z/))
|
|
86
|
+
days, hours, minutes, seconds, millis = m.captures
|
|
87
|
+
hours = (days.to_i * 24) + hours.to_i
|
|
88
|
+
minutes = (hours * 60) + minutes.to_i
|
|
89
|
+
seconds = (minutes * 60) + seconds.to_i
|
|
90
|
+
return (seconds * UNIT_US['s']) + (millis.to_s.ljust(3, '0').to_i * UNIT_US['ms'])
|
|
91
|
+
end
|
|
92
|
+
# anchored sequential matching (linear time, no backtracking over start positions)
|
|
93
|
+
scanner = StringScanner.new(value)
|
|
94
|
+
units = []
|
|
95
|
+
until scanner.eos?
|
|
96
|
+
Aspera.assert(scanner.scan(/(\d+)(ms|us|[wdhms])/), type: ParameterError) { "Invalid duration: #{value}" } # cspell:disable-line
|
|
97
|
+
units.push([scanner[1], scanner[2]])
|
|
98
|
+
end
|
|
99
|
+
Aspera.assert(!units.empty?, type: ParameterError) { "Invalid duration: #{value}" }
|
|
100
|
+
units.sum { |number, number_unit| number.to_i * UNIT_US[number_unit] }
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# @return [Integer] Duration in seconds, rounded
|
|
104
|
+
def rounded_seconds
|
|
105
|
+
(@microseconds.to_r / UNIT_US['s']).round
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
data/lib/aspera/uri_reader.rb
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'assert'
|
|
7
|
+
require_relative 'log'
|
|
8
|
+
require_relative 'rest'
|
|
9
|
+
require_relative 'temp_file_manager'
|
|
3
10
|
require 'uri'
|
|
4
11
|
require 'base64'
|
|
5
|
-
require 'aspera/assert'
|
|
6
|
-
require 'aspera/rest'
|
|
7
|
-
require 'aspera/temp_file_manager'
|
|
8
12
|
|
|
9
13
|
module Aspera
|
|
10
14
|
# Read content from a URI; supported schemes: file:, http:, https:, data:
|
|
@@ -25,13 +29,15 @@ module Aspera
|
|
|
25
29
|
# The canonical form built by {file_url} uses the `file:///` prefix.
|
|
26
30
|
module UriReader
|
|
27
31
|
SCHEME_FILE = 'file'
|
|
28
|
-
SCHEME_FILE_PFX1 = "#{SCHEME_FILE}:"
|
|
32
|
+
SCHEME_FILE_PFX1 = "#{SCHEME_FILE}:".freeze
|
|
29
33
|
# Canonical prefix for file: URLs (no host, three slashes).
|
|
30
34
|
# What follows is the literal path: relative or absolute (starting with a second slash).
|
|
31
|
-
SCHEME_FILE_PFX2 = "#{SCHEME_FILE_PFX1}///"
|
|
32
|
-
|
|
35
|
+
SCHEME_FILE_PFX2 = "#{SCHEME_FILE_PFX1}///".freeze
|
|
36
|
+
# Timeout in seconds when another URL remains to be tried
|
|
37
|
+
FAIL_FAST_TIMEOUT = 10
|
|
38
|
+
private_constant :SCHEME_FILE, :SCHEME_FILE_PFX1, :SCHEME_FILE_PFX2, :FAIL_FAST_TIMEOUT
|
|
33
39
|
class << self
|
|
34
|
-
# @return [Boolean] true if `url` uses the file: scheme
|
|
40
|
+
# @return [Boolean] true if `url` uses the file: scheme recognized by this module
|
|
35
41
|
def file?(url)
|
|
36
42
|
url.start_with?(SCHEME_FILE_PFX1)
|
|
37
43
|
end
|
|
@@ -64,13 +70,16 @@ module Aspera
|
|
|
64
70
|
# Bare paths (no scheme) are passed to File.read directly; leading `/~/`, `/./`, `/../`
|
|
65
71
|
# are expanded via `File.expand_path` after stripping the synthetic leading slash added by
|
|
66
72
|
# URI.
|
|
67
|
-
|
|
73
|
+
# @param uri_to_read [String] URI to read
|
|
74
|
+
# @param headers [Hash{String => String}] Additional HTTP request headers (schemes `http` and `https` only)
|
|
75
|
+
# @return [String] content
|
|
76
|
+
def read(uri_to_read, headers: {})
|
|
68
77
|
# Handle file: URLs directly to honour the file:///relative vs file:////absolute convention.
|
|
69
78
|
return File.read(file_path(uri_to_read)) if file?(uri_to_read)
|
|
70
79
|
uri = URI.parse(uri_to_read)
|
|
71
80
|
case uri.scheme
|
|
72
81
|
when 'http', 'https'
|
|
73
|
-
return Rest::Client.new(base_url: uri_to_read, redirect_max: 5).read(nil, headers: {'Accept' => '*/*'})
|
|
82
|
+
return Rest::Client.new(base_url: uri_to_read, redirect_max: 5).read(nil, headers: {'Accept' => '*/*'}.merge(headers))
|
|
74
83
|
when 'data'
|
|
75
84
|
metadata, encoded_data = uri.opaque.split(',', 2)
|
|
76
85
|
if metadata.end_with?(';base64')
|
|
@@ -87,6 +96,52 @@ module Aspera
|
|
|
87
96
|
end
|
|
88
97
|
end
|
|
89
98
|
|
|
99
|
+
# Read URL with a short timeout and no retry (temporarily changes global HTTP parameters)
|
|
100
|
+
# @param url [String] URL to read
|
|
101
|
+
# @param read_options [Hash] Options of {read} (e.g. `headers`)
|
|
102
|
+
# @return [String] content
|
|
103
|
+
def read_fail_fast(url, **read_options)
|
|
104
|
+
parameters = Rest::Parameters.instance
|
|
105
|
+
session_cb = parameters.session_cb
|
|
106
|
+
retry_max = parameters.retry_max
|
|
107
|
+
parameters.retry_max = 0
|
|
108
|
+
parameters.session_cb = lambda do |http_session|
|
|
109
|
+
session_cb&.call(http_session)
|
|
110
|
+
http_session.open_timeout = [http_session.open_timeout, FAIL_FAST_TIMEOUT].compact.min
|
|
111
|
+
http_session.read_timeout = [http_session.read_timeout, FAIL_FAST_TIMEOUT].compact.min
|
|
112
|
+
end
|
|
113
|
+
read(url, **read_options)
|
|
114
|
+
ensure
|
|
115
|
+
parameters.session_cb = session_cb
|
|
116
|
+
parameters.retry_max = retry_max
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Read the first URL that provides valid content.
|
|
120
|
+
# All but the last URL are read with a short timeout and no retry, so that fallback is quick.
|
|
121
|
+
# On failure of a URL (read error, or validation error), a warning is logged and the next URL is tried.
|
|
122
|
+
# The failure of the last URL is raised.
|
|
123
|
+
# @param urls [Array<String>] URLs, in order of preference
|
|
124
|
+
# @param what [String] description of the content, for messages
|
|
125
|
+
# @param read_options [Hash] Options of {read} (e.g. `headers`)
|
|
126
|
+
# @yield [content] Optional: validates and converts content, shall raise on invalid content
|
|
127
|
+
# @yieldparam content [String] content read
|
|
128
|
+
# @yieldreturn [Object] value returned by this method
|
|
129
|
+
# @return [Object] result of block if given, else content
|
|
130
|
+
def read_first(urls, what: 'content', **read_options)
|
|
131
|
+
Aspera.assert(!urls.empty?) { "no URL for #{what}" }
|
|
132
|
+
urls.each_with_index do |url, index|
|
|
133
|
+
last = index.eql?(urls.length - 1)
|
|
134
|
+
Log.log.debug { "Retrieving #{what} from #{url}" }
|
|
135
|
+
begin
|
|
136
|
+
content = last ? read(url, **read_options) : read_fail_fast(url, **read_options)
|
|
137
|
+
return block_given? ? yield(content) : content
|
|
138
|
+
rescue StandardError => e
|
|
139
|
+
raise if last
|
|
140
|
+
Log.log.warn { "Failed to retrieve #{what} from #{url}: #{e.message}, trying next" }
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
90
145
|
# Return the local file-system path for the content at `url`, downloading to a temp file if needed.
|
|
91
146
|
# For file: URLs the path is extracted directly (no download).
|
|
92
147
|
# For data: and http(s): URLs the content is written to a temporary file and its path is returned.
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
</svg>
|
|
6
6
|
</div>
|
|
7
7
|
|
|
8
|
-
<h1>Authentication
|
|
9
|
-
<p>
|
|
8
|
+
<h1>Authentication Received</h1>
|
|
9
|
+
<p>Return to your terminal: it completes the login and shows the result. You can then close this window.</p>
|
|
10
10
|
|
|
11
11
|
<% unless additional_info.to_s.empty? %>
|
|
12
12
|
<div class="info-box">
|
|
@@ -14,3 +14,7 @@
|
|
|
14
14
|
</div>
|
|
15
15
|
<% end %>
|
|
16
16
|
|
|
17
|
+
<%# The callback URL may contain a code or tokens: remove the query from the address bar and from the entry of the session history %>
|
|
18
|
+
<script>
|
|
19
|
+
if (window.history && history.replaceState) history.replaceState(null, '', location.pathname);
|
|
20
|
+
</script>
|
|
@@ -0,0 +1,109 @@
|
|
|
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_relative '../log'
|
|
8
|
+
require_relative '../cli/prompt'
|
|
9
|
+
require_relative '../cli/info'
|
|
10
|
+
require_relative '../sealed_hash'
|
|
11
|
+
require_relative '../rainbow'
|
|
12
|
+
require 'uri'
|
|
13
|
+
using Rainbow
|
|
14
|
+
|
|
15
|
+
module Aspera
|
|
16
|
+
module WebAuth
|
|
17
|
+
# Receives the result of a web login from the user, who gives it in the terminal.
|
|
18
|
+
# No server is started: used when the browser cannot reach the loopback address of this host (e.g. SSH session, without tunnel).
|
|
19
|
+
# The user gives either:
|
|
20
|
+
# - a code (`SealedHash`) shown by the browser of the workstation, after `ascli config web_login <code>` (`ascli` is installed there)
|
|
21
|
+
# - the URL the browser was redirected to (it shows a connection error), or its query
|
|
22
|
+
# Same interface as `Server` for the part used by OAuth clients: `received_request`.
|
|
23
|
+
class Paste
|
|
24
|
+
class << self
|
|
25
|
+
# Extract the query parameters from what the user pasted
|
|
26
|
+
# @param input [String] Code, or full redirect URL, or the query only (with or without leading `?`)
|
|
27
|
+
# @return [Hash{String=>String}] Query parameters, includes a non-empty `state`
|
|
28
|
+
# @raise [ParameterError] if the input has no query, or no `state`
|
|
29
|
+
def parse(input)
|
|
30
|
+
text = input.to_s.strip
|
|
31
|
+
raise ParameterError, 'Nothing was pasted' if text.empty?
|
|
32
|
+
params =
|
|
33
|
+
if SealedHash.sealed?(text)
|
|
34
|
+
data = SealedHash.unseal(text, base_key: Cli::Info::CMD_NAME)
|
|
35
|
+
raise ParameterError, 'This code is for ascli on the workstation: paste the code shown by the browser after login' if data.key?('login_url')
|
|
36
|
+
data
|
|
37
|
+
else
|
|
38
|
+
parse_query(text)
|
|
39
|
+
end
|
|
40
|
+
raise ParameterError, 'No "state" found in what was pasted' if params['state'].to_s.empty?
|
|
41
|
+
params
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
# @param text [String] Full redirect URL, or query
|
|
47
|
+
# @return [Hash{String=>String}]
|
|
48
|
+
def parse_query(text)
|
|
49
|
+
# fragment is not sent to a server, ignore it
|
|
50
|
+
text = text.sub(/#.*\z/m, '')
|
|
51
|
+
query =
|
|
52
|
+
if text.match?(%r{\A[a-z][a-z0-9+.-]*://}i)
|
|
53
|
+
URI.parse(text).query.to_s
|
|
54
|
+
else
|
|
55
|
+
text.delete_prefix('?')
|
|
56
|
+
end
|
|
57
|
+
raise ParameterError, 'No query found in pasted URL: copy the full URL from the address bar of the browser' if query.empty?
|
|
58
|
+
URI.decode_www_form(query).to_h
|
|
59
|
+
rescue URI::InvalidURIError, ArgumentError => e
|
|
60
|
+
raise ParameterError, "Pasted text is not a valid code, URL or query: #{e.message}"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# @param redirect_uri [String] Loopback URL registered for the login (the browser fails to connect to it)
|
|
65
|
+
# @param login_url [String, nil] URL of the login page: if set, a code is given to the user for `ascli` on the workstation
|
|
66
|
+
# @param reply_keys [Array, nil] Keys of the query needed to continue (with `login_url`)
|
|
67
|
+
def initialize(redirect_uri, login_url: nil, reply_keys: nil)
|
|
68
|
+
@redirect_uri = redirect_uri
|
|
69
|
+
@login_url = login_url
|
|
70
|
+
@reply_keys = reply_keys
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# @return [Boolean] true if the message given to the user contains the login URL (so it shall not be displayed separately)
|
|
74
|
+
def shows_login_url?
|
|
75
|
+
!@login_url.nil?
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Ask the user for the code, or the URL the browser was redirected to
|
|
79
|
+
# Input is not echoed on a terminal: it contains an authorization code or tokens.
|
|
80
|
+
# @return [Hash{String=>String}] The query
|
|
81
|
+
def received_request
|
|
82
|
+
Log.log.warn do
|
|
83
|
+
browser_steps = [
|
|
84
|
+
"The browser shows a connection error on #{@redirect_uri}: this is expected.",
|
|
85
|
+
'Copy the full URL from the address bar of the browser, and paste it in the prompt below.'
|
|
86
|
+
]
|
|
87
|
+
if @login_url.nil?
|
|
88
|
+
(['USER ACTION: Log in with the web browser, then:'] + browser_steps.map { |s| " - #{s}" }).join("\n")
|
|
89
|
+
else
|
|
90
|
+
code = SealedHash.seal({'login_url' => @login_url.to_s, 'redirect_uri' => @redirect_uri, 'reply_keys' => @reply_keys}, base_key: Cli::Info::CMD_NAME)
|
|
91
|
+
[
|
|
92
|
+
'USER ACTION: To continue, choose one of these two ways:',
|
|
93
|
+
" 1. With any browser (#{Cli::Info::CMD_NAME} is not needed on the workstation):",
|
|
94
|
+
' - Open this URL in a browser and log in:',
|
|
95
|
+
" #{@login_url.to_s.red}",
|
|
96
|
+
*browser_steps.map { |s| " - #{s}" },
|
|
97
|
+
" 2. If #{Cli::Info::CMD_NAME} is installed on the workstation that has the browser:",
|
|
98
|
+
' - Run there:',
|
|
99
|
+
" #{Cli::Info::CMD_NAME} config web_login #{code}",
|
|
100
|
+
' - Log in in the page that opens.',
|
|
101
|
+
' - Copy the code shown by the browser, and paste it in the prompt below.'
|
|
102
|
+
].join("\n")
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
self.class.parse(Cli::Prompt.prompt_user_input('Code or URL', sensitive: true))
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'server'
|
|
7
|
+
require_relative 'paste'
|
|
8
|
+
require_relative '../environment'
|
|
9
|
+
require_relative '../log'
|
|
10
|
+
|
|
11
|
+
module Aspera
|
|
12
|
+
module WebAuth
|
|
13
|
+
class << self
|
|
14
|
+
# Create the object that receives the result of a web login, according to `Environment#web_auth` (option `ui.web_auth`):
|
|
15
|
+
# `:port` listens on the loopback address of `redirect_uri`, `:paste` asks the user to give the result in the terminal.
|
|
16
|
+
# Both provide `received_request`.
|
|
17
|
+
# @param redirect_uri [String] Loopback URL that receives the result
|
|
18
|
+
# @param additional_info [String] Information in web page (only with `:port`)
|
|
19
|
+
# @param login_url [String, URI] URL of the login page: with `:paste`, a code for `ascli` on the workstation is given to the user,
|
|
20
|
+
# unless the browser is started by `ascli` (the user has no time to use the code, and the browser is local)
|
|
21
|
+
# @param reply_keys [Array<String>] Keys of the query that the client needs (with `login_url`)
|
|
22
|
+
# @return [Server, Paste]
|
|
23
|
+
def receiver(redirect_uri, additional_info = nil, login_url: nil, reply_keys: nil)
|
|
24
|
+
env = Environment.instance
|
|
25
|
+
case env.web_auth
|
|
26
|
+
when :paste
|
|
27
|
+
login_url = nil if env.browser_command || env.url_method.eql?(:graphical)
|
|
28
|
+
Paste.new(redirect_uri, login_url: login_url, reply_keys: reply_keys)
|
|
29
|
+
when :port
|
|
30
|
+
if env.url_method.eql?(:text) && env.browser_command.nil? && (ENV.key?('SSH_CONNECTION') || ENV.key?('SSH_TTY'))
|
|
31
|
+
Log.log.warn do
|
|
32
|
+
"Web login: the browser must reach port #{URI.parse(redirect_uri).port} of this host (SSH tunnel). " \
|
|
33
|
+
'If not possible, use option --ui.web_auth=paste'
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
Server.new(redirect_uri, additional_info)
|
|
37
|
+
else Aspera.error_unexpected_value(env.web_auth) { 'ui.web_auth' }
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Let the user open the login page, unless the receiver already gives the URL in its own message
|
|
42
|
+
# @param login_receiver [Server, Paste] Result of `receiver`
|
|
43
|
+
# @param login_url [String, URI] URL of the login page
|
|
44
|
+
def open_login_page(login_receiver, login_url)
|
|
45
|
+
return if login_receiver.is_a?(Paste) && login_receiver.shows_login_url?
|
|
46
|
+
Environment.instance.open_uri(login_url)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'server'
|
|
7
|
+
require_relative '../web_server_simple'
|
|
8
|
+
require_relative '../environment'
|
|
9
|
+
require_relative '../assert'
|
|
10
|
+
require 'uri'
|
|
11
|
+
|
|
12
|
+
module Aspera
|
|
13
|
+
module WebAuth
|
|
14
|
+
# Login on the workstation that has the browser, for `ascli` that runs on another host (option `ui.web_auth=paste`).
|
|
15
|
+
# The remote `ascli` gives a code (`SealedHash`) with the URL of the login page, the loopback URL to which the browser is redirected,
|
|
16
|
+
# and the keys of the reply. Here, a local server receives the redirection, and the page shown in the browser gives a code (type reply)
|
|
17
|
+
# to paste in the terminal of the remote `ascli`.
|
|
18
|
+
module Relay
|
|
19
|
+
# @!attribute [r] login_url
|
|
20
|
+
# @return [URI] URL of the login page (https)
|
|
21
|
+
# @!attribute [r] redirect_uri
|
|
22
|
+
# @return [String] Loopback URL to which the browser is redirected
|
|
23
|
+
# @!attribute [r] reply_keys
|
|
24
|
+
# @return [Array<String>] Keys of the query that are given to the remote `ascli`
|
|
25
|
+
# @!attribute [r] host
|
|
26
|
+
# @return [String] Host of the login page, calculated here (not given by the remote `ascli`)
|
|
27
|
+
Login = Struct.new(:login_url, :redirect_uri, :reply_keys, :host, keyword_init: true)
|
|
28
|
+
# Keys of the reply are names of query parameters
|
|
29
|
+
REPLY_KEY_REGEX = /\A[a-z][a-z0-9_]{0,63}\z/
|
|
30
|
+
MAX_REPLY_KEYS = 16
|
|
31
|
+
private_constant :REPLY_KEY_REGEX, :MAX_REPLY_KEYS
|
|
32
|
+
|
|
33
|
+
class << self
|
|
34
|
+
# The code comes from another host, or from a message: its content is checked.
|
|
35
|
+
# @param data [Hash] Content of a code of type login: `login_url`, `redirect_uri`, `reply_keys`
|
|
36
|
+
# @return [Login]
|
|
37
|
+
# @raise [ParameterError] if content is not acceptable
|
|
38
|
+
def parse(data)
|
|
39
|
+
Aspera.assert_type(data, Hash, type: ParameterError) { 'login code' }
|
|
40
|
+
login_url = parse_uri(data['login_url'], 'login_url')
|
|
41
|
+
raise ParameterError, "URL of the login page shall be https: #{login_url.scheme}://#{login_url.host}" unless login_url.scheme.eql?('https')
|
|
42
|
+
raise ParameterError, 'URL of the login page has no host' if login_url.host.to_s.empty?
|
|
43
|
+
redirect = parse_uri(data['redirect_uri'], 'redirect_uri')
|
|
44
|
+
raise ParameterError, "redirect_uri shall be http or https, with a port: #{redirect}" unless %w[http https].include?(redirect.scheme) && redirect.port
|
|
45
|
+
raise ParameterError, "redirect_uri host shall be loopback (localhost, 127.0.0.0/8, ::1): #{redirect.host}" unless WebServerSimple.loopback?(redirect.hostname.to_s)
|
|
46
|
+
keys = data['reply_keys']
|
|
47
|
+
valid_keys = keys.is_a?(Array) && !keys.empty? && keys.length <= MAX_REPLY_KEYS && keys.all? { |key| key.is_a?(String) && key.match?(REPLY_KEY_REGEX) }
|
|
48
|
+
raise ParameterError, 'reply_keys shall be a list of parameter names' unless valid_keys
|
|
49
|
+
Login.new(login_url: login_url, redirect_uri: redirect.to_s, reply_keys: keys, host: login_url.host.downcase)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Open the login page, receive the redirection, and show the code to the user in the browser.
|
|
53
|
+
# @param login [Login] Result of `parse`
|
|
54
|
+
# @return [nil]
|
|
55
|
+
def run(login)
|
|
56
|
+
server = Server.new(login.redirect_uri, "#{login.host} - login for ascli on another host", reply_keys: login.reply_keys)
|
|
57
|
+
Environment.instance.open_uri(login.login_url)
|
|
58
|
+
server.received_request
|
|
59
|
+
# the page that gives the code is sent after the request is received: wait for it before ending
|
|
60
|
+
server.wait_stopped
|
|
61
|
+
nil
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
# @return [URI]
|
|
67
|
+
def parse_uri(value, name)
|
|
68
|
+
raise ParameterError, "#{name} is missing" unless value.is_a?(String) && !value.empty?
|
|
69
|
+
URI.parse(value)
|
|
70
|
+
rescue URI::InvalidURIError => e
|
|
71
|
+
raise ParameterError, "#{name} is not a valid URL: #{e.message}"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|