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

feat: Provide script to upload assemblies into an Integration Account #257

Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
adf39eb
add Set-AzIntegrationAccountMaps.ps1 to project
pim-simons Dec 27, 2021
ddf02ef
add to project
pim-simons Dec 27, 2021
7832a2f
added Set-AzIntegrationAccountAssemblies and its unit tests
pim-simons Dec 27, 2021
a64460b
added integration tests
pim-simons Dec 29, 2021
901808e
added documentation
pim-simons Dec 29, 2021
f156766
Update src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Integrat…
pim-simons Dec 29, 2021
e670b73
Update src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Integrat…
pim-simons Dec 29, 2021
7420c78
Update src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Integrat…
pim-simons Dec 29, 2021
9ce6c7a
Update src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Integrat…
pim-simons Dec 29, 2021
5c1d883
Update src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Integrat…
pim-simons Dec 29, 2021
462243b
Update src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Integrat…
pim-simons Dec 29, 2021
2f0493d
Update src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.IntegrationAcco…
pim-simons Dec 29, 2021
30d8d95
Update src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.IntegrationAcco…
pim-simons Dec 29, 2021
0216dd7
Update src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.IntegrationAcco…
pim-simons Dec 29, 2021
adb421d
Update src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.IntegrationAcco…
pim-simons Dec 29, 2021
942f4df
Update src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.IntegrationAcco…
pim-simons Dec 29, 2021
1698aeb
keep naming of tests consistent
pim-simons Dec 29, 2021
f4395d3
descriptive names for context
pim-simons Dec 29, 2021
1694280
removed -ErrorAction Stop from Act
pim-simons Dec 29, 2021
7863ca1
don't use points at the end of logging statements
pim-simons Dec 29, 2021
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
Prev Previous commit
Next Next commit
added Set-AzIntegrationAccountAssemblies and its unit tests
pim-simons committed Dec 27, 2021
commit 7832a2f0a1a5d9cfe982bf093d161e517e58f148
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -88,4 +88,40 @@ function Set-AzIntegrationAccountMaps {
}
}

Export-ModuleMember -Function Set-AzIntegrationAccountMaps
Export-ModuleMember -Function Set-AzIntegrationAccountMaps

<#
.Synopsis
Upload/update a single, or multiple assemblies into an Azure Integration Account.

.Description
Provide a file- or folder-path to upload/update a single or multiple assemblies 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 assemblies are to be uploaded/updated.

.Parameter AssemblyFilePath
The full path of a assembly that should be uploaded/updated.

.Parameter AssembliesFolder
The path to a directory containing all assemblies that should be uploaded/updated.

.Parameter ArtifactsPrefix
The prefix, if any, that should be added to the assemblies before uploading/updating.
#>
function Set-AzIntegrationAccountAssemblies {
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] $AssemblyFilePath = $(if ($AssembliesFolder -eq '') { throw "Either the file path of a specific assembly or the file path of a folder containing multiple assemblies is required, e.g.: -AssemblyFilePath 'C:\Assemblies\assembly.dll' or -AssembliesFolder 'C:\Assemblies'" }),
[parameter(Mandatory = $false)][string] $AssembliesFolder = $(if ($AssemblyFilePath -eq '') { throw "Either the file path of a specific assembly or the file path of a folder containing multiple assemblies is required, e.g.: -AssemblyFilePath 'C:\Assemblies\assembly.dll' or -AssembliesFolder 'C:\Assemblies'" }),
[Parameter(Mandatory = $false)][string] $ArtifactsPrefix = ''
)

. $PSScriptRoot\Scripts\Set-AzIntegrationAccountAssemblies.ps1 -ResourceGroupName $ResourceGroupName -Name $Name -AssemblyFilePath $AssemblyFilePath -AssembliesFolder $AssembliesFolder -ArtifactsPrefix $ArtifactsPrefix
}

Export-ModuleMember -Function Set-AzIntegrationAccountAssemblies
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@
<ItemGroup>
<Compile Include="Arcus.Scripting.IntegrationAccount.psd1" />
<Compile Include="Arcus.Scripting.IntegrationAccount.psm1" />
<Compile Include="Scripts\Set-AzIntegrationAccountAssemblies.ps1" />
<Compile Include="Scripts\Set-AzIntegrationAccountMaps.ps1" />
<Compile Include="Scripts\Set-AzIntegrationAccountSchemas.ps1" />
</ItemGroup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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] $AssemblyFilePath = $(if ($AssembliesFolder -eq '') { throw "Either the file path of a specific assembly or the file path of a folder containing multiple assemblies is required, e.g.: -AssemblyFilePath 'C:\Assemblies\assembly.dll' or -AssembliesFolder 'C:\Assemblies'" }),
[parameter(Mandatory = $false)][string] $AssembliesFolder = $(if ($AssemblyFilePath -eq '') { throw "Either the file path of a specific assembly or the file path of a folder containing multiple assemblies is required, e.g.: -AssemblyFilePath 'C:\Assemblies\assembly.dll' or -AssembliesFolder 'C:\Assemblies'" }),
[Parameter(Mandatory = $false)][string] $ArtifactsPrefix = ''
)

if ($AssemblyFilePath -ne '' -and $AssembliesFolder -ne '') {
throw "Either the file path of a specific assembly or the file path of a folder containing multiple assemblies is required, e.g.: -AssemblyFilePath 'C:\Assemblies\assembly.dll' or -AssembliesFolder 'C:\Assemblies'"
}

function UploadAssembly {
param
(
[System.IO.FileInfo][parameter(Mandatory = $true)]$Assembly
)

$assemblyName = $Assembly.BaseName
if ($ArtifactsPrefix -ne '') {
$assemblyName = $ArtifactsPrefix + $assemblyName
}
Write-Host "Uploading assembly '$assemblyName' into the Integration Account '$Name'."
stijnmoreels marked this conversation as resolved.
Show resolved Hide resolved

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

try {
if ($existingAssembly -eq $null) {
Write-Verbose "Creating assembly '$assemblyName' in Azure Integration Account '$Name'"
$createdAssembly = New-AzIntegrationAccountAssembly -ResourceGroupName $ResourceGroupName -IntegrationAccount $Name -Name $assemblyName -AssemblyFilePath $Assembly.FullName -ErrorAction Stop
Write-Verbose ($createdAssembly | Format-List -Force | Out-String)
}
else {
Write-Verbose "Updating assembly '$assemblyName' in Azure Integration Account '$Name'"
$updatedAssembly = Set-AzIntegrationAccountAssembly -ResourceGroupName $ResourceGroupName -IntegrationAccount $Name -Name $assemblyName -AssemblyFilePath $Assembly.FullName -ErrorAction Stop
Write-Verbose ($updatedAssembly | Format-List -Force | Out-String)
}
Write-Host "Assembly '$assemblyName' has been uploaded into the Azure Integration Account '$Name'."
}
catch {
Write-Error "Failed to upload assembly '$assemblyName' in Azure Integration Account '$Name': '$($_.Exception.Message)_'"
stijnmoreels marked this conversation as resolved.
Show resolved Hide resolved
}
}

# 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'"
stijnmoreels marked this conversation as resolved.
Show resolved Hide resolved
}
else {
if ($AssembliesFolder -ne '' -and $AssemblyFilePath -eq '') {
foreach ($assembly in Get-ChildItem($AssembliesFolder) -File) {
UploadAssembly -Assembly $assembly
Write-Host '----------'
}
}
elseif ($AssembliesFolder -eq '' -and $AssemblyFilePath -ne '') {
[System.IO.FileInfo]$assembly = New-Object System.IO.FileInfo($AssemblyFilePath)
UploadAssembly -Assembly $assembly
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Describe "Arcus" {
Import-Module -Name $PSScriptRoot\..\Arcus.Scripting.IntegrationAccount -ErrorAction Stop

Describe "Arcus" {
InModuleScope Arcus.Scripting.IntegrationAccount {
pim-simons marked this conversation as resolved.
Show resolved Hide resolved
Context "Azure Integration Account Schemas" {
It "Providing both schemaFilePath and schemasFolder should fail" {
@@ -384,5 +386,197 @@
Assert-MockCalled New-AzIntegrationAccountMap -Times 0
}
}
Context "Azure Integration Account Assemblies" {
It "Providing both assemblyFilePath and assembliesFolder should fail" {
# Arrange
$resourceGroupName = "rg-infrastructure"
$integrationAccountName = "unexisting-integration-account"
$assemblyFilePath = "$PSScriptRoot\Files\IntegrationAccount\Assemblies\LibraryThatDoesSomething.dll"
$assembliesFolder = "$PSScriptRoot\Files\IntegrationAccount\Assemblies\"

# Act
{
Set-AzIntegrationAccountAssemblies -ResourceGroupName $resourceGroupName -Name $integrationAccountName -AssemblyFilePath $assemblyFilePath -AssembliesFolder $assembliesFolder -ErrorAction Stop
stijnmoreels marked this conversation as resolved.
Show resolved Hide resolved
} | Should -Throw -ExpectedMessage "Either the file path of a specific assembly or the file path of a folder containing multiple assemblies is required, e.g.: -AssemblyFilePath 'C:\Assemblies\assembly.dll' or -AssembliesFolder 'C:\Assemblies'"

# Assert
Assert-VerifiableMock
}
It "Providing neither a assemblyFilePath and assembliesFolder should fail" {
# Arrange
$resourceGroupName = "rg-infrastructure"
$integrationAccountName = "unexisting-integration-account"

# Act
{
Set-AzIntegrationAccountAssemblies -ResourceGroupName $resourceGroupName -Name $integrationAccountName -ErrorAction Stop
} | Should -Throw -ExpectedMessage "Either the file path of a specific assembly or the file path of a folder containing multiple assemblies is required, e.g.: -AssemblyFilePath 'C:\Assemblies\assembly.dll' or -AssembliesFolder 'C:\Assemblies'"

# Assert
Assert-VerifiableMock
}
It "Providing only the assemblyFilePath to create an assembly is OK" {
# Arrange
$subscriptionId = [guid]::NewGuid()
$resourceGroupName = "rg-infrastructure"
$integrationAccountName = "unexisting-integration-account"
$integrationAccountResourceId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Logic/integrationAccounts/$integrationAccountName"
$assemblyName = 'Dummy_New_Assembly'
pim-simons marked this conversation as resolved.
Show resolved Hide resolved
$assemblyResourceId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Logic/integrationAccounts/$integrationAccountName/assemblies/$assemblyName"
$assemblyFilePath = "$PSScriptRoot\Files\IntegrationAccount\Assemblies\$assemblyName.dll"
pim-simons marked this conversation as resolved.
Show resolved Hide resolved

Mock Get-AzIntegrationAccount {
return [pscustomobject]@{ Id = $integrationAccountResourceId; Name = $integrationAccountName; Type = 'Microsoft.Logic/integrationAccounts'; Location = 'westeurope'; Sku = 'Free' }
} -Verifiable

Mock Get-AzIntegrationAccountAssembly {
return $null
} -Verifiable

Mock Set-AzIntegrationAccountAssembly {
return $null
}

Mock New-AzIntegrationAccountAssembly {
return [pscustomobject]@{ Id = $assemblyResourceId; Name = $assemblyName; Type = 'Microsoft.Logic/integrationAccounts/assemblies'; CreatedTime = [datetime]::UtcNow; ChangedTime = [datetime]::UtcNow }
}

# Act
{
Set-AzIntegrationAccountAssemblies -ResourceGroupName $resourceGroupName -Name $integrationAccountName -AssemblyFilePath $assemblyFilePath -ErrorAction Stop
} | Should -Not -Throw

# Assert
Assert-VerifiableMock
Assert-MockCalled Get-AzIntegrationAccount -Times 1
Assert-MockCalled Get-AzIntegrationAccountAssembly -Times 1
Assert-MockCalled Set-AzIntegrationAccountAssembly -Times 0
Assert-MockCalled New-AzIntegrationAccountAssembly -Times 1
}
It "Providing only the assemblyFilePath to update an assembly is OK" {
# Arrange
$subscriptionId = [guid]::NewGuid()
$resourceGroupName = "rg-infrastructure"
$integrationAccountName = "unexisting-integration-account"
$integrationAccountResourceId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Logic/integrationAccounts/$integrationAccountName"
$assemblyName = 'Dummy_Existing_Assembly'
$assemblyResourceId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Logic/integrationAccounts/$integrationAccountName/assemblies/$assemblyName"
$assemblyFilePath = "$PSScriptRoot\Files\IntegrationAccount\Assemblies\$assemblyName.xslt"

Mock Get-AzIntegrationAccount {
return [pscustomobject]@{ Id = $integrationAccountResourceId; Name = $integrationAccountName; Type = 'Microsoft.Logic/integrationAccounts'; Location = 'westeurope'; Sku = 'Free' }
} -Verifiable

Mock Get-AzIntegrationAccountAssembly {
return [pscustomobject]@{ Id = $assemblyResourceId; Name = $assemblyName; Type = 'Microsoft.Logic/integrationAccounts/assemblies'; CreatedTime = [datetime]::UtcNow; ChangedTime = [datetime]::UtcNow }
} -Verifiable

Mock Set-AzIntegrationAccountAssembly {
return [pscustomobject]@{ Id = $assemblyResourceId; Name = $assemblyName; Type = 'Microsoft.Logic/integrationAccounts/assemblies'; CreatedTime = [datetime]::UtcNow; ChangedTime = [datetime]::UtcNow }
}

Mock New-AzIntegrationAccountAssembly {
return $null
}

# Act
{
Set-AzIntegrationAccountAssemblies -ResourceGroupName $resourceGroupName -Name $integrationAccountName -AssemblyFilePath $assemblyFilePath -ErrorAction Stop
} | Should -Not -Throw

# Assert
Assert-VerifiableMock
Assert-MockCalled Get-AzIntegrationAccount -Times 1
Assert-MockCalled Get-AzIntegrationAccountAssembly -Times 1
Assert-MockCalled Set-AzIntegrationAccountAssembly -Times 1
Assert-MockCalled New-AzIntegrationAccountAssembly -Times 0
}
It "Providing only a assembliesFolder to create assemblies is OK" {
# Arrange
$subscriptionId = [guid]::NewGuid()
$resourceGroupName = "rg-infrastructure"
$integrationAccountName = "unexisting-integration-account"
$integrationAccountResourceId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Logic/integrationAccounts/$integrationAccountName"
$assembliesFolder = "$PSScriptRoot\Files\IntegrationAccount\Assemblies\"

Mock Get-ChildItem {
return @(
new-item -name "assembly1.dll" -type file -fo
new-item -name "assembly2.dll" -type file -fo
pim-simons marked this conversation as resolved.
Show resolved Hide resolved
)
}

Mock Get-AzIntegrationAccount {
return [pscustomobject]@{ Id = $integrationAccountResourceId; Name = $integrationAccountName; Type = 'Microsoft.Logic/integrationAccounts'; Location = 'westeurope'; Sku = 'Free' }
} -Verifiable

Mock Get-AzIntegrationAccountAssembly {
return $null
} -Verifiable

Mock Set-AzIntegrationAccountAssembly {
return $null
}

Mock New-AzIntegrationAccountAssembly {
return [pscustomobject]@{ Id = 'fake-resource-id'; Name = 'Dummy.dll'; Type = 'Microsoft.Logic/integrationAccounts/assemblies'; CreatedTime = [datetime]::UtcNow; ChangedTime = [datetime]::UtcNow }
}

# Act
{
Set-AzIntegrationAccountAssemblies -ResourceGroupName $resourceGroupName -Name $integrationAccountName -AssembliesFolder $assembliesFolder -ErrorAction Stop
} | Should -Not -Throw

# Assert
Assert-VerifiableMock
Assert-MockCalled Get-AzIntegrationAccount -Times 1
Assert-MockCalled Get-AzIntegrationAccountAssembly -Times 2
Assert-MockCalled Set-AzIntegrationAccountAssembly -Times 0
Assert-MockCalled New-AzIntegrationAccountAssembly -Times 2
}
It "Providing only a assembliesFolder to update assemblies is OK" {
# Arrange
$subscriptionId = [guid]::NewGuid()
$resourceGroupName = "rg-infrastructure"
$integrationAccountName = "unexisting-integration-account"
$integrationAccountResourceId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Logic/integrationAccounts/$integrationAccountName"
$assembliesFolder = "$PSScriptRoot\Files\IntegrationAccount\Assemblies\"

Mock Get-ChildItem {
return @(
new-item -name "assembly1.dll" -type file -fo
new-item -name "assembly2.dll" -type file -fo
pim-simons marked this conversation as resolved.
Show resolved Hide resolved
)
}

Mock Get-AzIntegrationAccount {
return [pscustomobject]@{ Id = $integrationAccountResourceId; Name = $integrationAccountName; Type = 'Microsoft.Logic/integrationAccounts'; Location = 'westeurope'; Sku = 'Free' }
} -Verifiable

Mock Get-AzIntegrationAccountAssembly {
return [pscustomobject]@{ Id = 'fake-resource-id'; Name = 'Dummy.dll'; Type = 'Microsoft.Logic/integrationAccounts/assemblies'; CreatedTime = [datetime]::UtcNow; ChangedTime = [datetime]::UtcNow }
} -Verifiable

Mock Set-AzIntegrationAccountAssembly {
return [pscustomobject]@{ Id = 'fake-resource-id'; Name = 'Dummy.dll'; Type = 'Microsoft.Logic/integrationAccounts/assemblies'; CreatedTime = [datetime]::UtcNow; ChangedTime = [datetime]::UtcNow }
}

Mock New-AzIntegrationAccountAssembly {
return $null
}

# Act
{
Set-AzIntegrationAccountAssemblies -ResourceGroupName $resourceGroupName -Name $integrationAccountName -AssembliesFolder $assembliesFolder -ErrorAction Stop
} | Should -Not -Throw

# Assert
Assert-VerifiableMock
Assert-MockCalled Get-AzIntegrationAccount -Times 1
Assert-MockCalled Get-AzIntegrationAccountAssembly -Times 2
Assert-MockCalled Set-AzIntegrationAccountAssembly -Times 2
Assert-MockCalled New-AzIntegrationAccountAssembly -Times 0
}
}
}
}