-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24bc3d8
commit 8d64690
Showing
3 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
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,52 @@ | ||
<# | ||
.SYNOPSIS | ||
Purges the content from Azure Front Door (AFD) | ||
.DESCRIPTION | ||
Purges the content from Azure Front Door (AFD) | ||
.PARAMETER AFDProfileResourceGroup | ||
The Resource Group of the AFD | ||
.PARAMETER AFDProfileName | ||
The AFD Profile Name | ||
.PARAMETER AFDEndPointName | ||
The AFD EndPoint Name | ||
.PARAMETER PurgeContent | ||
The assest you wish to purge from the edge nodes | ||
Single URL Purge: Purge individual asset by specifying the full URL, e.g., "/pictures/image1.png" or "/pictures/image1" | ||
Wildcard purge: Purge all folders, sub-folders, and files under an endpoint with "/*" e.g. "/* " or "/pictures/*" | ||
Root domain purge: Purge the root of the endpoint with "/" in the path | ||
.EXAMPLE | ||
Invoke-AfdContentPurge.ps1 -AFDProfileResourceGroup aResourceGroup -AFDProfileName aAfdProfile -AFDEndPointName aAfdEndpoint -PurgeContent "/*" | ||
#> | ||
[CmdletBinding()] | ||
Param( | ||
[Parameter(Mandatory = $true)] | ||
[String]$AFDProfileResourceGroup, | ||
[Parameter(Mandatory = $true)] | ||
[String]$AFDProfileName, | ||
[Parameter(Mandatory = $true)] | ||
[String]$AFDEndPointName, | ||
[Parameter(Mandatory = $true)] | ||
[String]$PurgeContent | ||
) | ||
try { | ||
if ( $PurgeContent.Trim() -eq "" ) { | ||
throw "Purge Content blank will not run purge" | ||
} | ||
# --- Set AFD EndPoint | ||
$AFDEndpoint = Get-AzFrontDoorCdnEndpoint -ResourceGroupName $AFDProfileResourceGroup -ProfileName $AFDProfileName -EndpointName $AFDEndpointName | ||
if (!$AFDEndpoint) { | ||
throw "AFD Endpoint does not exist" | ||
} | ||
# --- Purging AFD EndPoint | ||
$AFDEndpoint | Clear-AzFrontDoorCdnEndpointContent -ContentPath $PurgeContent | ||
} | ||
catch { | ||
throw "$_" | ||
} | ||
|
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,32 @@ | ||
$Config = Get-Content $PSScriptRoot\..\Tests\Configuration\Unit.Tests.Config.json -Raw | ConvertFrom-Json | ||
Set-Location $PSScriptRoot\..\Infrastructure-Scripts\ | ||
|
||
Describe "Invoke-AfdContentPurge Unit Tests" -Tags @("Unit") { | ||
|
||
Context "Purge Content Parameter Blank" { | ||
It "Should throw an exception to warn that no content purge will be run" { | ||
{ ./Invoke-AfdContentPurge -AFDProfileResourceGroup $Config.resourceGroupName -AFDProfileName $Config.CdnProfileName -AFDEndPointName $Config.CDNEndPointName -PurgeContent $Config.blankPurge } | Should throw "Purge Content blank will not run purge" | ||
} | ||
} | ||
|
||
Context "Resource Group or CDN Profile does not exist" { | ||
It "ThShould throw an expection to warn that the the specified Resource Group or CDN Profile was not found in the subscription" { | ||
Mock Get-AzFrontDoorCdnEndpoint -MockWith { Return $null } | ||
{ ./Invoke-AfdContentPurge -AFDProfileResourceGroup $Config.resourceGroupName -AFDProfileName $Config.CdnProfileName -AFDEndPointName $Config.CDNEndPointName -PurgeContent $Config.purgeContent } | Should throw "AFD Endpoint does not exist" | ||
Assert-MockCalled -CommandName 'Get-AzFrontDoorCdnEndpoint' -Times 1 -Scope It | ||
} | ||
} | ||
|
||
Context "Parameters are ok" { | ||
It "Should call Clear-AzFrontDoorCdnEndpointContent" { | ||
Mock Get-AzFrontDoorCdnEndpoint -MockWith { | ||
$cdnEndpointExists = [Microsoft.Azure.PowerShell.Cmdlets.Cdn.Models.Api20240201.Endpoint]::new() | ||
return $cdnEndpointExists | ||
} | ||
Mock Clear-AzFrontDoorCdnEndpointContent -MockWith { Return $null } | ||
{ ./Invoke-AfdContentPurge -AFDProfileResourceGroup $Config.resourceGroupName -AFDProfileName $Config.CdnProfileName -AFDEndPointName $Config.CDNEndPointName -PurgeContent $Config.purgeContent } | Should Not Throw | ||
Assert-MockCalled -CommandName 'Get-AzFrontDoorCdnEndpoint' -Times 1 -Scope It | ||
Assert-MockCalled -CommandName 'Clear-AzFrontDoorCdnEndpointContent' -Times 1 -Scope It | ||
} | ||
} | ||
} |
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