prvng_core/nulib/lib_provisioning/utils/ssh.nu

149 lines
5.3 KiB
Text
Raw Normal View History

refactor(23 files): selective imports + dangling/broken cleanup (ADR-025 L2/L3) Large combined batch of 23 files refactored from star-imports to selective. Grouped because two sub-batches accumulated in staging without intermediate commit. === Orchestrator facades (Layer 3) === ai/mod.nu [12 symbols from ai/lib.nu] config/loader.nu [14 symbols from loader/mod.nu] config/accessor/mod.nu [15 symbols from accessor/functions.nu] sops/mod.nu [11 symbols from sops/lib.nu] user/mod.nu [16 symbols from user/config.nu] === Selective imports === defs/lists.nu utils/on_select (kept, selective) services/manager.nu (all dead dropped) webhook/ai_webhook.nu ai/lib [4] + settings/lib kms/lib.nu utils/error + utils/interface + plugins/kms gitea/locking.nu api_client [8] gitea/workspace_git.nu api_client [3] gitea/extension_publish.nu api_client [8] + config/loader infra_validator/rules_engine.nu config_loader [3] plugins/kms.nu config/accessor/core [config-get] coredns/api_client.nu config/loader [get-config] === Dangling imports removed (target file does not exist) === coredns/docker.nu ../utils/log.nu → deleted (uses corefile.nu [2]) coredns/zones.nu ../utils/log.nu → deleted (uses corefile.nu [1]) coredns/service.nu ../utils/log.nu → deleted (uses corefile.nu [2]) coredns/corefile.nu ../utils/log.nu → deleted === Broken paths cleaned up === project/detect.nu Former `use ../../../lib_provisioning *` resolved to non-existent path (core/lib_provisioning). Silent no-op at runtime. Removed. Error count went 19 -> 17. === Dead imports dropped === utils/ssh.nu config/accessor DROPPED (dead) utils/init.nu config/accessor DROPPED (dead) infra_validator/agent_interface.nu report_generator DROPPED (dead) === Dynamic imports preserved === providers/loader.nu line 179 `use ($provider_entry.entry_point) *` is intentional runtime dispatch — not convertible to selective. Validation: all files match pre-existing baseline. Gitea subsystem has known pre-existing 50-error noise (transitive); independent of this work. Refs: ADR-025
2026-04-17 12:13:13 +01:00
# config/accessor star-import was dead — dropped (ADR-025 Phase 3 Layer 2).
2025-10-07 10:32:04 +01:00
export def ssh_cmd [
settings: record
server: record
with_bash: bool
cmd: string
live_ip: string
] {
2025-10-07 10:32:04 +01:00
let ip = if $live_ip != "" {
$live_ip
} else {
2025-10-07 10:32:04 +01:00
#use ../../../../providers/prov_lib/middleware.nu mw_get_ip
feat(core): three-layer DAG, unified component arch, commands-registry cache, Nushell 0.112.2 migration - DAG architecture: `dag show/validate/export` (nulib/main_provisioning/dag.nu), config loader (lib_provisioning/config/loader/dag.nu), taskserv dag-executor. Backed by schemas/lib/dag/*.ncl; orchestrator emits NATS events via WorkspaceComposition::into_workflow. See ADR-020, ADR-021. - Unified Component Architecture: components/mod.nu, main_provisioning/ {components,workflow,extensions,ontoref-queries}.nu. Full workflow engine with topological sort and NATS subject emission. Blocks A-H complete (libre-daoshi). - Commands-registry: nulib/commands-registry.ncl (Nickel source, 314 lines) + JSON cache at ~/.cache/provisioning/commands-registry.json rebuilt on source change. cli/provisioning fast-path alias expansion avoids cold Nu startup. ADDING_COMMANDS.md documents new-command workflow. - Platform service manager: service-manager.nu (+573), startup.nu (+611), service-check.nu (+255); autostart/bootstrap/health/target refactored. - Nushell 0.112.2 migration: removed all try/catch and bash redirections; external commands prefixed with ^; type signatures enforced. Driven by scripts/refactor-try-catch{,-simplified}.nu. - TTY stack: removed shlib/*-tty.sh; replaced by cli/tty-dispatch.sh, tty-filter.sh, tty-commands.conf. - New domain modules: images/ (golden image lifecycle), workspace/{state,sync}.nu, main_provisioning/{bootstrap,cluster-deploy,fip,state}.nu, commands/{state, build,integrations/auth,utilities/alias}.nu, platform.nu expanded (+874). - Config loader overhaul: loader/core.nu slimmed (-759), cache/core.nu refactored (-454), removed legacy loaders/file_loader.nu (-330). - Thirteen new provisioning-<domain>.nu top-level modules for bash dispatcher. - Tests: test_workspace_state.nu (+351); updates to test_oci_registry, test_services. - README + CHANGELOG updated.
2026-04-17 04:27:33 +01:00
(mw_get_ip $settings $server ($server | get -o liveness_ip | default "public") false)
2025-10-07 10:32:04 +01:00
}
if $ip == "" { return false }
if not (check_connection $server $ip "ssh_cmd") { return false }
let remote_cmd = if $with_bash {
let ops = if (is-debug-enabled) { "-x" } else { "" }
2025-10-07 10:32:04 +01:00
$"bash ($ops) ($cmd)"
} else { $cmd }
let ssh_loglevel = if (is-debug-enabled) {
_print $"Run ($remote_cmd) in ($server.installer_user)@($ip)"
"-o LogLevel=info"
} else {
2025-10-07 10:32:04 +01:00
"-o LogLevel=quiet"
}
let ssh_op_0 = if ($env.SSH_OPS | length) > 0 { $env.SSH_OPS | get 0 } else { "" }
let ssh_op_1 = if ($env.SSH_OPS | length) > 1 { $env.SSH_OPS | get 1 } else { "" }
let res = (^ssh "-o" $ssh_op_0 "-o" $ssh_op_1 "-o" IdentitiesOnly=yes $ssh_loglevel
2025-10-07 10:32:04 +01:00
"-i" ($server.ssh_key_path | str replace ".pub" "")
$"($server.installer_user)@($ip)" ($remote_cmd) | complete)
2025-10-07 10:32:04 +01:00
if $res.exit_code != 0 {
_print $"❗ run ($remote_cmd) in ($server.hostname) errors ($res.stdout ) "
return false
}
if (is-debug-enabled) and $remote_cmd != "ls" { _print $res.stdout }
true
}
export def scp_to [
settings: record
server: record
source: list<string>
target: string
live_ip: string
] {
2025-10-07 10:32:04 +01:00
let ip = if $live_ip != "" {
$live_ip
} else {
2025-10-07 10:32:04 +01:00
#use ../../../../providers/prov_lib/middleware.nu mw_get_ip
feat(core): three-layer DAG, unified component arch, commands-registry cache, Nushell 0.112.2 migration - DAG architecture: `dag show/validate/export` (nulib/main_provisioning/dag.nu), config loader (lib_provisioning/config/loader/dag.nu), taskserv dag-executor. Backed by schemas/lib/dag/*.ncl; orchestrator emits NATS events via WorkspaceComposition::into_workflow. See ADR-020, ADR-021. - Unified Component Architecture: components/mod.nu, main_provisioning/ {components,workflow,extensions,ontoref-queries}.nu. Full workflow engine with topological sort and NATS subject emission. Blocks A-H complete (libre-daoshi). - Commands-registry: nulib/commands-registry.ncl (Nickel source, 314 lines) + JSON cache at ~/.cache/provisioning/commands-registry.json rebuilt on source change. cli/provisioning fast-path alias expansion avoids cold Nu startup. ADDING_COMMANDS.md documents new-command workflow. - Platform service manager: service-manager.nu (+573), startup.nu (+611), service-check.nu (+255); autostart/bootstrap/health/target refactored. - Nushell 0.112.2 migration: removed all try/catch and bash redirections; external commands prefixed with ^; type signatures enforced. Driven by scripts/refactor-try-catch{,-simplified}.nu. - TTY stack: removed shlib/*-tty.sh; replaced by cli/tty-dispatch.sh, tty-filter.sh, tty-commands.conf. - New domain modules: images/ (golden image lifecycle), workspace/{state,sync}.nu, main_provisioning/{bootstrap,cluster-deploy,fip,state}.nu, commands/{state, build,integrations/auth,utilities/alias}.nu, platform.nu expanded (+874). - Config loader overhaul: loader/core.nu slimmed (-759), cache/core.nu refactored (-454), removed legacy loaders/file_loader.nu (-330). - Thirteen new provisioning-<domain>.nu top-level modules for bash dispatcher. - Tests: test_workspace_state.nu (+351); updates to test_oci_registry, test_services. - README + CHANGELOG updated.
2026-04-17 04:27:33 +01:00
(mw_get_ip $settings $server ($server | get -o liveness_ip | default "public") false)
2025-10-07 10:32:04 +01:00
}
if $ip == "" { return false }
if not (check_connection $server $ip "scp_to") { return false }
let source_files = ($source | str join " ")
let ssh_op_0 = if ($env.SSH_OPS | length) > 0 { $env.SSH_OPS | get 0 } else { "" }
let ssh_op_1 = if ($env.SSH_OPS | length) > 1 { $env.SSH_OPS | get 1 } else { "" }
let ssh_loglevel = if (is-debug-enabled) {
2025-10-07 10:32:04 +01:00
_print $"Sending ($source | str join ' ') to ($server.installer_user)@($ip)/tmp/($target)"
_print $"scp -o ($ssh_op_0) -o ($ssh_op_1) -o IdentitiesOnly=yes -i ($server.ssh_key_path | str replace ".pub" "") ($source_files) ($server.installer_user)@($ip):($target)"
2025-10-07 10:32:04 +01:00
"-o LogLevel=info"
} else {
2025-10-07 10:32:04 +01:00
"-o LogLevel=quiet"
}
let res = (^scp "-o" $ssh_op_0 "-o" $ssh_op_1 "-o" IdentitiesOnly=yes $ssh_loglevel
2025-10-07 10:32:04 +01:00
"-i" ($server.ssh_key_path | str replace ".pub" "")
$source_files $"($server.installer_user)@($ip):($target)" | complete)
2025-10-07 10:32:04 +01:00
if $res.exit_code != 0 {
_print $"❗ copy ($target | str join ' ') to ($server.hostname) errors ($res.stdout ) "
return false
}
if (is-debug-enabled) { _print $res.stdout }
true
}
export def scp_from [
settings: record
server: record
source: string
target: string
live_ip: string
] {
2025-10-07 10:32:04 +01:00
let ip = if $live_ip != "" {
$live_ip
} else {
2025-10-07 10:32:04 +01:00
#use ../../../../providers/prov_lib/middleware.nu mw_get_ip
feat(core): three-layer DAG, unified component arch, commands-registry cache, Nushell 0.112.2 migration - DAG architecture: `dag show/validate/export` (nulib/main_provisioning/dag.nu), config loader (lib_provisioning/config/loader/dag.nu), taskserv dag-executor. Backed by schemas/lib/dag/*.ncl; orchestrator emits NATS events via WorkspaceComposition::into_workflow. See ADR-020, ADR-021. - Unified Component Architecture: components/mod.nu, main_provisioning/ {components,workflow,extensions,ontoref-queries}.nu. Full workflow engine with topological sort and NATS subject emission. Blocks A-H complete (libre-daoshi). - Commands-registry: nulib/commands-registry.ncl (Nickel source, 314 lines) + JSON cache at ~/.cache/provisioning/commands-registry.json rebuilt on source change. cli/provisioning fast-path alias expansion avoids cold Nu startup. ADDING_COMMANDS.md documents new-command workflow. - Platform service manager: service-manager.nu (+573), startup.nu (+611), service-check.nu (+255); autostart/bootstrap/health/target refactored. - Nushell 0.112.2 migration: removed all try/catch and bash redirections; external commands prefixed with ^; type signatures enforced. Driven by scripts/refactor-try-catch{,-simplified}.nu. - TTY stack: removed shlib/*-tty.sh; replaced by cli/tty-dispatch.sh, tty-filter.sh, tty-commands.conf. - New domain modules: images/ (golden image lifecycle), workspace/{state,sync}.nu, main_provisioning/{bootstrap,cluster-deploy,fip,state}.nu, commands/{state, build,integrations/auth,utilities/alias}.nu, platform.nu expanded (+874). - Config loader overhaul: loader/core.nu slimmed (-759), cache/core.nu refactored (-454), removed legacy loaders/file_loader.nu (-330). - Thirteen new provisioning-<domain>.nu top-level modules for bash dispatcher. - Tests: test_workspace_state.nu (+351); updates to test_oci_registry, test_services. - README + CHANGELOG updated.
2026-04-17 04:27:33 +01:00
(mw_get_ip $settings $server ($server | get -o liveness_ip | default "public") false)
2025-10-07 10:32:04 +01:00
}
if $ip == "" { return false }
if not (check_connection $server $ip "scp_from") { return false }
let ssh_op_0 = if ($env.SSH_OPS | length) > 0 { $env.SSH_OPS | get 0 } else { "" }
let ssh_op_1 = if ($env.SSH_OPS | length) > 1 { $env.SSH_OPS | get 1 } else { "" }
let ssh_loglevel = if (is-debug-enabled) {
2025-10-07 10:32:04 +01:00
_print $"Getting ($target | str join ' ') from ($server.installer_user)@($ip)/tmp/($target)"
"-o LogLevel=info"
} else {
2025-10-07 10:32:04 +01:00
"-o LogLevel=quiet"
}
let res = (^scp "-o" $ssh_op_0 "-o" $ssh_op_1 "-o" IdentitiesOnly=yes $ssh_loglevel
2025-10-07 10:32:04 +01:00
"-i" ($server.ssh_key_path | str replace ".pub" "")
$"($server.installer_user)@($ip):($source)" $target | complete)
2025-10-07 10:32:04 +01:00
if $res.exit_code != 0 {
_print $"❗ copy ($source) from ($server.hostname) to ($target) errors ($res.stdout ) "
return false
}
if (is-debug-enabled) { _print $res.stdout }
true
}
export def ssh_cp_run [
settings: record
server: record
source: list<string>
target: string
with_bash: bool
live_ip: string
ssh_remove: bool
] {
2025-10-07 10:32:04 +01:00
let ip = if $live_ip != "" {
$live_ip
} else {
2025-10-07 10:32:04 +01:00
#use ../../../../providers/prov_lib/middleware.nu mw_get_ip
feat(core): three-layer DAG, unified component arch, commands-registry cache, Nushell 0.112.2 migration - DAG architecture: `dag show/validate/export` (nulib/main_provisioning/dag.nu), config loader (lib_provisioning/config/loader/dag.nu), taskserv dag-executor. Backed by schemas/lib/dag/*.ncl; orchestrator emits NATS events via WorkspaceComposition::into_workflow. See ADR-020, ADR-021. - Unified Component Architecture: components/mod.nu, main_provisioning/ {components,workflow,extensions,ontoref-queries}.nu. Full workflow engine with topological sort and NATS subject emission. Blocks A-H complete (libre-daoshi). - Commands-registry: nulib/commands-registry.ncl (Nickel source, 314 lines) + JSON cache at ~/.cache/provisioning/commands-registry.json rebuilt on source change. cli/provisioning fast-path alias expansion avoids cold Nu startup. ADDING_COMMANDS.md documents new-command workflow. - Platform service manager: service-manager.nu (+573), startup.nu (+611), service-check.nu (+255); autostart/bootstrap/health/target refactored. - Nushell 0.112.2 migration: removed all try/catch and bash redirections; external commands prefixed with ^; type signatures enforced. Driven by scripts/refactor-try-catch{,-simplified}.nu. - TTY stack: removed shlib/*-tty.sh; replaced by cli/tty-dispatch.sh, tty-filter.sh, tty-commands.conf. - New domain modules: images/ (golden image lifecycle), workspace/{state,sync}.nu, main_provisioning/{bootstrap,cluster-deploy,fip,state}.nu, commands/{state, build,integrations/auth,utilities/alias}.nu, platform.nu expanded (+874). - Config loader overhaul: loader/core.nu slimmed (-759), cache/core.nu refactored (-454), removed legacy loaders/file_loader.nu (-330). - Thirteen new provisioning-<domain>.nu top-level modules for bash dispatcher. - Tests: test_workspace_state.nu (+351); updates to test_oci_registry, test_services. - README + CHANGELOG updated.
2026-04-17 04:27:33 +01:00
(mw_get_ip $settings $server ($server | get -o liveness_ip | default "public") false)
2025-10-07 10:32:04 +01:00
}
if $ip == "" {
2025-10-07 10:32:04 +01:00
_print $"❗ ssh_cp_run (_ansi red_bold)No IP(_ansi reset) to (_ansi green_bold)($server.hostname)(_ansi reset)"
return false
}
if not (scp_to $settings $server $source $target $ip) { return false }
if not (ssh_cmd $settings $server $with_bash $target $ip) { return false }
if $env.PROVISIONING_SSH_DEBUG? != null and $env.PROVISIONING_SSH_DEBUG { return true }
if $ssh_remove {
2025-10-07 10:32:04 +01:00
return (ssh_cmd $settings $server false $"rm -f ($target)" $ip)
}
true
}
export def check_connection [
server: record
ip: string
origin: string
] {
feat(core): three-layer DAG, unified component arch, commands-registry cache, Nushell 0.112.2 migration - DAG architecture: `dag show/validate/export` (nulib/main_provisioning/dag.nu), config loader (lib_provisioning/config/loader/dag.nu), taskserv dag-executor. Backed by schemas/lib/dag/*.ncl; orchestrator emits NATS events via WorkspaceComposition::into_workflow. See ADR-020, ADR-021. - Unified Component Architecture: components/mod.nu, main_provisioning/ {components,workflow,extensions,ontoref-queries}.nu. Full workflow engine with topological sort and NATS subject emission. Blocks A-H complete (libre-daoshi). - Commands-registry: nulib/commands-registry.ncl (Nickel source, 314 lines) + JSON cache at ~/.cache/provisioning/commands-registry.json rebuilt on source change. cli/provisioning fast-path alias expansion avoids cold Nu startup. ADDING_COMMANDS.md documents new-command workflow. - Platform service manager: service-manager.nu (+573), startup.nu (+611), service-check.nu (+255); autostart/bootstrap/health/target refactored. - Nushell 0.112.2 migration: removed all try/catch and bash redirections; external commands prefixed with ^; type signatures enforced. Driven by scripts/refactor-try-catch{,-simplified}.nu. - TTY stack: removed shlib/*-tty.sh; replaced by cli/tty-dispatch.sh, tty-filter.sh, tty-commands.conf. - New domain modules: images/ (golden image lifecycle), workspace/{state,sync}.nu, main_provisioning/{bootstrap,cluster-deploy,fip,state}.nu, commands/{state, build,integrations/auth,utilities/alias}.nu, platform.nu expanded (+874). - Config loader overhaul: loader/core.nu slimmed (-759), cache/core.nu refactored (-454), removed legacy loaders/file_loader.nu (-330). - Thirteen new provisioning-<domain>.nu top-level modules for bash dispatcher. - Tests: test_workspace_state.nu (+351); updates to test_oci_registry, test_services. - README + CHANGELOG updated.
2026-04-17 04:27:33 +01:00
if not (port_scan $ip ($server | get -o liveness_port | default 22) 1) {
2025-10-07 10:32:04 +01:00
_print (
$"\n🛑 (_ansi red)Error connection(_ansi reset) ($origin) (_ansi blue)($server.hostname)(_ansi reset) " +
feat(core): three-layer DAG, unified component arch, commands-registry cache, Nushell 0.112.2 migration - DAG architecture: `dag show/validate/export` (nulib/main_provisioning/dag.nu), config loader (lib_provisioning/config/loader/dag.nu), taskserv dag-executor. Backed by schemas/lib/dag/*.ncl; orchestrator emits NATS events via WorkspaceComposition::into_workflow. See ADR-020, ADR-021. - Unified Component Architecture: components/mod.nu, main_provisioning/ {components,workflow,extensions,ontoref-queries}.nu. Full workflow engine with topological sort and NATS subject emission. Blocks A-H complete (libre-daoshi). - Commands-registry: nulib/commands-registry.ncl (Nickel source, 314 lines) + JSON cache at ~/.cache/provisioning/commands-registry.json rebuilt on source change. cli/provisioning fast-path alias expansion avoids cold Nu startup. ADDING_COMMANDS.md documents new-command workflow. - Platform service manager: service-manager.nu (+573), startup.nu (+611), service-check.nu (+255); autostart/bootstrap/health/target refactored. - Nushell 0.112.2 migration: removed all try/catch and bash redirections; external commands prefixed with ^; type signatures enforced. Driven by scripts/refactor-try-catch{,-simplified}.nu. - TTY stack: removed shlib/*-tty.sh; replaced by cli/tty-dispatch.sh, tty-filter.sh, tty-commands.conf. - New domain modules: images/ (golden image lifecycle), workspace/{state,sync}.nu, main_provisioning/{bootstrap,cluster-deploy,fip,state}.nu, commands/{state, build,integrations/auth,utilities/alias}.nu, platform.nu expanded (+874). - Config loader overhaul: loader/core.nu slimmed (-759), cache/core.nu refactored (-454), removed legacy loaders/file_loader.nu (-330). - Thirteen new provisioning-<domain>.nu top-level modules for bash dispatcher. - Tests: test_workspace_state.nu (+351); updates to test_oci_registry, test_services. - README + CHANGELOG updated.
2026-04-17 04:27:33 +01:00
$"(_ansi blue_bold)($ip)(_ansi reset) at ($server | get -o liveness_port | default 22) (_ansi red_bold)failed(_ansi reset) "
2025-10-07 10:32:04 +01:00
)
return false
}
2025-10-07 10:32:04 +01:00
true
}