Refactor: changed appId configuration variable to clientId.

This commit is contained in:
2026-01-27 06:24:09 +01:00
parent 341332b362
commit e044813240

View File

@@ -50,18 +50,18 @@ try {
if (appIdList.length !== 1) { if (appIdList.length !== 1) {
throw new Error("App not found or multiple apps with the same name."); throw new Error("App not found or multiple apps with the same name.");
} }
config.appId = appIdList[0].appId; config.clientId = appIdList[0].appId;
} catch (error) { } catch (error) {
console.error("Failed to query Azure AD applications."); console.error("Failed to query Azure AD applications.");
process.exit(1); process.exit(1);
} }
if (config.appId) { if (config.clientId) {
console.log(`App already exists with ID: ${config.appId}`); console.log(`App already exists with Client ID: ${config.clientId}`);
} else { } else {
// Create the Azure AD application, capturing the JSON output, and extracting the .appId // Create the Azure AD application, capturing the JSON output, and extracting the .appId
try { try {
config.appId = execSync( config.clientId = execSync(
`az ad app create --display-name "${config.appName}" --query "appId" -o tsv`, `az ad app create --display-name "${config.appName}" --query "appId" -o tsv`,
) )
.toString() .toString()
@@ -70,15 +70,15 @@ if (config.appId) {
console.error("Failed to create Azure AD application."); console.error("Failed to create Azure AD application.");
process.exit(1); process.exit(1);
} }
console.log(`Created App with ID: ${config.appId}`); console.log(`Created App with Client ID: ${config.clientId}`);
} }
// Chech if service principal exists // Check if service principal exists
let spObjId; let spObjId;
try { try {
const spIdList = JSON.parse( const spIdList = JSON.parse(
execSync(`az ad sp list --filter "appId eq '${config.appId}'" -o json`) execSync(`az ad sp list --filter "appId eq '${config.clientId}'" -o json`)
.toString() .toString()
.trim(), .trim(),
); );
@@ -98,7 +98,7 @@ if (spObjId) {
// Now create the service principal for the app // Now create the service principal for the app
try { try {
spObjId = execSync( spObjId = execSync(
`az ad sp create --id ${config.appId} --query "id" -o tsv`, `az ad sp create --id ${config.clientId} --query "id" -o tsv`,
); );
console.log("Service principal created."); console.log("Service principal created.");
} catch (error) { } catch (error) {
@@ -117,7 +117,7 @@ if (args.values["generate-client-secret"]) {
"credential", "credential",
"reset", "reset",
"--id", "--id",
config.appId, config.clientId,
"--query", "--query",
"password", "password",
"-o", "-o",
@@ -138,7 +138,7 @@ if (args.values["write-env"] || args.values["generate-client-secret"]) {
// Write the APP_ID to the .env file // Write the APP_ID to the .env file
const envContent = `AZ_APP_NAME="${config.appName}" const envContent = `AZ_APP_NAME="${config.appName}"
ARM_TENANT_ID=${config.tenantId} ARM_TENANT_ID=${config.tenantId}
ARM_CLIENT_ID=${config.appId} ARM_CLIENT_ID=${config.clientId}
ARM_CLIENT_SECRET=${config.clientSecret || ""} ARM_CLIENT_SECRET=${config.clientSecret || ""}
`; `;