kstlib 0.0.1a0__py3-none-any.whl → 1.0.1__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.
Files changed (166) hide show
  1. kstlib/__init__.py +266 -1
  2. kstlib/__main__.py +16 -0
  3. kstlib/alerts/__init__.py +110 -0
  4. kstlib/alerts/channels/__init__.py +36 -0
  5. kstlib/alerts/channels/base.py +197 -0
  6. kstlib/alerts/channels/email.py +227 -0
  7. kstlib/alerts/channels/slack.py +389 -0
  8. kstlib/alerts/exceptions.py +72 -0
  9. kstlib/alerts/manager.py +651 -0
  10. kstlib/alerts/models.py +142 -0
  11. kstlib/alerts/throttle.py +263 -0
  12. kstlib/auth/__init__.py +139 -0
  13. kstlib/auth/callback.py +399 -0
  14. kstlib/auth/config.py +502 -0
  15. kstlib/auth/errors.py +127 -0
  16. kstlib/auth/models.py +316 -0
  17. kstlib/auth/providers/__init__.py +14 -0
  18. kstlib/auth/providers/base.py +393 -0
  19. kstlib/auth/providers/oauth2.py +645 -0
  20. kstlib/auth/providers/oidc.py +821 -0
  21. kstlib/auth/session.py +338 -0
  22. kstlib/auth/token.py +482 -0
  23. kstlib/cache/__init__.py +50 -0
  24. kstlib/cache/decorator.py +261 -0
  25. kstlib/cache/strategies.py +516 -0
  26. kstlib/cli/__init__.py +8 -0
  27. kstlib/cli/app.py +195 -0
  28. kstlib/cli/commands/__init__.py +5 -0
  29. kstlib/cli/commands/auth/__init__.py +39 -0
  30. kstlib/cli/commands/auth/common.py +122 -0
  31. kstlib/cli/commands/auth/login.py +325 -0
  32. kstlib/cli/commands/auth/logout.py +74 -0
  33. kstlib/cli/commands/auth/providers.py +57 -0
  34. kstlib/cli/commands/auth/status.py +291 -0
  35. kstlib/cli/commands/auth/token.py +199 -0
  36. kstlib/cli/commands/auth/whoami.py +106 -0
  37. kstlib/cli/commands/config.py +89 -0
  38. kstlib/cli/commands/ops/__init__.py +39 -0
  39. kstlib/cli/commands/ops/attach.py +49 -0
  40. kstlib/cli/commands/ops/common.py +269 -0
  41. kstlib/cli/commands/ops/list_sessions.py +252 -0
  42. kstlib/cli/commands/ops/logs.py +49 -0
  43. kstlib/cli/commands/ops/start.py +98 -0
  44. kstlib/cli/commands/ops/status.py +138 -0
  45. kstlib/cli/commands/ops/stop.py +60 -0
  46. kstlib/cli/commands/rapi/__init__.py +60 -0
  47. kstlib/cli/commands/rapi/call.py +341 -0
  48. kstlib/cli/commands/rapi/list.py +99 -0
  49. kstlib/cli/commands/rapi/show.py +206 -0
  50. kstlib/cli/commands/secrets/__init__.py +35 -0
  51. kstlib/cli/commands/secrets/common.py +425 -0
  52. kstlib/cli/commands/secrets/decrypt.py +88 -0
  53. kstlib/cli/commands/secrets/doctor.py +743 -0
  54. kstlib/cli/commands/secrets/encrypt.py +242 -0
  55. kstlib/cli/commands/secrets/shred.py +96 -0
  56. kstlib/cli/common.py +86 -0
  57. kstlib/config/__init__.py +76 -0
  58. kstlib/config/exceptions.py +110 -0
  59. kstlib/config/export.py +225 -0
  60. kstlib/config/loader.py +963 -0
  61. kstlib/config/sops.py +287 -0
  62. kstlib/db/__init__.py +54 -0
  63. kstlib/db/aiosqlcipher.py +137 -0
  64. kstlib/db/cipher.py +112 -0
  65. kstlib/db/database.py +367 -0
  66. kstlib/db/exceptions.py +25 -0
  67. kstlib/db/pool.py +302 -0
  68. kstlib/helpers/__init__.py +35 -0
  69. kstlib/helpers/exceptions.py +11 -0
  70. kstlib/helpers/time_trigger.py +396 -0
  71. kstlib/kstlib.conf.yml +890 -0
  72. kstlib/limits.py +963 -0
  73. kstlib/logging/__init__.py +108 -0
  74. kstlib/logging/manager.py +633 -0
  75. kstlib/mail/__init__.py +42 -0
  76. kstlib/mail/builder.py +626 -0
  77. kstlib/mail/exceptions.py +27 -0
  78. kstlib/mail/filesystem.py +248 -0
  79. kstlib/mail/transport.py +224 -0
  80. kstlib/mail/transports/__init__.py +19 -0
  81. kstlib/mail/transports/gmail.py +268 -0
  82. kstlib/mail/transports/resend.py +324 -0
  83. kstlib/mail/transports/smtp.py +326 -0
  84. kstlib/meta.py +72 -0
  85. kstlib/metrics/__init__.py +88 -0
  86. kstlib/metrics/decorators.py +1090 -0
  87. kstlib/metrics/exceptions.py +14 -0
  88. kstlib/monitoring/__init__.py +116 -0
  89. kstlib/monitoring/_styles.py +163 -0
  90. kstlib/monitoring/cell.py +57 -0
  91. kstlib/monitoring/config.py +424 -0
  92. kstlib/monitoring/delivery.py +579 -0
  93. kstlib/monitoring/exceptions.py +63 -0
  94. kstlib/monitoring/image.py +220 -0
  95. kstlib/monitoring/kv.py +79 -0
  96. kstlib/monitoring/list.py +69 -0
  97. kstlib/monitoring/metric.py +88 -0
  98. kstlib/monitoring/monitoring.py +341 -0
  99. kstlib/monitoring/renderer.py +139 -0
  100. kstlib/monitoring/service.py +392 -0
  101. kstlib/monitoring/table.py +129 -0
  102. kstlib/monitoring/types.py +56 -0
  103. kstlib/ops/__init__.py +86 -0
  104. kstlib/ops/base.py +148 -0
  105. kstlib/ops/container.py +577 -0
  106. kstlib/ops/exceptions.py +209 -0
  107. kstlib/ops/manager.py +407 -0
  108. kstlib/ops/models.py +176 -0
  109. kstlib/ops/tmux.py +372 -0
  110. kstlib/ops/validators.py +287 -0
  111. kstlib/py.typed +0 -0
  112. kstlib/rapi/__init__.py +118 -0
  113. kstlib/rapi/client.py +875 -0
  114. kstlib/rapi/config.py +861 -0
  115. kstlib/rapi/credentials.py +887 -0
  116. kstlib/rapi/exceptions.py +213 -0
  117. kstlib/resilience/__init__.py +101 -0
  118. kstlib/resilience/circuit_breaker.py +440 -0
  119. kstlib/resilience/exceptions.py +95 -0
  120. kstlib/resilience/heartbeat.py +491 -0
  121. kstlib/resilience/rate_limiter.py +506 -0
  122. kstlib/resilience/shutdown.py +417 -0
  123. kstlib/resilience/watchdog.py +637 -0
  124. kstlib/secrets/__init__.py +29 -0
  125. kstlib/secrets/exceptions.py +19 -0
  126. kstlib/secrets/models.py +62 -0
  127. kstlib/secrets/providers/__init__.py +79 -0
  128. kstlib/secrets/providers/base.py +58 -0
  129. kstlib/secrets/providers/environment.py +66 -0
  130. kstlib/secrets/providers/keyring.py +107 -0
  131. kstlib/secrets/providers/kms.py +223 -0
  132. kstlib/secrets/providers/kwargs.py +101 -0
  133. kstlib/secrets/providers/sops.py +209 -0
  134. kstlib/secrets/resolver.py +221 -0
  135. kstlib/secrets/sensitive.py +130 -0
  136. kstlib/secure/__init__.py +23 -0
  137. kstlib/secure/fs.py +194 -0
  138. kstlib/secure/permissions.py +70 -0
  139. kstlib/ssl.py +347 -0
  140. kstlib/ui/__init__.py +23 -0
  141. kstlib/ui/exceptions.py +26 -0
  142. kstlib/ui/panels.py +484 -0
  143. kstlib/ui/spinner.py +864 -0
  144. kstlib/ui/tables.py +382 -0
  145. kstlib/utils/__init__.py +48 -0
  146. kstlib/utils/dict.py +36 -0
  147. kstlib/utils/formatting.py +338 -0
  148. kstlib/utils/http_trace.py +237 -0
  149. kstlib/utils/lazy.py +49 -0
  150. kstlib/utils/secure_delete.py +205 -0
  151. kstlib/utils/serialization.py +247 -0
  152. kstlib/utils/text.py +56 -0
  153. kstlib/utils/validators.py +124 -0
  154. kstlib/websocket/__init__.py +97 -0
  155. kstlib/websocket/exceptions.py +214 -0
  156. kstlib/websocket/manager.py +1102 -0
  157. kstlib/websocket/models.py +361 -0
  158. kstlib-1.0.1.dist-info/METADATA +201 -0
  159. kstlib-1.0.1.dist-info/RECORD +163 -0
  160. {kstlib-0.0.1a0.dist-info → kstlib-1.0.1.dist-info}/WHEEL +1 -1
  161. kstlib-1.0.1.dist-info/entry_points.txt +2 -0
  162. kstlib-1.0.1.dist-info/licenses/LICENSE.md +9 -0
  163. kstlib-0.0.1a0.dist-info/METADATA +0 -29
  164. kstlib-0.0.1a0.dist-info/RECORD +0 -6
  165. kstlib-0.0.1a0.dist-info/licenses/LICENSE.md +0 -5
  166. {kstlib-0.0.1a0.dist-info → kstlib-1.0.1.dist-info}/top_level.txt +0 -0
kstlib/kstlib.conf.yml ADDED
@@ -0,0 +1,890 @@
1
+ # Default configuration for kstlib
2
+ # This file is used to set default values for the kstlib library.
3
+
4
+ ###########################################################################################
5
+ ## Datetime formatting (global settings for timestamp display)
6
+ ###########################################################################################
7
+ datetime:
8
+ # Format string for timestamps (pendulum format tokens)
9
+ # See: https://pendulum.eustace.io/docs/#tokens
10
+ # Common formats:
11
+ # - "YYYY-MM-DD HH:mm:ss" (ISO-like, default)
12
+ # - "DD/MM/YYYY HH:mm:ss" (European)
13
+ # - "MM/DD/YYYY hh:mm:ss A" (US with AM/PM)
14
+ # - "ddd D MMM YYYY HH:mm" (Human: "Mon 29 Jan 2026 15:30")
15
+ # Hard limit: max 64 chars, alphanumeric + common punctuation only
16
+ format: "YYYY-MM-DD HH:mm:ss"
17
+
18
+ # Timezone for display: "local" (system timezone) or IANA timezone name
19
+ # Examples: "local", "UTC", "Europe/Paris", "America/New_York"
20
+ # Hard limit: max 64 chars, validated against pendulum timezones
21
+ timezone: "local"
22
+
23
+ ###########################################################################################
24
+ ## Cache configuration
25
+ ###########################################################################################
26
+ cache:
27
+ # Default caching strategy (ttl | lru | memoize | file)
28
+ default_strategy: ttl
29
+
30
+ # TTL (Time-To-Live) cache settings
31
+ ttl:
32
+ default_seconds: 300 # 5 minutes
33
+ max_entries: 1000 # Maximum number of cached entries
34
+ cleanup_interval: 60 # Cleanup expired entries every 60s
35
+
36
+ # LRU (Least Recently Used) cache settings
37
+ lru:
38
+ maxsize: 128 # Maximum cache size
39
+ typed: false # Separate cache for different argument types
40
+
41
+ # File-based cache settings
42
+ file:
43
+ enabled: true
44
+ cache_dir: ".cache" # Directory for cache files
45
+ check_mtime: true # Invalidate cache on file modification
46
+ serializer: json # json (default) | pickle | auto
47
+ # Maximum cache file size (prevents OOM on corrupted files)
48
+ # Accepts: bytes (int) or human-readable string ("100M", "50 MiB")
49
+ # Hard limit enforced in code: 100 MiB
50
+ max_file_size: "50M"
51
+
52
+ # Async cache support
53
+ async_support:
54
+ enabled: true
55
+ executor_workers: 4 # ThreadPoolExecutor workers for sync functions
56
+
57
+ # Metrics and monitoring
58
+ metrics:
59
+ enabled: false # Track cache hits/misses (opt-in)
60
+ log_stats: false # Log statistics periodically
61
+ stats_interval: 300 # Log stats every 5 minutes
62
+
63
+ ###########################################################################################
64
+ ## Logging configuration
65
+ ###########################################################################################
66
+ logger:
67
+ defaults:
68
+ output: console # console | file | both
69
+
70
+ # Color theme for Rich console output
71
+ theme:
72
+ trace: "medium_purple4 on dark_olive_green1"
73
+ debug: "black on deep_sky_blue1"
74
+ info: "sky_blue1"
75
+ success: "black on sea_green3"
76
+ warning: "bold white on salmon1"
77
+ error: "bold white on deep_pink2"
78
+ critical: "blink bold white on red3"
79
+
80
+ # Icons for each log level
81
+ icons:
82
+ show: true
83
+ trace: "🔬"
84
+ debug: "🔎"
85
+ info: "📄"
86
+ success: "✅"
87
+ warning: "🚨"
88
+ error: "❌"
89
+ critical: "💀"
90
+
91
+ # Console handler settings
92
+ console:
93
+ level: WARNING # Log level: TRACE | DEBUG | INFO | SUCCESS | WARNING | ERROR | CRITICAL
94
+ datefmt: "%Y-%m-%d %H:%M:%S"
95
+ format: "::: PID %(process)d / TID %(thread)d ::: %(message)s"
96
+ show_path: true
97
+ tracebacks_show_locals: true
98
+
99
+ # File handler settings
100
+ # Two configuration styles are supported:
101
+ # - New style (recommended): file_path: ./logs/kstlib.log
102
+ # - Legacy style: log_path + log_dir + log_name (for backward compatibility)
103
+ # The new style takes priority if file_path is defined.
104
+ file:
105
+ level: WARNING # Log level: TRACE | DEBUG | INFO | SUCCESS | WARNING | ERROR | CRITICAL
106
+ datefmt: "%Y-%m-%d %H:%M:%S"
107
+ format: "[%(asctime)s | %(levelname)-8s] ::: PID %(process)d / TID %(thread)d ::: %(message)s"
108
+ # file_path: ./logs/kstlib.log # New style (recommended)
109
+ # auto_create_dir: true # New style auto-create
110
+ log_path: "./" # Legacy style (kept for backward compatibility)
111
+ log_dir: "logs"
112
+ log_name: "kstlib.log"
113
+ log_dir_auto_create: true
114
+
115
+ # File rotation settings
116
+ rotation:
117
+ when: midnight # midnight | S | M | H | D | W0-W6
118
+ interval: 1
119
+ backup_count: 7
120
+
121
+ presets:
122
+ dev:
123
+ output: console
124
+ console:
125
+ level: DEBUG
126
+ show_path: true
127
+ tracebacks_show_locals: true
128
+ icons:
129
+ show: true
130
+
131
+ prod:
132
+ output: file
133
+ file:
134
+ level: INFO
135
+ icons:
136
+ show: false
137
+
138
+ debug:
139
+ output: console
140
+ console:
141
+ level: DEBUG
142
+ show_path: true
143
+ tracebacks_show_locals: true
144
+ icons:
145
+ show: true
146
+
147
+ trace:
148
+ output: both
149
+ console:
150
+ level: TRACE
151
+ show_path: true
152
+ tracebacks_show_locals: true
153
+ file:
154
+ level: TRACE
155
+ icons:
156
+ show: true
157
+
158
+ # Mail trace preset - verbose SMTP/SSL debugging to dedicated file
159
+ # Usage: LogManager(preset="trace_mail") or logger.preset: trace_mail
160
+ trace_mail:
161
+ output: both
162
+ console:
163
+ level: WARNING # Keep console quiet
164
+ file:
165
+ level: TRACE
166
+ file_path: ./logs/mail-trace.log
167
+ auto_create_dir: true
168
+ icons:
169
+ show: true
170
+
171
+ ###########################################################################################
172
+ ## UI helpers configuration
173
+ ###########################################################################################
174
+ ui:
175
+ panels:
176
+ defaults:
177
+ panel:
178
+ # border_style supports any Rich color/style (e.g. "blue", "bold green")
179
+ border_style: "bright_blue"
180
+ title_align: "left"
181
+ subtitle_align: "left"
182
+ padding: [1, 2]
183
+ expand: true
184
+ highlight: false
185
+ # https://rich.readthedocs.io/en/stable/appendix/box.html#appendix-box
186
+ box: "ROUNDED"
187
+ content:
188
+ box: "SIMPLE"
189
+ expand: true
190
+ show_header: false
191
+ key_label: "Key"
192
+ value_label: "Value"
193
+ key_style: "bold white"
194
+ value_style: null
195
+ header_style: "bold"
196
+ pad_edge: false
197
+ sort_keys: false
198
+ use_markup: true
199
+ use_pretty: true
200
+ pretty_indent: 2
201
+ presets:
202
+ info:
203
+ panel:
204
+ border_style: "cyan"
205
+ title: "Information"
206
+ icon: "📘"
207
+ success:
208
+ panel:
209
+ border_style: "sea_green3"
210
+ title: "Success"
211
+ icon: "✅"
212
+ warning:
213
+ panel:
214
+ border_style: "orange3"
215
+ title: "Warning"
216
+ icon: "🔔"
217
+ error:
218
+ panel:
219
+ border_style: "red3"
220
+ title: "Error"
221
+ icon: "❌"
222
+ summary:
223
+ panel:
224
+ border_style: "light_steel_blue1"
225
+ title: "Execution Summary"
226
+ icon: "📝"
227
+ content:
228
+ sort_keys: true
229
+ key_style: "bold orchid2"
230
+ value_style: "dim white"
231
+ tables:
232
+ defaults:
233
+ table:
234
+ title: null
235
+ caption: null
236
+ box: "SIMPLE"
237
+ show_header: true
238
+ header_style: "bold cyan"
239
+ show_lines: false
240
+ row_styles: null
241
+ expand: true
242
+ pad_edge: false
243
+ highlight: false
244
+ columns:
245
+ - header: "Key"
246
+ key: "key"
247
+ justify: "left"
248
+ style: "bold white"
249
+ overflow: "fold"
250
+ no_wrap: false
251
+ - header: "Value"
252
+ key: "value"
253
+ justify: "left"
254
+ style: null
255
+ overflow: "fold"
256
+ no_wrap: false
257
+ presets:
258
+ inventory:
259
+ table:
260
+ title: "Inventory"
261
+ box: "SIMPLE_HEAVY"
262
+ show_lines: true
263
+ header_style: "bold yellow"
264
+ columns:
265
+ - header: "Component"
266
+ key: "component"
267
+ style: "bold"
268
+ width: 18
269
+ - header: "Version"
270
+ key: "version"
271
+ style: "cyan"
272
+ width: 12
273
+ - header: "Status"
274
+ key: "status"
275
+ justify: "center"
276
+ style: "bold"
277
+ width: 10
278
+ metrics:
279
+ table:
280
+ title: "Metrics"
281
+ box: "SIMPLE_HEAD"
282
+ header_style: "bold green"
283
+ columns:
284
+ - header: "Metric"
285
+ key: "metric"
286
+ style: "bold"
287
+ - header: "Value"
288
+ key: "value"
289
+ justify: "right"
290
+ spinners:
291
+ defaults:
292
+ # Spinner character style: BRAILLE | DOTS | LINE | ARROW | BLOCKS | CIRCLE | SQUARE | MOON | CLOCK
293
+ style: "BRAILLE"
294
+ # Position relative to message: before | after
295
+ position: "before"
296
+ # Animation type: spin | bounce | color_wave
297
+ animation_type: "spin"
298
+ # Seconds between animation frames
299
+ interval: 0.08
300
+ # Rich style for spinner character
301
+ spinner_style: "cyan"
302
+ # Rich style for message text (null = default)
303
+ text_style: null
304
+ # Character shown on success
305
+ done_character: "✓"
306
+ done_style: "green"
307
+ # Character shown on failure
308
+ fail_character: "✗"
309
+ fail_style: "red"
310
+ presets:
311
+ minimal:
312
+ style: "LINE"
313
+ spinner_style: "dim white"
314
+ interval: 0.1
315
+ fancy:
316
+ style: "BRAILLE"
317
+ spinner_style: "bold cyan"
318
+ interval: 0.06
319
+ blocks:
320
+ style: "BLOCKS"
321
+ spinner_style: "blue"
322
+ interval: 0.05
323
+ bounce:
324
+ animation_type: "bounce"
325
+ spinner_style: "yellow"
326
+ interval: 0.08
327
+ color_wave:
328
+ animation_type: "color_wave"
329
+ interval: 0.1
330
+
331
+ ###########################################################################################
332
+ ## Mail configuration
333
+ ###########################################################################################
334
+ mail:
335
+ # Attachment and message limits
336
+ limits:
337
+ # Maximum size for a single attachment
338
+ # Accepts: bytes (int) or human-readable string ("25M", "10 MiB")
339
+ # Hard limit enforced in code: 25 MiB
340
+ max_attachment_size: "25M"
341
+ # Maximum number of attachments per message
342
+ # Hard limit enforced in code: 50
343
+ max_attachments: 20
344
+
345
+ filesystem:
346
+ attachments_root: "~/.cache/kstlib/mail/attachments"
347
+ inline_root: "~/.cache/kstlib/mail/inline"
348
+ templates_root: "~/.cache/kstlib/mail/templates"
349
+ allow_external_attachments: false
350
+ allow_external_templates: false
351
+ auto_create_roots: true
352
+ enforce_permissions: true
353
+ max_permission_octal: 448 # 0o700
354
+
355
+ ###########################################################################################
356
+ ## Secrets configuration
357
+ ###########################################################################################
358
+ secrets:
359
+ name: "default"
360
+ providers:
361
+ - name: environment
362
+ settings:
363
+ prefix: "KSTLIB"
364
+ delimiter: "__"
365
+ - name: keyring
366
+ settings:
367
+ service: "kstlib"
368
+ sops:
369
+ # Path to the encrypted secrets file (set to null to disable by default)
370
+ path: null
371
+ # Override the sops executable if it is not on PATH
372
+ binary: "sops"
373
+ # autodetect | json | yaml | text
374
+ format: "auto"
375
+ # Maximum cached decrypted files (LRU eviction)
376
+ # Hard limit enforced in code: 256
377
+ max_cache_entries: 64
378
+
379
+ ###########################################################################################
380
+ ## Authentication configuration (OAuth2/OIDC)
381
+ ###########################################################################################
382
+ auth:
383
+ # Default provider to use when none specified
384
+ default_provider: null
385
+
386
+ # Token storage backend: "memory" (dev/testing), "file" (persistent), or "sops" (encrypted)
387
+ token_storage: "memory"
388
+
389
+ # OIDC discovery document cache TTL (seconds)
390
+ discovery_ttl: 3600
391
+
392
+ # TRACE level HTTP logging settings
393
+ trace:
394
+ # Pretty-print JSON bodies in TRACE logs (indent with 2 spaces)
395
+ pretty: true
396
+ # Maximum body length before truncation (chars)
397
+ # TRACE = debug mode, show full body by default
398
+ # Hard limit enforced in code: 10000 (10KB)
399
+ max_body_length: 10000
400
+
401
+ # Local callback server for authorization code flow
402
+ callback_server:
403
+ host: "127.0.0.1"
404
+ port: 8400
405
+ # Port range to try if primary port is busy (optional)
406
+ port_range: null # e.g., [8400, 8410]
407
+ # Timeout waiting for callback (seconds)
408
+ # Hard limit enforced in code: 600 (10 minutes)
409
+ timeout: 120
410
+
411
+ # Status display settings (kstlib auth status)
412
+ status:
413
+ # Access token considered "expiring soon" when remaining time < threshold
414
+ # Hard limits enforced in code: min 60s, max 3600s (1 hour)
415
+ expiring_soon_threshold: 120 # seconds (2 minutes)
416
+ # Refresh token considered "expiring soon" when remaining time < threshold
417
+ # Hard limits enforced in code: min 60s, max 172800s (48 hours)
418
+ # Typically higher since refresh tokens can live days/weeks/months
419
+ refresh_expiring_soon_threshold: 600 # seconds (10 minutes)
420
+ # Timezone for displaying timestamps: "local" or "utc"
421
+ display_timezone: "local"
422
+
423
+ # Token storage configuration per backend
424
+ storage:
425
+ file:
426
+ directory: "~/.config/kstlib/auth/tokens"
427
+ sops:
428
+ directory: "~/.config/kstlib/auth/tokens"
429
+
430
+ # Named providers (empty by default, users define their own)
431
+ providers: {}
432
+ # Example provider configuration:
433
+ # providers:
434
+ # corporate:
435
+ # type: "oidc" # oauth2 | oidc
436
+ #
437
+ # # OIDC Discovery modes:
438
+ # # - Auto: only issuer provided, endpoints auto-discovered
439
+ # # - Hybrid: issuer + some explicit endpoints (explicit wins)
440
+ # # - Manual: no issuer, all endpoints explicit (no discovery)
441
+ # issuer: "https://idp.corp.local/realms/main"
442
+ #
443
+ # client_id: "my-app"
444
+ # # Secret can be inline or SOPS reference
445
+ # client_secret: null # or "sops://secrets/auth.yaml#corporate.client_secret"
446
+ # scopes:
447
+ # - openid
448
+ # - profile
449
+ # - email
450
+ #
451
+ # # PKCE enabled by default (recommended for all clients)
452
+ # pkce: true
453
+ #
454
+ # # Optional endpoint overrides (auto-discovered if issuer provided)
455
+ # authorization_endpoint: null
456
+ # token_endpoint: null
457
+ # userinfo_endpoint: null
458
+ # jwks_uri: null
459
+ #
460
+ # # Custom HTTP headers sent with all IDP requests
461
+ # # Useful for load balancer validation, tenant routing, etc.
462
+ # headers: {}
463
+ # # Example:
464
+ # # headers:
465
+ # # Host: "idp.corp.local"
466
+ # # X-Tenant-Id: "corp"
467
+ #
468
+ # # Provider-specific token storage (overrides global)
469
+ # token_storage: null # "memory" | "file" | "sops"
470
+
471
+ ###########################################################################################
472
+ ## Utilities configuration
473
+ ###########################################################################################
474
+ utilities:
475
+ secure_delete:
476
+ method: "auto"
477
+ passes: 3
478
+ zero_last_pass: true
479
+ chunk_size: 1048576 # 1 MiB
480
+
481
+ ###########################################################################################
482
+ ## Resilience configuration
483
+ ###########################################################################################
484
+ resilience:
485
+ # --- Core components (used by WebSocket trading bots) ---
486
+
487
+ heartbeat:
488
+ # Seconds between heartbeats
489
+ # Hard limits enforced in code: min 1s, max 300s (5 minutes)
490
+ interval: 10
491
+
492
+ watchdog:
493
+ # Seconds of inactivity before triggering timeout callback
494
+ # Hard limits enforced in code: min 1s, max 3600s (1 hour)
495
+ timeout: 30
496
+
497
+ # --- Advanced components (for REST API calls, order placement) ---
498
+ # Note: WebSocket connections have built-in reconnection logic.
499
+ # These are useful for REST API resilience (e.g., placing orders, account queries).
500
+
501
+ shutdown:
502
+ # GracefulShutdown: Orderly cleanup on SIGTERM/SIGINT with prioritized callbacks.
503
+ # Use case: Ensure open orders are cancelled, positions closed before exit.
504
+ # Total timeout for all cleanup callbacks (seconds)
505
+ # Hard limits enforced in code: min 5s, max 300s (5 minutes)
506
+ timeout: 30
507
+ # Exit code when timeout exceeded
508
+ force_exit_code: 1
509
+
510
+ circuit_breaker:
511
+ # CircuitBreaker: Fail-fast pattern for external service calls.
512
+ # Use case: REST API calls (order placement, account info) - after N failures,
513
+ # stop calling the failing endpoint and fail immediately until recovery.
514
+ # Failures before opening circuit
515
+ # Hard limits enforced in code: min 1, max 100
516
+ max_failures: 5
517
+ # Cooldown before attempting recovery (seconds)
518
+ # Hard limits enforced in code: min 1s, max 3600s (1 hour)
519
+ reset_timeout: 60
520
+ # Calls allowed in half-open state for testing
521
+ # Hard limits enforced in code: min 1, max 10
522
+ half_open_max_calls: 1
523
+
524
+ ###########################################################################################
525
+ ## Database configuration
526
+ ###########################################################################################
527
+ db:
528
+ pool:
529
+ # Minimum connections to maintain in pool (0 = lazy pool, on-demand)
530
+ # Hard limits enforced in code: min 0, max 10
531
+ min_size: 1
532
+ # Maximum connections allowed in pool
533
+ # Hard limits enforced in code: min 1, max 100
534
+ max_size: 10
535
+ # Timeout for acquiring a connection (seconds)
536
+ # Hard limits enforced in code: min 1.0, max 300.0 (5 minutes)
537
+ acquire_timeout: 30.0
538
+ retry:
539
+ # Retry attempts on connection failure
540
+ # Hard limits enforced in code: min 1, max 10
541
+ max_attempts: 3
542
+ # Delay between retries (seconds)
543
+ # Hard limits enforced in code: min 0.1, max 60.0
544
+ delay: 0.5
545
+
546
+ # SQLCipher encryption (opt-in, requires: pip install kstlib[db-crypto])
547
+ # System deps: libsqlcipher-dev (Debian/Ubuntu), sqlcipher (macOS/brew)
548
+ cipher:
549
+ # Enable SQLCipher encryption (default: false)
550
+ enabled: false
551
+ # Key source: env | sops | passphrase
552
+ # - env: Read from environment variable (key_env)
553
+ # - sops: Read from SOPS-encrypted file (sops_path + sops_key)
554
+ # - passphrase: Direct passphrase (ONLY for development/testing)
555
+ key_source: env
556
+ # Environment variable containing the encryption key
557
+ key_env: "KSTLIB_DB_KEY"
558
+ # SOPS configuration (when key_source: sops)
559
+ sops_path: null
560
+ sops_key: "db_key"
561
+ # Direct passphrase (NEVER use in production)
562
+ passphrase: null
563
+
564
+ ###########################################################################################
565
+ ## Credentials configuration (multi-source credential resolution)
566
+ ###########################################################################################
567
+ credentials:
568
+ # Credentials are named entries that can be referenced by rapi services.
569
+ # Supported types: env, file, sops, provider
570
+ #
571
+ # Examples:
572
+ #
573
+ # # Type: env - from environment variable
574
+ # github:
575
+ # type: env
576
+ # var: "GITHUB_TOKEN"
577
+ #
578
+ # # Type: env - key+secret pair from environment
579
+ # kraken_env:
580
+ # type: env
581
+ # var_key: "KRAKEN_API_KEY"
582
+ # var_secret: "KRAKEN_API_SECRET"
583
+ #
584
+ # # Type: file - from JSON/YAML file with jq-like path extraction
585
+ # azure_cli:
586
+ # type: file
587
+ # path: "~/.azure/msal_token_cache.json"
588
+ # token_path: ".AccessToken.secret"
589
+ #
590
+ # # Type: file - key+secret from file fields
591
+ # api_file:
592
+ # type: file
593
+ # path: "~/.config/api_keys.json"
594
+ # key_field: "api_key"
595
+ # secret_field: "api_secret"
596
+ #
597
+ # # Type: sops - from SOPS-encrypted file
598
+ # kraken_prod:
599
+ # type: sops
600
+ # path: "secrets/kraken.sops.json"
601
+ # key_field: "api_key"
602
+ # secret_field: "api_secret"
603
+ #
604
+ # # Type: provider - from kstlib.auth provider (OAuth2/OIDC)
605
+ # corporate:
606
+ # type: provider
607
+ # provider: "corporate"
608
+
609
+ ###########################################################################################
610
+ ## REST API configuration (config-driven HTTP client)
611
+ ###########################################################################################
612
+ rapi:
613
+ # Hard limits enforced in code for deep defense:
614
+ # - timeout: min 1s, max 300s (5 minutes)
615
+ # - max_response_size: max 100M
616
+ # - max_retries: min 0, max 10
617
+ # - retry_delay: min 0.1s, max 60s
618
+ # - retry_backoff: min 1.0, max 5.0
619
+ limits:
620
+ timeout: 30 # Request timeout in seconds
621
+ max_response_size: "10M" # Maximum response body size
622
+ max_retries: 3 # Retry attempts on failure
623
+ retry_delay: 1.0 # Initial delay between retries (seconds)
624
+ retry_backoff: 2.0 # Exponential backoff multiplier
625
+
626
+ # Pretty-print settings for CLI output
627
+ # Controls formatting of JSON and XML responses in terminal
628
+ pretty_render:
629
+ # JSON indentation (spaces). Set to null or 0 to disable pretty-printing.
630
+ json: 2
631
+ # XML pretty-print. Set to true to enable formatted XML output.
632
+ xml: true
633
+
634
+ # API services and their endpoints
635
+ # Define your own APIs here or use external *.rapi.yml files
636
+ api: {}
637
+
638
+ # Example: Azure Resource Manager API
639
+ # azure:
640
+ # base_url: "https://management.azure.com"
641
+ # credentials: azure_cli # Reference to credentials section
642
+ # auth_type: bearer
643
+ # headers:
644
+ # X-Custom-Header: "service-value"
645
+ # endpoints:
646
+ # list_subscriptions:
647
+ # path: "/subscriptions"
648
+ # query:
649
+ # api-version: "2020-01-01"
650
+ # headers:
651
+ # X-Request-ID: "{request_id}"
652
+
653
+ ###########################################################################################
654
+ ## Alerts configuration (multi-channel alerting)
655
+ ###########################################################################################
656
+ alerts:
657
+ # Hard limits enforced in code for deep defense:
658
+ # - throttle.rate: min 1, max 1000 alerts per period
659
+ # - throttle.per: min 1.0, max 86400.0 seconds (1 day)
660
+ # - throttle.burst: min 1, max rate value
661
+
662
+ # Default throttle settings (anti-spam protection)
663
+ throttle:
664
+ rate: 10 # Maximum alerts per period
665
+ per: 60.0 # Period duration in seconds (1 minute)
666
+ burst: 5 # Initial burst capacity
667
+
668
+ # Default channel settings
669
+ channels:
670
+ # Timeout for sending alerts (seconds)
671
+ # Hard limits enforced in code: min 1.0, max 120.0
672
+ timeout: 30.0
673
+ # Retry attempts on delivery failure
674
+ # Hard limits enforced in code: min 0, max 5
675
+ max_retries: 2
676
+
677
+ presets:
678
+ dev:
679
+ throttle:
680
+ rate: 100 # More lenient for development
681
+ per: 60.0
682
+ burst: 20
683
+ channels:
684
+ timeout: 10.0
685
+ max_retries: 0
686
+
687
+ prod:
688
+ throttle:
689
+ rate: 10 # Strict rate limiting
690
+ per: 60.0
691
+ burst: 3
692
+ channels:
693
+ timeout: 30.0
694
+ max_retries: 3
695
+
696
+ critical_only:
697
+ throttle:
698
+ rate: 5 # Very strict for critical-only channels
699
+ per: 300.0 # 5 minutes
700
+ burst: 2
701
+
702
+ ###########################################################################################
703
+ ## Metrics configuration
704
+ ###########################################################################################
705
+ metrics:
706
+ # Enable colored output
707
+ colors: true
708
+
709
+ # Output destination: stderr | stdout
710
+ output: stderr
711
+
712
+ # Default behavior for @metrics decorator (can be overridden per-call)
713
+ defaults:
714
+ time: true # Track execution time
715
+ memory: true # Track peak memory (tracemalloc)
716
+ step: false # Enable step numbering
717
+
718
+ # Step format string
719
+ # Variables: {n} (step number), {title}, {function}, {module}, {file}, {line}
720
+ step_format: "[STEP {n}] {title}"
721
+
722
+ # Lap format string (for Stopwatch)
723
+ # Variables: {n} (lap number), {name}
724
+ lap_format: "[LAP {n}] {name}"
725
+
726
+ # Title format (auto-generated when no custom title provided)
727
+ # Variables: {function}, {module}, {file}, {line}
728
+ title_format: "{function} [dim green]({file}:{line})[/dim green]"
729
+
730
+ # Time display precision (decimal places for seconds)
731
+ time_precision: 3
732
+
733
+ # Thresholds for color warnings
734
+ thresholds:
735
+ time_warn: 5 # Warn color if >= 5 seconds
736
+ time_crit: 30 # Critical color if >= 30 seconds
737
+ memory_warn: 100000000 # Warn color if >= 100 MB
738
+ memory_crit: 500000000 # Critical color if >= 500 MB
739
+
740
+ # Icons (set to "" to disable)
741
+ icons:
742
+ time: "⏱"
743
+ memory: "🧠"
744
+ peak: "Peak:" # Text after memory icon
745
+
746
+ # Color theme (Rich style names)
747
+ # See: https://rich.readthedocs.io/en/stable/appendix/colors.html
748
+ theme:
749
+ label: "bold green"
750
+ title: "bold white"
751
+ text: "white"
752
+ muted: "dim"
753
+ table_header: "bold cyan"
754
+ time_ok: "cyan"
755
+ time_warn: "orange3"
756
+ time_crit: "bold red"
757
+ memory_ok: "rosy_brown"
758
+ memory_warn: "orange3"
759
+ memory_crit: "bold red"
760
+ step_number: "dim"
761
+ separator: "dim white"
762
+
763
+ # Summary display style: table | simple
764
+ summary_style: table
765
+
766
+ # Show percentage of total time in summaries
767
+ show_percentages: true
768
+
769
+ # Print metrics to stderr by default
770
+ print_results: true
771
+
772
+ ###########################################################################################
773
+ ## WebSocket configuration (proactive connection control)
774
+ ###########################################################################################
775
+ websocket:
776
+ # Ping/Pong heartbeat settings
777
+ ping:
778
+ # Seconds between ping frames
779
+ # Hard limits: [5, 60] - values outside bounds will be clamped
780
+ interval: 20
781
+ # Seconds to wait for pong response
782
+ # Hard limits: [5, 30]
783
+ timeout: 10
784
+
785
+ # Connection settings
786
+ connection:
787
+ # Timeout for initial connection (seconds)
788
+ # Hard limits: [5, 120]
789
+ timeout: 30
790
+
791
+ # Reconnection behavior
792
+ reconnect:
793
+ # Initial delay between reconnect attempts (seconds)
794
+ # Hard limits: [0, 300] - 0 = immediate reconnect allowed
795
+ delay: 1.0
796
+ # Maximum delay for exponential backoff (seconds)
797
+ # Hard limits: [1, 600]
798
+ max_delay: 60.0
799
+ # Maximum consecutive reconnection attempts
800
+ # Hard limits: [0, 100] - 0 = no retry
801
+ max_attempts: 10
802
+
803
+ # Message queue settings
804
+ queue:
805
+ # Maximum messages in queue (0 = unlimited)
806
+ # Hard limits: [0, 10000]
807
+ size: 1000
808
+
809
+ # Proactive control settings (KEY FEATURE)
810
+ proactive:
811
+ # Seconds between should_disconnect callback checks
812
+ # Hard limits: [1, 60]
813
+ disconnect_check_interval: 10.0
814
+ # Seconds between should_reconnect callback checks
815
+ # Hard limits: [0.5, 60]
816
+ reconnect_check_interval: 5.0
817
+ # Disconnect X seconds before 24h limit (Binance, etc.)
818
+ # Hard limits: [60, 3600] - at least 1min, max 1h
819
+ disconnect_margin: 300.0
820
+
821
+ # Presets for common use cases
822
+ presets:
823
+ trading:
824
+ ping: { interval: 15, timeout: 10 }
825
+ reconnect: { delay: 0.5, max_delay: 30.0, max_attempts: 20 }
826
+ proactive: { disconnect_check_interval: 5.0, reconnect_check_interval: 2.0 }
827
+ monitoring:
828
+ ping: { interval: 30, timeout: 15 }
829
+ reconnect: { delay: 5.0, max_delay: 120.0, max_attempts: 50 }
830
+ proactive: { disconnect_check_interval: 30.0, reconnect_check_interval: 10.0 }
831
+
832
+ # ============================================================================
833
+ # OPS - Session Management Configuration
834
+ # ============================================================================
835
+ # Config-driven session management for persistent processes (bots, services).
836
+ # Supports tmux (local dev) and container (Podman/Docker) backends.
837
+ #
838
+ # Hard limits enforced:
839
+ # - Session name: max 64 chars, alphanumeric + underscore + hyphen
840
+ # - Image name: max 256 chars, valid OCI format
841
+ # - Volumes: max 20, no path traversal
842
+ # - Ports: max 50, range 1-65535
843
+ # - Env vars: max 100, key max 128 chars, value max 32KB
844
+ # - Command: max 4096 chars, dangerous patterns blocked
845
+ # ============================================================================
846
+ ops:
847
+ # Default backend when not specified (tmux | container)
848
+ default_backend: tmux
849
+
850
+ # Tmux binary path (default: tmux)
851
+ tmux_binary: tmux
852
+
853
+ # Container runtime (podman | docker | null for auto-detect)
854
+ container_runtime: null
855
+
856
+ # Pre-defined sessions (config-driven)
857
+ # Sessions can be started with: kstlib ops start <name>
858
+ sessions: {}
859
+ # Example session configuration:
860
+ # mybot:
861
+ # backend: tmux # Override default_backend
862
+ # command: "python -m mybot.main" # Command to run
863
+ # working_dir: "/opt/mybot" # Working directory
864
+ # env: # Environment variables
865
+ # BOT_ENV: production
866
+ # LOG_LEVEL: INFO
867
+ #
868
+ # mybot-prod:
869
+ # backend: container
870
+ # image: "mybot:latest" # Container image (required)
871
+ # volumes: # Volume mounts (host:container[:ro|:rw])
872
+ # - "./data:/app/data"
873
+ # - "./logs:/app/logs:rw"
874
+ # ports: # Port mappings (host:container[/tcp|/udp])
875
+ # - "8080:80"
876
+ # log_volume: "./logs:/app/logs" # Persistent logs for post-mortem
877
+
878
+ ###########################################################################################
879
+ ## SSL/TLS configuration (global settings for all HTTP clients)
880
+ ###########################################################################################
881
+ ssl:
882
+ # Enable SSL certificate verification (default: true)
883
+ # Set to false ONLY for development with self-signed certificates
884
+ # WARNING: Disabling verification exposes you to MITM attacks
885
+ verify: true
886
+
887
+ # Custom CA bundle path for corporate PKI or self-signed certificates
888
+ # If provided, ssl_verify is implicitly true
889
+ # Accepts: null (use system CAs), or path to PEM file
890
+ ca_bundle: null