From 5742d94eb8b3b877436c5b01ec2f1b94edfdaced Mon Sep 17 00:00:00 2001 From: Frank Geisler Date: Mon, 25 Nov 2024 18:30:13 +0100 Subject: [PATCH] Worked on code quality --- powerrti/Public/Connect-RTIAccount.ps1 | 2 +- .../Public/Eventhouse/Get-RTIEventhouse.ps1 | 45 ++++++++++++------- .../Public/Eventhouse/New-RTIEventhouse.ps1 | 10 ++--- .../Eventhouse/Remove-RTIEventhouse.ps1 | 22 ++++----- .../Public/Eventhouse/Set-RtiEventhouse.ps1 | 20 ++++----- powerrti/Public/Invoke-RtiKQLCommand.ps1 | 16 +++---- .../Public/Workspace/New-RtiWorkspace.ps1 | 2 +- powerrti/powerrti.psd1 | 4 +- powerrti/powerrti.psm1 | 2 +- 9 files changed, 67 insertions(+), 56 deletions(-) diff --git a/powerrti/Public/Connect-RTIAccount.ps1 b/powerrti/Public/Connect-RTIAccount.ps1 index 0641e72..e67ad14 100644 --- a/powerrti/Public/Connect-RTIAccount.ps1 +++ b/powerrti/Public/Connect-RTIAccount.ps1 @@ -12,7 +12,7 @@ function Connect-RtiAccount { .PARAMETER TenantId The TenantId of the Azure Active Directory tenant you want to connect to and in which your Fabric Capacity is. - + .EXAMPLE Connect-RTIAccount ` -TenantID '12345678-1234-1234-1234-123456789012' diff --git a/powerrti/Public/Eventhouse/Get-RTIEventhouse.ps1 b/powerrti/Public/Eventhouse/Get-RTIEventhouse.ps1 index c0e53d7..85a8627 100644 --- a/powerrti/Public/Eventhouse/Get-RTIEventhouse.ps1 +++ b/powerrti/Public/Eventhouse/Get-RTIEventhouse.ps1 @@ -11,19 +11,19 @@ function Get-RtiEventhouse { parameters cannot be used together. .PARAMETER WorkspaceId - Id of the Fabric Workspace for which the Eventhouses should be retrieved. The value for WorkspaceId is a GUID. + Id of the Fabric Workspace for which the Eventhouses should be retrieved. The value for WorkspaceId is a GUID. An example of a GUID is '12345678-1234-1234-1234-123456789012'. .PARAMETER EventhouseName - The name of the Eventhouse to retrieve. This parameter cannot be used together with EventhouseID. + The name of the Eventhouse to retrieve. This parameter cannot be used together with EventhouseID. .PARAMETER EventhouseId - The Id of the Eventhouse to retrieve. This parameter cannot be used together with EventhouseName. The value for WorkspaceId is a GUID. + The Id of the Eventhouse to retrieve. This parameter cannot be used together with EventhouseName. The value for WorkspaceId is a GUID. An example of a GUID is '12345678-1234-1234-1234-123456789012'. .EXAMPLE Get-RTIEventhouse ` - -WorkspaceId '12345678-1234-1234-1234-123456789012' + -WorkspaceId '12345678-1234-1234-1234-123456789012' This example will give you all Eventhouses in the Workspace. @@ -39,18 +39,19 @@ function Get-RtiEventhouse { -WorkspaceId '12345678-1234-1234-1234-123456789012' ` -EventhouseId '12345678-1234-1234-1234-123456789012' - This example will give you all Information about the Eventhouse with the Id '12345678-1234-1234-1234-123456789012'. + This example will give you all Information about the Eventhouse with the Id '12345678-1234-1234-1234-123456789012'. .LINK https://learn.microsoft.com/en-us/rest/api/fabric/eventhouse/items/list-eventhouses?tabs=HTTP .NOTES - TODO: Add functionality to list all Eventhouses in the subscription. To do so fetch all workspaces + TODO: Add functionality to list all Eventhouses in the subscription. To do so fetch all workspaces and then all eventhouses in each workspace. Revsion History: - + - 2024-11-09 - FGE: Added DisplaName as Alias for EventhouseName + - 2024-11-16 - FGE: Added Verbose Output #> # @@ -69,34 +70,36 @@ function Get-RtiEventhouse { begin { - # Check if session is established - if not throw error + Write-Verbose "Checking if session is established. If not throw error" if ($null -eq $RTISession.headerParams) { throw "No session established to Fabric Real-Time Intelligence. Please run Connect-RTISession" } # You can either use Name or WorkspaceID + Write-Verbose "Checking if EventhouseName and EventhouseID are used together. This is not allowed" if ($PSBoundParameters.ContainsKey("EventhouseName") -and $PSBoundParameters.ContainsKey("EventhouseID")) { - throw "Parameters EventhouseName and EventhouseID cannot be used together" + throw "Parameters EventhouseName and EventhouseID cannot be used together" } # Create Eventhouse API - $eventhouseAPI = "$($RTISession.BaseFabricUrl)/v1/workspaces/$WorkspaceId/eventhouses" - - $eventhouseAPIEventhouseId = "$($RTISession.BaseFabricUrl)/v1/workspaces/$WorkspaceId/eventhouses/$EventhouseId" + $eventhouseAPI = "$($RTISession.BaseFabricUrl)/v1/workspaces/$WorkspaceId/eventhouses" + Write-Verbose "Creating the URL for the Eventhouse API: $eventhouseAPI" + $eventhouseAPIEventhouseId = "$($RTISession.BaseFabricUrl)/v1/workspaces/$WorkspaceId/eventhouses/$EventhouseId" + Write-Verbose "Creating the URL for the Eventhouse API when the Id is used: $eventhouseAPIEventhouseId" } process { if ($PSBoundParameters.ContainsKey("EventhouseId")) { - + Write-Verbose "Calling Eventhouse API with EventhouseId" $response = Invoke-RestMethod ` -Headers $RTISession.headerParams ` -Method GET ` -Uri $eventhouseAPIEventhouseId ` -ContentType "application/json" - # FGE: adding Members for convenience + Write-Verbose "Adding the member queryServiceUri" Add-Member ` -MemberType NoteProperty ` -Name 'queryServiceUri' ` @@ -104,6 +107,7 @@ process { -InputObject $response ` -Force + Write-Verbose "Adding the member ingestionServiceUri" Add-Member ` -MemberType NoteProperty ` -Name 'ingestionServiceUri' ` @@ -111,6 +115,7 @@ process { -InputObject $response ` -Force + Write-Verbose "Adding the member databasesItemIds" Add-Member ` -MemberType NoteProperty ` -Name 'databasesItemIds' ` @@ -118,17 +123,18 @@ process { -InputObject $response ` -Force + Write-Verbose "Adding the member minimumConsumptionUnits" Add-Member ` -MemberType NoteProperty ` -Name 'minimumConsumptionUnits' ` -Value $response.properties.minimumConsumptionUnits ` -InputObject $response ` -Force - + $response } else { - # Call Workspace API + Write-Verbose "Calling Eventhouse API without EventhouseId" $response = Invoke-RestMethod ` -Headers $RTISession.headerParams ` -Method GET ` @@ -136,7 +142,7 @@ process { -ContentType "application/json" foreach ($eventhouse in $response.value) { - # FGE: adding Members for convenience + Write-Verbose "Adding the member queryServiceUri" Add-Member ` -MemberType NoteProperty ` -Name 'queryServiceUri' ` @@ -144,6 +150,7 @@ process { -InputObject $eventhouse ` -Force + Write-Verbose "Adding the member ingestionServiceUri" Add-Member ` -MemberType NoteProperty ` -Name 'ingestionServiceUri' ` @@ -151,6 +158,7 @@ process { -InputObject $eventhouse ` -Force + Write-Verbose "Adding the member databasesItemIds" Add-Member ` -MemberType NoteProperty ` -Name 'databasesItemIds' ` @@ -158,6 +166,7 @@ process { -InputObject $eventhouse ` -Force + Write-Verbose "Adding the member minimumConsumptionUnits" Add-Member ` -MemberType NoteProperty ` -Name 'minimumConsumptionUnits' ` @@ -167,10 +176,12 @@ process { } if ($PSBoundParameters.ContainsKey("EventhouseName")) { + Write-Verbose "Filtering the Eventhouse by EventhouseName" $response.value | ` Where-Object { $_.displayName -eq $EventhouseName } } else { + Write-Verbose "Returning all Eventhouses" $response.value } } diff --git a/powerrti/Public/Eventhouse/New-RTIEventhouse.ps1 b/powerrti/Public/Eventhouse/New-RTIEventhouse.ps1 index 2438727..c5c367b 100644 --- a/powerrti/Public/Eventhouse/New-RTIEventhouse.ps1 +++ b/powerrti/Public/Eventhouse/New-RTIEventhouse.ps1 @@ -28,7 +28,7 @@ function New-RtiEventhouse { .NOTES Revsion History: - + - 2024-11-07 - FGE: Implemented SupportShouldProcess - 2024-11-09 - FGE: Added DisplaName as Alias for EventhouseName @@ -41,8 +41,8 @@ function New-RtiEventhouse { param ( [Parameter(Mandatory=$true)] - [string]$WorkspaceID, - + [string]$WorkspaceID, + [Parameter(Mandatory=$true)] [Alias("Name", "DisplayName")] [string]$EventhouseName, @@ -53,7 +53,7 @@ function New-RtiEventhouse { ) begin { - # Check if session is established - if not throw error + Write-Verbose "Checking if session is established. If not throw error" if ($null -eq $RTISession.headerParams) { throw "No session established to Fabric Real-Time Intelligence. Please run Connect-RTISession" } @@ -66,7 +66,7 @@ begin { -Depth 1 # Create Eventhouse API URL - $eventhouseApiUrl = "$($RTISession.BaseFabricUrl)/v1/workspaces/$WorkspaceId/eventhouses" + $eventhouseApiUrl = "$($RTISession.BaseFabricUrl)/v1/workspaces/$WorkspaceId/eventhouses" } process { diff --git a/powerrti/Public/Eventhouse/Remove-RTIEventhouse.ps1 b/powerrti/Public/Eventhouse/Remove-RTIEventhouse.ps1 index 1e4d135..493c299 100644 --- a/powerrti/Public/Eventhouse/Remove-RTIEventhouse.ps1 +++ b/powerrti/Public/Eventhouse/Remove-RTIEventhouse.ps1 @@ -9,11 +9,11 @@ function Remove-RtiEventhouse { Removes an existing Fabric Eventhouse .PARAMETER WorkspaceId - Id of the Fabric Workspace for which the Eventhouse should be deleted. The value for WorkspaceId is a GUID. + Id of the Fabric Workspace for which the Eventhouse should be deleted. The value for WorkspaceId is a GUID. An example of a GUID is '12345678-1234-1234-1234-123456789012'. .PARAMETER EventhouseId - The Id of the Eventhouse to delete. The value for EventhouseId is a GUID. + The Id of the Eventhouse to delete. The value for EventhouseId is a GUID. An example of a GUID is '12345678-1234-1234-1234-123456789012'. EventhouseId and EventhouseName cannot be used together. .PARAMETER EventhouseName @@ -23,20 +23,20 @@ function Remove-RtiEventhouse { Remove-RtiEventhouse ` -WorkspaceId '12345678-1234-1234-1234-123456789012' ` -EventhouseId '12345678-1234-1234-1234-123456789012' - - This example will delete the Eventhouse with the Id '12345678-1234-1234-1234-123456789012' from + + This example will delete the Eventhouse with the Id '12345678-1234-1234-1234-123456789012' from the Workspace with the Id '12345678-1234-1234-1234-123456789012'. .EXAMPLE Remove-RtiEventhouse ` -WorkspaceId '12345678-1234-1234-1234-123456789012' ` -EventhouseName 'MyEventhouse' - - This example will delete the Eventhouse with the name 'MyEventhouse' from the Workspace with the + + This example will delete the Eventhouse with the name 'MyEventhouse' from the Workspace with the Id '12345678-1234-1234-1234-123456789012'. .NOTES Revsion History: - + - 2024-11-07 - FGE: Implemented SupportShouldProcess - 2024-11-09 - FGE: Added DisplaName as Alias for EventhouseName @@ -48,8 +48,8 @@ function Remove-RtiEventhouse { param ( [Parameter(Mandatory=$true)] - [string]$WorkspaceId, - + [string]$WorkspaceId, + [Alias("Id")] [string]$EventhouseId, @@ -66,7 +66,7 @@ begin { # You can either use Name or WorkspaceID if ($PSBoundParameters.ContainsKey("EventhouseName") -and $PSBoundParameters.ContainsKey("EventhouseID")) { - throw "Parameters EventhouseName and EventhouseID cannot be used together" + throw "Parameters EventhouseName and EventhouseID cannot be used together" } if ($PSBoundParameters.ContainsKey("EventhouseName")) { @@ -78,7 +78,7 @@ begin { } # Create Eventhouse API URL - $eventhouseApiUrl = "$($RTISession.BaseFabricUrl)/v1/workspaces/$WorkspaceId/eventhouses/$EventhouseId" + $eventhouseApiUrl = "$($RTISession.BaseFabricUrl)/v1/workspaces/$WorkspaceId/eventhouses/$EventhouseId" } process { diff --git a/powerrti/Public/Eventhouse/Set-RtiEventhouse.ps1 b/powerrti/Public/Eventhouse/Set-RtiEventhouse.ps1 index a57e3b5..6909c92 100644 --- a/powerrti/Public/Eventhouse/Set-RtiEventhouse.ps1 +++ b/powerrti/Public/Eventhouse/Set-RtiEventhouse.ps1 @@ -9,11 +9,11 @@ function Set-RtiEventhouse { Updates Properties of an existing Fabric Eventhouse .PARAMETER WorkspaceId - Id of the Fabric Workspace for which the Eventhouse should be updated. The value for WorkspaceId is a GUID. + Id of the Fabric Workspace for which the Eventhouse should be updated. The value for WorkspaceId is a GUID. An example of a GUID is '12345678-1234-1234-1234-123456789012'. .PARAMETER EventhouseId - The Id of the Eventhouse to update. The value for EventhouseId is a GUID. + The Id of the Eventhouse to update. The value for EventhouseId is a GUID. An example of a GUID is '12345678-1234-1234-1234-123456789012'. .PARAMETER EventhouseNewName @@ -29,18 +29,18 @@ function Set-RtiEventhouse { -EventhouseNewName 'MyNewEventhouse' ` -EventhouseDescription 'This is my new Eventhouse' - This example will update the Eventhouse with the Id '12345678-1234-1234-1234-123456789012' + This example will update the Eventhouse with the Id '12345678-1234-1234-1234-123456789012' in the Workspace with the Id '12345678-1234-1234-1234-123456789012' to - have the name 'MyNewEventhouse' and the description + have the name 'MyNewEventhouse' and the description 'This is my new Eventhouse'. .NOTES TODO: Add functionality to update Eventhouse properties using EventhouseName instead of EventhouseId Revsion History: - + - 2024-11-07 - FGE: Implemented SupportShouldProcess - - 2024-11-09 - FGE: Added NewDisplaName as Alias for EventhouseName + - 2024-11-09 - FGE: Added NewDisplaName as Alias for EventhouseName .LINK https://learn.microsoft.com/en-us/rest/api/fabric/eventhouse/items/create-eventhouse?tabs=HTTP @@ -50,12 +50,12 @@ function Set-RtiEventhouse { param ( [Parameter(Mandatory=$true)] - [string]$WorkspaceId, + [string]$WorkspaceId, [Parameter(Mandatory=$true)] [Alias("Id")] - [string]$EventhouseId, - + [string]$EventhouseId, + [Alias("NewName", "NewDisplayName")] [string]$EventhouseNewName, @@ -87,7 +87,7 @@ begin { -Depth 1 # Create Eventhouse API URL - $eventhouseApiUrl = "$($RTISession.BaseFabricUrl)/v1/workspaces/$WorkspaceId/eventhouses/$EventhouseId" + $eventhouseApiUrl = "$($RTISession.BaseFabricUrl)/v1/workspaces/$WorkspaceId/eventhouses/$EventhouseId" } process { diff --git a/powerrti/Public/Invoke-RtiKQLCommand.ps1 b/powerrti/Public/Invoke-RtiKQLCommand.ps1 index 21c75d8..475ec91 100644 --- a/powerrti/Public/Invoke-RtiKQLCommand.ps1 +++ b/powerrti/Public/Invoke-RtiKQLCommand.ps1 @@ -7,23 +7,23 @@ function Invoke-RtiKQLCommand { .DESCRIPTION Executes a KQL command in a Kusto Database. The KQL command is executed in the Kusto Database - that is specified by the KQLDatabaseName or KQLDatabaseId parameter. The KQL command is executed - in the context of the Fabric Real-Time Intelligence session that is established by the + that is specified by the KQLDatabaseName or KQLDatabaseId parameter. The KQL command is executed + in the context of the Fabric Real-Time Intelligence session that is established by the Connect-RTISession cmdlet. .PARAMETER WorkspaceId - Id of the Fabric Workspace for which the KQL command should be executed. The value for WorkspaceId is a GUID. + Id of the Fabric Workspace for which the KQL command should be executed. The value for WorkspaceId is a GUID. An example of a GUID is '12345678-1234-1234-1234-123456789012'. .PARAMETER KQLDatabaseName The name of the KQLDatabase in which the KQL command should be executed. This parameter cannot be used together with KQLDatabaseId. .PARAMETER KQLDatabaseId - The Id of the KQLDatabase in which the KQL command should be executed. This parameter cannot be used together with KQLDatabaseName. + The Id of the KQLDatabase in which the KQL command should be executed. This parameter cannot be used together with KQLDatabaseName. The value for KQLDatabaseId is a GUID. An example of a GUID is '12345678-1234-1234-1234-123456789012'. .PARAMETER KQLCommand - The KQL command that should be executed in the Kusto Database. + The KQL command that should be executed in the Kusto Database. The KQL command is a string. An example of a string is '.create table MyTable (MyColumn: string)'. .EXAMPLE @@ -32,7 +32,7 @@ function Invoke-RtiKQLCommand { -KQLDatabaseName 'MyKQLDatabase' ` -KQLCommand '.create table MyTable (MyColumn: string)' - This example will create a table named 'MyTable' with a column named 'MyColumn' in + This example will create a table named 'MyTable' with a column named 'MyColumn' in the KQLDatabase 'MyKQLDatabase'. #> @@ -57,7 +57,7 @@ begin { } if ($PSBoundParameters.ContainsKey("KQLDatabaseName") -and $PSBoundParameters.ContainsKey("KQLDatabaseId")) { - throw "Parameters KQLDatabaseName and KQLDatabaseId cannot be used together" + throw "Parameters KQLDatabaseName and KQLDatabaseId cannot be used together" } # FGE: Get Kusto Database @@ -93,7 +93,7 @@ process { $KQLCommand = $KQLCommand | Out-String # FGE: It is crucial to have the .execute database script <| in the beginning, otherwise - # the Kusto API will not execute the script. + # the Kusto API will not execute the script. if (-not ($KQLCommand -match "\.execute database script <\|")) { $KQLCommand = ".execute database script <| $KQLCommand" } diff --git a/powerrti/Public/Workspace/New-RtiWorkspace.ps1 b/powerrti/Public/Workspace/New-RtiWorkspace.ps1 index cace565..cfc82ff 100644 --- a/powerrti/Public/Workspace/New-RtiWorkspace.ps1 +++ b/powerrti/Public/Workspace/New-RtiWorkspace.ps1 @@ -60,7 +60,7 @@ begin { -Depth 1 # Create Workspace API URL - $WorkspaceApiUrl = "$($RTISession.BaseFabricUrl)/v1/workspaces" + $WorkspaceApiUrl = "$($RTISession.BaseFabricUrl)/v1/workspaces" } process { diff --git a/powerrti/powerrti.psd1 b/powerrti/powerrti.psd1 index bb9d177..a4d501c 100644 --- a/powerrti/powerrti.psd1 +++ b/powerrti/powerrti.psd1 @@ -74,7 +74,7 @@ PowerShellVersion = '7.1' # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @( 'Connect-RtiAccount', - 'Get-RtiEventhouse', + 'Get-RtiEventhouse', 'Get-RtiEventstream', 'Get-RtiKQLDashboard', 'Get-RtiKQLDatabase', @@ -85,7 +85,7 @@ CmdletsToExport = @( 'New-RtiEventstream', 'New-RtiKQLDashboard', 'New-RtiKQLDatabase', - 'New-RtiWorkspace', + 'New-RtiWorkspace', 'Remove-RtiEventhouse', 'Remove-RtiEventstream', 'Remove-RtiKQLDatabase', diff --git a/powerrti/powerrti.psm1 b/powerrti/powerrti.psm1 index 8e1a6cc..56cc537 100644 --- a/powerrti/powerrti.psm1 +++ b/powerrti/powerrti.psm1 @@ -1,6 +1,6 @@ <# .DESCRIPTION -Powershell Modul that provides cmdlets to interact with the Real-Time Intelligence API +Powershell Modul that provides cmdlets to interact with the Real-Time Intelligence API of Microsoft Fabric. #> $scriptRoot = $PSScriptRoot + '\Public'