Skip to content

Commit afb37ed

Browse files
authored
feat: Provide script to upload agreements into an Integration Account (#265)
Co-authored-by: Pim Simons <pim.simons@codit.eu>
1 parent e89dc20 commit afb37ed

14 files changed

Lines changed: 1370 additions & 20 deletions
Binary file not shown.

src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psm1

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,40 @@ function Set-AzIntegrationAccountPartners {
212212
. $PSScriptRoot\Scripts\Set-AzIntegrationAccountPartners.ps1 -ResourceGroupName $ResourceGroupName -Name $Name -PartnerFilePath $PartnerFilePath -PartnersFolder $PartnersFolder -ArtifactsPrefix $ArtifactsPrefix
213213
}
214214

215-
Export-ModuleMember -Function Set-AzIntegrationAccountPartners
215+
Export-ModuleMember -Function Set-AzIntegrationAccountPartners
216+
217+
<#
218+
.Synopsis
219+
Upload/update a single, or multiple agreements into an Azure Integration Account.
220+
221+
.Description
222+
Provide a file- or folder-path to upload/update a single or multiple agreements into an Integration Account.
223+
224+
.Parameter ResourceGroupName
225+
The name of the Azure resource group where the Azure Integration Account is located.
226+
227+
.Parameter Name
228+
The name of the Azure Integration Account into which the agreements are to be uploaded/updated.
229+
230+
.Parameter AgreementFilePath
231+
The full path of a agreement that should be uploaded/updated.
232+
233+
.Parameter AgreementsFolder
234+
The path to a directory containing all agreements that should be uploaded/updated.
235+
236+
.Parameter ArtifactsPrefix
237+
The prefix, if any, that should be added to the agreements before uploading/updating.
238+
#>
239+
function Set-AzIntegrationAccountAgreements {
240+
param(
241+
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Resource group name is required"),
242+
[Parameter(Mandatory = $true)][string] $Name = $(throw "Name of the Integration Account is required"),
243+
[parameter(Mandatory = $false)][string] $AgreementFilePath = $(if ($AgreementsFolder -eq '') { throw "Either the file path of a specific agreement or the file path of a folder containing multiple agreements is required, e.g.: -AgreementFilePath 'C:\Agreements\agreement.json' or -AgreementsFolder 'C:\Agreements'" }),
244+
[parameter(Mandatory = $false)][string] $AgreementsFolder = $(if ($AgreementFilePath -eq '') { throw "Either the file path of a specific agreement or the file path of a folder containing multiple agreements is required, e.g.: -AgreementFilePath 'C:\Agreements\agreement.json' or -AgreementsFolder 'C:\Agreements'" }),
245+
[Parameter(Mandatory = $false)][string] $ArtifactsPrefix = ''
246+
)
247+
248+
. $PSScriptRoot\Scripts\Set-AzIntegrationAccountAgreements.ps1 -ResourceGroupName $ResourceGroupName -Name $Name -AgreementFilePath $AgreementFilePath -AgreementsFolder $AgreementsFolder -ArtifactsPrefix $ArtifactsPrefix
249+
}
250+
251+
Export-ModuleMember -Function Set-AzIntegrationAccountAgreements

src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.pssproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<ItemGroup>
3333
<Compile Include="Arcus.Scripting.IntegrationAccount.psd1" />
3434
<Compile Include="Arcus.Scripting.IntegrationAccount.psm1" />
35+
<Compile Include="Scripts\Set-AzIntegrationAccountAgreements.ps1" />
3536
<Compile Include="Scripts\Set-AzIntegrationAccountPartners.ps1" />
3637
<Compile Include="Scripts\Set-AzIntegrationAccountAssemblies.ps1" />
3738
<Compile Include="Scripts\Set-AzIntegrationAccountCertificates.ps1" />
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
Param(
2+
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Resource group name is required"),
3+
[Parameter(Mandatory = $true)][string] $Name = $(throw "Name of the Integration Account is required"),
4+
[parameter(Mandatory = $false)][string] $AgreementFilePath = $(if ($AgreementsFolder -eq '') { throw "Either the file path of a specific agreement or the file path of a folder containing multiple agreements is required, e.g.: -AgreementFilePath 'C:\Agreements\agreement.json' or -AgreementsFolder 'C:\Agreements'" }),
5+
[parameter(Mandatory = $false)][string] $AgreementsFolder = $(if ($AgreementFilePath -eq '') { throw "Either the file path of a specific agreement or the file path of a folder containing multiple agreements is required, e.g.: -AgreementFilePath 'C:\Agreements\agreement.json' or -AgreementsFolder 'C:\Agreements'" }),
6+
[Parameter(Mandatory = $false)][string] $ArtifactsPrefix = ''
7+
)
8+
9+
if ($AgreementFilePath -ne '' -and $AgreementsFolder -ne '') {
10+
throw "Either the file path of a specific agreement or the file path of a folder containing multiple agreements is required, e.g.: -AgreementFilePath 'C:\Agreements\agreement.json' or -AgreementsFolder 'C:\Agreements'"
11+
}
12+
13+
function UploadAgreement {
14+
param(
15+
[Parameter(Mandatory = $true)][System.IO.FileInfo] $Agreement
16+
)
17+
18+
$agreementData = Get-Content -Raw -Path $Agreement.FullName | ConvertFrom-Json
19+
20+
$agreementName = $agreementData.name
21+
if ($agreementName -eq $null -or $agreementName -eq '') {
22+
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the agreement name is empty"
23+
}
24+
25+
if ($ArtifactsPrefix -ne '') {
26+
$agreementName = $ArtifactsPrefix + $agreementName
27+
}
28+
Write-Host "Uploading agreement '$agreementName' into the Integration Account '$Name'"
29+
30+
$agreementType = $agreementData.properties.agreementType
31+
if ($agreementType -eq $null -or $agreementType -eq '') {
32+
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the agreement type is empty"
33+
}
34+
35+
$hostPartner = $agreementData.properties.hostPartner
36+
if ($hostPartner -eq $null -or $hostPartner -eq '') {
37+
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the host partner is empty"
38+
}
39+
40+
$hostIdentityQualifier = $agreementData.properties.hostIdentity.qualifier
41+
if ($hostIdentityQualifier -eq $null -or $hostIdentityQualifier -eq '') {
42+
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the host identity qualifier is empty"
43+
}
44+
45+
$hostIdentityQualifierValue = $agreementData.properties.hostIdentity.value
46+
if ($hostIdentityQualifierValue -eq $null -or $hostIdentityQualifierValue -eq '') {
47+
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the host identity value is empty"
48+
}
49+
50+
$guestPartner = $agreementData.properties.guestPartner
51+
if ($guestPartner -eq $null -or $guestPartner -eq '') {
52+
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the guest partner is empty"
53+
}
54+
55+
$guestIdentityQualifier = $agreementData.properties.guestIdentity.qualifier
56+
if ($guestIdentityQualifier -eq $null -or $guestIdentityQualifier -eq '') {
57+
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the guest identity qualifier is empty"
58+
}
59+
60+
$guestIdentityQualifierValue = $agreementData.properties.guestIdentity.value
61+
if ($guestIdentityQualifierValue -eq $null -or $guestIdentityQualifierValue -eq '') {
62+
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the guest identity value is empty"
63+
}
64+
65+
$agreementContent = $agreementData.properties.content | ConvertTo-Json -Depth 20 -Compress
66+
if ($agreementContent -eq $null -or $agreementContent -eq 'null' -or $agreementContent -eq '') {
67+
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the agreement content is empty"
68+
}
69+
70+
$existingAgreement = $null
71+
try {
72+
Write-Verbose "Checking if the agreement '$agreementName' already exists in the Azure Integration Account '$Name'"
73+
$existingAgreement = Get-AzIntegrationAccountAgreement -ResourceGroupName $ResourceGroupName -IntegrationAccount $Name -AgreementName $agreementName -ErrorAction Stop
74+
}
75+
catch {
76+
if ($_.Exception.Message.Contains('could not be found')) {
77+
Write-Verbose "No agreement '$agreementName' could not be found in Azure Integration Account '$Name'"
78+
}
79+
else {
80+
throw $_.Exception
81+
}
82+
}
83+
84+
try {
85+
if ($existingAgreement -eq $null) {
86+
Write-Verbose "Creating agreement '$agreementName' in Azure Integration Account '$Name'"
87+
$createdAgreement = New-AzIntegrationAccountAgreement -ResourceGroupName $ResourceGroupName -IntegrationAccount $Name -AgreementName $agreementName -AgreementType $agreementType -HostPartner $hostPartner -HostIdentityQualifier $hostIdentityQualifier -HostIdentityQualifierValue $hostIdentityQualifierValue -GuestPartner $guestPartner -GuestIdentityQualifier $guestIdentityQualifier -GuestIdentityQualifierValue $guestIdentityQualifierValue -AgreementContent $agreementContent -ErrorAction Stop
88+
Write-Verbose ($createdAgreement | Format-List -Force | Out-String)
89+
}
90+
else {
91+
Write-Verbose "Updating agreement '$agreementName' in Azure Integration Account '$Name'"
92+
$updatedAgreement = Set-AzIntegrationAccountAgreement -ResourceGroupName $ResourceGroupName -IntegrationAccount $Name -AgreementName $agreementName -AgreementType $agreementType -HostPartner $hostPartner -HostIdentityQualifier $hostIdentityQualifier -HostIdentityQualifierValue $hostIdentityQualifierValue -GuestPartner $guestPartner -GuestIdentityQualifier $guestIdentityQualifier -GuestIdentityQualifierValue $guestIdentityQualifierValue -AgreementContent $agreementContent -Force -ErrorAction Stop
93+
Write-Verbose ($updatedAgreement | Format-List -Force | Out-String)
94+
}
95+
Write-Host "Agreement '$agreementName' has been uploaded into the Azure Integration Account '$Name'"
96+
}
97+
catch {
98+
Write-Error "Failed to upload agreement '$agreementName' in Azure Integration Account '$Name': '$($_.Exception.Message)'"
99+
}
100+
}
101+
102+
$integrationAccount = Get-AzIntegrationAccount -ResourceGroupName $ResourceGroupName -Name $Name -ErrorAction SilentlyContinue
103+
if ($integrationAccount -eq $null) {
104+
Write-Error "Unable to find the Azure Integration Account with name '$Name' in resource group '$ResourceGroupName'"
105+
}
106+
else {
107+
if ($AgreementsFolder -ne '' -and $AgreementFilePath -eq '') {
108+
foreach ($agreement in Get-ChildItem($AgreementsFolder) -File) {
109+
UploadAgreement -Agreement $agreement
110+
Write-Host '----------'
111+
}
112+
}
113+
elseif ($AgreementsFolder -eq '' -and $AgreementFilePath -ne '') {
114+
[System.IO.FileInfo]$agreement = New-Object System.IO.FileInfo($AgreementFilePath)
115+
UploadAgreement -Agreement $agreement
116+
}
117+
}

src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountAssemblies.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ function UploadAssembly {
2020
if ($ArtifactsPrefix -ne '') {
2121
$assemblyName = $ArtifactsPrefix + $assemblyName
2222
}
23-
Write-Host "Uploading assembly '$assemblyName' into the Integration Account '$Name'"
23+
Write-Host "Uploading assembly '$assemblyName' into the Azure Integration Account '$Name'"
2424

2525
$existingAssembly = $null
2626
try {
27-
Write-Verbose "Checking if the assembly '$assemblyName' already exists in the Integration Account '$Name'"
27+
Write-Verbose "Checking if the assembly '$assemblyName' already exists in the Azure Integration Account '$Name'"
2828
$existingAssembly = Get-AzIntegrationAccountAssembly -ResourceGroupName $ResourceGroupName -IntegrationAccount $Name -Name $assemblyName -ErrorAction Stop
2929
}
3030
catch {
@@ -54,7 +54,6 @@ function UploadAssembly {
5454
}
5555
}
5656

57-
# Verify if Integration Account can be found based on the given information
5857
$integrationAccount = Get-AzIntegrationAccount -ResourceGroupName $ResourceGroupName -Name $Name -ErrorAction SilentlyContinue
5958
if ($integrationAccount -eq $null) {
6059
Write-Error "Unable to find the Azure Integration Account with name '$Name' in resource group '$ResourceGroupName'"

src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountCertificates.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ function UploadCertificate {
3232
if ($ArtifactsPrefix -ne '') {
3333
$certificateName = $ArtifactsPrefix + $certificateName
3434
}
35-
Write-Host "Uploading certificate '$certificateName' into the Integration Account '$Name'"
35+
Write-Host "Uploading certificate '$certificateName' into the Azure Integration Account '$Name'"
3636

3737
$existingCertificate = $null
3838
try {
39-
Write-Verbose "Checking if the certificate '$certificateName' already exists in the Integration Account '$Name'"
39+
Write-Verbose "Checking if the certificate '$certificateName' already exists in the Azure Integration Account '$Name'"
4040
$existingCertificate = Get-AzIntegrationAccountCertificate -ResourceGroupName $ResourceGroupName -IntegrationAccount $Name -CertificateName $certificateName -ErrorAction Stop
4141
}
4242
catch {
@@ -76,7 +76,6 @@ function UploadCertificate {
7676
}
7777
}
7878

79-
# Verify if Integration Account can be found based on the given information
8079
$integrationAccount = Get-AzIntegrationAccount -ResourceGroupName $ResourceGroupName -Name $Name -ErrorAction SilentlyContinue
8180
if ($integrationAccount -eq $null) {
8281
Write-Error "Unable to find the Azure Integration Account with name '$Name' in resource group '$ResourceGroupName'"

src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountMaps.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ function UploadMap {
2525
if ($ArtifactsPrefix -ne '') {
2626
$mapName = $ArtifactsPrefix + $mapName
2727
}
28-
Write-Host "Uploading map '$mapName' into the Integration Account '$Name'"
28+
Write-Host "Uploading map '$mapName' into the Azure Integration Account '$Name'"
2929

3030
$existingMap = $null
3131
try {
32-
Write-Verbose "Checking if the map '$mapName' already exists in the Integration Account '$Name'"
32+
Write-Verbose "Checking if the map '$mapName' already exists in the Azure Integration Account '$Name'"
3333
$existingMap = Get-AzIntegrationAccountMap -ResourceGroupName $ResourceGroupName -Name $Name -MapName $mapName -ErrorAction Stop
3434
}
3535
catch {
@@ -59,7 +59,6 @@ function UploadMap {
5959
}
6060
}
6161

62-
# Verify if Integration Account can be found based on the given information
6362
$integrationAccount = Get-AzIntegrationAccount -ResourceGroupName $ResourceGroupName -Name $Name -ErrorAction SilentlyContinue
6463
if ($integrationAccount -eq $null) {
6564
Write-Error "Unable to find the Azure Integration Account with name '$Name' in resource group '$ResourceGroupName'"

src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountPartners.ps1

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ function UploadPartner {
1919

2020
$partnerName = $partnerData.name
2121
if ($partnerName -eq $null -or $partnerName -eq '') {
22-
throw 'Partner name is empty'
22+
throw "Cannot upload Partner to Azure Integration Account '$Name' because the partner name is empty"
2323
}
2424

2525
if ($ArtifactsPrefix -ne '') {
2626
$partnerName = $ArtifactsPrefix + $partnerName
2727
}
28-
Write-Host "Uploading partner '$partnerName' into the Integration Account '$Name'"
28+
Write-Host "Uploading partner '$partnerName' into the Azure Integration Account '$Name'"
2929

3030
$businessIdentities = $null
3131
foreach ($businessIdentity in $partnerData.properties.content.b2b.businessIdentities) {
@@ -36,12 +36,12 @@ function UploadPartner {
3636
}
3737

3838
if ($businessIdentities.Count -eq 0) {
39-
throw "At least one business identity must be supplied"
39+
throw "Cannot upload Partner to Azure Integration Account '$Name' because at least one business identity must be supplied"
4040
}
4141

4242
$existingPartner = $null
4343
try {
44-
Write-Verbose "Checking if the partner '$partnerName' already exists in the Integration Account '$Name'"
44+
Write-Verbose "Checking if the partner '$partnerName' already exists in the Azure Integration Account '$Name'"
4545
$existingPartner = Get-AzIntegrationAccountPartner -ResourceGroupName $ResourceGroupName -IntegrationAccount $Name -PartnerName $partnerName -ErrorAction Stop
4646
}
4747
catch {
@@ -71,7 +71,6 @@ function UploadPartner {
7171
}
7272
}
7373

74-
# Verify if Integration Account can be found based on the given information
7574
$integrationAccount = Get-AzIntegrationAccount -ResourceGroupName $ResourceGroupName -Name $Name -ErrorAction SilentlyContinue
7675
if ($integrationAccount -eq $null) {
7776
Write-Error "Unable to find the Azure Integration Account with name '$Name' in resource group '$ResourceGroupName'"

src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ function UploadSchema {
2424
if ($ArtifactsPrefix -ne '') {
2525
$schemaName = $ArtifactsPrefix + $schemaName
2626
}
27-
Write-Host "Uploading schema '$schemaName' into the Integration Account '$Name'"
27+
Write-Host "Uploading schema '$schemaName' into the Azure Integration Account '$Name'"
2828

2929
## Check if the schema already exists
3030
$existingSchema = $null
3131
try {
32-
Write-Verbose "Checking if the schema '$schemaName' already exists in the Integration Account '$Name'"
32+
Write-Verbose "Checking if the schema '$schemaName' already exists in the Azure Integration Account '$Name'"
3333
$existingSchema = Get-AzIntegrationAccountSchema -ResourceGroupName $ResourceGroupName -Name $Name -SchemaName $schemaName -ErrorAction Stop
3434
}
3535
catch {
@@ -61,7 +61,6 @@ function UploadSchema {
6161
}
6262
}
6363

64-
# Verify if Integration Account can be found based on the given information
6564
$integrationAccount = Get-AzIntegrationAccount -ResourceGroupName $ResourceGroupName -Name $Name -ErrorAction SilentlyContinue
6665
if ($integrationAccount -eq $null) {
6766
Write-Error "Unable to find the Azure Integration Account with name '$Name' in resource group '$ResourceGroupName'"

0 commit comments

Comments
 (0)