Framework/Core/SVT/Services/Batch.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Set-StrictMode -Version Latest 
class Batch: SVTBase
{       
    Batch([string] $subscriptionId, [string] $resourceGroupName, [string] $resourceName): 
        Base($subscriptionId, $resourceGroupName, $resourceName) 
    {  }

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

    hidden [ControlResult] CheckBatchStorageSSE([ControlResult] $controlResult)
    {
        $batchResource = Get-AzureRmBatchAccount -AccountName $this.ResourceContext.ResourceName -ResourceGroupName $this.ResourceContext.ResourceGroupName
        if($batchResource)
        {
            if($batchResource.AutoStorageProperties -and (-not [string]::IsNullOrEmpty($batchResource.AutoStorageProperties.StorageAccountId)))
            {
                $storageAccount = Get-AzureRmResource -ResourceId $batchResource.AutoStorageProperties.StorageAccountId -ExpandProperties
                if($storageAccount -and $storageAccount.Properties)
                {

                    if([Helpers]::CheckMember($storageAccount,"Properties.encryption.services.blob.enabled") -and $storageAccount.Properties.encryption.services.blob.enabled -eq $true)
                    {
                        $controlResult.AddMessage([VerificationResult]::Passed,
                                "Storage Service Encryption is enabled on blob service of Storage Account [$($storageAccount.Name)] associated with Batch account",
                                $storageAccount.Properties.encryption.services); 
                    }
                    else
                    {
                        $controlResult.AddMessage([VerificationResult]::Failed,
                                "Storage Service Encryption is not enabled on blob service of Storage Account [$($storageAccount.Name)] associated with Batch account"); 
                    }
                }
                else
                {
                    $controlResult.AddMessage([MessageData]::new("No valid Storage Account found which is associated with Batch account", [MessageType]::Error)); 
                }
            }
            else
            {
                $controlResult.AddMessage([MessageData]::new("No valid Storage Account found which is associated with Batch account", [MessageType]::Error)); 
            }
        }
        else
        {
            $controlResult.AddMessage([MessageData]::new("We are not able to fetch the required data for the resource", [MessageType]::Error)); 
        }
        
        return $controlResult;
    }



    hidden [ControlResult] CheckBatchMetricAlert([ControlResult] $controlResult)
    {
        $this.CheckMetricAlertConfiguration($this.ControlSettings.MetricAlert.Batch, $controlResult, "");
        return $controlResult;
    }
}