Files
clawmates/crates/cm-db/src/repo/fleet_tailscale.rs
T
Omar SobhandClaude Opus 4.8 3554a3aaf2
ci / gates (push) Successful in 5s
ci / frontend (push) Successful in 23s
ci / rust (push) Failing after 27s
ci / e2e (push) Has been skipped
CI: remove k8s stages, fix the Docker-level pipeline green
Survey + fixes so the pipeline passes at the Docker level (no k8s).

- Remove k8s: drop the `sandbox-k8s` job (kind/Calico/--features k8s-tests) and the
  "Helm chart lints" gate step. release.yml was already k8s-clean.
- Rust job:
  - `cargo fmt --all` — fix pre-existing formatting drift (fmt --check was failing).
  - clippy -D warnings: fix 3 lib warnings (cm-brain sort_by_key→Reverse, cm-api
    fleet.rs doc list indentation, node_rules map_or→is_none_or).
  - Regenerate the .sqlx offline cache (was missing the cm-runtime run_loop test
    query → offline compile failed). DB-backed tests use testcontainers at runtime.
  - Set SQLX_OFFLINE=true on the rust + e2e jobs so query! macros compile against
    the committed cache deterministically (no DB needed at compile time).
- Frontend job:
  - Fix the 1 ESLint error (useAgentTelemetry: no setState-synchronously-in-effect;
    tag the slice with agentId + derive null on mismatch).
  - Fix 2 stale panel-params tests (`terminal` is a valid app id now; assert the
    current APP_IDS + use a genuinely-unknown id for the reject case).

Verified locally: fmt clean, clippy --all-targets -D warnings clean (offline),
frontend lint 0 errors, tsc clean, 86/86 frontend tests pass, build OK.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-26 18:15:31 -07:00

51 lines
1.5 KiB
Rust

//! Per-workspace Tailscale connection (BYO tailnet): the API key + tailnet we
//! use to read fleet network metrics. Used server-side only.
use cm_domain::WorkspaceId;
use sqlx::{PgPool, Row};
use crate::DbError;
/// Store (or replace) a workspace's Tailscale API key + tailnet.
pub async fn set(
pool: &PgPool,
workspace_id: WorkspaceId,
api_key: &str,
tailnet: &str,
) -> Result<(), DbError> {
sqlx::query(
"INSERT INTO workspace_tailscale (workspace_id, api_key, tailnet, connected_at)
VALUES ($1, $2, $3, now())
ON CONFLICT (workspace_id) DO UPDATE SET
api_key = excluded.api_key, tailnet = excluded.tailnet, connected_at = now()",
)
.bind(workspace_id.as_uuid())
.bind(api_key)
.bind(tailnet)
.execute(pool)
.await?;
Ok(())
}
/// Get a workspace's stored (api_key, tailnet), if connected.
pub async fn get(
pool: &PgPool,
workspace_id: WorkspaceId,
) -> Result<Option<(String, String)>, DbError> {
let row =
sqlx::query("SELECT api_key, tailnet FROM workspace_tailscale WHERE workspace_id = $1")
.bind(workspace_id.as_uuid())
.fetch_optional(pool)
.await?;
Ok(row.map(|r| (r.get("api_key"), r.get("tailnet"))))
}
/// Disconnect a workspace's Tailscale.
pub async fn delete(pool: &PgPool, workspace_id: WorkspaceId) -> Result<(), DbError> {
sqlx::query("DELETE FROM workspace_tailscale WHERE workspace_id = $1")
.bind(workspace_id.as_uuid())
.execute(pool)
.await?;
Ok(())
}