@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
51 lines • 2.02 kB
JavaScript
import { GitHubApiError } from "../../../../core/github/client.js";
import { login } from "../../../../core/github/repo.js";
import { IOResult } from "../../../../io/types.js";
import { FlagView } from "../../../spec/flag_view.js";
import { webOrigin } from "./accessor.js";
/** Check the resolved config secret, whose original environment/file source is not retained. */
export async function status(accessor, _paths, _texts, _ctx) {
const host = new URL(webOrigin(accessor)).hostname;
let account;
try {
account = await login(accessor.transport);
}
catch (err) {
if (!(err instanceof GitHubApiError) || ![401, 403].includes(err.status))
throw err;
return [
null,
new IOResult({
exitCode: 1,
stderr: new TextEncoder().encode(`${host}\n X Failed to log in using the token in Mirage configuration (HTTP ${String(err.status)})\n`),
}),
];
}
if (account === '')
return [
null,
new IOResult({
exitCode: 1,
stderr: new TextEncoder().encode(`${host}: authenticated response has no login\n`),
}),
];
return [
new TextEncoder().encode(`${host}\n ✓ Logged in to ${host} account ${account} (Mirage configuration)\n - Active account: true\n`),
new IOResult(),
];
}
/**
* `gh auth token`, refused: the token stays in Mirage configuration, where
* every gh verb reads it, and is never printed. Mirrors Python's token.
*/
export function token(accessor, _paths, _texts, ctx) {
const host = new FlagView(ctx.flags).asNonEmpty('hostname') ?? new URL(webOrigin(accessor)).hostname;
return [
null,
new IOResult({
exitCode: 1,
stderr: new TextEncoder().encode(`gh auth token: the token for ${host} stays in Mirage configuration and is never printed; gh commands use it directly\n`),
}),
];
}
//# sourceMappingURL=auth.js.map