inferyx-codegate 1.1.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.
- codegate/__init__.py +8 -0
- codegate/__main__.py +3 -0
- codegate/api/__init__.py +0 -0
- codegate/api/admin.py +457 -0
- codegate/api/deps.py +36 -0
- codegate/api/devproxy.py +132 -0
- codegate/api/public.py +371 -0
- codegate/app.py +115 -0
- codegate/auth/__init__.py +0 -0
- codegate/auth/csrf.py +43 -0
- codegate/auth/native.py +111 -0
- codegate/auth/passwords.py +88 -0
- codegate/auth/saml.py +222 -0
- codegate/auth/sessions.py +121 -0
- codegate/cli/__init__.py +0 -0
- codegate/cli/auth_cmd.py +168 -0
- codegate/cli/backup_cmd.py +114 -0
- codegate/cli/common.py +103 -0
- codegate/cli/doctor_cmd.py +136 -0
- codegate/cli/main.py +526 -0
- codegate/cli/nginx_setup.py +220 -0
- codegate/cli/setup_cmd.py +401 -0
- codegate/cli/ssh_setup.py +114 -0
- codegate/cli/upgrade_cmd.py +209 -0
- codegate/config.py +161 -0
- codegate/db.py +297 -0
- codegate/errors.py +122 -0
- codegate/jobs.py +133 -0
- codegate/pages.py +177 -0
- codegate/resources/__init__.py +20 -0
- codegate/resources/docker/Dockerfile +36 -0
- codegate/resources/nginx/codegate.conf.tmpl +51 -0
- codegate/resources/nginx/map.conf +5 -0
- codegate/resources/nginx/site.conf.tmpl +9 -0
- codegate/resources/nginx/user.conf.tmpl +19 -0
- codegate/resources/systemd/codegate-backup.service.tmpl +7 -0
- codegate/resources/systemd/codegate-backup.timer +10 -0
- codegate/resources/systemd/codegate.service.tmpl +20 -0
- codegate/static/admin/3rdpartylicenses.txt +614 -0
- codegate/static/admin/chunk-0r_p7pcB.js +672 -0
- codegate/static/admin/chunk-BoGqYCjO.js +1260 -0
- codegate/static/admin/chunk-BqiJ460N.js +1269 -0
- codegate/static/admin/chunk-BtoaIoDj.js +449 -0
- codegate/static/admin/chunk-CB4E-q63.js +255 -0
- codegate/static/admin/chunk-CMN75K3s.js +181 -0
- codegate/static/admin/chunk-CW_CPa20.js +106 -0
- codegate/static/admin/chunk-CcgsCK7w.js +393 -0
- codegate/static/admin/chunk-Cjwyuum6.js +375 -0
- codegate/static/admin/chunk-D6j6hnz3.js +1 -0
- codegate/static/admin/chunk-D9RytJgO.js +1 -0
- codegate/static/admin/chunk-DA6TldFU.js +35 -0
- codegate/static/admin/chunk-DFGdyoNb.js +1 -0
- codegate/static/admin/chunk-DXvCZ3pT.js +1 -0
- codegate/static/admin/chunk-DstgVdtz.js +27 -0
- codegate/static/admin/chunk-kPDFCwHP.js +102 -0
- codegate/static/admin/chunk-yikJ2ObQ.js +1 -0
- codegate/static/admin/favicon.ico +0 -0
- codegate/static/admin/index.html +14 -0
- codegate/static/admin/main-LWBML7JF.js +2347 -0
- codegate/static/admin/media/material-icons-JLIDJUWE.woff +0 -0
- codegate/static/admin/media/material-icons-LEZCGFVT.woff2 +0 -0
- codegate/static/admin/styles-YWRWGLKG.css +1 -0
- codegate/system/__init__.py +27 -0
- codegate/system/base.py +165 -0
- codegate/system/devdocker.py +90 -0
- codegate/system/fake.py +199 -0
- codegate/system/real.py +493 -0
- codegate/system/shell.py +40 -0
- codegate/users.py +262 -0
- codegate/workspace.py +355 -0
- inferyx_codegate-1.1.0.dist-info/METADATA +217 -0
- inferyx_codegate-1.1.0.dist-info/RECORD +74 -0
- inferyx_codegate-1.1.0.dist-info/WHEEL +4 -0
- inferyx_codegate-1.1.0.dist-info/entry_points.txt +2 -0
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@font-face{font-family:Material Icons;font-style:normal;font-weight:400;font-display:block;src:url("./media/material-icons-LEZCGFVT.woff2") format("woff2"),url("./media/material-icons-JLIDJUWE.woff") format("woff")}.material-icons{font-family:Material Icons;font-weight:400;font-style:normal;font-size:24px;line-height:1;letter-spacing:normal;text-transform:none;display:inline-block;white-space:nowrap;word-wrap:normal;direction:ltr;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-rendering:optimizeLegibility;font-feature-settings:"liga"}html{color-scheme:light;--mat-sys-background: #faf9fd;--mat-sys-error: #ba1a1a;--mat-sys-error-container: #ffdad6;--mat-sys-inverse-on-surface: #f2f0f4;--mat-sys-inverse-primary: #abc7ff;--mat-sys-inverse-surface: #2f3033;--mat-sys-on-background: #1a1b1f;--mat-sys-on-error: #ffffff;--mat-sys-on-error-container: #93000a;--mat-sys-on-primary: #ffffff;--mat-sys-on-primary-container: #00458f;--mat-sys-on-primary-fixed: #001b3f;--mat-sys-on-primary-fixed-variant: #00458f;--mat-sys-on-secondary: #ffffff;--mat-sys-on-secondary-container: #3e4759;--mat-sys-on-secondary-fixed: #131c2b;--mat-sys-on-secondary-fixed-variant: #3e4759;--mat-sys-on-surface: #1a1b1f;--mat-sys-on-surface-variant: #44474e;--mat-sys-on-tertiary: #ffffff;--mat-sys-on-tertiary-container: #0000ef;--mat-sys-on-tertiary-fixed: #00006e;--mat-sys-on-tertiary-fixed-variant: #0000ef;--mat-sys-outline: #74777f;--mat-sys-outline-variant: #c4c6d0;--mat-sys-primary: #005cbb;--mat-sys-primary-container: #d7e3ff;--mat-sys-primary-fixed: #d7e3ff;--mat-sys-primary-fixed-dim: #abc7ff;--mat-sys-scrim: #000000;--mat-sys-secondary: #565e71;--mat-sys-secondary-container: #dae2f9;--mat-sys-secondary-fixed: #dae2f9;--mat-sys-secondary-fixed-dim: #bec6dc;--mat-sys-shadow: #000000;--mat-sys-surface: #faf9fd;--mat-sys-surface-bright: #faf9fd;--mat-sys-surface-container: #efedf0;--mat-sys-surface-container-high: #e9e7eb;--mat-sys-surface-container-highest: #e3e2e6;--mat-sys-surface-container-low: #f4f3f6;--mat-sys-surface-container-lowest: #ffffff;--mat-sys-surface-dim: #dbd9dd;--mat-sys-surface-tint: #005cbb;--mat-sys-surface-variant: #e0e2ec;--mat-sys-tertiary: #343dff;--mat-sys-tertiary-container: #e0e0ff;--mat-sys-tertiary-fixed: #e0e0ff;--mat-sys-tertiary-fixed-dim: #bec2ff;--mat-sys-neutral-variant20: #2d3038;--mat-sys-neutral10: #1a1b1f;--mat-sys-level0: 0px 0px 0px 0px rgba(0, 0, 0, .2), 0px 0px 0px 0px rgba(0, 0, 0, .14), 0px 0px 0px 0px rgba(0, 0, 0, .12);--mat-sys-level1: 0px 2px 1px -1px rgba(0, 0, 0, .2), 0px 1px 1px 0px rgba(0, 0, 0, .14), 0px 1px 3px 0px rgba(0, 0, 0, .12);--mat-sys-level2: 0px 3px 3px -2px rgba(0, 0, 0, .2), 0px 3px 4px 0px rgba(0, 0, 0, .14), 0px 1px 8px 0px rgba(0, 0, 0, .12);--mat-sys-level3: 0px 3px 5px -1px rgba(0, 0, 0, .2), 0px 6px 10px 0px rgba(0, 0, 0, .14), 0px 1px 18px 0px rgba(0, 0, 0, .12);--mat-sys-level4: 0px 5px 5px -3px rgba(0, 0, 0, .2), 0px 8px 10px 1px rgba(0, 0, 0, .14), 0px 3px 14px 2px rgba(0, 0, 0, .12);--mat-sys-level5: 0px 7px 8px -4px rgba(0, 0, 0, .2), 0px 12px 17px 2px rgba(0, 0, 0, .14), 0px 5px 22px 4px rgba(0, 0, 0, .12);--mat-sys-body-large: 400 1rem / 1.5rem Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-body-large-font: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-body-large-line-height: 1.5rem;--mat-sys-body-large-size: 1rem;--mat-sys-body-large-tracking: .031rem;--mat-sys-body-large-weight: 400;--mat-sys-body-medium: 400 .875rem / 1.25rem Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-body-medium-font: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-body-medium-line-height: 1.25rem;--mat-sys-body-medium-size: .875rem;--mat-sys-body-medium-tracking: .016rem;--mat-sys-body-medium-weight: 400;--mat-sys-body-small: 400 .75rem / 1rem Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-body-small-font: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-body-small-line-height: 1rem;--mat-sys-body-small-size: .75rem;--mat-sys-body-small-tracking: .025rem;--mat-sys-body-small-weight: 400;--mat-sys-display-large: 400 3.562rem / 4rem Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-display-large-font: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-display-large-line-height: 4rem;--mat-sys-display-large-size: 3.562rem;--mat-sys-display-large-tracking: -.016rem;--mat-sys-display-large-weight: 400;--mat-sys-display-medium: 400 2.812rem / 3.25rem Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-display-medium-font: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-display-medium-line-height: 3.25rem;--mat-sys-display-medium-size: 2.812rem;--mat-sys-display-medium-tracking: 0;--mat-sys-display-medium-weight: 400;--mat-sys-display-small: 400 2.25rem / 2.75rem Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-display-small-font: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-display-small-line-height: 2.75rem;--mat-sys-display-small-size: 2.25rem;--mat-sys-display-small-tracking: 0;--mat-sys-display-small-weight: 400;--mat-sys-headline-large: 400 2rem / 2.5rem Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-headline-large-font: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-headline-large-line-height: 2.5rem;--mat-sys-headline-large-size: 2rem;--mat-sys-headline-large-tracking: 0;--mat-sys-headline-large-weight: 400;--mat-sys-headline-medium: 400 1.75rem / 2.25rem Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-headline-medium-font: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-headline-medium-line-height: 2.25rem;--mat-sys-headline-medium-size: 1.75rem;--mat-sys-headline-medium-tracking: 0;--mat-sys-headline-medium-weight: 400;--mat-sys-headline-small: 400 1.5rem / 2rem Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-headline-small-font: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-headline-small-line-height: 2rem;--mat-sys-headline-small-size: 1.5rem;--mat-sys-headline-small-tracking: 0;--mat-sys-headline-small-weight: 400;--mat-sys-label-large: 500 .875rem / 1.25rem Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-label-large-font: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-label-large-line-height: 1.25rem;--mat-sys-label-large-size: .875rem;--mat-sys-label-large-tracking: .006rem;--mat-sys-label-large-weight: 500;--mat-sys-label-large-weight-prominent: 700;--mat-sys-label-medium: 500 .75rem / 1rem Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-label-medium-font: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-label-medium-line-height: 1rem;--mat-sys-label-medium-size: .75rem;--mat-sys-label-medium-tracking: .031rem;--mat-sys-label-medium-weight: 500;--mat-sys-label-medium-weight-prominent: 700;--mat-sys-label-small: 500 .688rem / 1rem Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-label-small-font: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-label-small-line-height: 1rem;--mat-sys-label-small-size: .688rem;--mat-sys-label-small-tracking: .031rem;--mat-sys-label-small-weight: 500;--mat-sys-title-large: 400 1.375rem / 1.75rem Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-title-large-font: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-title-large-line-height: 1.75rem;--mat-sys-title-large-size: 1.375rem;--mat-sys-title-large-tracking: 0;--mat-sys-title-large-weight: 400;--mat-sys-title-medium: 500 1rem / 1.5rem Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-title-medium-font: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-title-medium-line-height: 1.5rem;--mat-sys-title-medium-size: 1rem;--mat-sys-title-medium-tracking: .009rem;--mat-sys-title-medium-weight: 500;--mat-sys-title-small: 500 .875rem / 1.25rem Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-title-small-font: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;--mat-sys-title-small-line-height: 1.25rem;--mat-sys-title-small-size: .875rem;--mat-sys-title-small-tracking: .006rem;--mat-sys-title-small-weight: 500;--mat-checkbox-touch-target-display: block;--mat-checkbox-state-layer-size: 36px;--mat-chip-container-height: 28px;--mat-chip-touch-target-display: none;--mat-expansion-header-collapsed-state-height: 44px;--mat-expansion-header-expanded-state-height: 60px;--mat-fab-small-touch-target-display: ;--mat-fab-touch-target-display: block;--mat-button-filled-touch-target-display: block;--mat-button-filled-container-height: 36px;--mat-button-outlined-container-height: 36px;--mat-button-outlined-touch-target-display: block;--mat-button-protected-touch-target-display: block;--mat-button-protected-container-height: 36px;--mat-button-text-touch-target-display: block;--mat-button-text-container-height: 36px;--mat-button-tonal-container-height: 36px;--mat-button-tonal-touch-target-display: block;--mat-form-field-container-height: 52px;--mat-form-field-filled-label-display: block;--mat-form-field-container-vertical-padding: 14px;--mat-form-field-filled-with-label-container-padding-top: 22px;--mat-form-field-filled-with-label-container-padding-bottom: 6px;--mat-icon-button-touch-target-display: block;--mat-icon-button-state-layer-size: 36px;--mat-list-list-item-leading-icon-start-space: 12px;--mat-list-list-item-leading-icon-end-space: 12px;--mat-list-list-item-one-line-container-height: 44px;--mat-list-list-item-two-line-container-height: 60px;--mat-list-list-item-three-line-container-height: 84px;--mat-paginator-container-size: 52px;--mat-paginator-form-field-container-height: 40px;--mat-paginator-form-field-container-vertical-padding: 8px;--mat-paginator-touch-target-display: block;--mat-radio-touch-target-display: block;--mat-radio-state-layer-size: 36px;--mat-tab-container-height: 44px;--mat-select-arrow-transform: translateY(-8px);--mat-button-toggle-height: 40px;--mat-stepper-header-height: 68px;--mat-table-header-container-height: 52px;--mat-table-footer-container-height: 48px;--mat-table-row-item-container-height: 48px;--mat-toolbar-standard-height: 60px;--mat-toolbar-mobile-height: 52px;--mat-tree-node-min-height: 44px;--mat-sys-corner-extra-large: 28px;--mat-sys-corner-extra-large-top: 28px 28px 0 0;--mat-sys-corner-extra-small: 4px;--mat-sys-corner-extra-small-top: 4px 4px 0 0;--mat-sys-corner-full: 9999px;--mat-sys-corner-large: 16px;--mat-sys-corner-large-end: 0 16px 16px 0;--mat-sys-corner-large-start: 16px 0 0 16px;--mat-sys-corner-large-top: 16px 16px 0 0;--mat-sys-corner-medium: 12px;--mat-sys-corner-none: 0;--mat-sys-corner-small: 8px;--mat-sys-dragged-state-layer-opacity: .16;--mat-sys-focus-state-layer-opacity: .12;--mat-sys-hover-state-layer-opacity: .08;--mat-sys-pressed-state-layer-opacity: .12}html,body{height:100%}body{margin:0;background:#f5f7fb;font-family:Inter,system-ui,-apple-system,Segoe UI,Roboto,sans-serif}.page{padding:24px;max-width:1400px;margin:0 auto;box-sizing:border-box}.page-head{display:flex;align-items:center;gap:12px;margin-bottom:20px;flex-wrap:wrap}.page-head h1{margin:0;font-size:22px;font-weight:600;flex:1}.card{background:#fff;border-radius:12px;border:1px solid #e5e9f2;padding:18px}.grid{display:grid;gap:16px}.muted{color:#6b7280;font-size:13px}.mono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12.5px}.spacer{flex:1}.row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.chip{display:inline-flex;align-items:center;padding:2px 10px;border-radius:999px;font-size:12px;font-weight:600;line-height:20px;white-space:nowrap}.chip.active,.chip.running{background:#dcfce7;color:#166534}.chip.pending,.chip.starting{background:#fef3c7;color:#92400e}.chip.disabled,.chip.exited,.chip.error{background:#fee2e2;color:#991b1b}.chip.none,.chip.missing,.chip.unknown{background:#e5e7eb;color:#374151}.chip.admin{background:#ede9fe;color:#5b21b6}.chip.custom{background:#e0f2fe;color:#075985}.bar{height:6px;border-radius:6px;background:#e5e7eb;overflow:hidden;min-width:60px}.bar>div{height:100%;background:#3b82f6;border-radius:6px}.bar.warn>div{background:#f59e0b}.bar.bad>div{background:#ef4444}table.mat-mdc-table{background:transparent}.table-wrap{overflow-x:auto;background:#fff;border-radius:12px;border:1px solid #e5e9f2}.full{width:100%}.form-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:4px 16px}.empty{text-align:center;padding:40px;color:#6b7280}.snack-error{--mdc-snackbar-container-color: #991b1b}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""System layer: Linux users, quotas, Docker, nginx, ports.
|
|
2
|
+
|
|
3
|
+
``get_system()`` returns the real implementation, or an in-memory fake when
|
|
4
|
+
``CODEGATE_DEV_MODE=true`` (lets you run the portal on a laptop).
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from functools import lru_cache
|
|
9
|
+
|
|
10
|
+
from ..config import get_settings
|
|
11
|
+
from .base import System
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@lru_cache
|
|
15
|
+
def get_system() -> System:
|
|
16
|
+
if get_settings().dev_mode and get_settings().dev_docker:
|
|
17
|
+
from .devdocker import DevDockerSystem
|
|
18
|
+
return DevDockerSystem()
|
|
19
|
+
if get_settings().dev_mode:
|
|
20
|
+
from .fake import FakeSystem
|
|
21
|
+
return FakeSystem()
|
|
22
|
+
from .real import RealSystem
|
|
23
|
+
return RealSystem()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def reset_system_cache() -> None:
|
|
27
|
+
get_system.cache_clear()
|
codegate/system/base.py
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""Abstract system interface + helpers shared by real and fake implementations."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import ipaddress
|
|
5
|
+
from abc import ABC, abstractmethod
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from datetime import datetime
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from ..config import get_settings
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class WorkspaceSpec:
|
|
15
|
+
"""Everything needed to create a user's container."""
|
|
16
|
+
username: str
|
|
17
|
+
uid: int
|
|
18
|
+
gid: int
|
|
19
|
+
home: Path
|
|
20
|
+
port: int
|
|
21
|
+
ip: str
|
|
22
|
+
image: str
|
|
23
|
+
cpu: float
|
|
24
|
+
mem_mb: int
|
|
25
|
+
pids: int
|
|
26
|
+
sudo: bool
|
|
27
|
+
internet: bool
|
|
28
|
+
shared_folder: bool
|
|
29
|
+
labels: dict[str, str] = field(default_factory=dict)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass
|
|
33
|
+
class ContainerStats:
|
|
34
|
+
running: bool
|
|
35
|
+
cpu_pct: float = 0.0
|
|
36
|
+
mem_mb: float = 0.0
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def container_name(username: str) -> str:
|
|
40
|
+
return f"{get_settings().container_prefix}{username}"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def ip_for_port(port: int) -> str:
|
|
44
|
+
"""Stable container IP derived from the user's port (one-to-one)."""
|
|
45
|
+
s = get_settings()
|
|
46
|
+
net = ipaddress.ip_network(s.docker_subnet)
|
|
47
|
+
idx = port - s.port_range_start + 10
|
|
48
|
+
return str(net.network_address + idx)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class System(ABC):
|
|
52
|
+
name = "abstract"
|
|
53
|
+
|
|
54
|
+
# ---------------- linux users ----------------
|
|
55
|
+
@abstractmethod
|
|
56
|
+
def linux_user(self, username: str) -> tuple[int, int, str] | None: ...
|
|
57
|
+
|
|
58
|
+
@abstractmethod
|
|
59
|
+
def uid_in_use(self, uid: int) -> bool: ...
|
|
60
|
+
|
|
61
|
+
@abstractmethod
|
|
62
|
+
def create_linux_user(self, username: str, uid: int, home: Path) -> None: ...
|
|
63
|
+
|
|
64
|
+
@abstractmethod
|
|
65
|
+
def delete_linux_user(self, username: str) -> None: ...
|
|
66
|
+
|
|
67
|
+
@abstractmethod
|
|
68
|
+
def ensure_home(self, username: str, uid: int, gid: int, home: Path) -> bool:
|
|
69
|
+
"""Create home dir if missing. Returns True if it was created."""
|
|
70
|
+
|
|
71
|
+
@abstractmethod
|
|
72
|
+
def archive_home(self, username: str, home: Path) -> str: ...
|
|
73
|
+
|
|
74
|
+
@abstractmethod
|
|
75
|
+
def remove_home(self, home: Path) -> None: ...
|
|
76
|
+
|
|
77
|
+
@abstractmethod
|
|
78
|
+
def home_usage_mb(self, home: Path) -> float: ...
|
|
79
|
+
|
|
80
|
+
@abstractmethod
|
|
81
|
+
def heartbeat(self, home: Path) -> datetime | None: ...
|
|
82
|
+
|
|
83
|
+
@abstractmethod
|
|
84
|
+
def add_to_shared_group(self, username: str, enabled: bool) -> None: ...
|
|
85
|
+
|
|
86
|
+
def restrict_host_login(self, username: str) -> None:
|
|
87
|
+
"""No host shell / SSH for a CodeGate-created Linux user."""
|
|
88
|
+
|
|
89
|
+
def strip_setuid(self, path: Path) -> list[str]:
|
|
90
|
+
"""Remove setuid/setgid bits from files under path. Returns the files changed."""
|
|
91
|
+
return []
|
|
92
|
+
|
|
93
|
+
# ---------------- quota ----------------
|
|
94
|
+
@abstractmethod
|
|
95
|
+
def quota_supported(self) -> bool: ...
|
|
96
|
+
|
|
97
|
+
@abstractmethod
|
|
98
|
+
def set_quota(self, username: str, disk_gb: int) -> None: ...
|
|
99
|
+
|
|
100
|
+
@abstractmethod
|
|
101
|
+
def clear_quota(self, username: str) -> None: ...
|
|
102
|
+
|
|
103
|
+
# ---------------- per-user etc files ----------------
|
|
104
|
+
@abstractmethod
|
|
105
|
+
def write_user_etc(self, spec: WorkspaceSpec) -> None: ...
|
|
106
|
+
|
|
107
|
+
@abstractmethod
|
|
108
|
+
def remove_user_etc(self, username: str) -> None: ...
|
|
109
|
+
|
|
110
|
+
# ---------------- ports ----------------
|
|
111
|
+
@abstractmethod
|
|
112
|
+
def port_free(self, port: int) -> bool: ...
|
|
113
|
+
|
|
114
|
+
# ---------------- docker ----------------
|
|
115
|
+
@abstractmethod
|
|
116
|
+
def docker_ok(self) -> bool: ...
|
|
117
|
+
|
|
118
|
+
@abstractmethod
|
|
119
|
+
def ensure_network(self) -> None: ...
|
|
120
|
+
|
|
121
|
+
@abstractmethod
|
|
122
|
+
def image_exists(self, image: str) -> bool: ...
|
|
123
|
+
|
|
124
|
+
@abstractmethod
|
|
125
|
+
def container_create(self, spec: WorkspaceSpec) -> str: ...
|
|
126
|
+
|
|
127
|
+
@abstractmethod
|
|
128
|
+
def container_remove(self, username: str) -> None: ...
|
|
129
|
+
|
|
130
|
+
@abstractmethod
|
|
131
|
+
def container_status(self, username: str) -> str:
|
|
132
|
+
"""'running' | 'exited' | 'created' | 'missing' | ..."""
|
|
133
|
+
|
|
134
|
+
@abstractmethod
|
|
135
|
+
def container_start(self, username: str) -> None: ...
|
|
136
|
+
|
|
137
|
+
@abstractmethod
|
|
138
|
+
def container_stop(self, username: str) -> None: ...
|
|
139
|
+
|
|
140
|
+
@abstractmethod
|
|
141
|
+
def container_restart(self, username: str) -> None: ...
|
|
142
|
+
|
|
143
|
+
@abstractmethod
|
|
144
|
+
def container_update(self, username: str, cpu: float, mem_mb: int, pids: int) -> None: ...
|
|
145
|
+
|
|
146
|
+
@abstractmethod
|
|
147
|
+
def container_stats(self, username: str) -> ContainerStats: ...
|
|
148
|
+
|
|
149
|
+
@abstractmethod
|
|
150
|
+
def set_internet(self, username: str, ip: str, allowed: bool) -> None: ...
|
|
151
|
+
|
|
152
|
+
# ---------------- nginx ----------------
|
|
153
|
+
@abstractmethod
|
|
154
|
+
def nginx_write_user(self, username: str, port: int) -> None: ...
|
|
155
|
+
|
|
156
|
+
@abstractmethod
|
|
157
|
+
def nginx_remove_user(self, username: str) -> None: ...
|
|
158
|
+
|
|
159
|
+
@abstractmethod
|
|
160
|
+
def nginx_apply(self) -> None:
|
|
161
|
+
"""Test config and reload. Must raise NginxError if the test fails."""
|
|
162
|
+
|
|
163
|
+
# ---------------- host ----------------
|
|
164
|
+
@abstractmethod
|
|
165
|
+
def host_stats(self) -> dict: ...
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""DEV MODE with real Docker (``codegate dev --docker``).
|
|
2
|
+
|
|
3
|
+
Linux users, quotas and nginx stay simulated (FakeSystem), but workspaces are
|
|
4
|
+
real code-server containers on the local Docker daemon, created by the same
|
|
5
|
+
code the server uses (RealSystem). Homes live under the dev data dir.
|
|
6
|
+
The backend proxies /editor/<user>/ to the container (see api/devproxy.py).
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
from .fake import FakeSystem
|
|
13
|
+
from .real import RealSystem
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class DevDockerSystem(FakeSystem):
|
|
17
|
+
name = "devdocker"
|
|
18
|
+
|
|
19
|
+
def __init__(self) -> None:
|
|
20
|
+
super().__init__()
|
|
21
|
+
self._real = RealSystem()
|
|
22
|
+
|
|
23
|
+
# ---------- homes: real folders (no chown; we're not root) ----------
|
|
24
|
+
def ensure_home(self, username, uid, gid, home):
|
|
25
|
+
created = not home.exists()
|
|
26
|
+
home.mkdir(parents=True, exist_ok=True)
|
|
27
|
+
super().ensure_home(username, uid, gid, home)
|
|
28
|
+
return created
|
|
29
|
+
|
|
30
|
+
def home_usage_mb(self, home):
|
|
31
|
+
return self._real.home_usage_mb(home)
|
|
32
|
+
|
|
33
|
+
def heartbeat(self, home):
|
|
34
|
+
return self._real.heartbeat(home)
|
|
35
|
+
|
|
36
|
+
# ---------- per-user passwd/group mounted into the container ----------
|
|
37
|
+
def write_user_etc(self, spec):
|
|
38
|
+
self._real.write_user_etc(spec)
|
|
39
|
+
|
|
40
|
+
def remove_user_etc(self, username):
|
|
41
|
+
self._real.remove_user_etc(username)
|
|
42
|
+
|
|
43
|
+
def port_free(self, port):
|
|
44
|
+
return self._real.port_free(port)
|
|
45
|
+
|
|
46
|
+
# ---------- docker: all real ----------
|
|
47
|
+
def docker_ok(self):
|
|
48
|
+
return self._real.docker_ok()
|
|
49
|
+
|
|
50
|
+
def ensure_network(self):
|
|
51
|
+
self._real.ensure_network()
|
|
52
|
+
|
|
53
|
+
def image_exists(self, image):
|
|
54
|
+
return self._real.image_exists(image)
|
|
55
|
+
|
|
56
|
+
def container_create(self, spec):
|
|
57
|
+
self._maybe_fail("container_create")
|
|
58
|
+
spec.home.mkdir(parents=True, exist_ok=True)
|
|
59
|
+
os.chmod(spec.home, 0o777) # container runs as the user's UID, not the laptop user
|
|
60
|
+
self._real.write_user_etc(spec)
|
|
61
|
+
return self._real.container_create(spec)
|
|
62
|
+
|
|
63
|
+
def container_remove(self, username):
|
|
64
|
+
self._real.container_remove(username)
|
|
65
|
+
|
|
66
|
+
def container_status(self, username):
|
|
67
|
+
return self._real.container_status(username)
|
|
68
|
+
|
|
69
|
+
def container_start(self, username):
|
|
70
|
+
self._real.container_start(username)
|
|
71
|
+
|
|
72
|
+
def container_stop(self, username):
|
|
73
|
+
self._real.container_stop(username)
|
|
74
|
+
|
|
75
|
+
def container_restart(self, username):
|
|
76
|
+
self._real.container_restart(username)
|
|
77
|
+
|
|
78
|
+
def container_update(self, username, cpu, mem_mb, pids):
|
|
79
|
+
self._real.container_update(username, cpu, mem_mb, pids)
|
|
80
|
+
|
|
81
|
+
def container_stats(self, username):
|
|
82
|
+
return self._real.container_stats(username)
|
|
83
|
+
|
|
84
|
+
def set_internet(self, username, ip, allowed):
|
|
85
|
+
pass # needs iptables on the host; not on a laptop
|
|
86
|
+
|
|
87
|
+
def host_stats(self):
|
|
88
|
+
st = super().host_stats()
|
|
89
|
+
st["docker_ok"] = self.docker_ok()
|
|
90
|
+
return st
|
codegate/system/fake.py
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"""In-memory fake system for development / demo (CODEGATE_DEV_MODE=true).
|
|
2
|
+
|
|
3
|
+
No root, Docker, nginx or useradd needed. State lives in a JSON file in data_dir
|
|
4
|
+
so it survives restarts. Set CODEGATE_FAKE_FAIL=<step> to simulate a failure
|
|
5
|
+
(e.g. container_create) and see rollback in action.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import os
|
|
11
|
+
import random
|
|
12
|
+
from datetime import datetime
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
from ..config import get_settings
|
|
16
|
+
from ..db import utcnow
|
|
17
|
+
from ..errors import DockerError
|
|
18
|
+
from .base import ContainerStats, System
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class FakeSystem(System):
|
|
22
|
+
name = "fake"
|
|
23
|
+
|
|
24
|
+
def __init__(self) -> None:
|
|
25
|
+
self.file = get_settings().data_dir / "fake-system.json"
|
|
26
|
+
|
|
27
|
+
# ---------- state ----------
|
|
28
|
+
def _load(self) -> dict:
|
|
29
|
+
if self.file.exists():
|
|
30
|
+
return json.loads(self.file.read_text())
|
|
31
|
+
return {"users": {}, "homes": {}, "containers": {}, "nginx": {}, "quota": {}}
|
|
32
|
+
|
|
33
|
+
def _save(self, st: dict) -> None:
|
|
34
|
+
self.file.parent.mkdir(parents=True, exist_ok=True)
|
|
35
|
+
self.file.write_text(json.dumps(st, indent=1))
|
|
36
|
+
|
|
37
|
+
def _maybe_fail(self, step: str) -> None:
|
|
38
|
+
if os.environ.get("CODEGATE_FAKE_FAIL") == step:
|
|
39
|
+
raise DockerError(f"Simulated failure in {step}", code="simulated_failure")
|
|
40
|
+
|
|
41
|
+
# ---------- linux ----------
|
|
42
|
+
def linux_user(self, username):
|
|
43
|
+
u = self._load()["users"].get(username)
|
|
44
|
+
return (u["uid"], u["gid"], u["home"]) if u else None
|
|
45
|
+
|
|
46
|
+
def uid_in_use(self, uid):
|
|
47
|
+
return any(u["uid"] == uid for u in self._load()["users"].values())
|
|
48
|
+
|
|
49
|
+
def create_linux_user(self, username, uid, home):
|
|
50
|
+
self._maybe_fail("create_linux_user")
|
|
51
|
+
st = self._load()
|
|
52
|
+
st["users"][username] = {"uid": uid, "gid": uid, "home": str(home)}
|
|
53
|
+
self._save(st)
|
|
54
|
+
|
|
55
|
+
def delete_linux_user(self, username):
|
|
56
|
+
st = self._load()
|
|
57
|
+
st["users"].pop(username, None)
|
|
58
|
+
self._save(st)
|
|
59
|
+
|
|
60
|
+
def ensure_home(self, username, uid, gid, home):
|
|
61
|
+
st = self._load()
|
|
62
|
+
created = str(home) not in st["homes"]
|
|
63
|
+
st["homes"][str(home)] = {"mb": st["homes"].get(str(home), {}).get("mb", 5.0)}
|
|
64
|
+
self._save(st)
|
|
65
|
+
return created
|
|
66
|
+
|
|
67
|
+
def archive_home(self, username, home):
|
|
68
|
+
return str(get_settings().archive_dir / f"{username}-{utcnow():%Y%m%d-%H%M%S}.tar.gz")
|
|
69
|
+
|
|
70
|
+
def remove_home(self, home):
|
|
71
|
+
st = self._load()
|
|
72
|
+
st["homes"].pop(str(home), None)
|
|
73
|
+
self._save(st)
|
|
74
|
+
|
|
75
|
+
def home_usage_mb(self, home):
|
|
76
|
+
h = self._load()["homes"].get(str(home))
|
|
77
|
+
return float(h["mb"]) + random.uniform(0, 50) if h else 0.0
|
|
78
|
+
|
|
79
|
+
def heartbeat(self, home):
|
|
80
|
+
c = next((c for c in self._load()["containers"].values() if c.get("home") == str(home)), None)
|
|
81
|
+
if c and c["status"] == "running":
|
|
82
|
+
return utcnow()
|
|
83
|
+
return None
|
|
84
|
+
|
|
85
|
+
def add_to_shared_group(self, username, enabled):
|
|
86
|
+
pass
|
|
87
|
+
|
|
88
|
+
# ---------- quota ----------
|
|
89
|
+
def quota_supported(self):
|
|
90
|
+
return True
|
|
91
|
+
|
|
92
|
+
def set_quota(self, username, disk_gb):
|
|
93
|
+
self._maybe_fail("set_quota")
|
|
94
|
+
st = self._load()
|
|
95
|
+
st["quota"][username] = disk_gb
|
|
96
|
+
self._save(st)
|
|
97
|
+
|
|
98
|
+
def clear_quota(self, username):
|
|
99
|
+
st = self._load()
|
|
100
|
+
st["quota"].pop(username, None)
|
|
101
|
+
self._save(st)
|
|
102
|
+
|
|
103
|
+
# ---------- etc ----------
|
|
104
|
+
def write_user_etc(self, spec):
|
|
105
|
+
pass
|
|
106
|
+
|
|
107
|
+
def remove_user_etc(self, username):
|
|
108
|
+
pass
|
|
109
|
+
|
|
110
|
+
# ---------- ports ----------
|
|
111
|
+
def port_free(self, port):
|
|
112
|
+
return True
|
|
113
|
+
|
|
114
|
+
# ---------- docker ----------
|
|
115
|
+
def docker_ok(self):
|
|
116
|
+
return True
|
|
117
|
+
|
|
118
|
+
def ensure_network(self):
|
|
119
|
+
pass
|
|
120
|
+
|
|
121
|
+
def image_exists(self, image):
|
|
122
|
+
return True
|
|
123
|
+
|
|
124
|
+
def container_create(self, spec):
|
|
125
|
+
self._maybe_fail("container_create")
|
|
126
|
+
st = self._load()
|
|
127
|
+
cid = f"fake{random.randint(10**9, 10**10)}"
|
|
128
|
+
st["containers"][spec.username] = {"id": cid, "status": "running", "home": str(spec.home),
|
|
129
|
+
"cpu": spec.cpu, "mem_mb": spec.mem_mb}
|
|
130
|
+
self._save(st)
|
|
131
|
+
return cid
|
|
132
|
+
|
|
133
|
+
def container_remove(self, username):
|
|
134
|
+
st = self._load()
|
|
135
|
+
st["containers"].pop(username, None)
|
|
136
|
+
self._save(st)
|
|
137
|
+
|
|
138
|
+
def container_status(self, username):
|
|
139
|
+
c = self._load()["containers"].get(username)
|
|
140
|
+
return c["status"] if c else "missing"
|
|
141
|
+
|
|
142
|
+
def _set(self, username, status):
|
|
143
|
+
st = self._load()
|
|
144
|
+
if username not in st["containers"]:
|
|
145
|
+
raise DockerError("Workspace container does not exist", code="container_missing",
|
|
146
|
+
status_code=404)
|
|
147
|
+
st["containers"][username]["status"] = status
|
|
148
|
+
self._save(st)
|
|
149
|
+
|
|
150
|
+
def container_start(self, username):
|
|
151
|
+
self._set(username, "running")
|
|
152
|
+
|
|
153
|
+
def container_stop(self, username):
|
|
154
|
+
if self.container_status(username) != "missing":
|
|
155
|
+
self._set(username, "exited")
|
|
156
|
+
|
|
157
|
+
def container_restart(self, username):
|
|
158
|
+
self._set(username, "running")
|
|
159
|
+
|
|
160
|
+
def container_update(self, username, cpu, mem_mb, pids):
|
|
161
|
+
st = self._load()
|
|
162
|
+
if username in st["containers"]:
|
|
163
|
+
st["containers"][username].update(cpu=cpu, mem_mb=mem_mb)
|
|
164
|
+
self._save(st)
|
|
165
|
+
|
|
166
|
+
def container_stats(self, username):
|
|
167
|
+
c = self._load()["containers"].get(username)
|
|
168
|
+
if not c or c["status"] != "running":
|
|
169
|
+
return ContainerStats(running=False)
|
|
170
|
+
return ContainerStats(running=True, cpu_pct=round(random.uniform(1, 40), 1),
|
|
171
|
+
mem_mb=round(random.uniform(200, min(900, c["mem_mb"])), 1))
|
|
172
|
+
|
|
173
|
+
def set_internet(self, username, ip, allowed):
|
|
174
|
+
pass
|
|
175
|
+
|
|
176
|
+
# ---------- nginx ----------
|
|
177
|
+
def nginx_write_user(self, username, port):
|
|
178
|
+
self._maybe_fail("nginx_write_user")
|
|
179
|
+
st = self._load()
|
|
180
|
+
st["nginx"][username] = port
|
|
181
|
+
self._save(st)
|
|
182
|
+
|
|
183
|
+
def nginx_remove_user(self, username):
|
|
184
|
+
st = self._load()
|
|
185
|
+
st["nginx"].pop(username, None)
|
|
186
|
+
self._save(st)
|
|
187
|
+
|
|
188
|
+
def nginx_apply(self):
|
|
189
|
+
self._maybe_fail("nginx_apply")
|
|
190
|
+
|
|
191
|
+
# ---------- host ----------
|
|
192
|
+
def host_stats(self):
|
|
193
|
+
return {"cpu_count": 8, "cpu_pct": round(random.uniform(5, 35), 1), "load": [0.4, 0.5, 0.6],
|
|
194
|
+
"mem_total_mb": 16384, "mem_used_mb": random.randint(3000, 7000),
|
|
195
|
+
"disk_total_gb": 200.0, "disk_used_gb": 61.5, "quota_enabled": True,
|
|
196
|
+
"docker_ok": True}
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
_ = (Path, datetime)
|