Decomposes the monolith `infra/setup/cli.ts` into clean `infra/setup/prompts/` and `infra/setup/commands/` directories while adhering to Cliffy idiomatic modularity. Validated via `deno check`, tests, and format. Co-authored-by: mrteye <1945243+mrteye@users.noreply.github.com>
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { Command } from "jsr:@cliffy/command@1.0.0-rc.7";
|
|
import * as colors from "jsr:@std/fmt@0.225.2/colors";
|
|
import { AuthSetupConfig, DEFAULT_AUTH_CONFIG, readEnv } from "../env.ts";
|
|
|
|
export async function handleTestConnection(domainName: string): Promise<void> {
|
|
console.log(
|
|
colors.bold(
|
|
colors.blue(`\n=== Testing Auth Connection (https://${domainName}) ===`),
|
|
),
|
|
);
|
|
|
|
try {
|
|
const controller = new AbortController();
|
|
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
|
const res1 = await fetch(`https://${domainName}/`, {
|
|
signal: controller.signal,
|
|
});
|
|
clearTimeout(timeoutId);
|
|
|
|
if (res1.status === 502 || res1.status === 503 || res1.status === 504) {
|
|
throw new Error(`Gateway error: ${res1.status}`);
|
|
}
|
|
|
|
if (res1.body) {
|
|
await res1.body.cancel();
|
|
}
|
|
|
|
console.log(
|
|
colors.green(
|
|
`✓ Auth service is up and reachable at https://${domainName}/`,
|
|
),
|
|
);
|
|
} catch (error) {
|
|
console.log(
|
|
colors.red(
|
|
`✗ Error: Could not reach the auth service at https://${domainName}/`,
|
|
),
|
|
);
|
|
if (error instanceof Error) {
|
|
console.log(colors.red(` Reason: ${error.message}`));
|
|
} else {
|
|
console.log(colors.red(` Reason: ${error}`));
|
|
}
|
|
console.log(
|
|
colors.red(
|
|
" Please verify the container is running and DNS/Traefik is resolving.",
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
export const testCommand = new Command()
|
|
.description("Test Auth Connection")
|
|
.action(async () => {
|
|
const loadedEnv = await readEnv();
|
|
const currentConfig: AuthSetupConfig = {
|
|
...DEFAULT_AUTH_CONFIG,
|
|
...loadedEnv,
|
|
};
|
|
await handleTestConnection(currentConfig.domainName);
|
|
});
|