#!/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 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); }