Framework/Core/FixControl/Services/SubscriptionCoreFix.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
61
62
63
64
65
66
67
68
69
70
71
72
73
Set-StrictMode -Version Latest 

class SubscriptionCoreFix: FixSubscriptionBase
{       
    SubscriptionCoreFix([string] $subscriptionId, [ArrayWrapper] $controls): 
        Base($subscriptionId, $controls) 
    { }

    [MessageData[]] AddRequiredCentralAccounts([PSObject] $parameters)
    {
        [MessageData[]] $detailedLogs = @();
        $detailedLogs += [MessageData]::new("Adding required central accounts to the subscription using AzSK command...");
        Set-AzSKSubscriptionRBAC `
            -SubscriptionId $this.SubscriptionContext.SubscriptionId `
            -Tags ([String]::Join(",", $parameters.Tags)) `
            -DoNotOpenOutputFolder
        $detailedLogs += [MessageData]::new("All required central accounts have been added to the subscription", [MessageType]::Update);
        return $detailedLogs;
    }
    
    [MessageData[]] RemoveDeprecatedAccounts([PSObject] $parameters)
    {
        [MessageData[]] $detailedLogs = @();
        $detailedLogs += [MessageData]::new("Removing deprecated accounts from the subscription using AzSK command...");
        Remove-AzSKSubscriptionRBAC -SubscriptionId $this.SubscriptionContext.SubscriptionId -DoNotOpenOutputFolder
        $detailedLogs += [MessageData]::new("All deprecated accounts have been removed from the subscription", [MessageType]::Update);
        return $detailedLogs;
    }

    [MessageData[]] ConfigureSecurityCenter([PSObject] $parameters)
    {
        [MessageData[]] $detailedLogs = @();
        $detailedLogs += [MessageData]::new("Configuring Security Center using AzSK command...");
        
        Set-AzSKAzureSecurityCenterPolicies `
            -SubscriptionId $this.SubscriptionContext.SubscriptionId `
            -SecurityContactEmails $parameters.SecurityContactEmails `
            -SecurityPhoneNumber $parameters.SecurityPhoneNumber `
            -DoNotOpenOutputFolder
        
        $detailedLogs += [MessageData]::new("Security Center has been configured", [MessageType]::Update);
        return $detailedLogs;
    }

    [MessageData[]] ConfigureARMPolicies([PSObject] $parameters)
    {
        [MessageData[]] $detailedLogs = @();
        $detailedLogs += [MessageData]::new("Configuring ARM policies using AzSK command...");
        
        Set-AzSKARMPolicies `
            -SubscriptionId $this.SubscriptionContext.SubscriptionId `
            -Tags ([String]::Join(",", $parameters.Tags)) `
            -DoNotOpenOutputFolder
        
        $detailedLogs += [MessageData]::new("ARM policies have been configured", [MessageType]::Update);
        return $detailedLogs;
    }
    
    [MessageData[]] ConfigureAlerts([PSObject] $parameters)
    {
        [MessageData[]] $detailedLogs = @();
        $detailedLogs += [MessageData]::new("Configuring alerts using AzSK command...");
        
        Set-AzSKAlerts `
            -SubscriptionId $this.SubscriptionContext.SubscriptionId `
            -SecurityContactEmails $parameters.SecurityContactEmails `
            -Tags ([String]::Join(",", $parameters.Tags)) `
            -DoNotOpenOutputFolder
        
        $detailedLogs += [MessageData]::new("Alerts have been configured", [MessageType]::Update);
        return $detailedLogs;
    }
}