Update: Refactored commands into their own source files.

This commit is contained in:
2026-03-05 23:28:08 +01:00
parent 9581ee1a31
commit ba7bacbe12
13 changed files with 443 additions and 377 deletions

View File

@@ -0,0 +1,57 @@
// SPDX-License-Identifier: MIT
import { acquireResourceTokenFromLogin } from "../../azure/index.ts";
import { getDevOpsApiToken } from "../../devops/index.ts";
import { loadPublicConfig } from "../../index.ts";
import type { CommandValues } from "./types.ts";
export function usageGetToken(): string {
return `Usage: sk-az-tools get-token --type|-t <azurerm|devops> [global options]
Options:
-t, --type <value> Token type: azurerm|devops`;
}
export async function runGetTokenCommand(values: CommandValues): Promise<unknown> {
const tokenType = (values.type ?? "").toString().trim().toLowerCase();
if (!tokenType) {
throw new Error("--type is required for get-token (allowed: azurerm, devops)");
}
const config = await loadPublicConfig();
if (!config.tenantId) {
throw new Error("tenantId is required");
}
if (!config.clientId) {
throw new Error("clientId is required");
}
if (tokenType === "azurerm") {
const result = await acquireResourceTokenFromLogin({
tenantId: config.tenantId,
clientId: config.clientId,
resource: "arm",
});
const accessToken = result?.accessToken;
if (!accessToken) {
throw new Error("Failed to obtain AzureRM token");
}
return {
tokenType,
accessToken,
};
}
if (tokenType === "devops") {
const accessToken = await getDevOpsApiToken(config.tenantId, config.clientId);
return {
tokenType,
accessToken,
};
}
throw new Error(`Invalid --type '${values.type}'. Allowed: azurerm, devops`);
}