Skip to content

Commit

Permalink
feat: Provide script to upload agreements into an Integration Account (
Browse files Browse the repository at this point in the history
…#265)

Co-authored-by: Pim Simons <[email protected]>
  • Loading branch information
pim-simons and pim-simons authored Jan 14, 2022
1 parent e89dc20 commit afb37ed
Show file tree
Hide file tree
Showing 14 changed files with 1,370 additions and 20 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,40 @@ function Set-AzIntegrationAccountPartners {
. $PSScriptRoot\Scripts\Set-AzIntegrationAccountPartners.ps1 -ResourceGroupName $ResourceGroupName -Name $Name -PartnerFilePath $PartnerFilePath -PartnersFolder $PartnersFolder -ArtifactsPrefix $ArtifactsPrefix
}

Export-ModuleMember -Function Set-AzIntegrationAccountPartners
Export-ModuleMember -Function Set-AzIntegrationAccountPartners

<#
.Synopsis
Upload/update a single, or multiple agreements into an Azure Integration Account.
.Description
Provide a file- or folder-path to upload/update a single or multiple agreements into an Integration Account.
.Parameter ResourceGroupName
The name of the Azure resource group where the Azure Integration Account is located.
.Parameter Name
The name of the Azure Integration Account into which the agreements are to be uploaded/updated.
.Parameter AgreementFilePath
The full path of a agreement that should be uploaded/updated.
.Parameter AgreementsFolder
The path to a directory containing all agreements that should be uploaded/updated.
.Parameter ArtifactsPrefix
The prefix, if any, that should be added to the agreements before uploading/updating.
#>
function Set-AzIntegrationAccountAgreements {
param(
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Resource group name is required"),
[Parameter(Mandatory = $true)][string] $Name = $(throw "Name of the Integration Account is required"),
[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'" }),
[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'" }),
[Parameter(Mandatory = $false)][string] $ArtifactsPrefix = ''
)

. $PSScriptRoot\Scripts\Set-AzIntegrationAccountAgreements.ps1 -ResourceGroupName $ResourceGroupName -Name $Name -AgreementFilePath $AgreementFilePath -AgreementsFolder $AgreementsFolder -ArtifactsPrefix $ArtifactsPrefix
}

Export-ModuleMember -Function Set-AzIntegrationAccountAgreements
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<ItemGroup>
<Compile Include="Arcus.Scripting.IntegrationAccount.psd1" />
<Compile Include="Arcus.Scripting.IntegrationAccount.psm1" />
<Compile Include="Scripts\Set-AzIntegrationAccountAgreements.ps1" />
<Compile Include="Scripts\Set-AzIntegrationAccountPartners.ps1" />
<Compile Include="Scripts\Set-AzIntegrationAccountAssemblies.ps1" />
<Compile Include="Scripts\Set-AzIntegrationAccountCertificates.ps1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
Param(
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Resource group name is required"),
[Parameter(Mandatory = $true)][string] $Name = $(throw "Name of the Integration Account is required"),
[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'" }),
[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'" }),
[Parameter(Mandatory = $false)][string] $ArtifactsPrefix = ''
)

if ($AgreementFilePath -ne '' -and $AgreementsFolder -ne '') {
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'"
}

function UploadAgreement {
param(
[Parameter(Mandatory = $true)][System.IO.FileInfo] $Agreement
)

$agreementData = Get-Content -Raw -Path $Agreement.FullName | ConvertFrom-Json

$agreementName = $agreementData.name
if ($agreementName -eq $null -or $agreementName -eq '') {
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the agreement name is empty"
}

if ($ArtifactsPrefix -ne '') {
$agreementName = $ArtifactsPrefix + $agreementName
}
Write-Host "Uploading agreement '$agreementName' into the Integration Account '$Name'"

$agreementType = $agreementData.properties.agreementType
if ($agreementType -eq $null -or $agreementType -eq '') {
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the agreement type is empty"
}

$hostPartner = $agreementData.properties.hostPartner
if ($hostPartner -eq $null -or $hostPartner -eq '') {
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the host partner is empty"
}

$hostIdentityQualifier = $agreementData.properties.hostIdentity.qualifier
if ($hostIdentityQualifier -eq $null -or $hostIdentityQualifier -eq '') {
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the host identity qualifier is empty"
}

$hostIdentityQualifierValue = $agreementData.properties.hostIdentity.value
if ($hostIdentityQualifierValue -eq $null -or $hostIdentityQualifierValue -eq '') {
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the host identity value is empty"
}

$guestPartner = $agreementData.properties.guestPartner
if ($guestPartner -eq $null -or $guestPartner -eq '') {
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the guest partner is empty"
}

$guestIdentityQualifier = $agreementData.properties.guestIdentity.qualifier
if ($guestIdentityQualifier -eq $null -or $guestIdentityQualifier -eq '') {
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the guest identity qualifier is empty"
}

$guestIdentityQualifierValue = $agreementData.properties.guestIdentity.value
if ($guestIdentityQualifierValue -eq $null -or $guestIdentityQualifierValue -eq '') {
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the guest identity value is empty"
}

$agreementContent = $agreementData.properties.content | ConvertTo-Json -Depth 20 -Compress
if ($agreementContent -eq $null -or $agreementContent -eq 'null' -or $agreementContent -eq '') {
throw "Cannot upload Agreement to Azure Integration Account '$Name' because the agreement content is empty"
}

$existingAgreement = $null
try {
Write-Verbose "Checking if the agreement '$agreementName' already exists in the Azure Integration Account '$Name'"
$existingAgreement = Get-AzIntegrationAccountAgreement -ResourceGroupName $ResourceGroupName -IntegrationAccount $Name -AgreementName $agreementName -ErrorAction Stop
}
catch {
if ($_.Exception.Message.Contains('could not be found')) {
Write-Verbose "No agreement '$agreementName' could not be found in Azure Integration Account '$Name'"
}
else {
throw $_.Exception
}
}

try {
if ($existingAgreement -eq $null) {
Write-Verbose "Creating agreement '$agreementName' in Azure Integration Account '$Name'"
$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
Write-Verbose ($createdAgreement | Format-List -Force | Out-String)
}
else {
Write-Verbose "Updating agreement '$agreementName' in Azure Integration Account '$Name'"
$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
Write-Verbose ($updatedAgreement | Format-List -Force | Out-String)
}
Write-Host "Agreement '$agreementName' has been uploaded into the Azure Integration Account '$Name'"
}
catch {
Write-Error "Failed to upload agreement '$agreementName' in Azure Integration Account '$Name': '$($_.Exception.Message)'"
}
}

$integrationAccount = Get-AzIntegrationAccount -ResourceGroupName $ResourceGroupName -Name $Name -ErrorAction SilentlyContinue
if ($integrationAccount -eq $null) {
Write-Error "Unable to find the Azure Integration Account with name '$Name' in resource group '$ResourceGroupName'"
}
else {
if ($AgreementsFolder -ne '' -and $AgreementFilePath -eq '') {
foreach ($agreement in Get-ChildItem($AgreementsFolder) -File) {
UploadAgreement -Agreement $agreement
Write-Host '----------'
}
}
elseif ($AgreementsFolder -eq '' -and $AgreementFilePath -ne '') {
[System.IO.FileInfo]$agreement = New-Object System.IO.FileInfo($AgreementFilePath)
UploadAgreement -Agreement $agreement
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ function UploadAssembly {
if ($ArtifactsPrefix -ne '') {
$assemblyName = $ArtifactsPrefix + $assemblyName
}
Write-Host "Uploading assembly '$assemblyName' into the Integration Account '$Name'"
Write-Host "Uploading assembly '$assemblyName' into the Azure Integration Account '$Name'"

$existingAssembly = $null
try {
Write-Verbose "Checking if the assembly '$assemblyName' already exists in the Integration Account '$Name'"
Write-Verbose "Checking if the assembly '$assemblyName' already exists in the Azure Integration Account '$Name'"
$existingAssembly = Get-AzIntegrationAccountAssembly -ResourceGroupName $ResourceGroupName -IntegrationAccount $Name -Name $assemblyName -ErrorAction Stop
}
catch {
Expand Down Expand Up @@ -54,7 +54,6 @@ function UploadAssembly {
}
}

# Verify if Integration Account can be found based on the given information
$integrationAccount = Get-AzIntegrationAccount -ResourceGroupName $ResourceGroupName -Name $Name -ErrorAction SilentlyContinue
if ($integrationAccount -eq $null) {
Write-Error "Unable to find the Azure Integration Account with name '$Name' in resource group '$ResourceGroupName'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ function UploadCertificate {
if ($ArtifactsPrefix -ne '') {
$certificateName = $ArtifactsPrefix + $certificateName
}
Write-Host "Uploading certificate '$certificateName' into the Integration Account '$Name'"
Write-Host "Uploading certificate '$certificateName' into the Azure Integration Account '$Name'"

$existingCertificate = $null
try {
Write-Verbose "Checking if the certificate '$certificateName' already exists in the Integration Account '$Name'"
Write-Verbose "Checking if the certificate '$certificateName' already exists in the Azure Integration Account '$Name'"
$existingCertificate = Get-AzIntegrationAccountCertificate -ResourceGroupName $ResourceGroupName -IntegrationAccount $Name -CertificateName $certificateName -ErrorAction Stop
}
catch {
Expand Down Expand Up @@ -76,7 +76,6 @@ function UploadCertificate {
}
}

# Verify if Integration Account can be found based on the given information
$integrationAccount = Get-AzIntegrationAccount -ResourceGroupName $ResourceGroupName -Name $Name -ErrorAction SilentlyContinue
if ($integrationAccount -eq $null) {
Write-Error "Unable to find the Azure Integration Account with name '$Name' in resource group '$ResourceGroupName'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ function UploadMap {
if ($ArtifactsPrefix -ne '') {
$mapName = $ArtifactsPrefix + $mapName
}
Write-Host "Uploading map '$mapName' into the Integration Account '$Name'"
Write-Host "Uploading map '$mapName' into the Azure Integration Account '$Name'"

$existingMap = $null
try {
Write-Verbose "Checking if the map '$mapName' already exists in the Integration Account '$Name'"
Write-Verbose "Checking if the map '$mapName' already exists in the Azure Integration Account '$Name'"
$existingMap = Get-AzIntegrationAccountMap -ResourceGroupName $ResourceGroupName -Name $Name -MapName $mapName -ErrorAction Stop
}
catch {
Expand Down Expand Up @@ -59,7 +59,6 @@ function UploadMap {
}
}

# Verify if Integration Account can be found based on the given information
$integrationAccount = Get-AzIntegrationAccount -ResourceGroupName $ResourceGroupName -Name $Name -ErrorAction SilentlyContinue
if ($integrationAccount -eq $null) {
Write-Error "Unable to find the Azure Integration Account with name '$Name' in resource group '$ResourceGroupName'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ function UploadPartner {

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

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

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

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

$existingPartner = $null
try {
Write-Verbose "Checking if the partner '$partnerName' already exists in the Integration Account '$Name'"
Write-Verbose "Checking if the partner '$partnerName' already exists in the Azure Integration Account '$Name'"
$existingPartner = Get-AzIntegrationAccountPartner -ResourceGroupName $ResourceGroupName -IntegrationAccount $Name -PartnerName $partnerName -ErrorAction Stop
}
catch {
Expand Down Expand Up @@ -71,7 +71,6 @@ function UploadPartner {
}
}

# Verify if Integration Account can be found based on the given information
$integrationAccount = Get-AzIntegrationAccount -ResourceGroupName $ResourceGroupName -Name $Name -ErrorAction SilentlyContinue
if ($integrationAccount -eq $null) {
Write-Error "Unable to find the Azure Integration Account with name '$Name' in resource group '$ResourceGroupName'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ function UploadSchema {
if ($ArtifactsPrefix -ne '') {
$schemaName = $ArtifactsPrefix + $schemaName
}
Write-Host "Uploading schema '$schemaName' into the Integration Account '$Name'"
Write-Host "Uploading schema '$schemaName' into the Azure Integration Account '$Name'"

## Check if the schema already exists
$existingSchema = $null
try {
Write-Verbose "Checking if the schema '$schemaName' already exists in the Integration Account '$Name'"
Write-Verbose "Checking if the schema '$schemaName' already exists in the Azure Integration Account '$Name'"
$existingSchema = Get-AzIntegrationAccountSchema -ResourceGroupName $ResourceGroupName -Name $Name -SchemaName $schemaName -ErrorAction Stop
}
catch {
Expand Down Expand Up @@ -61,7 +61,6 @@ function UploadSchema {
}
}

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

0 comments on commit afb37ed

Please sign in to comment.