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: Support Logic App Standard #415

Merged
merged 26 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3013a73
support Logic App Standard for Disable-AzLogicApp and Enable-AzLogicApp
pim-simons Oct 20, 2023
b2e325b
fix docs
pim-simons Oct 20, 2023
8c9f44a
add logic app standard support to `Disable-AzLogicAppsFromConfig` and…
pim-simons Nov 2, 2023
ffcf41b
minor cleanup
pim-simons Nov 2, 2023
3e89462
fixed unit tests
pim-simons Nov 3, 2023
8a6941a
added logic app standard unit tests
pim-simons Nov 3, 2023
f7267e8
use filter in getting running and waiting runs
pim-simons Nov 3, 2023
44a7f76
fix url params
pim-simons Nov 3, 2023
3f5a7b9
added Logic App Standard support for `Cancel-AzLogicAppRuns`
pim-simons Nov 3, 2023
361363f
fixes
pim-simons Nov 3, 2023
73d720a
added unittests for `Cancel-AzLogicAppRuns` for Logic App Standard
pim-simons Nov 3, 2023
679e51f
aligned error handling
pim-simons Nov 15, 2023
be418e1
add logic app standard support for `Resubmit-FailedAzLogicAppRuns`
pim-simons Nov 15, 2023
78b9897
added support for nextlink
pim-simons Nov 15, 2023
5984114
added nextlink functionality to `Cancel-AzLogicAppRuns`
pim-simons Nov 15, 2023
85dca7a
align error handling and unit tests
pim-simons Nov 15, 2023
ea340e4
added unit tests for `Resubmit-FailedAzLogicAppRuns`
pim-simons Nov 15, 2023
d597ccf
updated docs
pim-simons Nov 16, 2023
e4a6e0c
add Mock Get-AzCachedAccessToken
pim-simons Nov 16, 2023
3299474
Add Mock Get-AzCachedAccessToken
pim-simons Nov 16, 2023
aee1f81
Apply suggestions from code review
pim-simons Nov 17, 2023
f901fcd
aligned logging
pim-simons Nov 20, 2023
b0a253d
do not use global variables
pim-simons Nov 20, 2023
b0c7728
fix tests
pim-simons Nov 20, 2023
9961d82
Merge branch 'arcus-azure:main' into feature/logic-app-standard
pim-simons Nov 21, 2023
f5f1ec2
Merge branch 'arcus-azure:main' into feature/logic-app-standard
pim-simons Nov 21, 2023
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

Large diffs are not rendered by default.

354 changes: 354 additions & 0 deletions docs/preview/03-Features/powershell/azure-logic-apps-standard.md

Large diffs are not rendered by default.

Binary file modified src/Arcus.Scripting.LogicApps/Arcus.Scripting.LogicApps.psd1
Binary file not shown.
44 changes: 34 additions & 10 deletions src/Arcus.Scripting.LogicApps/Arcus.Scripting.LogicApps.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@

.Parameter LogicAppName
The name of the Azure Logic App.

.Parameter WorkflowName
[Optional] The name of the workflow in the Azure Logic App Standard Site.

.Parameter EnvironmentName
[Optional] The Azure Cloud environment in which the Azure Logic App resides.

.Parameter MaximumFollowNextPageLink
The number of times the script should retrieve the next page of Logic App runs, if not specified the entire run history of the Logic App will be retrieved.
[Optional] The number of times the script should retrieve the next page of Logic App runs, if not specified the entire run history of the Logic App will be retrieved.
pim-simons marked this conversation as resolved.
Show resolved Hide resolved

#>
function Cancel-AzLogicAppRuns {
param(
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of the resource group is required"),
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of the logic app is required"),
[Parameter(Mandatory = $false)][string] $WorkflowName = "",
[Parameter(Mandatory = $false)][string] $EnvironmentName = "AzureCloud",
[Parameter(Mandatory = $false)][int] $MaximumFollowNextPageLink = 10
)

. $PSScriptRoot\Scripts\Cancel-AzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -MaximumFollowNextPageLink $MaximumFollowNextPageLink
. $PSScriptRoot\Scripts\Cancel-AzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -WorkflowName $WorkflowName -EnvironmentName $EnvironmentName -MaximumFollowNextPageLink $MaximumFollowNextPageLink
}

Export-ModuleMember -Function Cancel-AzLogicAppRuns
Expand All @@ -40,29 +48,37 @@ Export-ModuleMember -Function Cancel-AzLogicAppRuns
.Parameter LogicAppName
The name of the Azure Logic App.

.Parameter WorkflowName
stijnmoreels marked this conversation as resolved.
Show resolved Hide resolved
[Optional] The name of the workflow in the Azure Logic App Standard Site.

.Parameter EnvironmentName
[Optional] The Azure Cloud environment in which the Azure Logic App resides.

.Parameter StartTime
The start time of the failed instances of the Azure Logic App.

.Parameter EndTime
The end time of the failed instances of the Azure Logic App.
[Optional] The end time of the failed instances of the Azure Logic App.

.Parameter MaximumFollowNextPageLink
The number of times the script should retrieve the next page of Logic App runs, if not specified the entire run history of the Logic App will be retrieved.
[Optional] The number of times the script should retrieve the next page of Logic App runs, if not specified the entire run history of the Logic App will be retrieved.

#>
function Resubmit-FailedAzLogicAppRuns {
param(
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of the resource group is required"),
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of the logic app is required"),
[Parameter(Mandatory = $false)][string] $WorkflowName = "",
[Parameter(Mandatory = $true)][datetime] $StartTime = $(throw "Start time is required"),
[Parameter(Mandatory = $false)][datetime] $EndTime,
[Parameter(Mandatory = $false)][string] $EnvironmentName = "AzureCloud",
[Parameter(Mandatory = $false)][int] $MaximumFollowNextPageLink = 10
)

if ($EndTime) {
. $PSScriptRoot\Scripts\Resubmit-FailedAzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -StartTime $StartTime -EndTime $EndTime -MaximumFollowNextPageLink $MaximumFollowNextPageLink
. $PSScriptRoot\Scripts\Resubmit-FailedAzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -WorkflowName $WorkflowName -EnvironmentName $EnvironmentName -StartTime $StartTime -EndTime $EndTime -MaximumFollowNextPageLink $MaximumFollowNextPageLink
} else {
. $PSScriptRoot\Scripts\Resubmit-FailedAzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -StartTime $StartTime -MaximumFollowNextPageLink $MaximumFollowNextPageLink
. $PSScriptRoot\Scripts\Resubmit-FailedAzLogicAppRuns.ps1 -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -WorkflowName $WorkflowName -EnvironmentName $EnvironmentName -StartTime $StartTime -MaximumFollowNextPageLink $MaximumFollowNextPageLink
}
}

Expand All @@ -86,6 +102,9 @@ Export-ModuleMember -Function Resubmit-FailedAzLogicAppRuns

.Parameter LogicAppName
The name of the Azure Logic App to be enabled.

.Parameter WorkflowName
[Optional] The name of the workflow in the Azure Logic App Standard Site.

.Parameter ApiVersion
[Optional] The version of the api to be used to disable the Azure Logic App.
Expand All @@ -100,11 +119,12 @@ function Disable-AzLogicApp {
[Parameter(Mandatory = $false)][string] $SubscriptionId = "",
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of the resource group is required"),
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of the logic app is required"),
[Parameter(Mandatory = $false)][string] $WorkflowName = "",
[Parameter(Mandatory = $false)][string] $ApiVersion = "2016-06-01",
[Parameter(Mandatory = $false)][string] $AccessToken = ""
)

. $PSScriptRoot\Scripts\Disable-AzLogicApp.ps1 -EnvironmentName $EnvironmentName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -ApiVersion $ApiVersion -AccessToken $AccessToken
. $PSScriptRoot\Scripts\Disable-AzLogicApp.ps1 -EnvironmentName $EnvironmentName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -WorkflowName $WorkflowName -ApiVersion $ApiVersion -AccessToken $AccessToken
}

Export-ModuleMember -Function Disable-AzLogicApp
Expand All @@ -123,7 +143,7 @@ Export-ModuleMember -Function Disable-AzLogicApp
If your solution consists of multiple interfaces, you can specify the flow-specific name of the configuration file, if not, the script will look for a file named 'deploy-orderControl.json' by default.

.Parameter ResourcePrefix
The prefix assigned to all Azure Logic Apps, which can differ per environment.
[Optional] The prefix assigned to all Azure Logic Apps, which can differ per environment.

.Parameter EnvironmentName
[Optional] The Azure Cloud environment in which the Azure Logic App resides.
Expand Down Expand Up @@ -163,6 +183,9 @@ Export-ModuleMember -Function Disable-AzLogicAppsFromConfig

.Parameter LogicAppName
The name of the Azure Logic App to be enabled.

.Parameter WorkflowName
[Optional] The name of the workflow in the Azure Logic App Standard Site.

.Parameter ApiVersion
[Optional] The version of the api to be used to enable the Azure Logic App.
Expand All @@ -178,11 +201,12 @@ function Enable-AzLogicApp {
[Parameter(Mandatory = $false)][string] $SubscriptionId = "",
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of resource group is reqiured"),
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of logic app is required"),
[Parameter(Mandatory = $false)][string] $WorkflowName = "",
[Parameter(Mandatory = $false)][string] $ApiVersion = "2016-06-01",
[Parameter(Mandatory = $false)][string] $AccessToken = ""
)

. $PSScriptRoot\Scripts\Enable-AzLogicApp.ps1 -EnvironmentName $EnvironmentName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -ApiVersion $ApiVersion -AccessToken $AccessToken
. $PSScriptRoot\Scripts\Enable-AzLogicApp.ps1 -EnvironmentName $EnvironmentName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -WorkflowName $WorkflowName -ApiVersion $ApiVersion -AccessToken $AccessToken
}

Export-ModuleMember -Function Enable-AzLogicApp
Expand All @@ -201,7 +225,7 @@ Export-ModuleMember -Function Enable-AzLogicApp
If your solution consists of multiple interfaces, you can specify the flow-specific name of the configuration file, if not, the script will look for a file named 'deploy-orderControl.json' by default.

.Parameter ResourcePrefix
The prefix assigned to all Azure Logic Apps, which can differ per environment.
[Optional] The prefix assigned to all Azure Logic Apps, which can differ per environment.

.Parameter EnvironmentName
[Optional] The Azure Cloud environment in which the Azure Logic App resides.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
<ItemGroup>
<Compile Include="Arcus.Scripting.LogicApps.psd1" />
<Compile Include="Arcus.Scripting.LogicApps.psm1" />
<Compile Include="Scripts\Get-AzLogicAppStandardResourceManagementUrl.ps1" />
<Compile Include="Scripts\Resubmit-FailedAzLogicAppRuns.ps1" />
<Compile Include="Scripts\Cancel-AzLogicAppRuns.ps1" />
<Compile Include="Scripts\Disable-AzLogicApp.ps1" />
<Compile Include="Scripts\Disable-AzLogicAppsFromConfig.ps1" />
<Compile Include="Scripts\Enable-AzLogicApp.ps1" />
<Compile Include="Scripts\Enable-AzLogicAppsFromConfig.ps1" />
<Compile Include="Scripts\Get-AzLogicAppResourceManagementUrl.ps1" />
<Compile Include="Scripts\Get-AzLogicAppConsumptionResourceManagementUrl.ps1" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="Build" />
Expand Down
79 changes: 71 additions & 8 deletions src/Arcus.Scripting.LogicApps/Scripts/Cancel-AzLogicAppRuns.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,82 @@
param(
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of the resource group is required"),
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of the logic app is required"),
[Parameter(Mandatory = $false)][string] $WorkflowName = "",
[Parameter(Mandatory = $false)][string] $EnvironmentName = "AzureCloud",
[Parameter(Mandatory = $false)][int] $MaximumFollowNextPageLink = 10
)

$Global:accessToken = "";
$Global:subscriptionId = "";

try {
$runs = Get-AzLogicAppRunHistory -ResourceGroupName $ResourceGroupName -Name $LogicAppName -FollowNextPageLink -MaximumFollowNextPageLink $MaximumFollowNextPageLink |
Where-Object {$_.Status -eq 'Running'}
if ($WorkflowName -eq "") {
$runs = Get-AzLogicAppRunHistory -ResourceGroupName $ResourceGroupName -Name $LogicAppName -FollowNextPageLink -MaximumFollowNextPageLink $MaximumFollowNextPageLink |
Where-Object {$_.Status -eq 'Running'}

foreach ($run in $runs) {
Stop-AzLogicAppRun -ResourceGroupName $ResourceGroupName -Name $LogicAppName -RunName $run.Name -Force
Write-Verbose "Cancelled run $run.Name for the Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'"
}
foreach ($run in $runs) {
Stop-AzLogicAppRun -ResourceGroupName $ResourceGroupName -Name $LogicAppName -RunName $run.Name -Force
Write-Verbose "Cancelled run $run.Name for the Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'"
pim-simons marked this conversation as resolved.
Show resolved Hide resolved
}

Write-Host "Successfully cancelled all running instances for the Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'" -ForegroundColor Green
} else {
$token = Get-AzCachedAccessToken -AssignGlobalVariables

$listRunningUrl = . $PSScriptRoot\Get-AzLogicAppStandardResourceManagementUrl.ps1 -EnvironmentName $EnvironmentName -SubscriptionId $Global:subscriptionId -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -WorkflowName $WorkflowName -Action 'listRunning'
$listRunningParams = @{
Method = 'Get'
Headers = @{
'authorization'="Bearer $Global:accessToken"
}
URI = $listRunningUrl
}

$runs = Invoke-WebRequest @listRunningParams -ErrorAction Stop
$runsContent = $runs.Content | ConvertFrom-Json
$allRuns = $runsContent.value

if ($runsContent.nextLink -ne $null) {
$nextPageCounter = 1
$nextPageUrl = $runsContent.nextLink
while ($nextPageUrl -ne $null -and $nextPageCounter -le $MaximumFollowNextPageLink) {
$nextPageCounter = $nextPageCounter + 1
$listRunningParams = @{
Method = 'Get'
Headers = @{
'authorization'="Bearer $Global:accessToken"
}
URI = $nextPageUrl
}

Write-Host "Successfully cancelled all running instances for the Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'" -ForegroundColor Green
$runsNextPage = Invoke-WebRequest @listRunningParams -ErrorAction Stop
$runsNextPageContent = $runsNextPage.Content | ConvertFrom-Json
$nextPageUrl = $runsNextPageContent.nextLink
$allRuns = $allRuns + $runsNextPageContent.value
}
}

foreach ($run in $allRuns) {
$runName = $run.name

$cancelUrl = . $PSScriptRoot\Get-AzLogicAppStandardResourceManagementUrl.ps1 -EnvironmentName $EnvironmentName -SubscriptionId $Global:subscriptionId -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -WorkflowName $WorkflowName -RunName $runName -Action 'cancel'
$cancelParams = @{
Method = 'Post'
Headers = @{
'authorization'="Bearer $Global:accessToken"
}
URI = $cancelUrl
}
$cancel = Invoke-WebRequest @cancelParams -ErrorAction Stop
Write-Verbose "Cancelled run '$runName' for the workflow '$WorkflowName' in Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'"
}

Write-Host "Successfully cancelled all running instances for the workflow '$WorkflowName' in Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'" -ForegroundColor Green
}
} catch {
throw "Failed to cancel all running instances for the Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'. Details: $($_.Exception.Message)"
if ($WorkflowName -eq "") {
throw "Failed to cancel all running instances for the Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'. Details: $($_.Exception.Message)"
} else {
throw "Failed to cancel all running instances for the workflow '$WorkflowName' in Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'. Details: $($_.Exception.Message)"
}
}
49 changes: 28 additions & 21 deletions src/Arcus.Scripting.LogicApps/Scripts/Disable-AzLogicApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,42 @@ param(
[Parameter(Mandatory = $false)][string] $SubscriptionId = "",
[Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of the resource group is required"),
[Parameter(Mandatory = $true)][string] $LogicAppName = $(throw "Name of the logic app is required"),
[Parameter(Mandatory = $false)][string] $WorkflowName = "",
[Parameter(Mandatory = $false)][string] $ApiVersion = "2016-06-01",
[Parameter(Mandatory = $false)][string] $AccessToken = ""
)

try{
if($SubscriptionId -eq "" -or $AccessToken -eq ""){
# Request accessToken in case the script contains records
$token = Get-AzCachedAccessToken
if ($WorkflowName -eq "") {
if ($SubscriptionId -eq "" -or $AccessToken -eq "") {
# Request accessToken in case the script contains records
$token = Get-AzCachedAccessToken

$AccessToken = $token.AccessToken
$SubscriptionId = $token.SubscriptionId
}
$AccessToken = $token.AccessToken
$SubscriptionId = $token.SubscriptionId
}

$fullUrl = . $PSScriptRoot\Get-AzLogicAppResourceManagementUrl.ps1 -EnvironmentName $EnvironmentName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -ApiVersion $ApiVersion -Action "disable"
$fullUrl = . $PSScriptRoot\Get-AzLogicAppConsumptionResourceManagementUrl.ps1 -EnvironmentName $EnvironmentName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -LogicAppName $LogicAppName -ApiVersion $ApiVersion -Action "disable"

Write-Verbose "Attempting to disable Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'..."
$params = @{
Method = 'Post'
Headers = @{
'authorization'="Bearer $AccessToken"
Write-Verbose "Attempting to disable Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'..."
$params = @{
Method = 'Post'
Headers = @{
'authorization'="Bearer $AccessToken"
}
URI = $fullUrl
}
URI = $fullUrl
}

$web = Invoke-WebRequest @params -ErrorAction Stop
Write-Host "Successfully disabled Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'" -ForegroundColor Green
}
catch {
Write-Warning "Failed to disable Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'"
$ErrorMessage = $_.Exception.Message
Write-Debug "Error: $ErrorMessage"
$web = Invoke-WebRequest @params -ErrorAction Stop
Write-Host "Successfully disabled Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'" -ForegroundColor Green
} else {
Set-AzAppServiceSetting -ResourceGroupName $ResourceGroupName -AppServiceName $LogicAppName -AppServiceSettingName "Workflows.$WorkflowName.FlowState" -AppServiceSettingValue "Disabled"
Write-Host "Successfully disabled workflow '$WorkflowName' in Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'" -ForegroundColor Green
}
} catch {
if ($WorkflowName -eq "") {
throw "Failed to disable Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'. Details: $($_.Exception.Message)"
} else {
throw "Failed to disable workflow '$WorkflowName' in Azure Logic App '$LogicAppName' in resource group '$ResourceGroupName'. Details: $($_.Exception.Message)"
}
}
Loading
Loading