Framework/Core/FixControl/Services/CDNFix.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Set-StrictMode -Version Latest 

class CDNFix: FixServicesBase
{
    [PSObject] $ResourceObject = $null;

    CDNFix([string] $subscriptionId, [ResourceConfig] $resourceConfig, [string] $resourceGroupName): 
        Base($subscriptionId, $resourceConfig, $resourceGroupName) 
    { }

    [MessageData[]] EnableHttpsProtocol([PSObject] $parameters)
    {
        [MessageData[]] $detailedLogs = @();
        $detailedLogs += [MessageData]::new("Enabling 'HTTPS' protocol for CDN endpoints in CDN Profile [$($this.ResourceName)]...");
    
        $cdnEndpoints = Get-AzCdnEndpoint -ProfileName $this.ResourceName `
                            -ResourceGroupName $this.ResourceGroupName `
                            -ErrorAction Stop
        $httpAllowedEndpointList =  $cdnEndpoints | Where-Object { $_.IsHttpAllowed -eq $true }


        $httpAllowedEndpointList |     ForEach-Object{

            $httpEndpoint= Get-AzCdnEndpoint -EndpointName $_.Name -ProfileName $this.ResourceName  -ResourceGroupName $this.ResourceGroupName
            $httpEndpoint.IsHttpAllowed =$false
            $httpEndpoint.IsHttpsAllowed =$true
            Set-AzCdnEndpoint -CdnEndpoint $httpEndpoint
        
        }
        $detailedLogs += [MessageData]::new("'HTTPS' protocol is enabled for all CDN endpoints in CDN Profile [$($this.ResourceName)]");
        return $detailedLogs;
    }

}