From 0d03c37c6ab68a9bee2361a904b6afcd80d05280 Mon Sep 17 00:00:00 2001 From: Aleksander Heintz Date: Mon, 7 Oct 2024 09:32:39 +0200 Subject: [PATCH] chore: fix pr issues --- .../BootstrapDatabase/CreateDatabaseRoleTask.cs | 2 +- .../BootstrapDatabase/CreateDatabaseSchemaTask.cs | 2 +- .../BootstrapDatabase/CreateDatabaseTask.cs | 2 +- .../src/Altinn.Authorization.DeployApi/Program.cs | 8 +++++++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/apps/Altinn.Authorization.DeployApi/src/Altinn.Authorization.DeployApi/BootstrapDatabase/CreateDatabaseRoleTask.cs b/src/apps/Altinn.Authorization.DeployApi/src/Altinn.Authorization.DeployApi/BootstrapDatabase/CreateDatabaseRoleTask.cs index f6d353e3..1c9120ce 100644 --- a/src/apps/Altinn.Authorization.DeployApi/src/Altinn.Authorization.DeployApi/BootstrapDatabase/CreateDatabaseRoleTask.cs +++ b/src/apps/Altinn.Authorization.DeployApi/src/Altinn.Authorization.DeployApi/BootstrapDatabase/CreateDatabaseRoleTask.cs @@ -43,7 +43,7 @@ WITH LOGIN { await cmd.ExecuteNonQueryAsync(cancellationToken); } - catch (PostgresException ex) when (ex.SqlState == "42710") + catch (PostgresException ex) when (ex.SqlState == PostgresErrorCodes.DuplicateObject) { if (pw.Updated) { diff --git a/src/apps/Altinn.Authorization.DeployApi/src/Altinn.Authorization.DeployApi/BootstrapDatabase/CreateDatabaseSchemaTask.cs b/src/apps/Altinn.Authorization.DeployApi/src/Altinn.Authorization.DeployApi/BootstrapDatabase/CreateDatabaseSchemaTask.cs index b4417e4f..e060ddd3 100644 --- a/src/apps/Altinn.Authorization.DeployApi/src/Altinn.Authorization.DeployApi/BootstrapDatabase/CreateDatabaseSchemaTask.cs +++ b/src/apps/Altinn.Authorization.DeployApi/src/Altinn.Authorization.DeployApi/BootstrapDatabase/CreateDatabaseSchemaTask.cs @@ -35,7 +35,7 @@ CREATE SCHEMA "{_schemaName}" { await cmd.ExecuteNonQueryAsync(cancellationToken); } - catch (PostgresException ex) when (ex.SqlState == "42P06") + catch (PostgresException ex) when (ex.SqlState == PostgresErrorCodes.DuplicateSchema) { // Schema already exists } diff --git a/src/apps/Altinn.Authorization.DeployApi/src/Altinn.Authorization.DeployApi/BootstrapDatabase/CreateDatabaseTask.cs b/src/apps/Altinn.Authorization.DeployApi/src/Altinn.Authorization.DeployApi/BootstrapDatabase/CreateDatabaseTask.cs index a8983cd8..01f83a88 100644 --- a/src/apps/Altinn.Authorization.DeployApi/src/Altinn.Authorization.DeployApi/BootstrapDatabase/CreateDatabaseTask.cs +++ b/src/apps/Altinn.Authorization.DeployApi/src/Altinn.Authorization.DeployApi/BootstrapDatabase/CreateDatabaseTask.cs @@ -29,7 +29,7 @@ CREATE DATABASE "{_databaseName}" { await cmd.ExecuteNonQueryAsync(cancellationToken); } - catch (PostgresException ex) when (ex.SqlState == "42P04") + catch (PostgresException ex) when (ex.SqlState == PostgresErrorCodes.DuplicateDatabase) { // Database already exists } diff --git a/src/apps/Altinn.Authorization.DeployApi/src/Altinn.Authorization.DeployApi/Program.cs b/src/apps/Altinn.Authorization.DeployApi/src/Altinn.Authorization.DeployApi/Program.cs index 528aeec8..c67413ff 100644 --- a/src/apps/Altinn.Authorization.DeployApi/src/Altinn.Authorization.DeployApi/Program.cs +++ b/src/apps/Altinn.Authorization.DeployApi/src/Altinn.Authorization.DeployApi/Program.cs @@ -12,7 +12,13 @@ } else { - cred = new ManagedIdentityCredential(); + var clientId = builder.Configuration.GetValue("ManagedIdentity:ClientId"); + if (string.IsNullOrEmpty(clientId)) + { + throw new InvalidOperationException("ManagedIdentity:ClientId is required in production mode"); + } + + cred = new ManagedIdentityCredential(clientId); } builder.Services.AddSingleton(cred);