Add scripts for managing Azure AD applications: setup, get, and delete

This commit is contained in:
2026-01-26 21:26:08 +01:00
parent ec6d8108bc
commit bf9a85199e
3 changed files with 176 additions and 0 deletions

40
bin/get-app.js Executable file
View File

@@ -0,0 +1,40 @@
#!/usr/bin/env node
const execSync = require('child_process').execSync;
const { config } = require('../config.js');
const { parseArgs } = require('node:util');
// Let's parse command line arguments:
// --app-name <name> to override the default app name from config.js
// --help to show usage information
// --env to print in environment variable format
const args = parseArgs({
options: {
'app-name': { type: 'string', short: 'a' },
'help': { type: 'boolean', short: 'h' },
'env': { type: 'boolean', short: 'e' }
}
});
// Get the Azure AD application ID by name
const queryResult = execSync(`az ad app list --query "[?displayName=='${config.appName}']"`).toString().trim();
const apps = JSON.parse(queryResult);
if (apps.length === 1) {
const appId = apps[0].appId;
if (args.values.env) {
const tenantId = execSync(`az account show --query "tenantId" -o tsv`).toString().trim();
console.log(`AZ_APP_NAME="${config.appName}"`);
console.log(`ARM_CLIENT_ID=${appId}`);
console.log(`ARM_TENANT_ID=${tenantId}`);
} else {
console.log(`Found App ID: ${appId} for App Name: "${config.appName}"`);
}
} else if (apps.length > 1) {
console.error(`Multiple apps found with the name: "${config.appName}". Please ensure app names are unique.`);
process.exit(1);
} else {
console.error(`No App found with name: "${config.appName}"`);
process.exit(1);
}