loft-cli 0.6.3__tar.gz → 0.11.0__tar.gz
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.
- {loft_cli-0.6.3 → loft_cli-0.11.0}/PKG-INFO +1 -1
- loft_cli-0.11.0/loft_cli/_builtins.py +608 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/cli.py +612 -16
- loft_cli-0.11.0/loft_cli/commands/prep.py +192 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/compiler/normalizer.py +106 -13
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/compiler/planner.py +441 -11
- loft_cli-0.11.0/loft_cli/local/__init__.py +5 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/local/ddl/bootstrap_tables.py +1 -0
- loft_cli-0.11.0/loft_cli/local/fleet.py +119 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/local/inventory.py +35 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/local/inventory_db.py +31 -3
- loft_cli-0.11.0/loft_cli/local/keys.py +100 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/local/remove.py +81 -16
- loft_cli-0.11.0/loft_cli/local/selector.py +209 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/local/ssh_config.py +34 -9
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/local/tunnel.py +60 -27
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/local/wireguard_store.py +97 -6
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/executor.py +243 -16
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/steps/compose.py +5 -2
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/steps/wireguard.py +10 -1
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/updater.py +76 -36
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli.egg-info/PKG-INFO +1 -1
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli.egg-info/SOURCES.txt +3 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/pyproject.toml +1 -1
- loft_cli-0.6.3/loft_cli/_builtins.py +0 -269
- loft_cli-0.6.3/loft_cli/local/keys.py +0 -45
- loft_cli-0.6.3/loft_cli/runtime/steps/__init__.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/README.md +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/__init__.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/addons/__init__.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/addons/goss/__init__.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/addons/goss/generator.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/addons/goss/renderer.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/addons/goss/shipper.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/agent_installer.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/checks/__init__.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/checks/compose.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/checks/container.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/checks/http.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/checks/nginx.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/checks/ports.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/checks/postgres.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/checks/ssh.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/checks/wireguard.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/compiler/__init__.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/compiler/parser.py +0 -0
- {loft_cli-0.6.3/loft_cli/local → loft_cli-0.11.0/loft_cli/local/ddl}/__init__.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/local/ddl/versionize_system.py +0 -0
- {loft_cli-0.6.3/loft_cli/local/ddl → loft_cli-0.11.0/loft_cli/logs}/__init__.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/logs/reader.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/logs/writer.py +0 -0
- {loft_cli-0.6.3/loft_cli/logs → loft_cli-0.11.0/loft_cli/runtime}/__init__.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/agent_transport.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/fabric_transport.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/secret_rotation.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/ssh.py +0 -0
- {loft_cli-0.6.3/loft_cli/runtime → loft_cli-0.11.0/loft_cli/runtime/steps}/__init__.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/steps/backup.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/steps/bootstrap.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/steps/container.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/steps/docker.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/steps/file_template.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/steps/nginx.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/steps/postgres.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/steps/postgres_ensure.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/steps/systemd.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli/runtime/transport.py +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli.egg-info/dependency_links.txt +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli.egg-info/entry_points.txt +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli.egg-info/requires.txt +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/loft_cli.egg-info/top_level.txt +0 -0
- {loft_cli-0.6.3 → loft_cli-0.11.0}/setup.cfg +0 -0
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
"""Register the built-in core spec kinds: bootstrap and service.
|
|
2
|
+
|
|
3
|
+
All imports are lazy (inside function bodies) to avoid circular import
|
|
4
|
+
issues between the compiler, specs, runtime, and registry modules.
|
|
5
|
+
This module is called exactly once by load_addons() at CLI startup.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _register_builtins() -> None:
|
|
12
|
+
"""Register bootstrap and service kinds across all registries."""
|
|
13
|
+
_register_resolvers()
|
|
14
|
+
_register_specs()
|
|
15
|
+
_register_normalizers()
|
|
16
|
+
_register_validators()
|
|
17
|
+
_register_planners()
|
|
18
|
+
_register_step_handlers()
|
|
19
|
+
_register_hooks()
|
|
20
|
+
_register_catalog_entries()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _register_specs() -> None:
|
|
24
|
+
from loft_cli_core.registry.specs import register_spec_kind
|
|
25
|
+
from loft_cli_core.specs.backup_job_schema import BackupJobSpec
|
|
26
|
+
from loft_cli_core.specs.blueprint_schema import BlueprintSpec
|
|
27
|
+
from loft_cli_core.specs.bootstrap_schema import BootstrapSpec
|
|
28
|
+
from loft_cli_core.specs.compose_project_schema import ComposeProjectSpec
|
|
29
|
+
from loft_cli_core.specs.file_template_schema import FileTemplateSpec
|
|
30
|
+
from loft_cli_core.specs.http_check_schema import HttpCheckSpec
|
|
31
|
+
from loft_cli_core.specs.package_schema import PackageSpec
|
|
32
|
+
from loft_cli_core.specs.postgres_ensure_schema import PostgresEnsureSpec
|
|
33
|
+
from loft_cli_core.specs.service_schema import ServiceSpec
|
|
34
|
+
from loft_cli_core.specs.stack_schema import StackSpec
|
|
35
|
+
from loft_cli_core.specs.systemd_timer_schema import SystemdTimerSpec
|
|
36
|
+
from loft_cli_core.specs.systemd_unit_schema import SystemdUnitSpec
|
|
37
|
+
|
|
38
|
+
register_spec_kind("bootstrap", BootstrapSpec)
|
|
39
|
+
register_spec_kind("service", ServiceSpec)
|
|
40
|
+
register_spec_kind("file_template", FileTemplateSpec)
|
|
41
|
+
register_spec_kind("compose_project", ComposeProjectSpec)
|
|
42
|
+
register_spec_kind("stack", StackSpec)
|
|
43
|
+
register_spec_kind("http_check", HttpCheckSpec)
|
|
44
|
+
register_spec_kind("backup_job", BackupJobSpec)
|
|
45
|
+
register_spec_kind("systemd_unit", SystemdUnitSpec)
|
|
46
|
+
register_spec_kind("systemd_timer", SystemdTimerSpec)
|
|
47
|
+
register_spec_kind("postgres_ensure", PostgresEnsureSpec)
|
|
48
|
+
register_spec_kind("package", PackageSpec)
|
|
49
|
+
register_spec_kind("blueprint", BlueprintSpec)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _register_normalizers() -> None:
|
|
53
|
+
from loft_cli.compiler.normalizer import (
|
|
54
|
+
_normalize_backup_job,
|
|
55
|
+
_normalize_blueprint,
|
|
56
|
+
_normalize_bootstrap,
|
|
57
|
+
_normalize_compose_project,
|
|
58
|
+
_normalize_file_template,
|
|
59
|
+
_normalize_http_check,
|
|
60
|
+
_normalize_package,
|
|
61
|
+
_normalize_postgres_ensure,
|
|
62
|
+
_normalize_service,
|
|
63
|
+
_normalize_stack,
|
|
64
|
+
_normalize_systemd_timer,
|
|
65
|
+
_normalize_systemd_unit,
|
|
66
|
+
)
|
|
67
|
+
from loft_cli_core.registry.normalizers import register_normalizer
|
|
68
|
+
|
|
69
|
+
register_normalizer("bootstrap", _normalize_bootstrap)
|
|
70
|
+
register_normalizer("service", _normalize_service)
|
|
71
|
+
register_normalizer("file_template", _normalize_file_template)
|
|
72
|
+
register_normalizer("compose_project", _normalize_compose_project)
|
|
73
|
+
register_normalizer("stack", _normalize_stack)
|
|
74
|
+
register_normalizer("http_check", _normalize_http_check)
|
|
75
|
+
register_normalizer("backup_job", _normalize_backup_job)
|
|
76
|
+
register_normalizer("postgres_ensure", _normalize_postgres_ensure)
|
|
77
|
+
register_normalizer("systemd_unit", _normalize_systemd_unit)
|
|
78
|
+
register_normalizer("systemd_timer", _normalize_systemd_timer)
|
|
79
|
+
register_normalizer("package", _normalize_package)
|
|
80
|
+
register_normalizer("blueprint", _normalize_blueprint)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _register_validators() -> None:
|
|
84
|
+
from loft_cli_core.registry.validators import register_validator
|
|
85
|
+
from loft_cli_core.specs.validators import (
|
|
86
|
+
validate_backup_job,
|
|
87
|
+
validate_blueprint,
|
|
88
|
+
validate_bootstrap,
|
|
89
|
+
validate_compose_project,
|
|
90
|
+
validate_file_template,
|
|
91
|
+
validate_http_check,
|
|
92
|
+
validate_package,
|
|
93
|
+
validate_postgres_ensure,
|
|
94
|
+
validate_service,
|
|
95
|
+
validate_stack,
|
|
96
|
+
validate_systemd_timer,
|
|
97
|
+
validate_systemd_unit,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
register_validator("bootstrap", validate_bootstrap)
|
|
101
|
+
register_validator("service", validate_service)
|
|
102
|
+
register_validator("file_template", validate_file_template)
|
|
103
|
+
register_validator("compose_project", validate_compose_project)
|
|
104
|
+
register_validator("stack", validate_stack)
|
|
105
|
+
register_validator("http_check", validate_http_check)
|
|
106
|
+
register_validator("backup_job", validate_backup_job)
|
|
107
|
+
register_validator("postgres_ensure", validate_postgres_ensure)
|
|
108
|
+
register_validator("systemd_unit", validate_systemd_unit)
|
|
109
|
+
register_validator("systemd_timer", validate_systemd_timer)
|
|
110
|
+
register_validator("package", validate_package)
|
|
111
|
+
register_validator("blueprint", validate_blueprint)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _register_planners() -> None:
|
|
115
|
+
from loft_cli.compiler.planner import (
|
|
116
|
+
_plan_backup_job,
|
|
117
|
+
_plan_blueprint,
|
|
118
|
+
_plan_bootstrap,
|
|
119
|
+
_plan_compose_project,
|
|
120
|
+
_plan_file_template,
|
|
121
|
+
_plan_http_check,
|
|
122
|
+
_plan_package,
|
|
123
|
+
_plan_postgres_ensure,
|
|
124
|
+
_plan_service,
|
|
125
|
+
_plan_stack,
|
|
126
|
+
_plan_systemd_timer,
|
|
127
|
+
_plan_systemd_unit,
|
|
128
|
+
)
|
|
129
|
+
from loft_cli_core.registry.planners import register_planner
|
|
130
|
+
|
|
131
|
+
register_planner("bootstrap", _plan_bootstrap)
|
|
132
|
+
register_planner("service", _plan_service)
|
|
133
|
+
register_planner("file_template", _plan_file_template)
|
|
134
|
+
register_planner("compose_project", _plan_compose_project)
|
|
135
|
+
register_planner("stack", _plan_stack)
|
|
136
|
+
register_planner("http_check", _plan_http_check)
|
|
137
|
+
register_planner("backup_job", _plan_backup_job)
|
|
138
|
+
register_planner("postgres_ensure", _plan_postgres_ensure)
|
|
139
|
+
register_planner("systemd_unit", _plan_systemd_unit)
|
|
140
|
+
register_planner("systemd_timer", _plan_systemd_timer)
|
|
141
|
+
register_planner("package", _plan_package)
|
|
142
|
+
register_planner("blueprint", _plan_blueprint)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _register_step_handlers() -> None:
|
|
146
|
+
from loft_cli_core.plan.models import StepKind
|
|
147
|
+
from loft_cli_core.registry.executors import register_step_handler
|
|
148
|
+
|
|
149
|
+
# Wrap Executor instance methods: handler(executor, step) -> StepResult.
|
|
150
|
+
# The executor's private _execute_* methods are left entirely unchanged.
|
|
151
|
+
register_step_handler(StepKind.GATE, lambda ex, step: ex._execute_gate(step))
|
|
152
|
+
register_step_handler(StepKind.SSH_COMMAND, lambda ex, step: ex._execute_ssh_command(step))
|
|
153
|
+
register_step_handler(StepKind.SSH_UPLOAD, lambda ex, step: ex._execute_ssh_upload(step))
|
|
154
|
+
register_step_handler(
|
|
155
|
+
StepKind.LOCAL_FILE_WRITE, lambda ex, step: ex._execute_local_file_write(step)
|
|
156
|
+
)
|
|
157
|
+
register_step_handler(
|
|
158
|
+
StepKind.LOCAL_DB_WRITE, lambda ex, step: ex._execute_local_db_write(step)
|
|
159
|
+
)
|
|
160
|
+
register_step_handler(StepKind.LOCAL_COMMAND, lambda ex, step: ex._execute_local_command(step))
|
|
161
|
+
register_step_handler(StepKind.VERIFY, lambda ex, step: ex._execute_verify(step))
|
|
162
|
+
register_step_handler(
|
|
163
|
+
StepKind.COMPOSE_HEALTH_CHECK,
|
|
164
|
+
lambda ex, step: ex._execute_compose_health_check(step),
|
|
165
|
+
)
|
|
166
|
+
register_step_handler(
|
|
167
|
+
StepKind.COMPOSE_HTTP_READY,
|
|
168
|
+
lambda ex, step: ex._execute_compose_http_ready(step),
|
|
169
|
+
)
|
|
170
|
+
register_step_handler(
|
|
171
|
+
StepKind.POST_DEPLOY_HTTP,
|
|
172
|
+
lambda ex, step: ex._execute_post_deploy_http(step),
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _register_hooks() -> None:
|
|
177
|
+
from loft_cli.local.inventory import (
|
|
178
|
+
record_backup_job_apply,
|
|
179
|
+
record_bootstrap,
|
|
180
|
+
record_compose_project_apply,
|
|
181
|
+
record_file_template_apply,
|
|
182
|
+
record_http_check_apply,
|
|
183
|
+
record_package_apply,
|
|
184
|
+
record_postgres_ensure_apply,
|
|
185
|
+
record_service_apply,
|
|
186
|
+
record_stack_apply,
|
|
187
|
+
record_systemd_timer_apply,
|
|
188
|
+
record_systemd_unit_apply,
|
|
189
|
+
)
|
|
190
|
+
from loft_cli_core.registry.hooks import KindHooks, register_kind_hooks
|
|
191
|
+
|
|
192
|
+
register_kind_hooks(
|
|
193
|
+
"bootstrap",
|
|
194
|
+
KindHooks(
|
|
195
|
+
needs_key_generation=True,
|
|
196
|
+
ssh_port_fallback=True,
|
|
197
|
+
on_inventory_record=record_bootstrap,
|
|
198
|
+
),
|
|
199
|
+
)
|
|
200
|
+
register_kind_hooks(
|
|
201
|
+
"service",
|
|
202
|
+
KindHooks(
|
|
203
|
+
needs_key_generation=False,
|
|
204
|
+
ssh_port_fallback=False,
|
|
205
|
+
on_inventory_record=record_service_apply,
|
|
206
|
+
),
|
|
207
|
+
)
|
|
208
|
+
register_kind_hooks(
|
|
209
|
+
"file_template",
|
|
210
|
+
KindHooks(
|
|
211
|
+
needs_key_generation=False,
|
|
212
|
+
ssh_port_fallback=False,
|
|
213
|
+
on_inventory_record=record_file_template_apply,
|
|
214
|
+
),
|
|
215
|
+
)
|
|
216
|
+
register_kind_hooks(
|
|
217
|
+
"compose_project",
|
|
218
|
+
KindHooks(
|
|
219
|
+
needs_key_generation=False,
|
|
220
|
+
ssh_port_fallback=False,
|
|
221
|
+
on_inventory_record=record_compose_project_apply,
|
|
222
|
+
),
|
|
223
|
+
)
|
|
224
|
+
register_kind_hooks(
|
|
225
|
+
"stack",
|
|
226
|
+
KindHooks(
|
|
227
|
+
needs_key_generation=False,
|
|
228
|
+
ssh_port_fallback=False,
|
|
229
|
+
on_inventory_record=record_stack_apply,
|
|
230
|
+
),
|
|
231
|
+
)
|
|
232
|
+
register_kind_hooks(
|
|
233
|
+
"http_check",
|
|
234
|
+
KindHooks(
|
|
235
|
+
needs_key_generation=False,
|
|
236
|
+
ssh_port_fallback=False,
|
|
237
|
+
on_inventory_record=record_http_check_apply,
|
|
238
|
+
),
|
|
239
|
+
)
|
|
240
|
+
register_kind_hooks(
|
|
241
|
+
"backup_job",
|
|
242
|
+
KindHooks(
|
|
243
|
+
needs_key_generation=False,
|
|
244
|
+
ssh_port_fallback=False,
|
|
245
|
+
on_inventory_record=record_backup_job_apply,
|
|
246
|
+
),
|
|
247
|
+
)
|
|
248
|
+
register_kind_hooks(
|
|
249
|
+
"postgres_ensure",
|
|
250
|
+
KindHooks(
|
|
251
|
+
needs_key_generation=False,
|
|
252
|
+
ssh_port_fallback=False,
|
|
253
|
+
on_inventory_record=record_postgres_ensure_apply,
|
|
254
|
+
),
|
|
255
|
+
)
|
|
256
|
+
register_kind_hooks(
|
|
257
|
+
"systemd_unit",
|
|
258
|
+
KindHooks(
|
|
259
|
+
needs_key_generation=False,
|
|
260
|
+
ssh_port_fallback=False,
|
|
261
|
+
on_inventory_record=record_systemd_unit_apply,
|
|
262
|
+
),
|
|
263
|
+
)
|
|
264
|
+
register_kind_hooks(
|
|
265
|
+
"systemd_timer",
|
|
266
|
+
KindHooks(
|
|
267
|
+
needs_key_generation=False,
|
|
268
|
+
ssh_port_fallback=False,
|
|
269
|
+
on_inventory_record=record_systemd_timer_apply,
|
|
270
|
+
),
|
|
271
|
+
)
|
|
272
|
+
register_kind_hooks(
|
|
273
|
+
"package",
|
|
274
|
+
KindHooks(
|
|
275
|
+
needs_key_generation=False,
|
|
276
|
+
ssh_port_fallback=False,
|
|
277
|
+
on_inventory_record=record_package_apply,
|
|
278
|
+
),
|
|
279
|
+
)
|
|
280
|
+
register_kind_hooks(
|
|
281
|
+
"blueprint",
|
|
282
|
+
KindHooks(
|
|
283
|
+
needs_key_generation=False,
|
|
284
|
+
ssh_port_fallback=False,
|
|
285
|
+
on_inventory_record=record_stack_apply, # blueprints expand like stacks
|
|
286
|
+
),
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def _extract_fields_from_model(model_class: type, prefix: str = "") -> list[dict]:
|
|
291
|
+
"""Recursively extract field metadata from a Pydantic v2 model class.
|
|
292
|
+
|
|
293
|
+
Returns a flat list of dicts with keys: name, type, required, description.
|
|
294
|
+
Nested block fields are recursively expanded with dot-notation names.
|
|
295
|
+
"""
|
|
296
|
+
fields: list[dict] = []
|
|
297
|
+
try:
|
|
298
|
+
model_fields = model_class.model_fields
|
|
299
|
+
except AttributeError:
|
|
300
|
+
return fields
|
|
301
|
+
|
|
302
|
+
for field_name, field_info in model_fields.items():
|
|
303
|
+
full_name = f"{prefix}.{field_name}" if prefix else field_name
|
|
304
|
+
annotation = field_info.annotation
|
|
305
|
+
required = field_info.is_required()
|
|
306
|
+
description = field_info.description or ""
|
|
307
|
+
|
|
308
|
+
# Try to get a clean type string
|
|
309
|
+
try:
|
|
310
|
+
if hasattr(annotation, "__origin__"):
|
|
311
|
+
type_str = str(annotation)
|
|
312
|
+
# Simplify common annotations
|
|
313
|
+
type_str = type_str.replace("typing.", "").replace("Optional[", "").rstrip("]")
|
|
314
|
+
elif annotation is None:
|
|
315
|
+
type_str = "any"
|
|
316
|
+
else:
|
|
317
|
+
type_str = getattr(annotation, "__name__", str(annotation))
|
|
318
|
+
except Exception:
|
|
319
|
+
type_str = str(annotation)
|
|
320
|
+
|
|
321
|
+
# Check if the annotation is a nested Pydantic model to expand
|
|
322
|
+
try:
|
|
323
|
+
from pydantic import BaseModel as _BaseModel
|
|
324
|
+
|
|
325
|
+
# Get the actual type (unwrap Optional/Union)
|
|
326
|
+
inner_type = annotation
|
|
327
|
+
if hasattr(annotation, "__origin__"):
|
|
328
|
+
args = getattr(annotation, "__args__", ())
|
|
329
|
+
# For Optional[X] (Union[X, None]), get X
|
|
330
|
+
non_none = [a for a in args if a is not type(None)]
|
|
331
|
+
if len(non_none) == 1:
|
|
332
|
+
inner_type = non_none[0]
|
|
333
|
+
|
|
334
|
+
if inner_type and isinstance(inner_type, type) and issubclass(inner_type, _BaseModel):
|
|
335
|
+
# Recurse into nested model — add the block-level entry plus its fields
|
|
336
|
+
fields.append(
|
|
337
|
+
{
|
|
338
|
+
"name": full_name,
|
|
339
|
+
"type": getattr(inner_type, "__name__", str(inner_type)),
|
|
340
|
+
"required": required,
|
|
341
|
+
"description": description,
|
|
342
|
+
}
|
|
343
|
+
)
|
|
344
|
+
# Expand sub-fields only for required/meaningful blocks
|
|
345
|
+
sub_fields = _extract_fields_from_model(inner_type, prefix=full_name)
|
|
346
|
+
fields.extend(sub_fields)
|
|
347
|
+
continue
|
|
348
|
+
except ImportError:
|
|
349
|
+
pass
|
|
350
|
+
|
|
351
|
+
fields.append(
|
|
352
|
+
{
|
|
353
|
+
"name": full_name,
|
|
354
|
+
"type": type_str,
|
|
355
|
+
"required": required,
|
|
356
|
+
"description": description,
|
|
357
|
+
}
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
return fields
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def _register_catalog_entries() -> None:
|
|
364
|
+
"""Register catalog entries for all built-in kinds with outputs and field metadata."""
|
|
365
|
+
from loft_cli_core.registry.catalog import (
|
|
366
|
+
CatalogEntry,
|
|
367
|
+
OutputTemplate,
|
|
368
|
+
register_catalog_entry,
|
|
369
|
+
)
|
|
370
|
+
from loft_cli_core.specs.backup_job_schema import BackupJobSpec
|
|
371
|
+
from loft_cli_core.specs.bootstrap_schema import BootstrapSpec
|
|
372
|
+
from loft_cli_core.specs.compose_project_schema import ComposeProjectSpec
|
|
373
|
+
from loft_cli_core.specs.file_template_schema import FileTemplateSpec
|
|
374
|
+
from loft_cli_core.specs.http_check_schema import HttpCheckSpec
|
|
375
|
+
from loft_cli_core.specs.package_schema import PackageSpec
|
|
376
|
+
from loft_cli_core.specs.postgres_ensure_schema import PostgresEnsureSpec
|
|
377
|
+
from loft_cli_core.specs.service_schema import ServiceSpec
|
|
378
|
+
from loft_cli_core.specs.stack_schema import StackSpec
|
|
379
|
+
from loft_cli_core.specs.systemd_timer_schema import SystemdTimerSpec
|
|
380
|
+
from loft_cli_core.specs.systemd_unit_schema import SystemdUnitSpec
|
|
381
|
+
|
|
382
|
+
# bootstrap
|
|
383
|
+
register_catalog_entry(
|
|
384
|
+
"bootstrap",
|
|
385
|
+
CatalogEntry(
|
|
386
|
+
kind="bootstrap",
|
|
387
|
+
description=(
|
|
388
|
+
"Harden a fresh Debian/Ubuntu host: SSH hardening, firewall, "
|
|
389
|
+
"admin user setup, and optional WireGuard VPN."
|
|
390
|
+
),
|
|
391
|
+
fields=_extract_fields_from_model(BootstrapSpec),
|
|
392
|
+
outputs=[
|
|
393
|
+
OutputTemplate(
|
|
394
|
+
name="ssh_alias",
|
|
395
|
+
description="SSH Host alias to connect to this host after bootstrap.",
|
|
396
|
+
example="ssh {provider}--{host.name} # e.g. ssh hetzner--dev-vps",
|
|
397
|
+
),
|
|
398
|
+
OutputTemplate(
|
|
399
|
+
name="ssh_port",
|
|
400
|
+
description="SSH port as configured by the bootstrap spec.",
|
|
401
|
+
example="2222",
|
|
402
|
+
),
|
|
403
|
+
],
|
|
404
|
+
),
|
|
405
|
+
)
|
|
406
|
+
|
|
407
|
+
# service
|
|
408
|
+
register_catalog_entry(
|
|
409
|
+
"service",
|
|
410
|
+
CatalogEntry(
|
|
411
|
+
kind="service",
|
|
412
|
+
description=(
|
|
413
|
+
"Install and configure services on a bootstrapped host: "
|
|
414
|
+
"PostgreSQL, Nginx, Docker, and individual containers."
|
|
415
|
+
),
|
|
416
|
+
fields=_extract_fields_from_model(ServiceSpec),
|
|
417
|
+
outputs=[
|
|
418
|
+
OutputTemplate(
|
|
419
|
+
name="postgres_host",
|
|
420
|
+
description="Hostname of the PostgreSQL server (when postgres is enabled).",
|
|
421
|
+
example="localhost",
|
|
422
|
+
),
|
|
423
|
+
OutputTemplate(
|
|
424
|
+
name="postgres_port",
|
|
425
|
+
description="Port PostgreSQL is listening on (when postgres is enabled).",
|
|
426
|
+
example="5432",
|
|
427
|
+
),
|
|
428
|
+
OutputTemplate(
|
|
429
|
+
name="postgres_database",
|
|
430
|
+
description="Name of the created database (when postgres.create_database is set).",
|
|
431
|
+
example="{postgres.create_database.name} # e.g. myapp",
|
|
432
|
+
),
|
|
433
|
+
OutputTemplate(
|
|
434
|
+
name="postgres_user",
|
|
435
|
+
description="Name of the created role (when postgres.create_role is set).",
|
|
436
|
+
example="{postgres.create_role.name} # e.g. myapp_user",
|
|
437
|
+
),
|
|
438
|
+
OutputTemplate(
|
|
439
|
+
name="nginx_site_url",
|
|
440
|
+
description="URL of the configured Nginx site (when nginx sites are declared).",
|
|
441
|
+
example="http://{nginx.sites[0].domain}",
|
|
442
|
+
),
|
|
443
|
+
],
|
|
444
|
+
),
|
|
445
|
+
)
|
|
446
|
+
|
|
447
|
+
# file_template
|
|
448
|
+
register_catalog_entry(
|
|
449
|
+
"file_template",
|
|
450
|
+
CatalogEntry(
|
|
451
|
+
kind="file_template",
|
|
452
|
+
description=(
|
|
453
|
+
"Render Jinja2 templates and upload managed configuration files to a remote host."
|
|
454
|
+
),
|
|
455
|
+
fields=_extract_fields_from_model(FileTemplateSpec),
|
|
456
|
+
),
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
# compose_project
|
|
460
|
+
register_catalog_entry(
|
|
461
|
+
"compose_project",
|
|
462
|
+
CatalogEntry(
|
|
463
|
+
kind="compose_project",
|
|
464
|
+
description=(
|
|
465
|
+
"Deploy a Docker Compose project: upload files, pull images, "
|
|
466
|
+
"start the stack, and verify health."
|
|
467
|
+
),
|
|
468
|
+
fields=_extract_fields_from_model(ComposeProjectSpec),
|
|
469
|
+
outputs=[
|
|
470
|
+
OutputTemplate(
|
|
471
|
+
name="project_dir",
|
|
472
|
+
description="Remote directory where the compose project files are uploaded.",
|
|
473
|
+
example="{project.directory} # e.g. /opt/myapp",
|
|
474
|
+
),
|
|
475
|
+
],
|
|
476
|
+
),
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
# stack
|
|
480
|
+
register_catalog_entry(
|
|
481
|
+
"stack",
|
|
482
|
+
CatalogEntry(
|
|
483
|
+
kind="stack",
|
|
484
|
+
description=(
|
|
485
|
+
"Group related resources into a single deployable application boundary, "
|
|
486
|
+
"executed in dependency order."
|
|
487
|
+
),
|
|
488
|
+
fields=_extract_fields_from_model(StackSpec),
|
|
489
|
+
),
|
|
490
|
+
)
|
|
491
|
+
|
|
492
|
+
# http_check
|
|
493
|
+
register_catalog_entry(
|
|
494
|
+
"http_check",
|
|
495
|
+
CatalogEntry(
|
|
496
|
+
kind="http_check",
|
|
497
|
+
description=(
|
|
498
|
+
"GET-only HTTP readiness probe with configurable retry and timeout. "
|
|
499
|
+
"Usable as a dependency gate in stacks."
|
|
500
|
+
),
|
|
501
|
+
fields=_extract_fields_from_model(HttpCheckSpec),
|
|
502
|
+
),
|
|
503
|
+
)
|
|
504
|
+
|
|
505
|
+
# backup_job
|
|
506
|
+
register_catalog_entry(
|
|
507
|
+
"backup_job",
|
|
508
|
+
CatalogEntry(
|
|
509
|
+
kind="backup_job",
|
|
510
|
+
description=(
|
|
511
|
+
"Define host-local backup operations (PostgreSQL dumps or directory backups) "
|
|
512
|
+
"with retention and scheduling via systemd timer."
|
|
513
|
+
),
|
|
514
|
+
fields=_extract_fields_from_model(BackupJobSpec),
|
|
515
|
+
),
|
|
516
|
+
)
|
|
517
|
+
|
|
518
|
+
# systemd_unit
|
|
519
|
+
register_catalog_entry(
|
|
520
|
+
"systemd_unit",
|
|
521
|
+
CatalogEntry(
|
|
522
|
+
kind="systemd_unit",
|
|
523
|
+
description=(
|
|
524
|
+
"Deploy and manage a host-native systemd service from structured declarations."
|
|
525
|
+
),
|
|
526
|
+
fields=_extract_fields_from_model(SystemdUnitSpec),
|
|
527
|
+
outputs=[
|
|
528
|
+
OutputTemplate(
|
|
529
|
+
name="unit_name",
|
|
530
|
+
description="The .service unit name as installed on the server.",
|
|
531
|
+
example="{unit.unit_name}.service # e.g. myapp.service",
|
|
532
|
+
),
|
|
533
|
+
],
|
|
534
|
+
),
|
|
535
|
+
)
|
|
536
|
+
|
|
537
|
+
# systemd_timer
|
|
538
|
+
register_catalog_entry(
|
|
539
|
+
"systemd_timer",
|
|
540
|
+
CatalogEntry(
|
|
541
|
+
kind="systemd_timer",
|
|
542
|
+
description=(
|
|
543
|
+
"Deploy scheduled execution via systemd timers: generates a .timer "
|
|
544
|
+
"and companion oneshot .service unit."
|
|
545
|
+
),
|
|
546
|
+
fields=_extract_fields_from_model(SystemdTimerSpec),
|
|
547
|
+
),
|
|
548
|
+
)
|
|
549
|
+
|
|
550
|
+
# postgres_ensure
|
|
551
|
+
register_catalog_entry(
|
|
552
|
+
"postgres_ensure",
|
|
553
|
+
CatalogEntry(
|
|
554
|
+
kind="postgres_ensure",
|
|
555
|
+
description=(
|
|
556
|
+
"Ensure PostgreSQL resources exist: users, databases, extensions, "
|
|
557
|
+
"and privilege grants."
|
|
558
|
+
),
|
|
559
|
+
fields=_extract_fields_from_model(PostgresEnsureSpec),
|
|
560
|
+
outputs=[
|
|
561
|
+
OutputTemplate(
|
|
562
|
+
name="database_url",
|
|
563
|
+
description="Connection string for the ensured PostgreSQL database.",
|
|
564
|
+
example=(
|
|
565
|
+
"postgres://{users[0].name}:***@{connection.host}:"
|
|
566
|
+
"{connection.port}/{databases[0].name}"
|
|
567
|
+
),
|
|
568
|
+
),
|
|
569
|
+
],
|
|
570
|
+
),
|
|
571
|
+
)
|
|
572
|
+
|
|
573
|
+
# package
|
|
574
|
+
register_catalog_entry(
|
|
575
|
+
"package",
|
|
576
|
+
CatalogEntry(
|
|
577
|
+
kind="package",
|
|
578
|
+
description=(
|
|
579
|
+
"Install or remove system packages on a remote host using the "
|
|
580
|
+
"native package manager (apt, yum/dnf)."
|
|
581
|
+
),
|
|
582
|
+
fields=_extract_fields_from_model(PackageSpec),
|
|
583
|
+
),
|
|
584
|
+
)
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
def _register_resolvers() -> None:
|
|
588
|
+
"""Register the built-in value resolvers: 'env' and 'file'."""
|
|
589
|
+
import os
|
|
590
|
+
from pathlib import Path
|
|
591
|
+
|
|
592
|
+
from loft_cli_core.registry.resolvers import register_resolver
|
|
593
|
+
|
|
594
|
+
def _resolve_env(key: str) -> str | None:
|
|
595
|
+
return os.environ.get(key)
|
|
596
|
+
|
|
597
|
+
def _resolve_file(key: str) -> str | None:
|
|
598
|
+
path = Path(key).expanduser()
|
|
599
|
+
if not path.is_absolute():
|
|
600
|
+
path = Path.cwd() / path
|
|
601
|
+
if not path.exists():
|
|
602
|
+
return None
|
|
603
|
+
content = path.read_text(encoding="utf-8")
|
|
604
|
+
# Strip a single trailing newline — common in key files, config files, etc.
|
|
605
|
+
return content.rstrip("\n")
|
|
606
|
+
|
|
607
|
+
register_resolver("env", _resolve_env)
|
|
608
|
+
register_resolver("file", _resolve_file)
|