kstlib 0.0.1a0__py3-none-any.whl → 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.
- kstlib/__init__.py +266 -1
- kstlib/__main__.py +16 -0
- kstlib/alerts/__init__.py +110 -0
- kstlib/alerts/channels/__init__.py +36 -0
- kstlib/alerts/channels/base.py +197 -0
- kstlib/alerts/channels/email.py +227 -0
- kstlib/alerts/channels/slack.py +389 -0
- kstlib/alerts/exceptions.py +72 -0
- kstlib/alerts/manager.py +651 -0
- kstlib/alerts/models.py +142 -0
- kstlib/alerts/throttle.py +263 -0
- kstlib/auth/__init__.py +139 -0
- kstlib/auth/callback.py +399 -0
- kstlib/auth/config.py +502 -0
- kstlib/auth/errors.py +127 -0
- kstlib/auth/models.py +316 -0
- kstlib/auth/providers/__init__.py +14 -0
- kstlib/auth/providers/base.py +393 -0
- kstlib/auth/providers/oauth2.py +645 -0
- kstlib/auth/providers/oidc.py +821 -0
- kstlib/auth/session.py +338 -0
- kstlib/auth/token.py +482 -0
- kstlib/cache/__init__.py +50 -0
- kstlib/cache/decorator.py +261 -0
- kstlib/cache/strategies.py +516 -0
- kstlib/cli/__init__.py +8 -0
- kstlib/cli/app.py +195 -0
- kstlib/cli/commands/__init__.py +5 -0
- kstlib/cli/commands/auth/__init__.py +39 -0
- kstlib/cli/commands/auth/common.py +122 -0
- kstlib/cli/commands/auth/login.py +325 -0
- kstlib/cli/commands/auth/logout.py +74 -0
- kstlib/cli/commands/auth/providers.py +57 -0
- kstlib/cli/commands/auth/status.py +291 -0
- kstlib/cli/commands/auth/token.py +199 -0
- kstlib/cli/commands/auth/whoami.py +106 -0
- kstlib/cli/commands/config.py +89 -0
- kstlib/cli/commands/ops/__init__.py +39 -0
- kstlib/cli/commands/ops/attach.py +49 -0
- kstlib/cli/commands/ops/common.py +269 -0
- kstlib/cli/commands/ops/list_sessions.py +252 -0
- kstlib/cli/commands/ops/logs.py +49 -0
- kstlib/cli/commands/ops/start.py +98 -0
- kstlib/cli/commands/ops/status.py +138 -0
- kstlib/cli/commands/ops/stop.py +60 -0
- kstlib/cli/commands/rapi/__init__.py +60 -0
- kstlib/cli/commands/rapi/call.py +341 -0
- kstlib/cli/commands/rapi/list.py +99 -0
- kstlib/cli/commands/rapi/show.py +206 -0
- kstlib/cli/commands/secrets/__init__.py +35 -0
- kstlib/cli/commands/secrets/common.py +425 -0
- kstlib/cli/commands/secrets/decrypt.py +88 -0
- kstlib/cli/commands/secrets/doctor.py +743 -0
- kstlib/cli/commands/secrets/encrypt.py +242 -0
- kstlib/cli/commands/secrets/shred.py +96 -0
- kstlib/cli/common.py +86 -0
- kstlib/config/__init__.py +76 -0
- kstlib/config/exceptions.py +110 -0
- kstlib/config/export.py +225 -0
- kstlib/config/loader.py +963 -0
- kstlib/config/sops.py +287 -0
- kstlib/db/__init__.py +54 -0
- kstlib/db/aiosqlcipher.py +137 -0
- kstlib/db/cipher.py +112 -0
- kstlib/db/database.py +367 -0
- kstlib/db/exceptions.py +25 -0
- kstlib/db/pool.py +302 -0
- kstlib/helpers/__init__.py +35 -0
- kstlib/helpers/exceptions.py +11 -0
- kstlib/helpers/time_trigger.py +396 -0
- kstlib/kstlib.conf.yml +890 -0
- kstlib/limits.py +963 -0
- kstlib/logging/__init__.py +108 -0
- kstlib/logging/manager.py +633 -0
- kstlib/mail/__init__.py +42 -0
- kstlib/mail/builder.py +626 -0
- kstlib/mail/exceptions.py +27 -0
- kstlib/mail/filesystem.py +248 -0
- kstlib/mail/transport.py +224 -0
- kstlib/mail/transports/__init__.py +19 -0
- kstlib/mail/transports/gmail.py +268 -0
- kstlib/mail/transports/resend.py +324 -0
- kstlib/mail/transports/smtp.py +326 -0
- kstlib/meta.py +72 -0
- kstlib/metrics/__init__.py +88 -0
- kstlib/metrics/decorators.py +1090 -0
- kstlib/metrics/exceptions.py +14 -0
- kstlib/monitoring/__init__.py +116 -0
- kstlib/monitoring/_styles.py +163 -0
- kstlib/monitoring/cell.py +57 -0
- kstlib/monitoring/config.py +424 -0
- kstlib/monitoring/delivery.py +579 -0
- kstlib/monitoring/exceptions.py +63 -0
- kstlib/monitoring/image.py +220 -0
- kstlib/monitoring/kv.py +79 -0
- kstlib/monitoring/list.py +69 -0
- kstlib/monitoring/metric.py +88 -0
- kstlib/monitoring/monitoring.py +341 -0
- kstlib/monitoring/renderer.py +139 -0
- kstlib/monitoring/service.py +392 -0
- kstlib/monitoring/table.py +129 -0
- kstlib/monitoring/types.py +56 -0
- kstlib/ops/__init__.py +86 -0
- kstlib/ops/base.py +148 -0
- kstlib/ops/container.py +577 -0
- kstlib/ops/exceptions.py +209 -0
- kstlib/ops/manager.py +407 -0
- kstlib/ops/models.py +176 -0
- kstlib/ops/tmux.py +372 -0
- kstlib/ops/validators.py +287 -0
- kstlib/py.typed +0 -0
- kstlib/rapi/__init__.py +118 -0
- kstlib/rapi/client.py +875 -0
- kstlib/rapi/config.py +861 -0
- kstlib/rapi/credentials.py +887 -0
- kstlib/rapi/exceptions.py +213 -0
- kstlib/resilience/__init__.py +101 -0
- kstlib/resilience/circuit_breaker.py +440 -0
- kstlib/resilience/exceptions.py +95 -0
- kstlib/resilience/heartbeat.py +491 -0
- kstlib/resilience/rate_limiter.py +506 -0
- kstlib/resilience/shutdown.py +417 -0
- kstlib/resilience/watchdog.py +637 -0
- kstlib/secrets/__init__.py +29 -0
- kstlib/secrets/exceptions.py +19 -0
- kstlib/secrets/models.py +62 -0
- kstlib/secrets/providers/__init__.py +79 -0
- kstlib/secrets/providers/base.py +58 -0
- kstlib/secrets/providers/environment.py +66 -0
- kstlib/secrets/providers/keyring.py +107 -0
- kstlib/secrets/providers/kms.py +223 -0
- kstlib/secrets/providers/kwargs.py +101 -0
- kstlib/secrets/providers/sops.py +209 -0
- kstlib/secrets/resolver.py +221 -0
- kstlib/secrets/sensitive.py +130 -0
- kstlib/secure/__init__.py +23 -0
- kstlib/secure/fs.py +194 -0
- kstlib/secure/permissions.py +70 -0
- kstlib/ssl.py +347 -0
- kstlib/ui/__init__.py +23 -0
- kstlib/ui/exceptions.py +26 -0
- kstlib/ui/panels.py +484 -0
- kstlib/ui/spinner.py +864 -0
- kstlib/ui/tables.py +382 -0
- kstlib/utils/__init__.py +48 -0
- kstlib/utils/dict.py +36 -0
- kstlib/utils/formatting.py +338 -0
- kstlib/utils/http_trace.py +237 -0
- kstlib/utils/lazy.py +49 -0
- kstlib/utils/secure_delete.py +205 -0
- kstlib/utils/serialization.py +247 -0
- kstlib/utils/text.py +56 -0
- kstlib/utils/validators.py +124 -0
- kstlib/websocket/__init__.py +97 -0
- kstlib/websocket/exceptions.py +214 -0
- kstlib/websocket/manager.py +1102 -0
- kstlib/websocket/models.py +361 -0
- kstlib-1.0.0.dist-info/METADATA +201 -0
- kstlib-1.0.0.dist-info/RECORD +163 -0
- {kstlib-0.0.1a0.dist-info → kstlib-1.0.0.dist-info}/WHEEL +1 -1
- kstlib-1.0.0.dist-info/entry_points.txt +2 -0
- kstlib-1.0.0.dist-info/licenses/LICENSE.md +9 -0
- kstlib-0.0.1a0.dist-info/METADATA +0 -29
- kstlib-0.0.1a0.dist-info/RECORD +0 -6
- kstlib-0.0.1a0.dist-info/licenses/LICENSE.md +0 -5
- {kstlib-0.0.1a0.dist-info → kstlib-1.0.0.dist-info}/top_level.txt +0 -0
kstlib/ops/base.py
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"""Abstract base protocol for session runners.
|
|
2
|
+
|
|
3
|
+
This module defines the protocol that all session runners must implement,
|
|
4
|
+
enabling backend abstraction for tmux and container-based session management.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import TYPE_CHECKING, Protocol, runtime_checkable
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from kstlib.ops.models import SessionConfig, SessionStatus
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@runtime_checkable
|
|
16
|
+
class AbstractRunner(Protocol):
|
|
17
|
+
"""Protocol defining the interface for session runners.
|
|
18
|
+
|
|
19
|
+
All session runners (TmuxRunner, ContainerRunner) must implement
|
|
20
|
+
this protocol to ensure consistent behavior across backends.
|
|
21
|
+
|
|
22
|
+
The protocol defines core operations for session lifecycle management:
|
|
23
|
+
- start: Create and start a new session
|
|
24
|
+
- stop: Stop a running session
|
|
25
|
+
- attach: Attach terminal to a session (replaces current process)
|
|
26
|
+
- status: Get current session status
|
|
27
|
+
- logs: Retrieve session logs
|
|
28
|
+
- exists: Check if a session exists
|
|
29
|
+
- list_sessions: List all sessions managed by this runner
|
|
30
|
+
|
|
31
|
+
Examples:
|
|
32
|
+
>>> def run_session(runner: AbstractRunner, config: SessionConfig) -> None:
|
|
33
|
+
... status = runner.start(config)
|
|
34
|
+
... print(f"Session {status.name} started with PID {status.pid}")
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def start(self, config: SessionConfig) -> SessionStatus:
|
|
38
|
+
"""Create and start a new session.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
config: Session configuration including name, command, etc.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
SessionStatus with current state after starting.
|
|
45
|
+
|
|
46
|
+
Raises:
|
|
47
|
+
SessionExistsError: If a session with this name already exists.
|
|
48
|
+
SessionStartError: If the session failed to start.
|
|
49
|
+
BackendNotFoundError: If the backend binary is not available.
|
|
50
|
+
"""
|
|
51
|
+
...
|
|
52
|
+
|
|
53
|
+
def stop(
|
|
54
|
+
self,
|
|
55
|
+
name: str,
|
|
56
|
+
*,
|
|
57
|
+
graceful: bool = True,
|
|
58
|
+
timeout: int = 10,
|
|
59
|
+
) -> bool:
|
|
60
|
+
"""Stop a running session.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
name: Session name to stop.
|
|
64
|
+
graceful: If True, send SIGTERM first and wait for graceful shutdown.
|
|
65
|
+
If False, send SIGKILL immediately.
|
|
66
|
+
timeout: Seconds to wait for graceful shutdown before forcing.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
True if the session was stopped, False if it was not running.
|
|
70
|
+
|
|
71
|
+
Raises:
|
|
72
|
+
SessionNotFoundError: If the session does not exist.
|
|
73
|
+
SessionStopError: If the session could not be stopped.
|
|
74
|
+
"""
|
|
75
|
+
...
|
|
76
|
+
|
|
77
|
+
def attach(self, name: str) -> None:
|
|
78
|
+
"""Attach terminal to a running session.
|
|
79
|
+
|
|
80
|
+
This method replaces the current process with the attach command
|
|
81
|
+
using os.execvp. It does not return on success.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
name: Session name to attach to.
|
|
85
|
+
|
|
86
|
+
Raises:
|
|
87
|
+
SessionNotFoundError: If the session does not exist.
|
|
88
|
+
SessionAttachError: If attachment failed.
|
|
89
|
+
|
|
90
|
+
Note:
|
|
91
|
+
This method uses os.execvp and does not return on success.
|
|
92
|
+
The calling process is replaced by the attach command.
|
|
93
|
+
"""
|
|
94
|
+
...
|
|
95
|
+
|
|
96
|
+
def status(self, name: str) -> SessionStatus:
|
|
97
|
+
"""Get the current status of a session.
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
name: Session name to query.
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
SessionStatus with current state information.
|
|
104
|
+
|
|
105
|
+
Raises:
|
|
106
|
+
SessionNotFoundError: If the session does not exist.
|
|
107
|
+
"""
|
|
108
|
+
...
|
|
109
|
+
|
|
110
|
+
def logs(self, name: str, lines: int = 100) -> str:
|
|
111
|
+
"""Retrieve recent logs from a session.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
name: Session name to get logs from.
|
|
115
|
+
lines: Number of lines to retrieve (default 100).
|
|
116
|
+
|
|
117
|
+
Returns:
|
|
118
|
+
String containing the log output with ANSI codes preserved.
|
|
119
|
+
|
|
120
|
+
Raises:
|
|
121
|
+
SessionNotFoundError: If the session does not exist.
|
|
122
|
+
"""
|
|
123
|
+
...
|
|
124
|
+
|
|
125
|
+
def exists(self, name: str) -> bool:
|
|
126
|
+
"""Check if a session with the given name exists.
|
|
127
|
+
|
|
128
|
+
Args:
|
|
129
|
+
name: Session name to check.
|
|
130
|
+
|
|
131
|
+
Returns:
|
|
132
|
+
True if the session exists, False otherwise.
|
|
133
|
+
"""
|
|
134
|
+
...
|
|
135
|
+
|
|
136
|
+
def list_sessions(self) -> list[SessionStatus]:
|
|
137
|
+
"""List all sessions managed by this runner.
|
|
138
|
+
|
|
139
|
+
Returns:
|
|
140
|
+
List of SessionStatus for all sessions.
|
|
141
|
+
Empty list if no sessions exist.
|
|
142
|
+
"""
|
|
143
|
+
...
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
__all__ = [
|
|
147
|
+
"AbstractRunner",
|
|
148
|
+
]
|