Framework/Core/SVT/Services/CDN.ps1

Set-StrictMode -Version Latest
class CDN: SVTBase
{
    hidden [PSObject] $ResourceObject;

    CDN([string] $subscriptionId, [string] $resourceGroupName, [string] $resourceName):
        Base($subscriptionId, $resourceGroupName, $resourceName)
    {
        
    }

    CDN([string] $subscriptionId, [SVTResource] $svtResource):
        Base($subscriptionId, $svtResource)
    {
       
    }

    hidden [ControlResult] CheckCDNHttpsProtocol([ControlResult] $controlResult)
    {
        $cdnEndpoints = Get-AzureRmCdnEndpoint -ProfileName $this.ResourceContext.ResourceName `
                            -ResourceGroupName $this.ResourceContext.ResourceGroupName `
                            -ErrorAction Stop

        if(($cdnEndpoints | Measure-Object).Count -eq 0)
        {
            $controlResult.AddMessage([VerificationResult]::Passed,
                                        [MessageData]::new("No CDN endpoints are found in the CDN profile.")); 
        }
        else
        {
            $httpAllowedEndpointList =  $cdnEndpoints | Where-Object { $_.IsHttpAllowed -eq $true }

            if(($httpAllowedEndpointList | Measure-Object).Count -eq 0)
            {
                $controlResult.AddMessage([VerificationResult]::Passed,
                                        [MessageData]::new("All CDN endpoints in the CDN profile [" + $this.ResourceContext.ResourceName + "] are using HTTPS protocol only - ", ($cdnEndpoints | Select-Object -Property Name, HostName, OriginHostHeader, IsHttpAllowed, IsHttpsAllowed))); 
            }
            else
            {
                $controlResult.AddMessage([VerificationResult]::Failed,
                                        [MessageData]::new("Below CDN endpoints in the CDN profile [" + $this.ResourceContext.ResourceName + "] are using HTTP protocol - ", ($httpAllowedEndpointList | Select-Object -Property Name, HostName, OriginHostHeader, IsHttpAllowed, IsHttpsAllowed))); 
            }
        }
 
        return $controlResult;    
    }
}