Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add base uri for web api #425

Merged
merged 5 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions .azure/applications/web-api-eu/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ param location string

@minLength(3)
@secure()
param containerAppEnvironmentId string
param containerAppEnvironmentName string
@minLength(3)
@secure()
param appInsightConnectionString string
@minLength(3)
@minLength(5)
@secure()
param appConfigurationName string
@minLength(3)
Expand All @@ -23,8 +23,12 @@ param environmentKeyVaultName string
var namePrefix = 'dp-be-${environment}'
var baseImageUrl = 'ghcr.io/digdir/dialogporten-'

resource appConfig 'Microsoft.AppConfiguration/configurationStores@2023-03-01' existing = {
name: '${namePrefix}-appConfiguration'
resource appConfiguration 'Microsoft.AppConfiguration/configurationStores@2023-03-01' existing = {
name: appConfigurationName
}

resource containerAppEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' existing = {
name: containerAppEnvironmentName
}

var containerAppEnvVars = [
Expand All @@ -38,7 +42,7 @@ var containerAppEnvVars = [
}
{
name: 'AZURE_APPCONFIG_URI'
value: appConfig.properties.endpoint
value: appConfiguration.properties.endpoint
}
{
name: 'ASPNETCORE_URLS'
Expand All @@ -59,7 +63,19 @@ module containerApp '../../modules/containerApp/main.bicep' = {
image: '${baseImageUrl}webapi:${imageTag}'
location: location
envVariables: containerAppEnvVars
containerAppEnvId: containerAppEnvironmentId
containerAppEnvId: containerAppEnvironment.id
}
}

var appConfigWebApiEuFqdn = 'https://${containerAppName}.${containerAppEnvironment.properties.defaultDomain}'

module appConfigConfigurations '../../modules/appConfiguration/upsertKeyValue.bicep' = {
name: 'AppConfig_Add_DialogPortenBaseUri'
params: {
configStoreName: appConfigurationName
key: 'WebApi:DialogPortenBaseUri'
value: appConfigWebApiEuFqdn
keyValueType: 'custom'
}
}

Expand Down
2 changes: 1 addition & 1 deletion .azure/applications/web-api-eu/staging.bicepparam
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ param imageTag = readEnvironmentVariable('IMAGE_TAG')

// secrets
param environmentKeyVaultName = readEnvironmentVariable('ENVIRONMENT_KEY_VAULT_NAME')
param containerAppEnvironmentId = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_ID')
param containerAppEnvironmentName = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_NAME')
param appInsightConnectionString = readEnvironmentVariable('APP_INSIGHTS_CONNECTION_STRING')
param appConfigurationName = readEnvironmentVariable('APP_CONFIGURATION_NAME')
2 changes: 1 addition & 1 deletion .azure/applications/web-api-eu/test.bicepparam
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ param imageTag = readEnvironmentVariable('IMAGE_TAG')

// secrets
param environmentKeyVaultName = readEnvironmentVariable('ENVIRONMENT_KEY_VAULT_NAME')
param containerAppEnvironmentId = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_ID')
param containerAppEnvironmentName = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_NAME')
param appInsightConnectionString = readEnvironmentVariable('APP_INSIGHTS_CONNECTION_STRING')
param appConfigurationName = readEnvironmentVariable('APP_CONFIGURATION_NAME')
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using './main.bicep'
param environment = 'staging'
param location = 'norwayeast'
param imageTag = readEnvironmentVariable('IMAGE_TAG', '')
param containerAppEnvironmentId = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_ID', '')
param containerAppEnvironmentId = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_NAME', '')

//secrets
param adoConnectionStringSecretUri = readEnvironmentVariable('ADO_CONNECTION_STRING_SECRET_URI', '')
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ param location = 'norwayeast'

//secrets
param imageTag = readEnvironmentVariable('IMAGE_TAG')
param containerAppEnvironmentId = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_ID')
param containerAppEnvironmentId = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_NAME')
param adoConnectionStringSecretUri = readEnvironmentVariable('ADO_CONNECTION_STRING_SECRET_URI')
40 changes: 28 additions & 12 deletions .azure/applications/web-api-so/main.bicep
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
targetScope = 'resourceGroup'

@minLength(1)
@minLength(3)
param imageTag string
@minLength(1)
@minLength(3)
param environment string
@minLength(1)
@minLength(3)
param location string

@minLength(1)
@minLength(3)
@secure()
param containerAppEnvironmentId string
@minLength(1)
param containerAppEnvironmentName string
@minLength(3)
@secure()
param appInsightConnectionString string
@minLength(1)
@minLength(5)
@secure()
param appConfigurationName string
@minLength(1)
@minLength(3)
@secure()
param environmentKeyVaultName string

var namePrefix = 'dp-be-${environment}'
var baseImageUrl = 'ghcr.io/digdir/dialogporten-'

resource appConfig 'Microsoft.AppConfiguration/configurationStores@2023-03-01' existing = {
name: '${namePrefix}-appConfiguration'
resource appConfiguration 'Microsoft.AppConfiguration/configurationStores@2023-03-01' existing = {
name: appConfigurationName
}

resource containerAppEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' existing = {
name: containerAppEnvironmentName
}

var containerAppEnvVars = [
Expand All @@ -38,7 +42,7 @@ var containerAppEnvVars = [
}
{
name: 'AZURE_APPCONFIG_URI'
value: appConfig.properties.endpoint
value: appConfiguration.properties.endpoint
}
{
name: 'ASPNETCORE_URLS'
Expand All @@ -63,7 +67,19 @@ module containerApp '../../modules/containerApp/main.bicep' = {
image: '${baseImageUrl}webapi:${imageTag}'
location: location
envVariables: containerAppEnvVars
containerAppEnvId: containerAppEnvironmentId
containerAppEnvId: containerAppEnvironment.id
}
}

var appConfigWebApiEuFqdn = 'https://${containerAppName}.${containerAppEnvironment.properties.defaultDomain}'

module appConfigConfigurations '../../modules/appConfiguration/upsertKeyValue.bicep' = {
name: 'AppConfig_Add_DialogPortenBaseUri'
params: {
configStoreName: appConfigurationName
key: 'WebApi:DialogPortenBaseUri'
value: appConfigWebApiEuFqdn
keyValueType: 'custom'
oskogstad marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 1 addition & 1 deletion .azure/applications/web-api-so/staging.bicepparam
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ param imageTag = readEnvironmentVariable('IMAGE_TAG')

// secrets
param environmentKeyVaultName = readEnvironmentVariable('ENVIRONMENT_KEY_VAULT_NAME')
param containerAppEnvironmentId = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_ID')
param containerAppEnvironmentName = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_NAME')
param appInsightConnectionString = readEnvironmentVariable('APP_INSIGHTS_CONNECTION_STRING')
param appConfigurationName = readEnvironmentVariable('APP_CONFIGURATION_NAME')
2 changes: 1 addition & 1 deletion .azure/applications/web-api-so/test.bicepparam
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ param imageTag = readEnvironmentVariable('IMAGE_TAG')

// secrets
param environmentKeyVaultName = readEnvironmentVariable('ENVIRONMENT_KEY_VAULT_NAME')
param containerAppEnvironmentId = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_ID')
param containerAppEnvironmentName = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_NAME')
param appInsightConnectionString = readEnvironmentVariable('APP_INSIGHTS_CONNECTION_STRING')
param appConfigurationName = readEnvironmentVariable('APP_CONFIGURATION_NAME')
6 changes: 3 additions & 3 deletions .github/workflows/action-deploy-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
required: true
AZURE_ENVIRONMENT_KEY_VAULT_NAME:
required: true
AZURE_CONTAINER_APP_ENVIRONMENT_ID:
AZURE_CONTAINER_APP_ENVIRONMENT_NAME:
required: true
AZURE_APP_INSIGHTS_CONNECTION_STRING:
required: true
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
# IMAGE_TAG: ${{ inputs.gitShortSha }}
# # secrets
# ADO_CONNECTION_STRING_SECRET_URI: ${{ secrets.AZURE_ADO_CONNECTION_STRING_SECRET_URI }}
# CONTAINER_APP_ENVIRONMENT_ID: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_ID }}
# CONTAINER_APP_ENVIRONMENT_NAME: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_NAME }}
# with:
# scope: resourcegroup
# template: ./.azure/applications/web-api-migration-job/main.bicep
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
# parameters
IMAGE_TAG: ${{ inputs.gitShortSha }}
# secrets
CONTAINER_APP_ENVIRONMENT_ID: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_ID }}
CONTAINER_APP_ENVIRONMENT_NAME: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_NAME }}
APP_INSIGHTS_CONNECTION_STRING: ${{ secrets.AZURE_APP_INSIGHTS_CONNECTION_STRING }}
APP_CONFIGURATION_NAME: ${{ secrets.AZURE_APP_CONFIGURATION_NAME }}
ENVIRONMENT_KEY_VAULT_NAME: ${{ secrets.AZURE_ENVIRONMENT_KEY_VAULT_NAME }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
AZURE_RESOURCE_GROUP_NAME: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
AZURE_ADO_CONNECTION_STRING_SECRET_URI: ${{ secrets.AZURE_ADO_CONNECTION_STRING_SECRET_URI }}
AZURE_ENVIRONMENT_KEY_VAULT_NAME: ${{ secrets.AZURE_ENVIRONMENT_KEY_VAULT_NAME }}
AZURE_CONTAINER_APP_ENVIRONMENT_ID: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_ID }}
AZURE_CONTAINER_APP_ENVIRONMENT_NAME: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_NAME }}
AZURE_APP_INSIGHTS_CONNECTION_STRING: ${{ secrets.AZURE_APP_INSIGHTS_CONNECTION_STRING }}
AZURE_APP_CONFIGURATION_NAME: ${{ secrets.AZURE_APP_CONFIGURATION_NAME }}
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
using Digdir.Domain.Dialogporten.Domain.Dialogs.Events.Activities;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.Common.Events;

internal sealed class DialogActivityEventToAltinnForwarder : DomainEventToAltinnForwarderBase,
INotificationHandler<DialogActivityCreatedDomainEvent>
{
public DialogActivityEventToAltinnForwarder(ICloudEventBus cloudEventBus, IDialogDbContext db, IOptions<ApplicationSettings> settings)
: base(cloudEventBus, db, settings) { }
public DialogActivityEventToAltinnForwarder(ICloudEventBus cloudEventBus, IDialogDbContext db, IConfiguration configuration)
: base(cloudEventBus, db, configuration) { }

public async Task Handle(DialogActivityCreatedDomainEvent domainEvent, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Digdir.Library.Entity.Abstractions.Features.EventPublisher;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.Common.Events;
Expand All @@ -13,8 +14,8 @@ internal sealed class DialogElementEventToAltinnForwarder : DomainEventToAltinnF
INotificationHandler<DialogElementCreatedDomainEvent>,
INotificationHandler<DialogElementDeletedDomainEvent>
{
public DialogElementEventToAltinnForwarder(ICloudEventBus cloudEventBus, IDialogDbContext db, IOptions<ApplicationSettings> settings)
: base(cloudEventBus, db, settings)
public DialogElementEventToAltinnForwarder(ICloudEventBus cloudEventBus, IDialogDbContext db, IConfiguration configuration)
: base(cloudEventBus, db, configuration)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Digdir.Domain.Dialogporten.Domain.Dialogs.Events;
using Digdir.Library.Entity.Abstractions.Features.EventPublisher;
using MediatR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.Common.Events;
Expand All @@ -14,8 +15,8 @@ internal sealed class DialogEventToAltinnForwarder : DomainEventToAltinnForwarde
INotificationHandler<DialogSeenDomainEvent>
{
public DialogEventToAltinnForwarder(ICloudEventBus cloudEventBus, IDialogDbContext db,
IOptions<ApplicationSettings> settings)
: base(cloudEventBus, db, settings) { }
IConfiguration configuration)
oskogstad marked this conversation as resolved.
Show resolved Hide resolved
: base(cloudEventBus, db, configuration) { }

public async Task Handle(DialogCreatedDomainEvent domainEvent, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Configuration;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.Common.Events;

internal class DomainEventToAltinnForwarderBase
{
protected readonly ICloudEventBus CloudEventBus;
protected readonly IDialogDbContext Db;
private readonly DialogportenSettings _dialogportenSettings;
private readonly IConfiguration _configuration;

protected DomainEventToAltinnForwarderBase(ICloudEventBus cloudEventBus, IDialogDbContext db, IOptions<ApplicationSettings> settings)
protected DomainEventToAltinnForwarderBase(ICloudEventBus cloudEventBus, IDialogDbContext db, IConfiguration configuration)
{
CloudEventBus = cloudEventBus ?? throw new ArgumentNullException(nameof(cloudEventBus));
Db = db ?? throw new ArgumentNullException(nameof(db));
_dialogportenSettings = settings.Value.Dialogporten ?? throw new ArgumentNullException(nameof(settings));
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
}

protected string DialogportenBaseUrl() => _dialogportenSettings.BaseUri.ToString();
protected string? DialogportenBaseUrl() => _configuration["WebApi:DialogPortenBaseUri"];

protected async Task<DialogEntity> GetDialog(Guid dialogId, CancellationToken cancellationToken)
{
Expand Down
7 changes: 1 addition & 6 deletions src/Digdir.Domain.Dialogporten.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,7 @@ static void BuildAndRun(string[] args)
{
config.PostProcess = (document, _) =>
{
var dialogportenBaseUri = builder.Configuration
.GetSection(ApplicationSettings.ConfigurationSectionName)
.Get<ApplicationSettings>()!
.Dialogporten
.BaseUri
.ToString();
var dialogportenBaseUri = builder.Configuration["WebApi:DialogPortenBaseUri"];

document.Servers.Clear();
document.Servers.Add(new OpenApiServer { Url = dialogportenBaseUri });
Expand Down
Loading