From 57e4adc69c07486c75254c29ad1ac07b8afc4fb1 Mon Sep 17 00:00:00 2001 From: Bert Hausmans Date: Thu, 22 Jan 2026 22:56:29 +0100 Subject: [PATCH] Remove JIRA_SCHEMA_ID from entire application - Remove JIRA_SCHEMA_ID from all documentation, config files, and scripts - Update generate-schema.ts to always auto-discover schemas dynamically - Runtime application already discovers schemas via /objectschema/list API - Build script now automatically selects schema with most objects - Remove JIRA_SCHEMA_ID from docker-compose.yml, Azure setup scripts, and all docs - Application is now fully schema-agnostic and discovers schemas automatically --- CLAUDE.md | 1 - backend/scripts/generate-schema.ts | 76 +++++++++++++++---- docker-compose.yml | 1 - docs/AUTHENTICATION-ENV-VARS.md | 1 - docs/AZURE-RESOURCES-OVERVIEW.md | 2 - .../AZURE-APP-SERVICE-DEPLOYMENT.md | 6 +- .../GREEN-FIELD-DEPLOYMENT-GUIDE.md | 2 - docs/DOCKER-COMPOSE-WARNINGS.md | 2 - docs/PRODUCTION-DEPLOYMENT.md | 1 - .../AZURE-NEW-SUBSCRIPTION-SETUP.md | 7 -- .../LOCAL-DEVELOPMENT-SETUP.md | 1 - docs/cmdb-insight-specificatie.md | 1 - scripts/configure-app-settings-direct.sh | 6 -- scripts/setup-azure-resources.sh | 3 - 14 files changed, 63 insertions(+), 47 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index cc3fc36..a55b97f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -156,7 +156,6 @@ Dutch hospital reference architecture with 90+ application functions organized i ```env # Jira Data Center JIRA_HOST=https://jira.zuyderland.nl -JIRA_SCHEMA_ID= # Jira Authentication Method: 'pat' or 'oauth' JIRA_AUTH_METHOD=pat # Choose: 'pat' (Personal Access Token) or 'oauth' (OAuth 2.0) diff --git a/backend/scripts/generate-schema.ts b/backend/scripts/generate-schema.ts index f104d51..dd37f53 100644 --- a/backend/scripts/generate-schema.ts +++ b/backend/scripts/generate-schema.ts @@ -10,6 +10,11 @@ * and their attributes, ensuring the data model is always in sync with the * actual CMDB configuration. * + * Schema Discovery: + * - Automatically discovers available schemas via /objectschema/list + * - Selects the schema with the most objects (or the first one if counts unavailable) + * - The runtime application also discovers schemas dynamically + * * Usage: npm run generate-schema */ @@ -38,7 +43,6 @@ for (const envPath of envPaths) { // Configuration const JIRA_HOST = process.env.JIRA_HOST || ''; const JIRA_PAT = process.env.JIRA_PAT || ''; -const JIRA_SCHEMA_ID = process.env.JIRA_SCHEMA_ID || ''; const OUTPUT_DIR = path.resolve(__dirname, '../src/generated'); @@ -255,6 +259,36 @@ class JiraSchemaFetcher { } } + /** + * List all available schemas + */ + async listSchemas(): Promise { + try { + const response = await fetch(`${this.baseUrl}/objectschema/list`, { + headers: this.headers, + }); + + if (!response.ok) { + console.error(`Failed to list schemas: ${response.status} ${response.statusText}`); + return []; + } + + const result = await response.json(); + + // Handle both array and object responses + if (Array.isArray(result)) { + return result; + } else if (result && typeof result === 'object' && 'objectschemas' in result) { + return result.objectschemas || []; + } + + return []; + } catch (error) { + console.error(`Error listing schemas:`, error); + return []; + } + } + /** * Test the connection */ @@ -819,17 +853,10 @@ async function main() { process.exit(1); } - if (!JIRA_SCHEMA_ID) { - console.error('❌ ERROR: JIRA_SCHEMA_ID environment variable is required'); - console.error(' Set this in your .env file: JIRA_SCHEMA_ID=6'); - process.exit(1); - } - if (envLoaded) { console.log(`🔧 Environment: ${envLoaded}`); } console.log(`📡 Jira Host: ${JIRA_HOST}`); - console.log(`📋 Schema ID: ${JIRA_SCHEMA_ID}`); console.log(`📁 Output Dir: ${OUTPUT_DIR}`); console.log(''); @@ -852,20 +879,41 @@ async function main() { console.log('✅ Connection successful'); console.log(''); - // Fetch schema info - console.log('📋 Fetching schema information...'); - const schema = await fetcher.fetchSchema(JIRA_SCHEMA_ID); - if (!schema) { - console.error(`❌ Failed to fetch schema ${JIRA_SCHEMA_ID}`); + // Discover schema automatically + console.log('📋 Discovering available schemas...'); + const schemas = await fetcher.listSchemas(); + + if (schemas.length === 0) { + console.error('❌ No schemas found'); + console.error(' Please ensure Jira Assets is configured and accessible'); process.exit(1); } + + // Select the schema with the most objects (or the first one if counts unavailable) + const schema = schemas.reduce((prev, current) => { + const prevCount = prev.objectCount || 0; + const currentCount = current.objectCount || 0; + return currentCount > prevCount ? current : prev; + }); + + const selectedSchemaId = schema.id.toString(); + console.log(` Found ${schemas.length} schema(s)`); + if (schemas.length > 1) { + console.log(' Available schemas:'); + schemas.forEach(s => { + const marker = s.id === schema.id ? ' → ' : ' '; + console.log(`${marker}${s.id}: ${s.name} (${s.objectSchemaKey}) - ${s.objectCount || 0} objects`); + }); + console.log(` Using schema: ${schema.name} (ID: ${selectedSchemaId})`); + } + console.log(` Schema: ${schema.name} (${schema.objectSchemaKey})`); console.log(` Total objects: ${schema.objectCount || 'unknown'}`); console.log(''); // Fetch ALL object types from the schema console.log('📦 Fetching all object types from schema...'); - const allObjectTypes = await fetcher.fetchAllObjectTypes(JIRA_SCHEMA_ID); + const allObjectTypes = await fetcher.fetchAllObjectTypes(selectedSchemaId); if (allObjectTypes.length === 0) { console.error('❌ No object types found in schema'); diff --git a/docker-compose.yml b/docker-compose.yml index 6e82098..cbf6d30 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,7 +34,6 @@ services: # Optional Jira/AI variables (set in .env file or environment) - JIRA_HOST=${JIRA_HOST} - JIRA_PAT=${JIRA_PAT} - - JIRA_SCHEMA_ID=${JIRA_SCHEMA_ID} - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} volumes: - ./backend/src:/app/src diff --git a/docs/AUTHENTICATION-ENV-VARS.md b/docs/AUTHENTICATION-ENV-VARS.md index bdbd44d..704e94d 100644 --- a/docs/AUTHENTICATION-ENV-VARS.md +++ b/docs/AUTHENTICATION-ENV-VARS.md @@ -134,7 +134,6 @@ The following environment variables have been **REMOVED** from the codebase and - `SESSION_SECRET`: Should be a secure random string in production (generate with `openssl rand -base64 32`) - `ENCRYPTION_KEY`: Must be exactly 32 bytes when base64 decoded (generate with `openssl rand -base64 32`) -- `JIRA_SCHEMA_ID`: Required for Jira Assets integration ### Application Branding diff --git a/docs/AZURE-RESOURCES-OVERVIEW.md b/docs/AZURE-RESOURCES-OVERVIEW.md index c58b991..a50fcca 100644 --- a/docs/AZURE-RESOURCES-OVERVIEW.md +++ b/docs/AZURE-RESOURCES-OVERVIEW.md @@ -78,7 +78,6 @@ These secrets should be stored in Azure Key Vault: | `SessionSecret` | Session encryption secret | `a1b2c3d4e5f6...` (32+ chars) | | `JiraOAuthClientId` | Jira OAuth Client ID | `OAuthClientId123` | | `JiraOAuthClientSecret` | Jira OAuth Client Secret | `OAuthSecret456` | -| `JiraSchemaId` | Jira Assets Schema ID | `schema-123` | | `DatabasePassword` | PostgreSQL admin password | `SecurePassword123!` | --- @@ -171,7 +170,6 @@ az webapp log tail --name cmdb-frontend-prod --resource-group rg-cmdb-insight-pr - `JIRA_OAUTH_CLIENT_ID` (from Key Vault) - `JIRA_OAUTH_CLIENT_SECRET` (from Key Vault) - `JIRA_OAUTH_CALLBACK_URL` -- `JIRA_SCHEMA_ID` (from Key Vault) - `SESSION_SECRET` (from Key Vault) - `FRONTEND_URL` - `APPINSIGHTS_INSTRUMENTATIONKEY` diff --git a/docs/Core deployment guides/AZURE-APP-SERVICE-DEPLOYMENT.md b/docs/Core deployment guides/AZURE-APP-SERVICE-DEPLOYMENT.md index 990958a..44634a1 100644 --- a/docs/Core deployment guides/AZURE-APP-SERVICE-DEPLOYMENT.md +++ b/docs/Core deployment guides/AZURE-APP-SERVICE-DEPLOYMENT.md @@ -170,7 +170,6 @@ az webapp config appsettings set \ DATABASE_PASSWORD=your-database-password \ DATABASE_SSL=true \ JIRA_BASE_URL=https://jira.zuyderland.nl \ - JIRA_SCHEMA_ID=your-schema-id \ JIRA_PAT=your-pat-token \ SESSION_SECRET=$(openssl rand -hex 32) \ FRONTEND_URL=https://zdl-cmdb-insight-prd-frontend-webapp.azurewebsites.net @@ -195,7 +194,6 @@ az webapp config appsettings set \ PORT=3001 \ DATABASE_TYPE=sqlite \ JIRA_BASE_URL=https://jira.zuyderland.nl \ - JIRA_SCHEMA_ID=your-schema-id \ JIRA_PAT=your-pat-token \ SESSION_SECRET=$(openssl rand -hex 32) \ FRONTEND_URL=https://zdl-cmdb-insight-prd-frontend-webapp.azurewebsites.net @@ -251,7 +249,6 @@ az keyvault create \ ```bash az keyvault secret set --vault-name kv-cmdb-insight-prod --name JiraPat --value "your-token" az keyvault secret set --vault-name kv-cmdb-insight-prod --name SessionSecret --value "$(openssl rand -hex 32)" -az keyvault secret set --vault-name kv-cmdb-insight-prod --name JiraSchemaId --value "your-schema-id" ``` ### Stap 3: Grant Access @@ -294,8 +291,7 @@ az webapp config appsettings set \ --resource-group zdl-cmdb-insight-prd-euwe-rg \ --settings \ JIRA_PAT="@Microsoft.KeyVault(SecretUri=https://kv-cmdb-insight-prod.vault.azure.net/secrets/JiraPat/)" \ - SESSION_SECRET="@Microsoft.KeyVault(SecretUri=https://kv-cmdb-insight-prod.vault.azure.net/secrets/SessionSecret/)" \ - JIRA_SCHEMA_ID="@Microsoft.KeyVault(SecretUri=https://kv-cmdb-insight-prod.vault.azure.net/secrets/JiraSchemaId/)" + SESSION_SECRET="@Microsoft.KeyVault(SecretUri=https://kv-cmdb-insight-prod.vault.azure.net/secrets/SessionSecret/)" ``` --- diff --git a/docs/Core deployment guides/GREEN-FIELD-DEPLOYMENT-GUIDE.md b/docs/Core deployment guides/GREEN-FIELD-DEPLOYMENT-GUIDE.md index 5d46d75..6fd0940 100644 --- a/docs/Core deployment guides/GREEN-FIELD-DEPLOYMENT-GUIDE.md +++ b/docs/Core deployment guides/GREEN-FIELD-DEPLOYMENT-GUIDE.md @@ -72,7 +72,6 @@ DATABASE_URL=postgresql://... # Jira Assets JIRA_HOST=https://jira.zuyderland.nl -JIRA_SCHEMA_ID= JIRA_SERVICE_ACCOUNT_TOKEN= # Jira Authentication Method @@ -228,7 +227,6 @@ services: - DATABASE_TYPE=postgres - DATABASE_URL=${DATABASE_URL} - JIRA_HOST=${JIRA_HOST} - - JIRA_SCHEMA_ID=${JIRA_SCHEMA_ID} - JIRA_SERVICE_ACCOUNT_TOKEN=${JIRA_SERVICE_ACCOUNT_TOKEN} - SESSION_SECRET=${SESSION_SECRET} ports: diff --git a/docs/DOCKER-COMPOSE-WARNINGS.md b/docs/DOCKER-COMPOSE-WARNINGS.md index 87983c7..7782531 100644 --- a/docs/DOCKER-COMPOSE-WARNINGS.md +++ b/docs/DOCKER-COMPOSE-WARNINGS.md @@ -35,7 +35,6 @@ nano .env ```bash export JIRA_HOST=https://jira.zuyderland.nl export JIRA_PAT=your_token -export JIRA_SCHEMA_ID=your_schema_id export ANTHROPIC_API_KEY=your_key docker-compose up @@ -51,7 +50,6 @@ De warnings zijn **niet kritisch**. De applicatie werkt ook zonder deze variabel # Jira Assets JIRA_HOST=https://jira.zuyderland.nl JIRA_PAT=your_personal_access_token -JIRA_SCHEMA_ID=your_schema_id # AI (optioneel) ANTHROPIC_API_KEY=your_anthropic_key diff --git a/docs/PRODUCTION-DEPLOYMENT.md b/docs/PRODUCTION-DEPLOYMENT.md index 9f86303..709a014 100644 --- a/docs/PRODUCTION-DEPLOYMENT.md +++ b/docs/PRODUCTION-DEPLOYMENT.md @@ -26,7 +26,6 @@ Deze guide beschrijft hoe je de CMDB Insight applicatie veilig en betrouwbaar in ```bash # .env (niet committen!) JIRA_HOST=https://jira.zuyderland.nl -JIRA_SCHEMA_ID=your-schema-id JIRA_AUTH_METHOD=oauth # of 'pat' JIRA_OAUTH_CLIENT_ID=your-client-id JIRA_OAUTH_CLIENT_SECRET=your-client-secret diff --git a/docs/Setup and configuration/AZURE-NEW-SUBSCRIPTION-SETUP.md b/docs/Setup and configuration/AZURE-NEW-SUBSCRIPTION-SETUP.md index 9f457c6..d89dd5e 100644 --- a/docs/Setup and configuration/AZURE-NEW-SUBSCRIPTION-SETUP.md +++ b/docs/Setup and configuration/AZURE-NEW-SUBSCRIPTION-SETUP.md @@ -283,7 +283,6 @@ JIRA_PAT="your-jira-personal-access-token" SESSION_SECRET=$(openssl rand -hex 32) JIRA_OAUTH_CLIENT_ID="your-oauth-client-id" JIRA_OAUTH_CLIENT_SECRET="your-oauth-client-secret" -JIRA_SCHEMA_ID="your-schema-id" # Add secrets az keyvault secret set \ @@ -306,11 +305,6 @@ az keyvault secret set \ --name "JiraOAuthClientSecret" \ --value "$JIRA_OAUTH_CLIENT_SECRET" -az keyvault secret set \ - --vault-name $KEY_VAULT_NAME \ - --name "JiraSchemaId" \ - --value "$JIRA_SCHEMA_ID" - # If using PostgreSQL, add database password az keyvault secret set \ --vault-name $KEY_VAULT_NAME \ @@ -436,7 +430,6 @@ az webapp config appsettings set \ JIRA_OAUTH_CLIENT_ID="@Microsoft.KeyVault(SecretUri=https://${KEY_VAULT_NAME}.vault.azure.net/secrets/JiraOAuthClientId/)" \ JIRA_OAUTH_CLIENT_SECRET="@Microsoft.KeyVault(SecretUri=https://${KEY_VAULT_NAME}.vault.azure.net/secrets/JiraOAuthClientSecret/)" \ JIRA_OAUTH_CALLBACK_URL="https://${BACKEND_APP_NAME}.azurewebsites.net/api/auth/callback" \ - JIRA_SCHEMA_ID="@Microsoft.KeyVault(SecretUri=https://${KEY_VAULT_NAME}.vault.azure.net/secrets/JiraSchemaId/)" \ SESSION_SECRET="@Microsoft.KeyVault(SecretUri=https://${KEY_VAULT_NAME}.vault.azure.net/secrets/SessionSecret/)" \ FRONTEND_URL="https://${FRONTEND_APP_NAME}.azurewebsites.net" \ APPINSIGHTS_INSTRUMENTATIONKEY="${INSTRUMENTATION_KEY}" diff --git a/docs/Setup and configuration/LOCAL-DEVELOPMENT-SETUP.md b/docs/Setup and configuration/LOCAL-DEVELOPMENT-SETUP.md index 0098e7a..d54c5de 100644 --- a/docs/Setup and configuration/LOCAL-DEVELOPMENT-SETUP.md +++ b/docs/Setup and configuration/LOCAL-DEVELOPMENT-SETUP.md @@ -132,7 +132,6 @@ DATABASE_URL=postgresql://cmdb:cmdb-dev@localhost:5432/cmdb_insight # Jira (optioneel) JIRA_HOST=https://jira.zuyderland.nl JIRA_PAT=your_token -JIRA_SCHEMA_ID=your_schema_id # AI (optioneel) ANTHROPIC_API_KEY=your_key diff --git a/docs/cmdb-insight-specificatie.md b/docs/cmdb-insight-specificatie.md index 0f83bd7..d90d8c7 100644 --- a/docs/cmdb-insight-specificatie.md +++ b/docs/cmdb-insight-specificatie.md @@ -952,7 +952,6 @@ cmdb-insight/ # Jira Assets JIRA_HOST=https://jira.zuyderland.nl JIRA_PAT=your_personal_access_token_here -JIRA_SCHEMA_ID=your_schema_id # Object Type IDs (ophalen via API) JIRA_APPLICATION_COMPONENT_TYPE_ID=your_type_id diff --git a/scripts/configure-app-settings-direct.sh b/scripts/configure-app-settings-direct.sh index 007875b..2378fdf 100755 --- a/scripts/configure-app-settings-direct.sh +++ b/scripts/configure-app-settings-direct.sh @@ -22,13 +22,11 @@ FRONTEND_URL="https://${FRONTEND_APP_NAME}.azurewebsites.net" echo "" echo "📝 Configure these values:" -echo " JIRA_SCHEMA_ID: (your Jira schema ID)" echo " JIRA_PAT: (your Jira Personal Access Token)" echo " Or JIRA_OAUTH_CLIENT_ID and JIRA_OAUTH_CLIENT_SECRET" echo "" # Prompt for values (or set them as environment variables) -read -p "Enter JIRA_SCHEMA_ID (or press Enter to skip): " JIRA_SCHEMA_ID read -p "Enter JIRA_PAT (or press Enter to skip): " JIRA_PAT read -p "Enter JIRA_OAUTH_CLIENT_ID (or press Enter to skip): " JIRA_OAUTH_CLIENT_ID read -p "Enter JIRA_OAUTH_CLIENT_SECRET (or press Enter to skip): " JIRA_OAUTH_CLIENT_SECRET @@ -39,10 +37,6 @@ echo "🔧 Configuring backend app settings..." # Build settings string SETTINGS="NODE_ENV=production PORT=3001 JIRA_BASE_URL=https://jira.zuyderland.nl SESSION_SECRET=${SESSION_SECRET} FRONTEND_URL=${FRONTEND_URL}" -if [ -n "$JIRA_SCHEMA_ID" ]; then - SETTINGS="${SETTINGS} JIRA_SCHEMA_ID=${JIRA_SCHEMA_ID}" -fi - if [ -n "$JIRA_PAT" ]; then SETTINGS="${SETTINGS} JIRA_PAT=${JIRA_PAT}" fi diff --git a/scripts/setup-azure-resources.sh b/scripts/setup-azure-resources.sh index af5b1fd..3ba5539 100755 --- a/scripts/setup-azure-resources.sh +++ b/scripts/setup-azure-resources.sh @@ -200,13 +200,11 @@ echo " - JiraPat (if using PAT authentication)" echo " - SessionSecret (generate with: openssl rand -hex 32)" echo " - JiraOAuthClientId (if using OAuth)" echo " - JiraOAuthClientSecret (if using OAuth)" -echo " - JiraSchemaId" echo "" echo "Commands to add secrets:" echo " az keyvault secret set --vault-name $KEY_VAULT_NAME --name SessionSecret --value \$(openssl rand -hex 32)" echo " az keyvault secret set --vault-name $KEY_VAULT_NAME --name JiraOAuthClientId --value " echo " az keyvault secret set --vault-name $KEY_VAULT_NAME --name JiraOAuthClientSecret --value " -echo " az keyvault secret set --vault-name $KEY_VAULT_NAME --name JiraSchemaId --value " echo "" echo -e "${GREEN}Step 5: Creating Application Insights...${NC}" @@ -382,7 +380,6 @@ echo "1. Add secrets to Key Vault:" echo " az keyvault secret set --vault-name $KEY_VAULT_NAME --name SessionSecret --value \$(openssl rand -hex 32)" echo " az keyvault secret set --vault-name $KEY_VAULT_NAME --name JiraOAuthClientId --value " echo " az keyvault secret set --vault-name $KEY_VAULT_NAME --name JiraOAuthClientSecret --value " -echo " az keyvault secret set --vault-name $KEY_VAULT_NAME --name JiraSchemaId --value " echo "" echo "2. Update backend app settings to use Key Vault references:" echo " See AZURE-NEW-SUBSCRIPTION-SETUP.md for details"