Framework/Core/SVT/Services/DataFactory.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#using namespace Microsoft.Azure.Commands.DataFactory.Models
Set-StrictMode -Version Latest 
class DataFactory: SVTBase
{       

    hidden [PSObject] $ResourceObject;
    hidden [ADFDetails] $adfDetails = [ADFDetails]::new()

    DataFactory([string] $subscriptionId, [string] $resourceGroupName, [string] $resourceName): 
        Base($subscriptionId, $resourceGroupName, $resourceName) 
    { 
        $this.GetResourceObject();
    }

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


    }

    hidden [PSObject] GetResourceObject()
    {
        if (-not $this.ResourceObject) {
            $this.ResourceObject = Get-AzDataFactory -Name $this.ResourceContext.ResourceName -ResourceGroupName $this.ResourceContext.ResourceGroupName
                if(-not $this.ResourceObject)
                {
                    throw ([SuppressedException]::new(("Resource '{0}' not found under Resource Group '{1}'" -f ($this.ResourceContext.ResourceName), ($this.ResourceContext.ResourceGroupName)), [SuppressedExceptionType]::InvalidOperation))
                }
            $this.GetADFDetails();
            $this.AddResourceMetadata($this.adfDetails);
        }

        return $this.ResourceObject;
    }
        
    
    hidden [ControlResult] CheckDataFactoryLinkedService([ControlResult] $controlResult)
    {

        if(($this.adfDetails.LinkedserviceDetails | Measure-Object).Count -gt 0)
        {           
            $linkedServicesProps = $this.adfDetails.LinkedserviceDetails | Select-Object -Property LinkedServiceName, Properties

            $controlResult.SetStateData("Linked Service Details:", $linkedServicesProps);
             


            $controlResult.AddMessage([VerificationResult]::Verify, 
                            "Validate that the following Linked Services are using encryption in transit. Total Linked Services found - $(($this.adfDetails.linkedservicedetails | Measure-Object).Count)",
                            $linkedServicesProps);
        }
        else
        {
            $controlResult.AddMessage([VerificationResult]::Passed, 
                                        [MessageData]::new("The are no Linked Services configured in Data Factory - ["+ $this.ResourceContext.ResourceName +"]"));
        }       
                          
        return $controlResult;
    }

    hidden GetADFDetails(){
    
        # Get linked services details
        
        $this.adfDetails.LinkedserviceDetails += Get-AzDataFactoryLinkedService -ResourceGroupName $this.ResourceContext.ResourceGroupName -DataFactoryName $this.ResourceContext.ResourceName;
        

        try{
        # Get pipelines count

             $pipelines = @();
             $pipelines += Get-AzDataFactoryPipeline -ResourceGroupName $this.ResourceContext.ResourceGroupName -DataFactoryName $this.ResourceContext.ResourceName;
             $this.adfDetails.PipelinesCount = ($pipelines | Measure-Object).Count;

       
             #Get Dataset count
             $datasets = @();
             $datasets += Get-AzDataFactoryDataset -ResourceGroupName $this.ResourceContext.ResourceGroupName -DataFactoryName $this.ResourceContext.ResourceName;
             $this.adfDetails.DatasetsCount +=  ($datasets | Measure-Object).Count;
        }
        catch{
            

        }
    
    }
}

Class ADFDetails{

[int]$PipelinesCount;  #default 0
[PSObject]$LinkedserviceDetails;
[int]$DatasetsCount;   # default 0

}