sinapsis_cli 1.0.0__py3-none-any.whl
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.
- sinapsis_cli/__init__.py +13 -0
- sinapsis_cli/commands/__init__.py +0 -0
- sinapsis_cli/commands/cloud/__init__.py +0 -0
- sinapsis_cli/commands/cloud/_agent_selection.py +112 -0
- sinapsis_cli/commands/cloud/_secrets_render.py +15 -0
- sinapsis_cli/commands/cloud/_webhook_render.py +19 -0
- sinapsis_cli/commands/cloud/agents.py +137 -0
- sinapsis_cli/commands/cloud/api_keys.py +155 -0
- sinapsis_cli/commands/cloud/files.py +135 -0
- sinapsis_cli/commands/cloud/jobs.py +532 -0
- sinapsis_cli/commands/cloud/packages.py +164 -0
- sinapsis_cli/commands/cloud/schedules.py +392 -0
- sinapsis_cli/commands/cloud/secrets.py +96 -0
- sinapsis_cli/commands/cloud/templates.py +95 -0
- sinapsis_cli/commands/cloud/webhooks.py +156 -0
- sinapsis_cli/commands/common/__init__.py +0 -0
- sinapsis_cli/commands/common/auth.py +219 -0
- sinapsis_cli/commands/common/profiles.py +156 -0
- sinapsis_cli/commands/common/telemetry.py +150 -0
- sinapsis_cli/commands/local_api/__init__.py +0 -0
- sinapsis_cli/commands/local_api/jobs.py +284 -0
- sinapsis_cli/commands/local_venv/__init__.py +0 -0
- sinapsis_cli/commands/local_venv/_templates_render.py +56 -0
- sinapsis_cli/commands/local_venv/jobs.py +76 -0
- sinapsis_cli/commands/local_venv/templates.py +47 -0
- sinapsis_cli/composition.py +215 -0
- sinapsis_cli/config.py +446 -0
- sinapsis_cli/execution.py +77 -0
- sinapsis_cli/main.py +185 -0
- sinapsis_cli/main_multi.py +152 -0
- sinapsis_cli/shared/__init__.py +3 -0
- sinapsis_cli/shared/jobs.py +134 -0
- sinapsis_cli/shared/terminal.py +8 -0
- sinapsis_cli/shared/writer.py +427 -0
- sinapsis_cli/state.py +310 -0
- sinapsis_cli/telemetry/__init__.py +7 -0
- sinapsis_cli/telemetry/collector.py +84 -0
- sinapsis_cli/telemetry/core.py +331 -0
- sinapsis_cli/telemetry/scheduler.py +234 -0
- sinapsis_cli/telemetry/transport.py +150 -0
- sinapsis_cli-1.0.0.dist-info/METADATA +386 -0
- sinapsis_cli-1.0.0.dist-info/RECORD +46 -0
- sinapsis_cli-1.0.0.dist-info/WHEEL +4 -0
- sinapsis_cli-1.0.0.dist-info/entry_points.txt +5 -0
- sinapsis_cli-1.0.0.dist-info/licenses/LICENSE-APACHE +202 -0
- sinapsis_cli-1.0.0.dist-info/licenses/LICENSE-MIT +21 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
"""Cloud job scheduling commands backed by the authenticated Sinapsis SDK."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from datetime import datetime, time
|
|
6
|
+
from enum import StrEnum
|
|
7
|
+
from uuid import UUID
|
|
8
|
+
|
|
9
|
+
import typer
|
|
10
|
+
from pydantic import ValidationError
|
|
11
|
+
from rich.console import Console
|
|
12
|
+
from rich.table import Table
|
|
13
|
+
from sinapsis_contracts.cloud_api.models.scheduling import (
|
|
14
|
+
AgentSchedule,
|
|
15
|
+
ScheduleCreate,
|
|
16
|
+
ScheduleFields,
|
|
17
|
+
SchedulePage,
|
|
18
|
+
SchedulePatch,
|
|
19
|
+
ScheduleRunPage,
|
|
20
|
+
ScheduleType,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
from sinapsis_cli.execution import ExecutionContext, create_api_client
|
|
24
|
+
from sinapsis_cli.state import get_agent_selection, record_agent_selection
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass(frozen=True, slots=True)
|
|
28
|
+
class ScheduleCLISettings:
|
|
29
|
+
"""Immutable defaults shared by the scheduling commands."""
|
|
30
|
+
|
|
31
|
+
default_timezone: str = "UTC"
|
|
32
|
+
seconds_per_hour: int = 3600
|
|
33
|
+
default_list_limit: int = 100
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
SETTINGS = ScheduleCLISettings()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class Weekday(StrEnum):
|
|
40
|
+
"""Human-friendly weekday arguments in Python's Monday-first convention."""
|
|
41
|
+
|
|
42
|
+
MON = "mon"
|
|
43
|
+
TUE = "tue"
|
|
44
|
+
WED = "wed"
|
|
45
|
+
THU = "thu"
|
|
46
|
+
FRI = "fri"
|
|
47
|
+
SAT = "sat"
|
|
48
|
+
SUN = "sun"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _parse_datetime(value: str) -> datetime:
|
|
52
|
+
"""Require an ISO 8601 timestamp with an explicit UTC offset."""
|
|
53
|
+
try:
|
|
54
|
+
parsed = datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
55
|
+
except ValueError as error:
|
|
56
|
+
raise typer.BadParameter("Expected ISO 8601, e.g. 2026-12-01T09:00:00+00:00") from error
|
|
57
|
+
if parsed.tzinfo is None or parsed.utcoffset() is None:
|
|
58
|
+
raise typer.BadParameter("--once requires an explicit offset, e.g. +00:00 or Z")
|
|
59
|
+
return parsed
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _parse_local_time(value: str) -> time:
|
|
63
|
+
"""Parse a local wall-clock time without an embedded timezone offset."""
|
|
64
|
+
try:
|
|
65
|
+
parsed = time.fromisoformat(value)
|
|
66
|
+
except ValueError as error:
|
|
67
|
+
raise typer.BadParameter("Expected local time HH:MM or HH:MM:SS") from error
|
|
68
|
+
if parsed.tzinfo is not None:
|
|
69
|
+
raise typer.BadParameter("Use --timezone for daily/weekly times, not a time offset")
|
|
70
|
+
return parsed
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _make_recurrence(
|
|
74
|
+
*,
|
|
75
|
+
once: str | None,
|
|
76
|
+
daily: str | None,
|
|
77
|
+
weekly: str | None,
|
|
78
|
+
every_hours: int | None,
|
|
79
|
+
weekday: list[Weekday] | None,
|
|
80
|
+
timezone: str,
|
|
81
|
+
) -> ScheduleFields:
|
|
82
|
+
"""Validate exactly one recurrence mode through shared public contracts."""
|
|
83
|
+
modes = (once, daily, weekly, every_hours)
|
|
84
|
+
if sum(value is not None for value in modes) != 1:
|
|
85
|
+
raise typer.BadParameter("Choose exactly one of --once, --daily, --weekly, or --every-hours")
|
|
86
|
+
|
|
87
|
+
if weekday and weekly is None:
|
|
88
|
+
raise typer.BadParameter("--weekday requires --weekly")
|
|
89
|
+
|
|
90
|
+
fields: dict[str, object] = {"timezone": timezone}
|
|
91
|
+
if once is not None:
|
|
92
|
+
fields.update(schedule_type=ScheduleType.ONCE, run_at=_parse_datetime(once))
|
|
93
|
+
elif daily is not None:
|
|
94
|
+
fields.update(schedule_type=ScheduleType.DAILY, local_time=_parse_local_time(daily))
|
|
95
|
+
elif weekly is not None:
|
|
96
|
+
if not weekday:
|
|
97
|
+
raise typer.BadParameter("--weekly requires at least one --weekday (mon to sun)")
|
|
98
|
+
fields.update(
|
|
99
|
+
schedule_type=ScheduleType.WEEKLY,
|
|
100
|
+
local_time=_parse_local_time(weekly),
|
|
101
|
+
weekdays=sorted({list(Weekday).index(day) for day in weekday}),
|
|
102
|
+
)
|
|
103
|
+
else:
|
|
104
|
+
if every_hours is None or every_hours <= 0:
|
|
105
|
+
raise typer.BadParameter("--every-hours must be a positive whole number")
|
|
106
|
+
fields.update(
|
|
107
|
+
schedule_type=ScheduleType.INTERVAL,
|
|
108
|
+
interval_seconds=every_hours * SETTINGS.seconds_per_hour,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
try:
|
|
112
|
+
return ScheduleFields.model_validate(fields)
|
|
113
|
+
except ValidationError as error:
|
|
114
|
+
raise typer.BadParameter(str(error)) from error
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _optional_recurrence(
|
|
118
|
+
*,
|
|
119
|
+
once: str | None,
|
|
120
|
+
daily: str | None,
|
|
121
|
+
weekly: str | None,
|
|
122
|
+
every_hours: int | None,
|
|
123
|
+
weekday: list[Weekday] | None,
|
|
124
|
+
timezone: str | None,
|
|
125
|
+
) -> ScheduleFields | None:
|
|
126
|
+
"""Build a replacement recurrence or leave the current one intact."""
|
|
127
|
+
if not any(value is not None for value in (once, daily, weekly, every_hours)):
|
|
128
|
+
if timezone is not None or weekday:
|
|
129
|
+
raise typer.BadParameter("Changing timezone or weekdays requires a full recurrence mode")
|
|
130
|
+
return None
|
|
131
|
+
if timezone is None:
|
|
132
|
+
raise typer.BadParameter("Specify --timezone when replacing a recurrence")
|
|
133
|
+
return _make_recurrence(
|
|
134
|
+
once=once,
|
|
135
|
+
daily=daily,
|
|
136
|
+
weekly=weekly,
|
|
137
|
+
every_hours=every_hours,
|
|
138
|
+
weekday=weekday,
|
|
139
|
+
timezone=timezone,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _format_time(value: datetime | None) -> str:
|
|
144
|
+
"""Render an optional timestamp without hiding its timezone offset."""
|
|
145
|
+
return value.isoformat(timespec="seconds") if value is not None else "—"
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _print_schedule(schedule: AgentSchedule) -> None:
|
|
149
|
+
"""Display one schedule and its saved agent/version identifiers."""
|
|
150
|
+
typer.echo(f"Schedule: {schedule.name}")
|
|
151
|
+
typer.echo(f"ID: {schedule.id} Status: {schedule.status.value}")
|
|
152
|
+
typer.echo(f"Agent: {schedule.agent_id} Version: {schedule.agent_version_id}")
|
|
153
|
+
typer.echo(f"Recurrence: {schedule.schedule_type.value} Timezone: {schedule.timezone}")
|
|
154
|
+
if schedule.run_at is not None:
|
|
155
|
+
typer.echo(f"Runs once: {_format_time(schedule.run_at)}")
|
|
156
|
+
elif schedule.local_time is not None:
|
|
157
|
+
typer.echo(f"Local time: {schedule.local_time.isoformat(timespec='minutes')}")
|
|
158
|
+
if schedule.weekdays:
|
|
159
|
+
days = ", ".join(list(Weekday)[day].value for day in schedule.weekdays)
|
|
160
|
+
typer.echo(f"Weekdays: {days}")
|
|
161
|
+
if schedule.interval_seconds is not None:
|
|
162
|
+
typer.echo(f"Every {schedule.interval_seconds // SETTINGS.seconds_per_hour} hours")
|
|
163
|
+
if schedule.preset_id is not None:
|
|
164
|
+
typer.echo(f"Preset: {schedule.preset_id}")
|
|
165
|
+
typer.echo(f"Next run: {_format_time(schedule.next_run_at)}")
|
|
166
|
+
typer.echo(f"Last run: {_format_time(schedule.last_run_at)}")
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _print_schedule_page(page: SchedulePage) -> None:
|
|
170
|
+
"""Render schedules in a compact table suitable for terminals."""
|
|
171
|
+
if not page.items:
|
|
172
|
+
typer.echo("No schedules found.")
|
|
173
|
+
return
|
|
174
|
+
table = Table(title="Agent schedules")
|
|
175
|
+
for heading in ("Name", "ID", "Status", "Recurrence", "Next run"):
|
|
176
|
+
table.add_column(heading)
|
|
177
|
+
for item in page.items:
|
|
178
|
+
table.add_row(
|
|
179
|
+
item.name,
|
|
180
|
+
str(item.id),
|
|
181
|
+
item.status.value,
|
|
182
|
+
item.schedule_type.value,
|
|
183
|
+
_format_time(item.next_run_at),
|
|
184
|
+
)
|
|
185
|
+
Console().print(table)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _print_runs(page: ScheduleRunPage) -> None:
|
|
189
|
+
"""Render dispatch history with job IDs usable by ``jobs status``."""
|
|
190
|
+
if not page.items:
|
|
191
|
+
typer.echo("No scheduled runs found.")
|
|
192
|
+
return
|
|
193
|
+
table = Table(title="Scheduled runs")
|
|
194
|
+
for heading in ("Scheduled for", "Status", "Job ID", "Attempts", "Error"):
|
|
195
|
+
table.add_column(heading)
|
|
196
|
+
for item in page.items:
|
|
197
|
+
table.add_row(
|
|
198
|
+
_format_time(item.scheduled_for),
|
|
199
|
+
item.status.value,
|
|
200
|
+
item.redis_job_id,
|
|
201
|
+
str(item.attempt_count),
|
|
202
|
+
item.last_error or "",
|
|
203
|
+
)
|
|
204
|
+
Console().print(table)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
async def resolve_schedule_selection(agents_resource, profile: str, agent_id: UUID | None, version_id: UUID | None):
|
|
208
|
+
"""Resolve and authenticate all four documented ID-selection combinations."""
|
|
209
|
+
selected = get_agent_selection(profile)
|
|
210
|
+
resolved_agent = agent_id or (selected[0] if selected else None)
|
|
211
|
+
if resolved_agent is None:
|
|
212
|
+
raise typer.BadParameter("No selected agent; provide --agent-id or register one")
|
|
213
|
+
|
|
214
|
+
if version_id is not None:
|
|
215
|
+
candidate = version_id
|
|
216
|
+
elif agent_id is None and selected is not None:
|
|
217
|
+
candidate = selected[1]
|
|
218
|
+
else:
|
|
219
|
+
candidate = None
|
|
220
|
+
|
|
221
|
+
saved = (
|
|
222
|
+
await agents_resource.version(resolved_agent, candidate)
|
|
223
|
+
if candidate is not None
|
|
224
|
+
else await agents_resource.latest_version(resolved_agent)
|
|
225
|
+
)
|
|
226
|
+
if saved.agent_id != resolved_agent:
|
|
227
|
+
raise typer.BadParameter("Version does not belong to the specified agent")
|
|
228
|
+
return saved
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def create_app(execution: ExecutionContext) -> typer.Typer:
|
|
232
|
+
"""Build the ``jobs schedule`` command group for the current Cloud profile."""
|
|
233
|
+
app = typer.Typer(
|
|
234
|
+
name="schedule",
|
|
235
|
+
help="Schedule saved agent versions and manage recurring jobs.",
|
|
236
|
+
no_args_is_help=True,
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
@app.command("create")
|
|
240
|
+
def create(
|
|
241
|
+
name: str = typer.Option(..., "--name", help="Friendly schedule name."),
|
|
242
|
+
agent_id: UUID | None = typer.Option(None, "--agent-id", help="Saved agent UUID; defaults to last selection."),
|
|
243
|
+
agent_version_id: UUID | None = typer.Option(
|
|
244
|
+
None, "--agent-version-id", help="Immutable version UUID; defaults to saved or newest."
|
|
245
|
+
),
|
|
246
|
+
preset_id: UUID | None = typer.Option(None, "--preset-id", help="Optional saved agent preset UUID."),
|
|
247
|
+
once: str | None = typer.Option(None, "--once", help="Once at ISO 8601 timestamp with UTC offset."),
|
|
248
|
+
daily: str | None = typer.Option(None, "--daily", help="Daily at local time HH:MM."),
|
|
249
|
+
weekly: str | None = typer.Option(None, "--weekly", help="Weekly at local time HH:MM."),
|
|
250
|
+
every_hours: int | None = typer.Option(None, "--every-hours", help="Fixed elapsed interval in hours."),
|
|
251
|
+
weekday: list[Weekday] | None = typer.Option(None, "--weekday", help="Weekday for --weekly; repeat."),
|
|
252
|
+
timezone: str = typer.Option(SETTINGS.default_timezone, "--timezone", help="IANA timezone."),
|
|
253
|
+
) -> None:
|
|
254
|
+
"""Schedule an existing, saved agent version; do not submit YAML directly."""
|
|
255
|
+
recurrence = _make_recurrence(
|
|
256
|
+
once=once,
|
|
257
|
+
daily=daily,
|
|
258
|
+
weekly=weekly,
|
|
259
|
+
every_hours=every_hours,
|
|
260
|
+
weekday=weekday,
|
|
261
|
+
timezone=timezone,
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
async def operation() -> None:
|
|
265
|
+
async with create_api_client(execution) as client:
|
|
266
|
+
saved = await resolve_schedule_selection(
|
|
267
|
+
client.agents, execution.profile_name, agent_id, agent_version_id
|
|
268
|
+
)
|
|
269
|
+
request = ScheduleCreate(
|
|
270
|
+
**recurrence.model_dump(),
|
|
271
|
+
name=name,
|
|
272
|
+
agent_id=saved.agent_id,
|
|
273
|
+
agent_version_id=saved.id,
|
|
274
|
+
preset_id=preset_id,
|
|
275
|
+
)
|
|
276
|
+
created = await client.schedules.create(request)
|
|
277
|
+
record_agent_selection(execution.profile_name, saved.agent_id, saved.id)
|
|
278
|
+
typer.echo("Schedule created.")
|
|
279
|
+
_print_schedule(created)
|
|
280
|
+
|
|
281
|
+
asyncio.run(operation())
|
|
282
|
+
|
|
283
|
+
@app.command("list")
|
|
284
|
+
def list_schedules(
|
|
285
|
+
limit: int = typer.Option(SETTINGS.default_list_limit, "--limit", min=1, max=200),
|
|
286
|
+
) -> None:
|
|
287
|
+
"""List schedules owned by the current Cloud user."""
|
|
288
|
+
|
|
289
|
+
async def operation() -> None:
|
|
290
|
+
async with create_api_client(execution) as client:
|
|
291
|
+
page = await client.schedules.list(limit=limit)
|
|
292
|
+
_print_schedule_page(page)
|
|
293
|
+
|
|
294
|
+
asyncio.run(operation())
|
|
295
|
+
|
|
296
|
+
@app.command("show")
|
|
297
|
+
def show(schedule_id: UUID = typer.Argument(..., help="Schedule UUID.")) -> None:
|
|
298
|
+
"""Display recurrence details and the next expected run."""
|
|
299
|
+
|
|
300
|
+
async def operation() -> None:
|
|
301
|
+
async with create_api_client(execution) as client:
|
|
302
|
+
schedule = await client.schedules.get(schedule_id)
|
|
303
|
+
_print_schedule(schedule)
|
|
304
|
+
|
|
305
|
+
asyncio.run(operation())
|
|
306
|
+
|
|
307
|
+
@app.command("update")
|
|
308
|
+
def update(
|
|
309
|
+
schedule_id: UUID = typer.Argument(..., help="Schedule UUID."),
|
|
310
|
+
name: str | None = typer.Option(None, "--name", help="New schedule name."),
|
|
311
|
+
once: str | None = typer.Option(None, "--once", help="Replace with one-time execution."),
|
|
312
|
+
daily: str | None = typer.Option(None, "--daily", help="Replace with a daily local time."),
|
|
313
|
+
weekly: str | None = typer.Option(None, "--weekly", help="Replace with a weekly local time."),
|
|
314
|
+
every_hours: int | None = typer.Option(None, "--every-hours", help="Replace with fixed interval."),
|
|
315
|
+
weekday: list[Weekday] | None = typer.Option(None, "--weekday", help="Repeat for weekly days."),
|
|
316
|
+
timezone: str | None = typer.Option(None, "--timezone", help="IANA timezone for new recurrence."),
|
|
317
|
+
) -> None:
|
|
318
|
+
"""Rename a schedule or replace its complete recurrence definition."""
|
|
319
|
+
recurrence = _optional_recurrence(
|
|
320
|
+
once=once,
|
|
321
|
+
daily=daily,
|
|
322
|
+
weekly=weekly,
|
|
323
|
+
every_hours=every_hours,
|
|
324
|
+
weekday=weekday,
|
|
325
|
+
timezone=timezone,
|
|
326
|
+
)
|
|
327
|
+
if name is None and recurrence is None:
|
|
328
|
+
raise typer.BadParameter("Provide --name or a new recurrence")
|
|
329
|
+
patch = SchedulePatch(name=name, recurrence=recurrence)
|
|
330
|
+
patch = SchedulePatch.model_validate(patch.model_dump(exclude_none=True))
|
|
331
|
+
|
|
332
|
+
async def operation() -> None:
|
|
333
|
+
async with create_api_client(execution) as client:
|
|
334
|
+
updated = await client.schedules.update(schedule_id, patch)
|
|
335
|
+
typer.echo("Schedule updated.")
|
|
336
|
+
_print_schedule(updated)
|
|
337
|
+
|
|
338
|
+
asyncio.run(operation())
|
|
339
|
+
|
|
340
|
+
@app.command("pause")
|
|
341
|
+
def pause(schedule_id: UUID = typer.Argument(..., help="Schedule UUID.")) -> None:
|
|
342
|
+
"""Pause future occurrences without deleting the schedule."""
|
|
343
|
+
|
|
344
|
+
async def operation() -> None:
|
|
345
|
+
async with create_api_client(execution) as client:
|
|
346
|
+
schedule = await client.schedules.pause(schedule_id)
|
|
347
|
+
_print_schedule(schedule)
|
|
348
|
+
|
|
349
|
+
asyncio.run(operation())
|
|
350
|
+
|
|
351
|
+
@app.command("resume")
|
|
352
|
+
def resume(schedule_id: UUID = typer.Argument(..., help="Schedule UUID.")) -> None:
|
|
353
|
+
"""Resume a paused schedule and recalculate its next occurrence."""
|
|
354
|
+
|
|
355
|
+
async def operation() -> None:
|
|
356
|
+
async with create_api_client(execution) as client:
|
|
357
|
+
schedule = await client.schedules.resume(schedule_id)
|
|
358
|
+
_print_schedule(schedule)
|
|
359
|
+
|
|
360
|
+
asyncio.run(operation())
|
|
361
|
+
|
|
362
|
+
@app.command("delete")
|
|
363
|
+
def delete(
|
|
364
|
+
schedule_id: UUID = typer.Argument(..., help="Schedule UUID."),
|
|
365
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation prompt."),
|
|
366
|
+
) -> None:
|
|
367
|
+
"""Disable a schedule, retaining dispatch and job history."""
|
|
368
|
+
if not yes and not typer.confirm(f"Disable schedule {schedule_id}?"):
|
|
369
|
+
raise typer.Abort()
|
|
370
|
+
|
|
371
|
+
async def operation() -> None:
|
|
372
|
+
async with create_api_client(execution) as client:
|
|
373
|
+
await client.schedules.delete(schedule_id)
|
|
374
|
+
typer.echo(f"Schedule disabled: {schedule_id}")
|
|
375
|
+
|
|
376
|
+
asyncio.run(operation())
|
|
377
|
+
|
|
378
|
+
@app.command("runs")
|
|
379
|
+
def runs(
|
|
380
|
+
schedule_id: UUID = typer.Argument(..., help="Schedule UUID."),
|
|
381
|
+
limit: int = typer.Option(SETTINGS.default_list_limit, "--limit", min=1, max=200),
|
|
382
|
+
) -> None:
|
|
383
|
+
"""Display scheduled dispatches and their Redis job identifiers."""
|
|
384
|
+
|
|
385
|
+
async def operation() -> None:
|
|
386
|
+
async with create_api_client(execution) as client:
|
|
387
|
+
page = await client.schedules.runs(schedule_id, limit=limit)
|
|
388
|
+
_print_runs(page)
|
|
389
|
+
|
|
390
|
+
asyncio.run(operation())
|
|
391
|
+
|
|
392
|
+
return app
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""Secret commands for the Sinapsis CLI."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from uuid import UUID
|
|
5
|
+
|
|
6
|
+
import typer
|
|
7
|
+
from sinapsis_contracts.cloud_api.models.secrets.payloads import CreateSecretRequest
|
|
8
|
+
|
|
9
|
+
from sinapsis_cli.execution import ExecutionContext, create_api_client, get_execution_context
|
|
10
|
+
|
|
11
|
+
from ._secrets_render import print_user_secrets
|
|
12
|
+
|
|
13
|
+
app = typer.Typer(name="secrets", help="Manage secrets.", no_args_is_help=True)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.command()
|
|
17
|
+
def create(
|
|
18
|
+
ctx: typer.Context,
|
|
19
|
+
label_args: list[str] = typer.Argument(None, metavar="LABEL", help="Label for the secret (e.g. 'my-label')."),
|
|
20
|
+
label_opt: str | None = typer.Option(None, "--label", "-l", help="Label for the secret."),
|
|
21
|
+
value: str | None = typer.Option(None, "--value", "-v", help="Secret value. If omitted, prompt securely."),
|
|
22
|
+
) -> None:
|
|
23
|
+
"""Create a new secret."""
|
|
24
|
+
label = label_opt
|
|
25
|
+
|
|
26
|
+
if not label and label_args:
|
|
27
|
+
if len(label_args) == 2 and label_args[0].lower() == "label":
|
|
28
|
+
label = label_args[1]
|
|
29
|
+
elif len(label_args) == 1:
|
|
30
|
+
label = label_args[0].removeprefix("label=")
|
|
31
|
+
else:
|
|
32
|
+
label = " ".join(label_args)
|
|
33
|
+
|
|
34
|
+
if not label:
|
|
35
|
+
raise typer.BadParameter("Label is required. Use `create LABEL` or `create --label LABEL`.")
|
|
36
|
+
|
|
37
|
+
if value is None:
|
|
38
|
+
value = typer.prompt("Secret value", hide_input=True, confirmation_prompt=True)
|
|
39
|
+
|
|
40
|
+
payload = CreateSecretRequest(label=label, secret=value)
|
|
41
|
+
asyncio.run(_create(get_execution_context(ctx), payload))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
async def _create(execution: ExecutionContext, payload: CreateSecretRequest) -> None:
|
|
45
|
+
async with create_api_client(execution) as client:
|
|
46
|
+
secret = await client.secrets.create(payload)
|
|
47
|
+
|
|
48
|
+
typer.echo(f"Created secret {secret.label!r}.")
|
|
49
|
+
typer.echo(f"Metadata ID: {secret.id}")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@app.command("list")
|
|
53
|
+
def list_secrets(ctx: typer.Context) -> None:
|
|
54
|
+
"""List stored secret metadata."""
|
|
55
|
+
asyncio.run(_list_secrets(get_execution_context(ctx)))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
async def _list_secrets(execution: ExecutionContext) -> None:
|
|
59
|
+
async with create_api_client(execution) as client:
|
|
60
|
+
response = await client.secrets.list_user_secrets()
|
|
61
|
+
|
|
62
|
+
if not response.secrets:
|
|
63
|
+
typer.echo("No secrets found.")
|
|
64
|
+
return
|
|
65
|
+
|
|
66
|
+
print_user_secrets(response)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@app.command()
|
|
70
|
+
def get(ctx: typer.Context, metadata_id: UUID = typer.Argument(..., help="Metadata ID of the secret.")) -> None:
|
|
71
|
+
"""Get metadata for a stored secret."""
|
|
72
|
+
asyncio.run(_get(get_execution_context(ctx), metadata_id))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
async def _get(execution: ExecutionContext, metadata_id: UUID) -> None:
|
|
76
|
+
async with create_api_client(execution) as client:
|
|
77
|
+
secret = await client.secrets.get(metadata_id)
|
|
78
|
+
|
|
79
|
+
typer.echo(f"Label: {secret.label}")
|
|
80
|
+
typer.echo(f"Metadata ID: {secret.id}")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@app.command()
|
|
84
|
+
def delete(ctx: typer.Context, metadata_id: UUID = typer.Argument(..., help="Metadata ID of the secret.")) -> None:
|
|
85
|
+
"""Delete a stored secret."""
|
|
86
|
+
if not typer.confirm(f"Delete secret {metadata_id!r}?"):
|
|
87
|
+
raise typer.Abort()
|
|
88
|
+
|
|
89
|
+
asyncio.run(_delete(get_execution_context(ctx), metadata_id))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
async def _delete(execution: ExecutionContext, metadata_id: UUID) -> None:
|
|
93
|
+
async with create_api_client(execution) as client:
|
|
94
|
+
await client.secrets.delete(metadata_id)
|
|
95
|
+
|
|
96
|
+
typer.echo(f"Deleted secret: {metadata_id}")
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""User-facing Cloud template and package discovery."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import json
|
|
5
|
+
from uuid import UUID
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
|
|
9
|
+
from sinapsis_cli.execution import ExecutionContext, create_api_client, get_execution_context
|
|
10
|
+
|
|
11
|
+
app = typer.Typer(name="templates", help="Search published Cloud templates.", no_args_is_help=True)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _render_page(page) -> None:
|
|
15
|
+
for item in page.items:
|
|
16
|
+
typer.echo(
|
|
17
|
+
f"{item.get('class_name') or item.get('title') or item.get('name')} "
|
|
18
|
+
f"[{item.get('package', item.get('version', ''))}] "
|
|
19
|
+
f"{item.get('id', '')}"
|
|
20
|
+
)
|
|
21
|
+
typer.echo(f"Showing {len(page.items)} of {page.total} results (offset {page.offset})")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@app.command("search")
|
|
25
|
+
def search_templates(
|
|
26
|
+
ctx: typer.Context,
|
|
27
|
+
query: str = typer.Argument(..., help="Class, tag, description or capability."),
|
|
28
|
+
category: str | None = typer.Option(None, "--category"),
|
|
29
|
+
package: str | None = typer.Option(None, "--package"),
|
|
30
|
+
tag: str | None = typer.Option(None, "--tag"),
|
|
31
|
+
limit: int = typer.Option(50, "--limit", min=1, max=200),
|
|
32
|
+
offset: int = typer.Option(0, "--offset", min=0),
|
|
33
|
+
) -> None:
|
|
34
|
+
"""Search the authorized docs catalog with relevance ranking."""
|
|
35
|
+
asyncio.run(_search(get_execution_context(ctx), query, category, package, tag, limit, offset))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
async def _search(
|
|
39
|
+
execution: ExecutionContext,
|
|
40
|
+
query: str,
|
|
41
|
+
category: str | None,
|
|
42
|
+
package: str | None,
|
|
43
|
+
tag: str | None,
|
|
44
|
+
limit: int,
|
|
45
|
+
offset: int,
|
|
46
|
+
) -> None:
|
|
47
|
+
async with create_api_client(execution) as client:
|
|
48
|
+
result = await client.templates.search(
|
|
49
|
+
query, category=category, package=package, tag=tag, limit=limit, offset=offset
|
|
50
|
+
)
|
|
51
|
+
_render_page(result)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@app.command("list")
|
|
55
|
+
def list_templates(
|
|
56
|
+
ctx: typer.Context,
|
|
57
|
+
limit: int = typer.Option(50, "--limit", min=1, max=200),
|
|
58
|
+
offset: int = typer.Option(0, "--offset", min=0),
|
|
59
|
+
) -> None:
|
|
60
|
+
"""List templates visible to this user."""
|
|
61
|
+
asyncio.run(_list(get_execution_context(ctx), limit, offset))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
async def _list(execution: ExecutionContext, limit: int, offset: int) -> None:
|
|
65
|
+
async with create_api_client(execution) as client:
|
|
66
|
+
result = await client.templates.list(limit=limit, offset=offset)
|
|
67
|
+
_render_page(result)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@app.command("show")
|
|
71
|
+
def show_template(ctx: typer.Context, template_id: UUID) -> None:
|
|
72
|
+
"""Display one published template's full documentation."""
|
|
73
|
+
asyncio.run(_show(get_execution_context(ctx), template_id))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
async def _show(execution: ExecutionContext, template_id: UUID) -> None:
|
|
77
|
+
async with create_api_client(execution) as client:
|
|
78
|
+
result = await client.templates.get(template_id)
|
|
79
|
+
typer.echo(json.dumps(result, indent=2, default=str))
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@app.command("packages")
|
|
83
|
+
def list_packages(
|
|
84
|
+
ctx: typer.Context,
|
|
85
|
+
limit: int = typer.Option(50, "--limit", min=1, max=200),
|
|
86
|
+
offset: int = typer.Option(0, "--offset", min=0),
|
|
87
|
+
) -> None:
|
|
88
|
+
"""List packages containing templates accessible to this user."""
|
|
89
|
+
asyncio.run(_packages(get_execution_context(ctx), limit, offset))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
async def _packages(execution: ExecutionContext, limit: int, offset: int) -> None:
|
|
93
|
+
async with create_api_client(execution) as client:
|
|
94
|
+
result = await client.templates.packages(limit=limit, offset=offset)
|
|
95
|
+
_render_page(result)
|