Formatted the script.
This commit is contained in:
@@ -9,7 +9,9 @@ import { spawnSync } from "node:child_process";
|
|||||||
function runAz(args, options = {}) {
|
function runAz(args, options = {}) {
|
||||||
const result = spawnSync("az", args, {
|
const result = spawnSync("az", args, {
|
||||||
encoding: "utf8",
|
encoding: "utf8",
|
||||||
stdio: options.quiet ? ["ignore", "ignore", "ignore"] : ["ignore", "pipe", "pipe"],
|
stdio: options.quiet
|
||||||
|
? ["ignore", "ignore", "ignore"]
|
||||||
|
: ["ignore", "pipe", "pipe"],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
@@ -17,7 +19,9 @@ function runAz(args, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result.status !== 0 && options.allowFailure !== true) {
|
if (result.status !== 0 && options.allowFailure !== true) {
|
||||||
throw new Error((result.stderr || "").trim() || `az ${args.join(" ")} failed`);
|
throw new Error(
|
||||||
|
(result.stderr || "").trim() || `az ${args.join(" ")} failed`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -119,20 +123,29 @@ Options:
|
|||||||
const requiredResourceAccess = [
|
const requiredResourceAccess = [
|
||||||
{
|
{
|
||||||
resourceAppId: "00000003-0000-0000-c000-000000000000",
|
resourceAppId: "00000003-0000-0000-c000-000000000000",
|
||||||
resourceAccess: [{ id: "0e263e50-5827-48a4-b97c-d940288653c7", type: "Scope" }],
|
resourceAccess: [
|
||||||
|
{ id: "0e263e50-5827-48a4-b97c-d940288653c7", type: "Scope" },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
resourceAppId: "499b84ac-1321-427f-aa17-267ca6975798",
|
resourceAppId: "499b84ac-1321-427f-aa17-267ca6975798",
|
||||||
resourceAccess: [{ id: "ee69721e-6c3a-468f-a9ec-302d16a4c599", type: "Scope" }],
|
resourceAccess: [
|
||||||
|
{ id: "ee69721e-6c3a-468f-a9ec-302d16a4c599", type: "Scope" },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
resourceAppId: "797f4846-ba00-4fd7-ba43-dac1f8f63013",
|
resourceAppId: "797f4846-ba00-4fd7-ba43-dac1f8f63013",
|
||||||
resourceAccess: [{ id: "41094075-9dad-400e-a0bd-54e686782033", type: "Scope" }],
|
resourceAccess: [
|
||||||
|
{ id: "41094075-9dad-400e-a0bd-54e686782033", type: "Scope" },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "create-pca-"));
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "create-pca-"));
|
||||||
const requiredResourceAccessFile = path.join(tempDir, "required-resource-accesses.json");
|
const requiredResourceAccessFile = path.join(
|
||||||
|
tempDir,
|
||||||
|
"required-resource-accesses.json",
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
@@ -166,27 +179,43 @@ Options:
|
|||||||
{ quiet: true },
|
{ quiet: true },
|
||||||
);
|
);
|
||||||
} catch {
|
} catch {
|
||||||
console.error(`Error: Failed to configure application '${appName}' (${appId}).`);
|
console.error(
|
||||||
|
`Error: Failed to configure application '${appName}' (${appId}).`,
|
||||||
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
fs.rmSync(tempDir, { recursive: true, force: true });
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
runAz(["ad", "sp", "create", "--id", appId], { quiet: true, allowFailure: true });
|
runAz(["ad", "sp", "create", "--id", appId], {
|
||||||
|
quiet: true,
|
||||||
|
allowFailure: true,
|
||||||
|
});
|
||||||
|
|
||||||
const adminConsentResult = runAz(
|
const adminConsentResult = runAz(
|
||||||
["ad", "app", "permission", "admin-consent", "--id", appId],
|
["ad", "app", "permission", "admin-consent", "--id", appId],
|
||||||
{ quiet: true, allowFailure: true },
|
{ quiet: true, allowFailure: true },
|
||||||
);
|
);
|
||||||
if (adminConsentResult.status !== 0) {
|
if (adminConsentResult.status !== 0) {
|
||||||
console.error(`Error: Failed to grant admin consent for '${appName}' (${appId}).`);
|
console.error(
|
||||||
|
`Error: Failed to grant admin consent for '${appName}' (${appId}).`,
|
||||||
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const tenantId = runAz(["account", "show", "--query", "tenantId", "-o", "tsv"]).stdout;
|
const tenantId = runAz([
|
||||||
|
"account",
|
||||||
|
"show",
|
||||||
|
"--query",
|
||||||
|
"tenantId",
|
||||||
|
"-o",
|
||||||
|
"tsv",
|
||||||
|
]).stdout;
|
||||||
if (!tenantId) {
|
if (!tenantId) {
|
||||||
console.error("Error: Failed to resolve tenantId from current Azure CLI context.");
|
console.error(
|
||||||
|
"Error: Failed to resolve tenantId from current Azure CLI context.",
|
||||||
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user