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

chore: Integration Account - Provide script to upload schemas. #178

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
89 changes: 89 additions & 0 deletions docs/preview/features/powershell/azure-integration-account.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: "Scripts related to interacting with an Azure Integration Account"
layout: default
---

# Azure Integration Account

This module provides the following capabilities:
- [Uploading schemas into an Azure Integration Account](#uploading-schemas-into-an-azure-integration-account)

## Installation

To have access to the following features, you have to import the module:

```powershell
PS> Install-Module -Name Arcus.Scripting.IntegrationAccount
```

## Uploading schemas into an Azure Integration Account

Upload/update a single, or multiple schemas into an Azure Integration Account.

| Parameter | Mandatory | Description |
| ---------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `ResourceGroupName` | yes | The name of the Azure resource group where the Azure Integration Account is located. |
| `Name` | yes | The name of the Azure Integration Account into which the schemas are to be uploaded/updated. |
| `SchemaFilePath` | no | The full path of a schema that should be uploaded/updated. (Mandatory if SchemasFolder has not been specified). |
| `SchemasFolder` | no | The path to a directory containing all schemas that should be uploaded/updated. (Mandatory if SchemaFilePath has not been specified). |
| `ArtifactsPrefix` | no | The prefix, if any, that should be added to the schemas before uploading/updating. |
| `RemoveFileExtensions` | no | Indicator (switch) whether the extension should be removed from the name before uploading/updating. |

**Example**

Uploading a *single schema* into an Integration Account.
```powershell
PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemaFilePath "C:\Schemas\MySchema.xsd"
# Uploading schema 'MySchema.xsd' into the Integration Account 'my-integration-account'
# Schema 'MySchema.xsd' has been uploaded into the Integration Account.
```

Uploading a *single schema* into an Integration Account and remove the file-extension.
```powershell
PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemaFilePath "C:\Schemas\MySchema.xsd" -RemoveFileExtensions
# Uploading schema 'MySchema' into the Integration Account 'my-integration-account'
# Schema 'MySchema' has been uploaded into the Integration Account.
```
Uploading a *single schema* into an Integration Account and set add a prefix to the name of the schema within the Integration Account.
```powershell
PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemaFilePath "C:\Schemas\MySchema.xsd" -ArtifactsPrefix 'dev-'
# Uploading schema 'dev-MySchema.xsd' into the Integration Account 'my-integration-account'
# Schema 'dev-MySchema.xsd' has been uploaded into the Integration Account.
```

Uploading *all schemas* located in a specific folder into an Integration Account.
```powershell
PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemasFolder "C:\Schemas"
# Uploading schema 'MyFirstSchema.xsd' into the Integration Account 'my-integration-account'
# Schema 'MyFirstSchema.xsd' has been uploaded into the Integration Account.
# ----------
# Uploading schema 'MySecondSchema.xsd' into the Integration Account 'my-integration-account'
# Schema 'MySecondSchema.xsd' has been uploaded into the Integration Account.
# ----------
```

Uploading *all schemas* located in a specific folder into an Integration Account and remove the file-extension.
```powershell
PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemasFolder "C:\Schemas" -RemoveFileExtensions
# Uploading schema 'MyFirstSchema' into the Integration Account 'my-integration-account'
# Schema 'MyFirstSchema' has been uploaded into the Integration Account.
# ----------
# Uploading schema 'MySecondSchema' into the Integration Account 'my-integration-account'
# Schema 'MySecondSchema' has been uploaded into the Integration Account.
# ----------
```

Uploading *all schemas* located in a specific folder into an Integration Account and remove the file-extension.
```powershell
PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemasFolder "C:\Schemas" -ArtifactsPrefix 'dev-'
# Uploading schema 'dev-MyFirstSchema.xsd' into the Integration Account 'my-integration-account'
# Schema 'dev-MyFirstSchema.xsd' has been uploaded into the Integration Account.
# ----------
# Uploading schema 'dev-MySecondSchema.xsd' into the Integration Account 'my-integration-account'
# Schema 'dev-MySecondSchema.xsd' has been uploaded into the Integration Account.
# ----------
```




1 change: 1 addition & 0 deletions docs/preview/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ For more granular packages we recommend reading the documentation.
* Automate Azure API Management tasks ([powershell](features/powershell/azure-api-management))
* Automate Azure Data Factory tasks ([powershell](features/powershell/azure-data-factory))
* Automate Azure DevOps tasks ([powershell](features/powershell/azure-devops))
* Automate Azure Integration Account tasks ([powershell](features/powershell/azure-integration-account))
* Automate Azure Key Vault tasks ([powershell](features/powershell/azure-key-vault))
* Automate Azure Logic Apps tasks ([powershell](features/powershell/azure-logic-apps))
* Automate Azure Resource Manager (ARM) tasks ([powershell](features/powershell/arm))
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<#
.Synopsis
Upload/update a single, or multiple schemas into an Azure Integration Account.

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

.Parameter SchemaFilePath
The full path of a schema that should be uploaded/updated.

.Parameter SchemasFolder
The path to a directory containing all schemas that should be uploaded/updated.

.Parameter ArtifactsPrefix
The prefix, if any, that should be added to the schemas before uploading/updating.

.Parameter RemoveFileExtensions
Indicator whether the extension should be removed from the name before uploading/updating.

#>
mbraekman marked this conversation as resolved.
Show resolved Hide resolved
function Set-AzIntegrationAccountSchemas {
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] $SchemaFilePath = $(if ($SchemasFolder -eq '') { throw "Either the file path of a specific schema or the file path of a folder containing multiple schemas is required, e.g.: -SchemaFilePath 'C:\Schemas\Schema.xsd' or -SchemasFolder 'C:\Schemas'" }),
[parameter(Mandatory = $false)][string] $SchemasFolder = $(if ($SchemaFilePath -eq '') { throw "Either the file path of a specific schema or the file path of a folder containing multiple schemas is required, e.g.: -SchemaFilePath 'C:\Schemas\Schema.xsd' or -SchemasFolder 'C:\Schemas'" }),
mbraekman marked this conversation as resolved.
Show resolved Hide resolved
[Parameter(Mandatory = $false)][string] $ArtifactsPrefix = '',
[Parameter(Mandatory = $false)][switch] $RemoveFileExtensions = $false
)

if($RemoveFileExtensions) {
. $PSScriptRoot\Scripts\Set-AzIntegrationAccountSchemas.ps1 -ResourceGroupName $ResourceGroupName -Name $Name -SchemaFilePath $SchemaFilePath -SchemasFolder $SchemasFolder -ArtifactsPrefix $ArtifactsPrefix -RemoveFileExtensions
} else {
. $PSScriptRoot\Scripts\Set-AzIntegrationAccountSchemas.ps1 -ResourceGroupName $ResourceGroupName -Name $Name -SchemaFilePath $SchemaFilePath -SchemasFolder $SchemasFolder -ArtifactsPrefix $ArtifactsPrefix
}
}

Export-ModuleMember -Function Set-AzIntegrationAccountSchemas
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{AFCEA845-372E-4000-85FD-5672D7551527}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Arcus.Scripting.IntegrationAccount</RootNamespace>
<AssemblyName>Arcus.Scripting.IntegrationAccount</AssemblyName>
<Name>Arcus.Scripting.IntegrationAccount</Name>
<ProjectHome />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Folder Include="Scripts\" />
</ItemGroup>
<ItemGroup>
<Compile Include="Arcus.Scripting.IntegrationAccount.psd1" />
<Compile Include="Arcus.Scripting.IntegrationAccount.psm1" />
<Compile Include="Scripts\Set-AzIntegrationAccountSchemas.ps1" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="Build" />
<Import Project="$(MSBuildExtensionsPath)\PowerShell Tools for Visual Studio\PowerShellTools.targets" Condition="Exists('$(MSBuildExtensionsPath)\PowerShell Tools for Visual Studio\PowerShellTools.targets')" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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] $SchemaFilePath = $(if ($SchemasFolder -eq '') { throw "Either the file path of a specific schema or the file path of a folder containing multiple schemas is required, e.g.: -SchemaFilePath 'C:\Schemas\Schema.xsd' or -SchemasFolder 'C:\Schemas'" }),
[parameter(Mandatory = $false)][string] $SchemasFolder = $(if ($SchemaFilePath -eq '') { throw "Either the file path of a specific schema or the file path of a folder containing multiple schemas is required, e.g.: -SchemaFilePath 'C:\Schemas\Schema.xsd' or -SchemasFolder 'C:\Schemas'" }),
[Parameter(Mandatory = $false)][string] $ArtifactsPrefix = '',
[Parameter(Mandatory = $false)][switch] $RemoveFileExtensions = $false
)

if ($SchemaFilePath -ne '' -and $SchemasFolder -ne '') {
throw "Either the file path of a specific schema or the file path of a folder containing multiple schemas is required, e.g.: -SchemaFilePath 'C:\Schemas\Schema.xsd' or -SchemasFolder 'C:\Schemas'"
}

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

$schemaName = $Schema.Name
if ($RemoveFileExtensions) {
$schemaName = $Schema.BaseName
}
if ($ArtifactsPrefix -ne '') {
$schemaName = $ArtifactsPrefix + $schemaName
}
Write-Host "Uploading schema '$schemaName' into the 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."
mbraekman marked this conversation as resolved.
Show resolved Hide resolved
$existingSchema = Get-AzIntegrationAccountSchema -ResourceGroupName $ResourceGroupName -Name $Name -SchemaName $schemaName -ErrorAction Stop
}
catch {
if ($_.Exception.Message.Contains('could not be found')) {
Write-Verbose "Schema '$schemaName' could not be found."
mbraekman marked this conversation as resolved.
Show resolved Hide resolved
}
else {
throw $_.Exception
}
}

try {
if ($existingSchema -eq $null) {
# Create the schema
Write-Verbose "Creating schema '$schemaName'"
mbraekman marked this conversation as resolved.
Show resolved Hide resolved
$createdSchema = New-AzIntegrationAccountSchema -ResourceGroupName $ResourceGroupName -Name $Name -SchemaName $schemaName -SchemaFilePath $schema.FullName -ErrorAction Stop
Write-Verbose ($createdSchema | Format-List -Force | Out-String)
}
else {
# Update the schema
Write-Verbose "Updating schema '$schemaName'"
mbraekman marked this conversation as resolved.
Show resolved Hide resolved
$updatedSchema = Set-AzIntegrationAccountSchema -ResourceGroupName $ResourceGroupName -Name $Name -SchemaName $schemaName -SchemaFilePath $schema.FullName -ErrorAction Stop -Force
Write-Verbose ($updatedSchema | Format-List -Force | Out-String)
}
Write-Host "Schema '$schemaName' has been uploaded into the Integration Account."
mbraekman marked this conversation as resolved.
Show resolved Hide resolved
}
catch {
Write-Error "Failed to upload schema '$schemaName' in Integration Account '$Name': '$($_.Exception.Message)_'"
mbraekman 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 Integration Account with name '$Name' in resource group '$ResourceGroupName'"
mbraekman marked this conversation as resolved.
Show resolved Hide resolved
}
else {
if ($SchemasFolder -ne '' -and $SchemaFilePath -eq '') {
foreach ($schema in Get-ChildItem("$schemasFolder") -File) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious. Placing the string folder into another string, is this some extra-guard for string formatting or some kind?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, more because I made a mistake here. Tested this with a hard-coded value first but didn't replace the quotes surrounding the hard-coded value 😅

UploadSchema -Schema $schema
Write-Host '----------'
}
}
elseif ($schemasFolder -eq '' -and $SchemaFilePath -ne '') {
[System.IO.FileInfo]$schema = New-Object System.IO.FileInfo("$SchemaFilePath")
UploadSchema -Schema $schema
}
}

Loading