aspera-cli 4.28.0 → 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 +143 -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 +103 -26
- data/SECURITY.md +70 -0
- data/bin/ascli +8 -5
- data/bin/asession +9 -6
- data/docs/README.md +1633 -609
- 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 +20 -20
- data/lib/aspera/ascmd.rb +8 -5
- data/lib/aspera/ascp/installation.rb +71 -65
- 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 +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 +176 -0
- data/lib/aspera/cli/async_transfer_store.rb +7 -4
- data/lib/aspera/cli/bootstrapper.rb +37 -33
- data/lib/aspera/cli/command_line.rb +24 -6
- data/lib/aspera/cli/command_registry.rb +6 -1
- data/lib/aspera/cli/command_spec.rb +34 -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 +3 -0
- data/lib/aspera/cli/extended_value.rb +61 -27
- data/lib/aspera/cli/formatter.rb +29 -22
- data/lib/aspera/cli/gem_checker.rb +9 -6
- data/lib/aspera/cli/hints.rb +22 -10
- data/lib/aspera/cli/http.rb +12 -9
- 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 +15 -14
- 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 +65 -12
- data/lib/aspera/cli/options.schema.yaml +487 -63
- data/lib/aspera/cli/parser.rb +56 -32
- data/lib/aspera/cli/plugins/alee.rb +7 -4
- data/lib/aspera/cli/plugins/aoc.rb +244 -35
- data/lib/aspera/cli/plugins/ats.rb +9 -8
- data/lib/aspera/cli/plugins/base.rb +17 -12
- data/lib/aspera/cli/plugins/basic_auth.rb +5 -2
- data/lib/aspera/cli/plugins/config.rb +198 -103
- 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 +28 -25
- 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 +28 -22
- data/lib/aspera/cli/plugins/node.rb +31 -30
- data/lib/aspera/cli/plugins/oauth.rb +5 -1
- data/lib/aspera/cli/plugins/orchestrator.rb +272 -72
- data/lib/aspera/cli/plugins/preview.rb +69 -44
- data/lib/aspera/cli/plugins/server.rb +63 -11
- data/lib/aspera/cli/plugins/shares.rb +86 -16
- data/lib/aspera/cli/plugins/transferd.rb +223 -0
- data/lib/aspera/cli/preset_actions.rb +144 -30
- data/lib/aspera/cli/preset_manager.rb +52 -18
- data/lib/aspera/cli/prompt.rb +4 -1
- data/lib/aspera/cli/result.rb +12 -8
- data/lib/aspera/cli/runner.rb +69 -46
- data/lib/aspera/cli/secret_finder.rb +4 -1
- data/lib/aspera/cli/security.rb +79 -9
- 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 +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 +29 -20
- 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 +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/duration.rb +5 -2
- data/lib/aspera/environment.rb +21 -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 +4 -2
- 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 +91 -70
- data/lib/aspera/oauth/client/boot.rb +7 -4
- data/lib/aspera/oauth/client/factory.rb +6 -3
- data/lib/aspera/oauth/client/generic.rb +5 -1
- data/lib/aspera/oauth/client/json_credentials.rb +4 -1
- data/lib/aspera/oauth/client/jwt.rb +6 -3
- data/lib/aspera/oauth/client/shares_web.rb +85 -0
- data/lib/aspera/oauth/client/url_json.rb +4 -1
- data/lib/aspera/oauth/client/web.rb +39 -12
- data/lib/aspera/oauth/server/pkce.rb +6 -5
- data/lib/aspera/orchestrator_workflow_checker.rb +119 -1
- 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 +8 -4
- 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 +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 +22 -29
- 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 +43 -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 +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 +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 +16 -14
- 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 +3 -0
- data/lib/aspera/transfer/resumer.rb +6 -4
- data/lib/aspera/transfer/spec.rb +9 -22
- data/lib/aspera/transfer/units.rb +75 -0
- data/lib/aspera/uri_reader.rb +57 -7
- 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.txt +81 -0
- data/skills/ascli/SKILL.md +88 -0
- data.tar.gz.sig +0 -0
- metadata +72 -19
- metadata.gz.sig +0 -0
- 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,610 @@
|
|
|
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 '../environment'
|
|
9
|
+
require_relative '../yaml'
|
|
10
|
+
require_relative '../secret/hider'
|
|
11
|
+
require_relative '../schema/registry'
|
|
12
|
+
require_relative '../schema/validator'
|
|
13
|
+
require 'json'
|
|
14
|
+
require 'securerandom'
|
|
15
|
+
require 'etc'
|
|
16
|
+
require 'fileutils'
|
|
17
|
+
require 'socket'
|
|
18
|
+
|
|
19
|
+
module Aspera
|
|
20
|
+
module Products
|
|
21
|
+
# Run the transfer daemon as a system service: configuration of `transferd.json` and systemd unit
|
|
22
|
+
class TransferdService
|
|
23
|
+
# Number of random bytes of a generated API key
|
|
24
|
+
API_KEY_BYTES = 32
|
|
25
|
+
DEFAULT_SERVICE_NAME = 'aspera-transferd'
|
|
26
|
+
DEFAULT_USER = 'asperadaemon'
|
|
27
|
+
DEFAULT_UNIT_DIR = '/etc/systemd/system'
|
|
28
|
+
DEFAULT_AFTER = ['network.target'].freeze
|
|
29
|
+
# Default location of the configuration file, also the default of the daemon
|
|
30
|
+
CONFIG_FILE = '/etc/transferd/transferd.json'
|
|
31
|
+
# Environment variables of the daemon that override the configuration file
|
|
32
|
+
ENV_OVERRIDES = %w[TRANSFERD_ADDRESS TRANSFERD_PORT TRANSFERD_MGMT_ADDRESS TRANSFERD_MGMT_PORT].freeze
|
|
33
|
+
# Mode of files that may contain a secret, and of the folder of the configuration
|
|
34
|
+
FILE_MODE = 0o640
|
|
35
|
+
DIR_MODE = 0o750
|
|
36
|
+
# Seconds between two checks of the port
|
|
37
|
+
WAIT_INTERVAL = 0.5
|
|
38
|
+
# Keys of `transferd.json` that contain a secret
|
|
39
|
+
SECRET_KEYS = %w[api_key].freeze
|
|
40
|
+
# Name of the link to the version in use, in the layout `<prefix>/<version>`
|
|
41
|
+
CURRENT_LINK = 'current'
|
|
42
|
+
# Name of the folder of a version in the layout
|
|
43
|
+
VERSION_PATTERN = /\A\d+(\.\d+)*\z/
|
|
44
|
+
private_constant :API_KEY_BYTES, :FILE_MODE, :DIR_MODE, :WAIT_INTERVAL, :SECRET_KEYS, :VERSION_PATTERN
|
|
45
|
+
|
|
46
|
+
# Access to the system: root folder, commands and network. Replaceable in tests.
|
|
47
|
+
class Host
|
|
48
|
+
# @return [String] Root folder: all files are written below it (`/` for a real installation)
|
|
49
|
+
# @return [Numeric] Seconds to wait for the daemon to listen
|
|
50
|
+
# @return [Symbol] Operating system, see `Environment::OS_*`
|
|
51
|
+
# @return [Integer] Effective user id of the process
|
|
52
|
+
attr_reader :root, :timeout, :os, :euid
|
|
53
|
+
|
|
54
|
+
# @param root [String] Root folder of the file system
|
|
55
|
+
# @param runner [#call] Receives the command words, returns `[output, success]`, default: run the command
|
|
56
|
+
# @param listening [#call] Receives address and port, returns `true` if a server listens, default: try to connect
|
|
57
|
+
# @param timeout [Numeric] Seconds to wait for the daemon to listen
|
|
58
|
+
# @param os [Symbol] Operating system, default: the current one
|
|
59
|
+
# @param euid [Integer] Effective user id, default: the one of the process
|
|
60
|
+
# @param systemctl [Boolean] `true` if `systemctl` is available, default: look for it in `PATH`
|
|
61
|
+
def initialize(root: '/', runner: nil, listening: nil, timeout: 30, os: nil, euid: nil, systemctl: nil)
|
|
62
|
+
@root = root
|
|
63
|
+
@os = os || Environment.instance.os
|
|
64
|
+
@euid = euid || ::Process.euid
|
|
65
|
+
@systemctl = systemctl.nil? ? ENV.fetch('PATH', '').split(File::PATH_SEPARATOR).any? { |dir| File.executable?(File.join(dir, 'systemctl')) } : systemctl
|
|
66
|
+
@runner = runner || lambda do |*cmd|
|
|
67
|
+
out, err, status = Environment.secure_execute(*cmd, mode: :capture, exception: false)
|
|
68
|
+
[out.to_s + err.to_s, status.success?]
|
|
69
|
+
end
|
|
70
|
+
@listening = listening || lambda do |address, port|
|
|
71
|
+
Socket.tcp(address, port, connect_timeout: 1) { true }
|
|
72
|
+
rescue SystemCallError, IOError
|
|
73
|
+
false
|
|
74
|
+
end
|
|
75
|
+
@timeout = timeout
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# @param path [String] Absolute path in the real file system
|
|
79
|
+
# @return [String] Path below the root folder
|
|
80
|
+
def path(path)
|
|
81
|
+
File.join(@root, path)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# @param cmd [Array<String>] Command to run
|
|
85
|
+
# @return [Array(String, Boolean)] Output and success
|
|
86
|
+
def run(*cmd)
|
|
87
|
+
@runner.call(*cmd)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# @return [Boolean] `true` if a server listens on this address and port
|
|
91
|
+
def listening?(address, port)
|
|
92
|
+
@listening.call(address, port)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# @return [Boolean] `true` if `systemctl` is available
|
|
96
|
+
def systemctl?
|
|
97
|
+
@systemctl
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
class << self
|
|
102
|
+
# Generate the text of the systemd unit file.
|
|
103
|
+
# @param options [Hash] Service and execution options (from CONFIG or specific keys)
|
|
104
|
+
# @return [String] systemd unit file content
|
|
105
|
+
def unit(options = {})
|
|
106
|
+
Aspera.assert_type(options, Hash) { 'options' }
|
|
107
|
+
opts = json_hash(options)
|
|
108
|
+
opts = opts['service'].merge(opts) if opts['service'].is_a?(Hash)
|
|
109
|
+
executable = opts['executable'] || opts['exec'] || opts['bin'] ||
|
|
110
|
+
(opts['sdk_folder'] ? File.join(opts['sdk_folder'], 'bin', 'transferd') : '/opt/aspera/transferd/bin/transferd')
|
|
111
|
+
config_file = opts['config_file'] || opts['config'] || opts['config_path'] || opts['file'] || '/etc/transferd/transferd.json'
|
|
112
|
+
user = opts['user'] || DEFAULT_USER
|
|
113
|
+
group = opts['group']
|
|
114
|
+
after = opts['after'] || DEFAULT_AFTER
|
|
115
|
+
after = Array(after).join(' ')
|
|
116
|
+
env = opts['environment'] || {}
|
|
117
|
+
|
|
118
|
+
lines = [
|
|
119
|
+
'[Unit]',
|
|
120
|
+
"Description=#{opts['description'] || 'IBM Aspera Transfer Daemon'}",
|
|
121
|
+
"After=#{after}",
|
|
122
|
+
'',
|
|
123
|
+
'[Service]',
|
|
124
|
+
"Type=#{opts['type'] || 'simple'}",
|
|
125
|
+
"User=#{user}"
|
|
126
|
+
]
|
|
127
|
+
lines << "Group=#{group}" if group && !group.empty?
|
|
128
|
+
lines << "ExecStart=#{executable} --config #{config_file}"
|
|
129
|
+
lines << "Restart=#{opts['restart'] || 'always'}"
|
|
130
|
+
env.keys.sort.each do |k|
|
|
131
|
+
lines << %Q(Environment="#{k}=#{env[k]}")
|
|
132
|
+
end
|
|
133
|
+
lines.push(
|
|
134
|
+
'',
|
|
135
|
+
'[Install]',
|
|
136
|
+
"WantedBy=#{opts['wanted_by'] || 'multi-user.target'}",
|
|
137
|
+
''
|
|
138
|
+
)
|
|
139
|
+
lines.join("\n")
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Build the content of `transferd.json`.
|
|
143
|
+
# Order of precedence: values computed from `sdk_folder`, then `existing`, then `overrides`.
|
|
144
|
+
# A key set to `nil` in `overrides` is removed.
|
|
145
|
+
# @param existing [Hash, nil] Content of the existing configuration file, `nil` or empty if none
|
|
146
|
+
# @param overrides [Hash] Values given by the user (section `config` of the user parameter)
|
|
147
|
+
# @param sdk_folder [String] Folder of the SDK, used for `fasp_runtime`
|
|
148
|
+
# @param file [String,nil] Path of the existing file, for error messages
|
|
149
|
+
# @return [Hash] Validated configuration, with String keys
|
|
150
|
+
# @raise [ParameterError] if the result does not conform to the schema of the daemon
|
|
151
|
+
def config(existing, overrides, sdk_folder, file: nil)
|
|
152
|
+
Aspera.assert_type(existing, Hash, NilClass) { 'existing' }
|
|
153
|
+
Aspera.assert_type(overrides, Hash) { 'overrides' }
|
|
154
|
+
Aspera.assert_type(sdk_folder, String) { 'sdk_folder' }
|
|
155
|
+
existing = json_hash(existing || {})
|
|
156
|
+
computed = {
|
|
157
|
+
'fasp_runtime' => {
|
|
158
|
+
'use_embedded' => false,
|
|
159
|
+
'user_defined' => {'bin' => sdk_folder, 'etc' => sdk_folder}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
result = merge(merge(computed, existing), json_hash(overrides))
|
|
163
|
+
auth = result['authentication']
|
|
164
|
+
auth['api_key'] = SecureRandom.hex(API_KEY_BYTES) if auth.is_a?(Hash) && auth['enabled'].eql?(true) && !auth.key?('api_key')
|
|
165
|
+
errors = validate(result, existing, file)
|
|
166
|
+
Aspera.assert(errors.empty?, type: ParameterError) { "Invalid transferd configuration:\n#{errors.join("\n")}" }
|
|
167
|
+
return result
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# Layout of versions side by side: `<prefix>/<version>` folders and the link `<prefix>/current`.
|
|
171
|
+
# It is used when the SDK folder is named `current`. The paths in the unit and in `transferd.json` go through the link,
|
|
172
|
+
# so that switching the link and restarting the service is enough to change the version.
|
|
173
|
+
# @param sdk_folder [String] Folder of the SDK
|
|
174
|
+
# @return [Boolean] `true` if the layout is used
|
|
175
|
+
def layout?(sdk_folder)
|
|
176
|
+
File.basename(sdk_folder).eql?(CURRENT_LINK)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# @param sdk_folder [String] Folder of the SDK
|
|
180
|
+
# @return [String] Folder of the version in use if the layout is used, else `sdk_folder` as is
|
|
181
|
+
def resolve(sdk_folder)
|
|
182
|
+
layout?(sdk_folder) && File.symlink?(sdk_folder) ? File.realpath(sdk_folder) : sdk_folder
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# @param sdk_folder [String] Link `current` of the layout
|
|
186
|
+
# @return [Array<Hash>] Installed versions, oldest first: `version`, `folder`, `current`
|
|
187
|
+
def versions(sdk_folder)
|
|
188
|
+
assert_layout(sdk_folder)
|
|
189
|
+
prefix = File.dirname(sdk_folder)
|
|
190
|
+
current = link_target(sdk_folder)
|
|
191
|
+
names = Dir.exist?(prefix) ? Dir.children(prefix) : []
|
|
192
|
+
return names
|
|
193
|
+
.select { |name| name.match?(VERSION_PATTERN) && File.exist?(executable(File.join(prefix, name))) }
|
|
194
|
+
.sort_by { |name| Gem::Version.new(name) }
|
|
195
|
+
.map { |name| {'version' => name, 'folder' => File.join(prefix, name), 'current' => name.eql?(current)} }
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# Switch the link `current` to an installed version and restart the service.
|
|
199
|
+
# If the restart fails, the link is set back to the previous version and the service is restarted again.
|
|
200
|
+
# @param user_config [Hash] `CONFIG`
|
|
201
|
+
# @param sdk_folder [String] Link `current` of the layout
|
|
202
|
+
# @param version [String] Installed version
|
|
203
|
+
# @return [Array<String>] Actions done, or to do with `dry_run`; empty if the version is already in use
|
|
204
|
+
def use(user_config, sdk_folder, version, host: Host.new, dry_run: false)
|
|
205
|
+
assert_layout(sdk_folder)
|
|
206
|
+
folder = version_folder(sdk_folder, version)
|
|
207
|
+
Aspera.assert(File.exist?(executable(folder)), type: ParameterError) { "Version #{version} is not installed in #{folder}" }
|
|
208
|
+
previous = link_target(sdk_folder)
|
|
209
|
+
return [] if previous.eql?(version)
|
|
210
|
+
opts = service_options(user_config)
|
|
211
|
+
steps = [["link #{sdk_folder} to #{version}", -> { switch_link(sdk_folder, version) }]]
|
|
212
|
+
if File.exist?(unit_path(host, opts))
|
|
213
|
+
config_file = host.path(CONFIG_FILE)
|
|
214
|
+
conf = File.exist?(config_file) ? read_config(config_file) : {}
|
|
215
|
+
steps << ["restart #{opts['name']}", -> { systemctl(host, 'restart', opts['name']) }]
|
|
216
|
+
steps.concat(wait_steps(host, opts, conf))
|
|
217
|
+
end
|
|
218
|
+
return with_rollback(sdk_folder, previous, opts, host) { run_steps(steps, dry_run) }
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
# Install the SDK if not present, then configure and start the service.
|
|
222
|
+
# With the layout, the SDK is installed in `<prefix>/<version>`, the link `current` is set to it, and
|
|
223
|
+
# it is set back to the previous version if the service cannot be started.
|
|
224
|
+
# @param user_config [Hash] `CONFIG`: sections `service` and `config`
|
|
225
|
+
# @param sdk_folder [String] Folder of the SDK, or link `current` of the layout
|
|
226
|
+
# @param host [Host] Access to the system
|
|
227
|
+
# @param dry_run [Boolean] `true`: change nothing, only return the actions
|
|
228
|
+
# @param install_sdk [#call] Installs the SDK, called if `transferd` is not there.
|
|
229
|
+
# With the layout it receives the folder of the version, else no argument.
|
|
230
|
+
# @param version [String] Version to install and use, mandatory with the layout, else ignored
|
|
231
|
+
# @return [Array<String>] Actions done, or to do with `dry_run`
|
|
232
|
+
def install(user_config, sdk_folder, host: Host.new, dry_run: false, install_sdk: nil, version: nil)
|
|
233
|
+
steps = []
|
|
234
|
+
previous = nil
|
|
235
|
+
if layout?(sdk_folder)
|
|
236
|
+
folder = version_folder(sdk_folder, version)
|
|
237
|
+
previous = link_target(sdk_folder)
|
|
238
|
+
unless File.exist?(executable(folder))
|
|
239
|
+
Aspera.assert(!install_sdk.nil?, type: ParameterError) { "SDK is not installed in #{folder}" }
|
|
240
|
+
steps << ["install the SDK in #{folder}", -> { install_sdk.call(folder) }]
|
|
241
|
+
end
|
|
242
|
+
steps << ["link #{sdk_folder} to #{version}", -> { switch_link(sdk_folder, version) }] unless previous.eql?(version)
|
|
243
|
+
elsif !File.exist?(executable(sdk_folder))
|
|
244
|
+
Aspera.assert(!install_sdk.nil?, type: ParameterError) { "SDK is not installed in #{sdk_folder}" }
|
|
245
|
+
steps << ["install the SDK in #{sdk_folder}", install_sdk]
|
|
246
|
+
end
|
|
247
|
+
steps.concat(configure_steps(user_config, sdk_folder, host, dry_run))
|
|
248
|
+
return run_steps(steps, dry_run) unless layout?(sdk_folder)
|
|
249
|
+
with_rollback(sdk_folder, previous, service_options(user_config), host) { run_steps(steps, dry_run) }
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
# Merge `CONFIG` in the configuration file, write the unit, then (re)start the service.
|
|
253
|
+
# @return [Array<String>] Actions done, or to do with `dry_run`
|
|
254
|
+
def configure(user_config, sdk_folder, host: Host.new, dry_run: false)
|
|
255
|
+
run_steps(configure_steps(user_config, sdk_folder, host, dry_run), dry_run)
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
# State of the service. The API key is never returned.
|
|
259
|
+
# @return [Hash] Version, state of the service, endpoint, and whether it listens
|
|
260
|
+
def status(user_config, sdk_folder, host: Host.new)
|
|
261
|
+
opts = service_options(user_config)
|
|
262
|
+
unit_file = host.path(File.join(opts['unit_dir'], "#{opts['name']}.service"))
|
|
263
|
+
config_file = host.path(CONFIG_FILE)
|
|
264
|
+
# only booleans and the endpoint are read: the API key is never copied in the result
|
|
265
|
+
config = File.exist?(config_file) ? read_config(config_file) : {}
|
|
266
|
+
env = unit_file_environment(unit_file)
|
|
267
|
+
address = env['TRANSFERD_ADDRESS'] || config['address'] || '127.0.0.1'
|
|
268
|
+
port = (env['TRANSFERD_PORT'] || config['port']).to_i
|
|
269
|
+
version = File.exist?(executable(sdk_folder)) ? host.run(executable(sdk_folder), 'version').first : ''
|
|
270
|
+
return {
|
|
271
|
+
'service' => opts['name'],
|
|
272
|
+
'sdk_folder' => resolve(sdk_folder),
|
|
273
|
+
'installed' => File.exist?(unit_file),
|
|
274
|
+
'version' => version[/\d+\.\d+\.\d+/],
|
|
275
|
+
'enabled' => host.run('systemctl', 'is-enabled', opts['name']).first.strip,
|
|
276
|
+
'active' => host.run('systemctl', 'is-active', opts['name']).first.strip,
|
|
277
|
+
'config_file' => CONFIG_FILE,
|
|
278
|
+
'address' => address,
|
|
279
|
+
'port' => port,
|
|
280
|
+
'listening' => port.positive? && host.listening?(connect_address(address), port),
|
|
281
|
+
'authentication' => config.dig('authentication', 'enabled').eql?(true),
|
|
282
|
+
'tls' => config.dig('tls', 'enabled').eql?(true),
|
|
283
|
+
'environment' => env
|
|
284
|
+
}
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
# Stop and remove the service.
|
|
288
|
+
# @param purge [Boolean] Also remove the configuration file and the log folder
|
|
289
|
+
# @return [Array<String>] Actions done, or to do with `dry_run`
|
|
290
|
+
def uninstall(user_config, host: Host.new, dry_run: false, purge: false)
|
|
291
|
+
opts = service_options(user_config)
|
|
292
|
+
unit_file = host.path(File.join(opts['unit_dir'], "#{opts['name']}.service"))
|
|
293
|
+
steps = []
|
|
294
|
+
if File.exist?(unit_file)
|
|
295
|
+
steps << ["stop and disable #{opts['name']}", -> { systemctl(host, 'disable', '--now', opts['name'], check: false) }]
|
|
296
|
+
steps << ["remove #{unit_file}", -> { File.delete(unit_file) }]
|
|
297
|
+
steps << ['reload systemd', -> { systemctl(host, 'daemon-reload') }]
|
|
298
|
+
end
|
|
299
|
+
steps.concat(purge_steps(host)) if purge
|
|
300
|
+
run_steps(steps, dry_run)
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
# @param user_config [Hash] `CONFIG`
|
|
304
|
+
# @return [Hash] Validated `service` section with defaults, plus `config` section as `overrides`
|
|
305
|
+
def service_options(user_config)
|
|
306
|
+
Aspera.assert_type(user_config, Hash) { 'CONFIG' }
|
|
307
|
+
conf = json_hash(user_config)
|
|
308
|
+
service = conf['service'] || {}
|
|
309
|
+
errors = Schema::Validator.instance.errors(service, Schema::Registry::SERVICE_OPTIONS)
|
|
310
|
+
Aspera.assert(errors.empty?, type: ParameterError) { "Invalid service parameters:\n#{errors.join("\n")}" }
|
|
311
|
+
return {
|
|
312
|
+
'name' => DEFAULT_SERVICE_NAME,
|
|
313
|
+
'user' => DEFAULT_USER,
|
|
314
|
+
'unit_dir' => DEFAULT_UNIT_DIR,
|
|
315
|
+
'after' => DEFAULT_AFTER,
|
|
316
|
+
'environment' => {}
|
|
317
|
+
}.merge(service).merge('overrides' => conf['config'] || {})
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
# Refuse to run on a host that cannot run the service: systemd on Linux, as root.
|
|
321
|
+
# Not checked with `dry_run`: the actions are only shown, so that it works everywhere.
|
|
322
|
+
# @param host [Host] Access to the system
|
|
323
|
+
# @param dry_run [Boolean] `true`: change nothing, no check
|
|
324
|
+
# @raise [Error] if the host is not supported or the user is not root
|
|
325
|
+
def assert_supported(host, dry_run: false)
|
|
326
|
+
return if dry_run
|
|
327
|
+
Aspera.assert(host.os.eql?(Environment::OS_LINUX), type: Error) { "The service requires Linux with systemd, this is: #{host.os}" }
|
|
328
|
+
Aspera.assert(host.systemctl?, type: Error) { 'The service requires systemd: command systemctl not found' }
|
|
329
|
+
Aspera.assert(host.euid.zero?, type: Error) { 'The service must be managed as root (use sudo), or use --dry-run=yes to only see the actions' }
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
# @return [String] Version of transferd that the configuration schema matches
|
|
333
|
+
def schema_version
|
|
334
|
+
schema_hash['$comment'].to_s[/transferd (\d+\.\d+\.\d+)/, 1]
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
# Warn (never fail) if the SDK is not the version that the configuration schema matches.
|
|
338
|
+
# @param sdk_folder [String] Folder of the SDK, or link `current` of the layout
|
|
339
|
+
# @param host [Host] Access to the system
|
|
340
|
+
# @return [String, nil] The warning, or `nil` if versions are the same or the version is unknown
|
|
341
|
+
def check_version(sdk_folder, host: Host.new)
|
|
342
|
+
exe = executable(sdk_folder)
|
|
343
|
+
return unless File.exist?(exe)
|
|
344
|
+
sdk_version = host.run(exe, 'version').first[/\d+\.\d+\.\d+/]
|
|
345
|
+
return if sdk_version.nil? || sdk_version.eql?(schema_version)
|
|
346
|
+
relation = Gem::Version.new(sdk_version) > Gem::Version.new(schema_version) ? 'newer' : 'older'
|
|
347
|
+
message = "transferd #{sdk_version} is #{relation} than the version of the configuration schema (#{schema_version}): some settings may be unknown or refused"
|
|
348
|
+
Log.log.warn(message)
|
|
349
|
+
return message
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
private
|
|
353
|
+
|
|
354
|
+
def assert_layout(sdk_folder)
|
|
355
|
+
Aspera.assert(layout?(sdk_folder), type: ParameterError) { "The SDK folder must be named #{CURRENT_LINK} to use versions: #{sdk_folder}" }
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
# @return [String] Folder of a version, next to the link `current`
|
|
359
|
+
def version_folder(sdk_folder, version)
|
|
360
|
+
Aspera.assert(version.is_a?(String) && version.match?(VERSION_PATTERN), type: ParameterError) { "Invalid version: #{version.inspect}" }
|
|
361
|
+
File.join(File.dirname(sdk_folder), version)
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
# @return [String, nil] Name of the folder the link points to, or `nil` if there is no link
|
|
365
|
+
def link_target(link)
|
|
366
|
+
File.symlink?(link) ? File.basename(File.readlink(link)) : nil
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
# Atomically set the link to a version (relative target)
|
|
370
|
+
def switch_link(link, version)
|
|
371
|
+
Aspera.assert(File.symlink?(link) || !File.exist?(link), type: Error) { "#{link} exists and is not a link" }
|
|
372
|
+
temporary = "#{link}.new"
|
|
373
|
+
FileUtils.rm_f(temporary)
|
|
374
|
+
File.symlink(version, temporary)
|
|
375
|
+
File.rename(temporary, link)
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
# @return [String] Path of the unit file
|
|
379
|
+
def unit_path(host, opts)
|
|
380
|
+
host.path(File.join(opts['unit_dir'], "#{opts['name']}.service"))
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
# Run the block, and if it fails, set back the link to the previous version and restart the service.
|
|
384
|
+
def with_rollback(sdk_folder, previous, opts, host)
|
|
385
|
+
yield
|
|
386
|
+
rescue StandardError
|
|
387
|
+
Log.log.error { "Failed, going back to version #{previous || 'none'}" }
|
|
388
|
+
if previous.nil?
|
|
389
|
+
File.delete(sdk_folder) if File.symlink?(sdk_folder)
|
|
390
|
+
else
|
|
391
|
+
switch_link(sdk_folder, previous)
|
|
392
|
+
systemctl(host, 'restart', opts['name'], check: false) if File.exist?(unit_path(host, opts))
|
|
393
|
+
end
|
|
394
|
+
raise
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
# @return [String] Path of `transferd` in the SDK
|
|
398
|
+
def executable(sdk_folder)
|
|
399
|
+
File.join(sdk_folder, 'transferd')
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
# @return [Hash] Content of the configuration file (JSON or YAML)
|
|
403
|
+
def read_config(file)
|
|
404
|
+
Yaml.safe_load(File.read(file)) || {}
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
# @return [Hash] Copy of the configuration without secret
|
|
408
|
+
def hidden(config)
|
|
409
|
+
Secret::Hider.instance.hidden_copy(config)
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
# @return [Hash] Environment variables of the daemon found in the unit file
|
|
413
|
+
def unit_file_environment(unit_file)
|
|
414
|
+
return {} unless File.exist?(unit_file)
|
|
415
|
+
File.readlines(unit_file, chomp: true).filter_map do |line|
|
|
416
|
+
name, value = line.match(/^Environment="([A-Z_]+)=(.*)"$/)&.captures
|
|
417
|
+
[name, value] if ENV_OVERRIDES.include?(name)
|
|
418
|
+
end.to_h
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
# @return [String] Address to connect to, to reach a server that listens on `address`
|
|
422
|
+
def connect_address(address)
|
|
423
|
+
%w[0.0.0.0 ::].include?(address) ? '127.0.0.1' : address
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
# @param host [Host]
|
|
427
|
+
# @param args [Array<String>] Arguments of `systemctl`
|
|
428
|
+
# @param check [Boolean] Fail if the command fails
|
|
429
|
+
# @return [String] Output
|
|
430
|
+
def systemctl(host, *args, check: true)
|
|
431
|
+
out, success = host.run('systemctl', *args)
|
|
432
|
+
Aspera.assert(success || !check, type: Error) { "systemctl #{args.join(' ')} failed: #{out}" }
|
|
433
|
+
out
|
|
434
|
+
end
|
|
435
|
+
|
|
436
|
+
# @param steps [Array<Array(String, #call)>] Description and action
|
|
437
|
+
# @param dry_run [Boolean] `true`: do not call the actions
|
|
438
|
+
# @return [Array<String>] Descriptions
|
|
439
|
+
def run_steps(steps, dry_run)
|
|
440
|
+
steps.each do |description, action|
|
|
441
|
+
Log.log.info(description)
|
|
442
|
+
action.call unless dry_run
|
|
443
|
+
end
|
|
444
|
+
steps.map(&:first)
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
# @return [Array<Array(String, #call)>] Steps to write the files and (re)start the service
|
|
448
|
+
def configure_steps(user_config, sdk_folder, host, dry_run)
|
|
449
|
+
opts = service_options(user_config)
|
|
450
|
+
user = opts['user']
|
|
451
|
+
pw = account(user)
|
|
452
|
+
steps = []
|
|
453
|
+
if pw.nil?
|
|
454
|
+
message = "Account #{user} does not exist, create it with: useradd --system --no-create-home --shell /usr/sbin/nologin #{user}"
|
|
455
|
+
Aspera.assert(dry_run, type: ParameterError) { message }
|
|
456
|
+
steps << [message, -> {}]
|
|
457
|
+
end
|
|
458
|
+
uid = pw&.uid
|
|
459
|
+
gid = group_id(opts['group'], pw)
|
|
460
|
+
config_file = host.path(CONFIG_FILE)
|
|
461
|
+
conf = config(File.exist?(config_file) ? read_config(config_file) : nil, opts['overrides'], sdk_folder, file: config_file)
|
|
462
|
+
Secret::Hider.instance.add_secret_keys(SECRET_KEYS)
|
|
463
|
+
Secret::Hider.instance.add_secret_values(conf.dig('authentication', 'api_key'))
|
|
464
|
+
unit_file = host.path(File.join(opts['unit_dir'], "#{opts['name']}.service"))
|
|
465
|
+
unit_text = unit(
|
|
466
|
+
executable: executable(sdk_folder),
|
|
467
|
+
config_file: CONFIG_FILE,
|
|
468
|
+
user: user,
|
|
469
|
+
group: opts['group'],
|
|
470
|
+
after: opts['after'],
|
|
471
|
+
environment: opts['environment']
|
|
472
|
+
)
|
|
473
|
+
owner = "#{user}:#{opts['group'] || 'primary group'}"
|
|
474
|
+
steps << ["create folder #{File.dirname(config_file)} (mode #{DIR_MODE.to_s(8)}, owner #{owner})",
|
|
475
|
+
-> { write_dir(File.dirname(config_file), DIR_MODE, uid, gid) }]
|
|
476
|
+
log_directory = conf['log_directory']
|
|
477
|
+
if log_directory.is_a?(String) && log_directory.start_with?('/')
|
|
478
|
+
log_dir = host.path(log_directory)
|
|
479
|
+
steps << ["create folder #{log_dir} (owner #{owner})", -> { write_dir(log_dir, DIR_MODE, uid, gid) }]
|
|
480
|
+
end
|
|
481
|
+
steps << ["write #{config_file} (mode #{FILE_MODE.to_s(8)}, owner #{owner}):\n#{JSON.pretty_generate(hidden(conf))}",
|
|
482
|
+
-> { write_file(config_file, "#{JSON.pretty_generate(conf)}\n", uid, gid) }]
|
|
483
|
+
steps << ["write #{unit_file} (mode #{FILE_MODE.to_s(8)}):\n#{unit_text}", -> { write_file(unit_file, unit_text, nil, nil) }]
|
|
484
|
+
steps << ['reload systemd', -> { systemctl(host, 'daemon-reload') }]
|
|
485
|
+
steps << ["enable and restart #{opts['name']}", -> { %w[enable restart].each { |action| systemctl(host, action, opts['name']) } }]
|
|
486
|
+
steps.concat(wait_steps(host, opts, conf))
|
|
487
|
+
return steps
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
# @return [Array<Array(String, #call)>] Step to wait for the daemon, none if the port is dynamic
|
|
491
|
+
def wait_steps(host, opts, conf)
|
|
492
|
+
port = (opts['environment']['TRANSFERD_PORT'] || conf['port']).to_i
|
|
493
|
+
return [] unless port.positive?
|
|
494
|
+
address = connect_address(opts['environment']['TRANSFERD_ADDRESS'] || conf['address'] || '127.0.0.1')
|
|
495
|
+
return [["wait for #{address}:#{port}", -> { wait_listening(host, address, port, opts['name']) }]]
|
|
496
|
+
end
|
|
497
|
+
|
|
498
|
+
# @return [Array<Array(String, #call)>] Steps to remove the configuration file and the log folder
|
|
499
|
+
def purge_steps(host)
|
|
500
|
+
config_file = host.path(CONFIG_FILE)
|
|
501
|
+
steps = []
|
|
502
|
+
log_directory = read_config(config_file)['log_directory'] if File.exist?(config_file)
|
|
503
|
+
steps << ["remove #{host.path(log_directory)}", -> { FileUtils.rm_rf(host.path(log_directory)) }] if log_directory.is_a?(String) && log_directory.start_with?('/') && log_directory.length > 1
|
|
504
|
+
steps << ["remove #{config_file}", -> { FileUtils.rm_f(config_file) }]
|
|
505
|
+
steps << ["remove folder #{File.dirname(config_file)} if empty", -> { Dir.rmdir(File.dirname(config_file)) if Dir.empty?(File.dirname(config_file)) }]
|
|
506
|
+
return steps
|
|
507
|
+
end
|
|
508
|
+
|
|
509
|
+
# @return [Etc::Passwd, nil] The account, or `nil` if it does not exist
|
|
510
|
+
def account(user)
|
|
511
|
+
Etc.getpwnam(user)
|
|
512
|
+
rescue ArgumentError
|
|
513
|
+
nil
|
|
514
|
+
end
|
|
515
|
+
|
|
516
|
+
# @return [Integer, nil] Id of the group, or primary group of the account
|
|
517
|
+
def group_id(group, account)
|
|
518
|
+
return account&.gid if group.nil?
|
|
519
|
+
Etc.getgrnam(group).gid
|
|
520
|
+
rescue ArgumentError
|
|
521
|
+
raise ParameterError, "Group #{group} does not exist"
|
|
522
|
+
end
|
|
523
|
+
|
|
524
|
+
def write_dir(path, mode, uid, gid)
|
|
525
|
+
FileUtils.mkdir_p(path)
|
|
526
|
+
Environment.restrict_file_access(path, mode: mode)
|
|
527
|
+
File.chown(uid, gid, path) if uid
|
|
528
|
+
end
|
|
529
|
+
|
|
530
|
+
def write_file(path, content, uid, gid)
|
|
531
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
532
|
+
Environment.write_file_restricted(path, force: true, mode: FILE_MODE) { content }
|
|
533
|
+
File.chown(uid, gid, path) if uid
|
|
534
|
+
end
|
|
535
|
+
|
|
536
|
+
def wait_listening(host, address, port, name)
|
|
537
|
+
deadline = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) + host.timeout
|
|
538
|
+
until host.listening?(address, port)
|
|
539
|
+
Aspera.assert(::Process.clock_gettime(::Process::CLOCK_MONOTONIC) < deadline, type: Error) do
|
|
540
|
+
"Service #{name} does not listen on #{address}:#{port} after #{host.timeout} seconds, see: journalctl -u #{name}"
|
|
541
|
+
end
|
|
542
|
+
sleep(WAIT_INTERVAL)
|
|
543
|
+
end
|
|
544
|
+
end
|
|
545
|
+
|
|
546
|
+
# @param value [Object] Value with Symbol or String keys
|
|
547
|
+
# @return [Object] JSON view of value: String keys
|
|
548
|
+
def json_hash(value)
|
|
549
|
+
JSON.parse(JSON.generate(value))
|
|
550
|
+
end
|
|
551
|
+
|
|
552
|
+
# Deep merge, entries set to `nil` in `over` are removed
|
|
553
|
+
# @param base [Hash] Initial values
|
|
554
|
+
# @param over [Hash] Values to apply
|
|
555
|
+
# @return [Hash] New Hash
|
|
556
|
+
def merge(base, over)
|
|
557
|
+
over.each_with_object(base.dup) do |(key, value), result|
|
|
558
|
+
if value.nil?
|
|
559
|
+
result.delete(key)
|
|
560
|
+
elsif value.is_a?(Hash)
|
|
561
|
+
result[key] = merge(result[key].is_a?(Hash) ? result[key] : {}, value)
|
|
562
|
+
else
|
|
563
|
+
result[key] = value
|
|
564
|
+
end
|
|
565
|
+
end
|
|
566
|
+
end
|
|
567
|
+
|
|
568
|
+
# @return [JSONSchemer::Schema] compiled schema of `transferd.json`
|
|
569
|
+
def schema
|
|
570
|
+
@schema ||=
|
|
571
|
+
begin
|
|
572
|
+
require 'json_schemer'
|
|
573
|
+
JSONSchemer.schema(schema_hash)
|
|
574
|
+
end
|
|
575
|
+
end
|
|
576
|
+
|
|
577
|
+
# @return [Hash] Schema of `transferd.json`
|
|
578
|
+
def schema_hash
|
|
579
|
+
# JSON is read with the YAML loader: it accepts the header comment added by `rake tools:openapi`
|
|
580
|
+
@schema_hash ||= Yaml.safe_load(File.read(File.join(File.expand_path('../..', __dir__), Schema::Registry::LOCATIONS[:transferd])))
|
|
581
|
+
end
|
|
582
|
+
|
|
583
|
+
# @param config [Hash] Configuration to validate
|
|
584
|
+
# @param existing [Hash] Content of the existing file
|
|
585
|
+
# @param file [String, nil] Path of the existing file
|
|
586
|
+
# @return [Array<String>] error messages, empty if valid
|
|
587
|
+
def validate(config, existing, file)
|
|
588
|
+
schema.validate(config).map do |error|
|
|
589
|
+
# tell the user when the faulty value comes from a file that was not written by this call
|
|
590
|
+
path = error['data_pointer'].to_s.split('/').drop(1)
|
|
591
|
+
origin = file && in_hash?(existing, path) ? " (existing file: #{file})" : ''
|
|
592
|
+
"#{error['error']}#{origin}"
|
|
593
|
+
end
|
|
594
|
+
end
|
|
595
|
+
|
|
596
|
+
# @param hash [Hash] Hash to look into
|
|
597
|
+
# @param path [Array] Keys of nested Hashes
|
|
598
|
+
# @return [Boolean] `true` if the path exists in hash
|
|
599
|
+
def in_hash?(hash, path)
|
|
600
|
+
return false if path.empty?
|
|
601
|
+
path.reduce(hash) do |node, key|
|
|
602
|
+
return false unless node.is_a?(Hash) && node.key?(key)
|
|
603
|
+
node[key]
|
|
604
|
+
end
|
|
605
|
+
true
|
|
606
|
+
end
|
|
607
|
+
end
|
|
608
|
+
end
|
|
609
|
+
end
|
|
610
|
+
end
|
|
@@ -70,7 +70,7 @@ function shExpMatch(str, shell_expr) {
|
|
|
70
70
|
}
|
|
71
71
|
function weekdayRange(wd1, wd2, gmt) {
|
|
72
72
|
var today = new Date();
|
|
73
|
-
var days = 'SUNMONTUEWEDTHUFRISAT';
|
|
73
|
+
var days = 'SUNMONTUEWEDTHUFRISAT';
|
|
74
74
|
wd1 = wd1.toUpperCase();
|
|
75
75
|
if (wd2 == undefined)
|
|
76
76
|
wd2 = wd1;
|
|
@@ -138,7 +138,7 @@ function dateRange() {
|
|
|
138
138
|
else
|
|
139
139
|
return false;
|
|
140
140
|
} else if (typeof arg == 'string') {
|
|
141
|
-
var months = 'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC';
|
|
141
|
+
var months = 'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC';
|
|
142
142
|
arg = arg.toUpperCase();
|
|
143
143
|
arg = months.indexOf(arg);
|
|
144
144
|
if (arg == -1)
|
data/lib/aspera/rainbow.rb
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
3
6
|
# Load Rainbow with terminal detection (tty, TERM=dumb, NO_COLOR, CLICOLOR, CLICOLOR_FORCE)
|
|
4
7
|
# and its String refinement.
|
|
5
8
|
# Each file using colors must still activate it with: using Rainbow
|