Refactored configuration loading function.
This commit is contained in:
1
src/cli/commands/auth.ts
Normal file
1
src/cli/commands/auth.ts
Normal file
@@ -0,0 +1 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { acquireResourceTokenFromLogin } from "../../azure/index.ts";
|
||||
import { getDevOpsApiToken } from "../../devops/index.ts";
|
||||
import { loadPublicConfig } from "../../index.ts";
|
||||
import { loadConfig } from "../../index.ts";
|
||||
|
||||
import type { CommandValues } from "./types.ts";
|
||||
|
||||
@@ -19,13 +19,7 @@ export async function runGetTokenCommand(values: CommandValues): Promise<unknown
|
||||
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");
|
||||
}
|
||||
const config = await loadConfig("public-config");
|
||||
|
||||
if (tokenType === "azurerm") {
|
||||
const result = await acquireResourceTokenFromLogin({
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { login } from "../../azure/index.ts";
|
||||
import { loadPublicConfig } from "../../index.ts";
|
||||
import { loadConfig } from "../../index.ts";
|
||||
|
||||
import type { CommandValues } from "./types.ts";
|
||||
|
||||
@@ -17,7 +17,7 @@ Options:
|
||||
}
|
||||
|
||||
export async function runLoginCommand(values: CommandValues): Promise<unknown> {
|
||||
const config = await loadPublicConfig();
|
||||
const config = await loadConfig("public-config");
|
||||
return login({
|
||||
tenantId: config.tenantId,
|
||||
clientId: config.clientId,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { logout } from "../../azure/index.ts";
|
||||
import { loadPublicConfig } from "../../index.ts";
|
||||
import { loadConfig } from "../../index.ts";
|
||||
|
||||
import type { CommandValues } from "./types.ts";
|
||||
|
||||
@@ -13,7 +13,7 @@ Options:
|
||||
}
|
||||
|
||||
export async function runLogoutCommand(values: CommandValues): Promise<unknown> {
|
||||
const config = await loadPublicConfig();
|
||||
const config = await loadConfig("public-config");
|
||||
return logout({
|
||||
tenantId: config.tenantId,
|
||||
clientId: config.clientId,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { acquireResourceTokenFromLogin } from "../../azure/index.ts";
|
||||
import { getDevOpsApiToken } from "../../devops/index.ts";
|
||||
import { loadPublicConfig } from "../../index.ts";
|
||||
import { loadConfig } from "../../index.ts";
|
||||
|
||||
import type { CommandValues } from "./types.ts";
|
||||
|
||||
@@ -54,13 +54,7 @@ async function getAutoAuthorizationHeader(url: URL): Promise<string | null> {
|
||||
return null;
|
||||
}
|
||||
|
||||
const config = await loadPublicConfig();
|
||||
if (!config.tenantId) {
|
||||
throw new Error("tenantId is required");
|
||||
}
|
||||
if (!config.clientId) {
|
||||
throw new Error("clientId is required");
|
||||
}
|
||||
const config = await loadConfig("public-config");
|
||||
|
||||
if (host === "management.azure.com") {
|
||||
const result = await acquireResourceTokenFromLogin({
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { minimatch } from "minimatch";
|
||||
|
||||
import { loadPublicConfig } from "../../index.ts";
|
||||
import { loadConfig } from "../../index.ts";
|
||||
import { getGraphClient } from "../../graph/auth.ts";
|
||||
|
||||
type PermissionRow = {
|
||||
@@ -28,7 +28,7 @@ export function filterByDisplayName<T extends DisplayNameRow>(rows: T[], pattern
|
||||
}
|
||||
|
||||
export async function getGraphClientFromPublicConfig(): Promise<{ client: any }> {
|
||||
const config = await loadPublicConfig();
|
||||
const config = await loadConfig("public-config");
|
||||
return getGraphClient({
|
||||
tenantId: config.tenantId,
|
||||
clientId: config.clientId,
|
||||
|
||||
Reference in New Issue
Block a user