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<string>("ManagedIdentity:ClientId"); + if (string.IsNullOrEmpty(clientId)) + { + throw new InvalidOperationException("ManagedIdentity:ClientId is required in production mode"); + } + + cred = new ManagedIdentityCredential(clientId); } builder.Services.AddSingleton(cred);