generated from arcus-azure/arcus.github.template
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Provide script to upload agreements into an Integration Account (…
…#265) Co-authored-by: Pim Simons <[email protected]>
- Loading branch information
1 parent
e89dc20
commit afb37ed
Showing
14 changed files
with
1,370 additions
and
20 deletions.
There are no files selected for viewing
Binary file modified
BIN
+86 Bytes
(100%)
src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psd1
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountAgreements.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.