Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(control-api): add isRegistryAuthActive derived from the connection row
Jose Ramirez3f98ffd8d59e
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 33b3b25bf..10b6fa044 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.377",+ "version": "0.1.378","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.377",+ "version": "0.1.378","dependencies": {"@clerum/image-policy": "file:../packages/image-policy","@clerum/llm-providers": "file:../packages/llm-providers",diff --git a/control-api/package.json b/control-api/package.jsonindex 07f496b31..488fe3784 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.377",+ "version": "0.1.378","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/services/registryConnectionDb.ts b/control-api/src/services/registryConnectionDb.tsindex 1826b500a..11455dfe4 100644--- a/control-api/src/services/registryConnectionDb.ts+++ b/control-api/src/services/registryConnectionDb.ts@@ -214,3 +214,21 @@ export async function resolveMachineCreds(): Promise<{clientSecret: config.registryClientSecret,}}++/**+ * Registry auth is ACTIVE when this deployment actually holds usable machine+ * credentials.+ *+ * Self-hosted derives it from the claimed connection row, so connecting is the+ * only operator action — there is no env var to set and no restart. Managed+ * keeps CLERUM_REGISTRY_AUTH_ENABLED, because managed has no row (its creds+ * come from env).+ *+ * Note this checks CREDENTIALS, not row presence: a 'pending' row, and an+ * 'approved' row whose claim has not landed, both correctly report inactive.+ * That falls out of resolveMachineCreds, which null-checks clientId/clientSecret.+ */+export async function isRegistryAuthActive(): Promise<boolean> {+ if (config.registryConnectionMode === 'managed') return config.registryAuthEnabled+ return (await resolveMachineCreds()) !== null+}diff --git a/control-api/test/services.registryConnectionDb.test.ts b/control-api/test/services.registryConnectionDb.test.tsindex 5d5aa7a6a..f3fa6a6ca 100644--- a/control-api/test/services.registryConnectionDb.test.ts+++ b/control-api/test/services.registryConnectionDb.test.ts@@ -10,6 +10,7 @@ import {__resetRegistryConnectionCacheForTests,deleteConnection,getRegistryConnection,+ isRegistryAuthActive,markConnected,resolveMachineCreds,resolveVoucherSigningMaterial,@@ -445,3 +446,62 @@ describe('getRegistryConnection — cache TTL', () => {}})})++describe('isRegistryAuthActive', () => {+ it('managed: returns the env value verbatim (true)', async () => {+ cfg.registryConnectionMode = 'managed'+ cfg.registryAuthEnabled = true+ expect(await isRegistryAuthActive()).toBe(true)+ })++ it('managed: returns the env value verbatim (false)', async () => {+ cfg.registryConnectionMode = 'managed'+ cfg.registryAuthEnabled = false+ expect(await isRegistryAuthActive()).toBe(false)+ })++ it('self-hosted: false with no connection row', async () => {+ cfg.registryConnectionMode = 'self-hosted'+ dbQuery.mockResolvedValue({ rows: [], rowCount: 0 })+ expect(await isRegistryAuthActive()).toBe(false)+ })++ // Kills a `row !== null` implementation. The DB status CHECK is+ // ('pending','approved','connected') — there is NO 'connecting' status. An+ // auto-approved-but-unclaimed row is status='approved' with a null client_id.+ it('self-hosted: false for an approved row with no client_id', async () => {+ cfg.registryConnectionMode = 'self-hosted'+ cfg.oauthEncryptionKey = randomBytes(32).toString('hex')+ dbQuery.mockResolvedValue({+ rows: [+ makeRawRow(cfg.oauthEncryptionKey, {+ status: 'approved',+ client_id: null,+ client_secret_encrypted: null,+ }),+ ],+ rowCount: 1,+ })+ expect(await isRegistryAuthActive()).toBe(false)+ })++ it('self-hosted: true for a claimed row', async () => {+ cfg.registryConnectionMode = 'self-hosted'+ cfg.oauthEncryptionKey = randomBytes(32).toString('hex')+ const encSecret = encryptOAuthSecret(+ deriveOAuthEncryptionKey(cfg.oauthEncryptionKey),+ 'db-secret-abc'+ )+ dbQuery.mockResolvedValue({+ rows: [+ makeRawRow(cfg.oauthEncryptionKey, {+ status: 'connected',+ client_id: 'db-cid',+ client_secret_encrypted: encSecret,+ }),+ ],+ rowCount: 1,+ })+ expect(await isRegistryAuthActive()).toBe(true)+ })+})