From b3ba2c2350f06b449f772a81621443982387d0fe Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Tue, 13 Sep 2022 17:32:52 +0200 Subject: [PATCH 1/7] .net 6 functions v4 --- ...AltinnApplicationsOwnerSystemFunctions.xml | 242 +++++++++++++++++- .../Functions/Functions.csproj | 42 ++- .../Functions/Models/CloudEvent.cs | 2 +- 3 files changed, 259 insertions(+), 27 deletions(-) diff --git a/src/Altinn-application-owner-system/Functions/AltinnApplicationsOwnerSystemFunctions.xml b/src/Altinn-application-owner-system/Functions/AltinnApplicationsOwnerSystemFunctions.xml index 3fa93eb..d3c9139 100644 --- a/src/Altinn-application-owner-system/Functions/AltinnApplicationsOwnerSystemFunctions.xml +++ b/src/Altinn-application-owner-system/Functions/AltinnApplicationsOwnerSystemFunctions.xml @@ -39,6 +39,11 @@ The blob container to store incomming data + + + The blob container where registered subscription info are stored + + The base adress for Maskinporten in the environment where this Application Owner System is used Example: https://ver2.maskinporten.no @@ -59,6 +64,16 @@ Thumbprint for when running functions locally + + + Datatype for xml feedback. If not set no feedback is generated + + + + + Eventtype to generate xml feedback for + + Configuration object used to hold settings for the KeyVault. @@ -94,6 +109,11 @@ Name of the queue to push confirmation + + + Name of the queue to push feedback + + Azure Function that confirmes that data for a given instance is downloaded @@ -110,6 +130,43 @@ A representing the result of the asynchronous operation. + + + Azure Function that confirmes that data for a given instance is downloaded + + + + + Initializes a new instance of the class. + + + + + Function method that removes event subscription when file is added to blob storage + + A representing the result of the asynchronous operationŒ. + + + + Azure Function that confirmes that data for a given instance is downloaded + + + + + Initializes a new instance of the class. + + + + + Function method that is triggered by new element on events-feedback queue + + A representing the result of the asynchronous operation. + + + + Creates an instance for a given event + + Azure Function responsible for downloading data for a given instance. @@ -117,7 +174,7 @@ When finished it forward CloudEvent to confirmation queue - + Initializes a new instance of the class. @@ -153,6 +210,22 @@ Webhook method to receive CloudEvents from Altinn Platform Events + + + Azure Function that confirmes that data for a given instance is downloaded + + + + + Initializes a new instance of the class. + + + + + Function method that register a new subscription when file is added to blob storage + + A representing the result of the asynchronous operationŒ. + This extension is created to make it easy to add a bearer token to a HttpRequests. @@ -164,6 +237,12 @@ A HttpResponseMessage + + + Extension that add authorization header to request + + A HttpResponseMessage + Extension that add authorization header to request @@ -173,6 +252,15 @@ The request Uri A HttpResponseMessage + + + Extension that add authorization header to request + + The HttpClient + the authorization token (jwt) + The request Uri + A HttpResponseMessage + Represents a cloud event. Based on CloudEvent: https://github.com/cloudevents/spec/blob/v1.0/spec.md. @@ -258,6 +346,74 @@ Exception. Only populated if the push failed. + + + Subscription model + + + + + Gets or sets the subscription id + + + + + Gets or sets the subscription description + + + + + Gets or sets the subscription endpoint + + + + + Gets or sets the subscription sourceFilter + + + + + Gets or sets the subscription subjectFilter + + + + + Gets or sets the subscription alternativeSubjectFilter + + + + + Gets or sets the subscription typeFilter + + + + + Gets or sets the subscription consumer + + + + + Gets or sets the subscription createdBy + + + + + Gets or sets the subscription created + + + + + Deserializes the subscription from a JSON string. + + The JSON string to deserialize + The deserialized subscription + + + + Serializes the subscription to a JSON string. + + Serialized subscription + App implementation of the instance service that talks to the given app @@ -274,6 +430,9 @@ + + + HttpClient wrapper responsible for calling Altinn Platform Authentication to convert MaskinPorten token to AltinnToken @@ -380,6 +539,9 @@ + + + Class that handles integration with Azure Blob Storage. @@ -390,14 +552,39 @@ Initializes a new instance of the class. + + + Saves data in blob storage defined in configuration. + + + + + + SubscriptionService implements ISubscription and handles subscriptions against Altinn. + + + + + Create a instance of SubscriptionService + + + + + + + + + + + Interface for handling form data related operations @@ -418,6 +605,14 @@ The body of the request isn't used for anything despite this being a POST operation. + + + Add feedback. + + + Add feedback to an instance. + + Interface that defines the Authentication service responsible for converting MaskinPorten token to AltinnToken @@ -494,6 +689,13 @@ The content to push to the queue in string format Returns a queue receipt + + + Pushes the provided content to the feedback queue + + The content to push to the queue in string format + Returns a queue receipt + Interface for Storage where Application Owner system store received data @@ -509,6 +711,44 @@ Saves a stream to blob + + + Save registered subscription information + + + + + Delete blob from container + + + + + Interface for managing event subscriptions + + + + + Register a new subscription + + Name of the blob + The subscription to register + The registered subscription + + + + Get a subscription by id + + The id of the subscription + The subscription + + + + Delete a subscription by id + + Name of the blob + The id of the subscription + The deleted subscription + Host program for Azure Function diff --git a/src/Altinn-application-owner-system/Functions/Functions.csproj b/src/Altinn-application-owner-system/Functions/Functions.csproj index 5fe87c3..168952f 100644 --- a/src/Altinn-application-owner-system/Functions/Functions.csproj +++ b/src/Altinn-application-owner-system/Functions/Functions.csproj @@ -1,42 +1,34 @@  - net5.0 - v3 + net6.0 + v4 Exe AltinnApplicationsOwnerSystemFunctions AltinnApplicationsOwnerSystem.Functions - - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/src/Altinn-application-owner-system/Functions/Models/CloudEvent.cs b/src/Altinn-application-owner-system/Functions/Models/CloudEvent.cs index 734154d..8c0689c 100644 --- a/src/Altinn-application-owner-system/Functions/Models/CloudEvent.cs +++ b/src/Altinn-application-owner-system/Functions/Models/CloudEvent.cs @@ -79,7 +79,7 @@ public class CloudEvent /// Serialized cloud event public string Serialize() { - return JsonSerializer.Serialize(this, new JsonSerializerOptions { IgnoreNullValues = true }); + return JsonSerializer.Serialize(this, new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }); } /// From 33286a79d922934d7f7027b168ceb39901b59f00 Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Tue, 13 Sep 2022 17:33:15 +0200 Subject: [PATCH 2/7] deployment --- .../provision_application_owner_system.ps1 | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/deployment/provision_application_owner_system.ps1 b/deployment/provision_application_owner_system.ps1 index de5e9d5..41cfe35 100755 --- a/deployment/provision_application_owner_system.ps1 +++ b/deployment/provision_application_owner_system.ps1 @@ -11,14 +11,14 @@ param ( - [Parameter(Mandatory=$True)][string]$subscription, - [Parameter(Mandatory=$True)][string]$aosEnvironment, - [Parameter(Mandatory=$True)][string]$maskinportenclient, - [Parameter(Mandatory=$True)][string]$maskinportenclientcert, + [Parameter(Mandatory=$True)][string]$subscription, + [Parameter(Mandatory=$True)][string]$aosEnvironment, + [Parameter(Mandatory=$True)][string]$maskinportenclient, + [Parameter(Mandatory=$True)][string]$maskinportenclientcert, [Parameter(Mandatory=$True)][string]$maskinportenclientcertpwd, - [Parameter(Mandatory=$True)][string]$maskinportenuri, - [Parameter(Mandatory=$True)][string]$appsuri, - [Parameter(Mandatory=$True)][string]$platformuri, + [Parameter(Mandatory=$True)][string]$maskinportenuri, + [Parameter(Mandatory=$True)][string]$appsuri, + [Parameter(Mandatory=$True)][string]$platformuri, [string]$location = "norwayeast", [string]$resourcePrefix = "aos" ) @@ -27,9 +27,9 @@ param ( az account set --subscription $subscription $aosResourceGroupName = "$resourcePrefix-$aosEnvironment-rg" -$keyvaultname = "$resourcePrefix-$aosEnvironment-keyvault" +$keyvaultname = "$resourcePrefix-$aosEnvironment-keyvault" $storageAccountName = $resourcePrefix+$aosEnvironment+"storage" -$functionName = "$resourcePrefix-$aosEnvironment-function" +$functionName = "$resourcePrefix-$aosEnvironment-function" #### Check if resource group for AKS exists @@ -60,7 +60,7 @@ Write-Output "Import Maskinporten cert" az keyvault certificate import --vault-name $keyvaultname -n maskinportenclientcert -f $maskinportenclientcert --password $maskinportenclientcertpwd Write-Output "Create Function App" -az functionapp create --resource-group $aosResourceGroupName --consumption-plan-location $location --runtime dotnet-isolated --functions-version 3 --name $functionName --storage-account $storageAccountName +az functionapp create --resource-group $aosResourceGroupName --consumption-plan-location $location --runtime dotnet-isolated --functions-version 4 --name $functionName --storage-account $storageAccountName az functionapp identity assign -g $aosResourceGroupName -n $functionName $funcprincialId = az functionapp identity show --name $functionName --resource-group $aosResourceGroupName --query principalId --output tsv From c5cbb35fb4004dad3b562930ba00ee43bf81f7aa Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Tue, 13 Sep 2022 17:36:20 +0200 Subject: [PATCH 3/7] removed newtonsoft nuget ref --- src/Altinn-application-owner-system/Functions/Functions.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Altinn-application-owner-system/Functions/Functions.csproj b/src/Altinn-application-owner-system/Functions/Functions.csproj index 168952f..751a497 100644 --- a/src/Altinn-application-owner-system/Functions/Functions.csproj +++ b/src/Altinn-application-owner-system/Functions/Functions.csproj @@ -21,7 +21,6 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive From 71ce92c5c9506e3fd523abc5743846136c9dd983 Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Wed, 14 Sep 2022 12:54:01 +0200 Subject: [PATCH 4/7] dotnet isolated -> dotnet --- deployment/provision_application_owner_system.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/provision_application_owner_system.ps1 b/deployment/provision_application_owner_system.ps1 index 41cfe35..e277064 100755 --- a/deployment/provision_application_owner_system.ps1 +++ b/deployment/provision_application_owner_system.ps1 @@ -60,7 +60,7 @@ Write-Output "Import Maskinporten cert" az keyvault certificate import --vault-name $keyvaultname -n maskinportenclientcert -f $maskinportenclientcert --password $maskinportenclientcertpwd Write-Output "Create Function App" -az functionapp create --resource-group $aosResourceGroupName --consumption-plan-location $location --runtime dotnet-isolated --functions-version 4 --name $functionName --storage-account $storageAccountName +az functionapp create --resource-group $aosResourceGroupName --consumption-plan-location $location --runtime dotnet --functions-version 4 --name $functionName --storage-account $storageAccountName az functionapp identity assign -g $aosResourceGroupName -n $functionName $funcprincialId = az functionapp identity show --name $functionName --resource-group $aosResourceGroupName --query principalId --output tsv From 2266ff22125e84d540f79c9d8fb209c27cb00606 Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Wed, 14 Sep 2022 14:44:09 +0200 Subject: [PATCH 5/7] working script --- deployment/provision_application_owner_system.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/provision_application_owner_system.ps1 b/deployment/provision_application_owner_system.ps1 index e277064..99d481d 100755 --- a/deployment/provision_application_owner_system.ps1 +++ b/deployment/provision_application_owner_system.ps1 @@ -80,7 +80,7 @@ az functionapp config appsettings set --name $functionname --resource-group $aos az functionapp config appsettings set --name $functionname --resource-group $aosResourceGroupName --settings "KeyVault:KeyVaultURI=$vaultUri" -Write-Output "Set config" +Write-Output "Publish app" Set-Location ..\src\Altinn-application-owner-system\Functions -func azure functionapp publish $functionName +func azure functionapp publish $functionName --force Set-Location ..\..\..\deployment \ No newline at end of file From 77f9b75f3bdcd937957ea9651f462af295e8861e Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Wed, 14 Sep 2022 16:16:51 +0200 Subject: [PATCH 6/7] script working --- deployment/provision_application_owner_system.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/provision_application_owner_system.ps1 b/deployment/provision_application_owner_system.ps1 index 99d481d..df5010d 100755 --- a/deployment/provision_application_owner_system.ps1 +++ b/deployment/provision_application_owner_system.ps1 @@ -60,7 +60,7 @@ Write-Output "Import Maskinporten cert" az keyvault certificate import --vault-name $keyvaultname -n maskinportenclientcert -f $maskinportenclientcert --password $maskinportenclientcertpwd Write-Output "Create Function App" -az functionapp create --resource-group $aosResourceGroupName --consumption-plan-location $location --runtime dotnet --functions-version 4 --name $functionName --storage-account $storageAccountName +az functionapp create --resource-group $aosResourceGroupName --consumption-plan-location $location --runtime dotnet --runtime-version 6 --functions-version 4 --name $functionName --storage-account $storageAccountName az functionapp identity assign -g $aosResourceGroupName -n $functionName $funcprincialId = az functionapp identity show --name $functionName --resource-group $aosResourceGroupName --query principalId --output tsv @@ -82,5 +82,5 @@ az functionapp config appsettings set --name $functionname --resource-group $aos Write-Output "Publish app" Set-Location ..\src\Altinn-application-owner-system\Functions -func azure functionapp publish $functionName --force +func azure functionapp publish $functionName --csharp Set-Location ..\..\..\deployment \ No newline at end of file From 784ae36351fe1535a63b5bca08100c6c4c7b8650 Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Wed, 14 Sep 2022 16:47:55 +0200 Subject: [PATCH 7/7] updated packages --- .../Functions/Functions.csproj | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Altinn-application-owner-system/Functions/Functions.csproj b/src/Altinn-application-owner-system/Functions/Functions.csproj index 751a497..15358f0 100644 --- a/src/Altinn-application-owner-system/Functions/Functions.csproj +++ b/src/Altinn-application-owner-system/Functions/Functions.csproj @@ -15,10 +15,11 @@ - - - + + + +