Framework/Core/SVT/Services/BotService.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

Set-StrictMode -Version Latest 
class BotService: AzSVTBase
{
    hidden [PSObject] $ResourceObject;

    BotService([string] $subscriptionId, [SVTResource] $svtResource):
        Base($subscriptionId, $svtResource)
    {
        $this.GetResourceObject();
    }

    hidden [PSObject] GetResourceObject()
    {
        if (-not $this.ResourceObject)
        {
            # Get App Service details
            $this.ResourceObject =  Get-AzResource -Name $this.ResourceContext.ResourceName `
            -ResourceGroupName $this.ResourceContext.ResourceGroupName `
            -ResourceType $this.ResourceContext.ResourceType

            if(-not $this.ResourceObject)
            {
                throw ([SuppressedException]::new(("Resource '$($this.ResourceContext.ResourceName)' not found under Resource Group '$($this.ResourceContext.ResourceGroupName)'"), [SuppressedExceptionType]::InvalidOperation))
            }
            
        }

        return $this.ResourceObject;
    }

    hidden [ControlResult] CheckBotConfiguredChannels([ControlResult] $controlResult)
    {
        # Get custom domain URLs
        $ConfiguredChannels = $this.ResourceObject.Properties.enabledChannels

        # Combine custom domain name and SSL configuration TCP

        if(($ConfiguredChannels | Measure-Object).Count -gt 0)
        {
            $controlResult.AddMessage([VerificationResult]::Verify,
                                    [MessageData]::new("Configured Channles for Bot Service " + $this.ResourceContext.ResourceName, $this.ResourceObject.Properties.enabledChannels));
        }

        return $controlResult;
    }

    hidden [ControlResult] CheckAIConfigured([ControlResult] $controlResult)
    {
        # Get custom domain URLs
        $developerAppInsightsApplicationId = $this.ResourceObject.Properties.developerAppInsightsApplicationId

        # Combine custom domain name and SSL configuration TCP

        if($developerAppInsightsApplicationId -ne "")
        {
            $controlResult.AddMessage([VerificationResult]::Verify,
                                    [MessageData]::new("Application Insights is configured for the Bot Service "+ $this.ResourceContext.ResourceName  +". Please verify if critical data is not stored."));
        }
        else
        {
            $controlResult.AddMessage([VerificationResult]::Passed,
                                    [MessageData]::new("Application Insights is not Configured for " +  $this.ResourceContext.ResourceName + ". Please refer recommendation of the same to implement."));
        }

        return $controlResult;
    }
}