diff --git a/.github/copilot-commit-message-instructions.md b/.github/copilot-commit-message-instructions.md index 57e25aea..3309bf16 100644 --- a/.github/copilot-commit-message-instructions.md +++ b/.github/copilot-commit-message-instructions.md @@ -3,6 +3,6 @@ Capitalize the subject/description line Do not end the subject line with a period Separate the subject from the body with a blank line Use the imperative mood in the subject line -The subject line should be a single sentence with an action word and target with some reasoning add "for Pester Help Tests" +The subject line should be a single sentence with an action word and a target with some reasoning for the change Use the body to explain what and why in a friendly kind manner Say thank you at the end of the message diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 94b9d25a..8e8e29df 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -67,7 +67,7 @@ jobs: if: success() || failure() Test_Stage_test_windows_core: name: Windows (PowerShell) - runs-on: windows-2019 + runs-on: windows-latest needs: - Build_Stage_Package_Module steps: @@ -94,7 +94,7 @@ jobs: if: success() || failure() Test_Stage_test_windows_ps: name: Windows (Windows PowerShell) - runs-on: windows-2019 + runs-on: windows-latest needs: - Build_Stage_Package_Module steps: diff --git a/.vscode/settings.json b/.vscode/settings.json index 7770c550..b1a8d0c2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,18 +20,19 @@ "*.ps1xml": "xml" }, "cSpell.words": [ - "COMPANYNAME", - "ICONURI", - "LICENSEURI", - "PROJECTURI", - "RELEASENOTES", + "Balabuch", "buildhelpers", + "COMPANYNAME", "endregion", "gitversion", "icontains", + "ICONURI", "keepachangelog", + "LICENSEURI", "notin", + "PROJECTURI", "pscmdlet", + "RELEASENOTES", "steppable" ], "[markdown]": { diff --git a/CHANGELOG.md b/CHANGELOG.md index 304b9985..fb029a8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed unnecessary or duplicate functions (e.g., `Get-AllFabricDatasetRefreshes`, `Get-AllFabricCapacities`). - Removed obsolete scripts and commented-out configuration paths. +- Removed `Invoke-FabricAPIRequest` and replaced it by `Invoke-FabricRestMethodExtended` +- Removed `Confirm-FabricAuthToken` +- Renamed `Test-TokenExpired` to `Confirm-TokenState` and extended it using `EnableTokenRefresh` Feature Flag +- Removed `Set-FabricApiHeaders` and merged the entire logic to `Connect-FabricAccount` ### Security diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7884d664..c26620c8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,9 +32,9 @@ The workflow for using this and developing the code is shown below. Install-Module Microsoft.PowerShell.PSResourceGet -Force ``` -3. Develop your updates in the source directory +3. Start a fresh new PowerShell session to avoid anythjing from your current working sessions to interfere with the module development and building. Develop your updates in the source directory. - You should also resolve all dependencies before you start developing. This will ensure that you have all the required modules installed and loaded into your session. +You should also resolve all dependencies before you start developing. This will ensure that you have all the required modules, and only them, installed and loaded into your session. ```PowerShell .\build.ps1 -ResolveDependency -Tasks noop -UsePSResourceGet @@ -83,7 +83,11 @@ The workflow for using this and developing the code is shown below. ```PowerShell ./build.ps1 -Tasks build,test ``` -8. Once you are ready to submit your changes for review please ensure that you update the `CHANGELOG.md` file with a summary of your changes. This is important as it helps us keep track of what has changed in the module and makes it easier for users to see what has been added or changed. + This will run all the tests in the `tests` folder and output the results to the console. If there are any issues with the code, they will be reported here. + +8. It is always a good idea to develop in a brand new clean session and also once you have finished your changes, you should open a new session, build the module and run a few commands to ensure that everything is working as expected. This will help you catch any issues that may have been introduced during development and also make sure that you have not missed any dependancies. + +9. Once you are ready to submit your changes for review please ensure that you update the `CHANGELOG.md` file with a summary of your changes. This is important as it helps us keep track of what has changed in the module and makes it easier for users to see what has been added or changed. You can use the [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format for this. diff --git a/README.md b/README.md index 212ccef8..cf96d006 100644 --- a/README.md +++ b/README.md @@ -66,12 +66,12 @@ Refer to the individual function documentation for detailed usage instructions. Every now and again the authentication token might time out. Run this to get a new one: ```powershell -Set-FabricAuthToken +Update-FabricToken ``` If you want to change user context run this: ```powershell -Set-FabricAuthToken -reset +Connect-FabricAccount ``` @@ -89,10 +89,14 @@ Contributions to FabricTools are welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to develop, test and the process for submitting pull requests to us. ## Authors +_(in alphabetical order)_ +- **Tiago Balabuch** - *Huge contribution (90% functions)* - [tiagobalabuch](https://github.com/tiagobalabuch) - **Ioana Bouariu** - *Initial work* - [Jojobit](https://github.com/Jojobit) - **Frank Geisler** - *Author of RTI functions* - [Frank Geisler](https://github.com/Frank-Geisler) - **Kamil Nowinski** - *Refactoring, unification, further commands* - [NowinskiK](https://github.com/NowinskiK) +- **Jess Pomfret** - *Automation, great experience with PowerShell* - [jpomfret](https://github.com/jpomfret) +- **Rob Sewell** - *Automation/DevOps, Governance and experience brought from dbatools* - [SQLDBAWithABeard](https://github.com/SQLDBAWithABeard) See also the list of [contributors](https://github.com/dataplat/FabricTools/contributors) who participated in this project. @@ -103,4 +107,5 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file ## Acknowledgments - GitHub Copilot and ChatGPT for helping with the documentation -- [**Rui Romano**](https://github.com/RuiRomano) - His work on a [Fabric PowerShell module](https://github.com/RuiRomano/fabricps-pbip) has been included into this module with his permission. Thanks, Rui! +- [**Rui Romano**](https://github.com/RuiRomano) - His work on a [Fabric PowerShell module](https://github.com/microsoft/Analysis-Services/tree/master/pbidevmode/fabricps-pbip) has been included into this module with his permission. Thanks, Rui! +- [**Tiago Balabuch**](https://github.com/tiagobalabuch) and his phenomenal huge work that make this module more robust and very well organised. diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index adef59f5..b3783f10 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -21,7 +21,7 @@ 'Sampler.GitHubTasks' = 'latest' MarkdownLinkCheck = 'latest' PSFramework = 'latest' - 'Az.Accounts' = '4.2.0' - 'Az.Resources' = '6.15.1' - 'MicrosoftPowerBIMgmt' = '1.2.1111' + 'Az.Accounts' = '5.0.0' + 'Az.Resources' = '6.15.1' + 'MicrosoftPowerBIMgmt' = '1.2.1111' } diff --git a/build.yaml b/build.yaml index 470eaafc..f6069d26 100644 --- a/build.yaml +++ b/build.yaml @@ -104,7 +104,7 @@ Pester: # - FunctionalQuality # - TestQuality Tag: - CodeCoverageThreshold: 0.35 # 85 # Set to 0 to bypass + CodeCoverageThreshold: 0.30 # 85 # Set to 0 to bypass #CodeCoverageOutputFile: JaCoCo_$OsShortName.xml #CodeCoverageOutputFileEncoding: ascii # Use this if code coverage should be merged from several pipeline test jobs. @@ -157,4 +157,3 @@ ChangelogConfig: GitConfig: UserName: Automation Bot UserEmail: automation_bot@fabrictools.io - diff --git a/helper/GetFunctionList.ps1 b/helper/GetFunctionList.ps1 index fc9d5e26..dbad9e0a 100644 --- a/helper/GetFunctionList.ps1 +++ b/helper/GetFunctionList.ps1 @@ -1,12 +1,25 @@ -$path = ".\FabricTools\public" +$path = ".\source\public" $op = Get-ChildItem -Path $path -Recurse -Filter *.ps1 | Select-Object -ExpandProperty Name | Sort-Object #$op = $op | ForEach-Object { " ""$_""," } $op | Out-File '.\Output\FunctionList-main-public.txt' -$path = ".\FabricTools\tiago\public" -$tp = Get-ChildItem -Path $path -Recurse -Filter *.ps1 | Select-Object -ExpandProperty Name | Sort-Object -$tp | Out-File '.\Output\FunctionList-tiago-public.txt' +# Author Table +# This script generates a table of PowerShell script authors from the specified directory. +$authorTable = @{} +$op | ForEach-Object { + $file = $_.FullName + $name = $_.Name + $content = Get-Content $file + $authorLine = $content | Where-Object { $_ -match 'Author:\s*(.+)' } | Select-Object -First 1 + if ($authorLine -match 'Author:\s*(.+)') { + $author = $matches[1].Trim() + $authorTable[$name] = $author + } else { + $authorTable[$name] = $null + } +} +$authorTable -$common = Compare-Object -ReferenceObject $op -DifferenceObject $tp -IncludeEqual -ExcludeDifferent | Select-Object -ExpandProperty InputObject -$common -$common | Out-File '.\Output\FunctionList-public-collision.txt' +## Not a singular name option for functions (#26) +Get-Command -Module FabricTools |where Name -like '*s' +Get-Command -Module FabricTools|ForEach-Object { $name = $_.Name; $_.Parameters.Values | Where Name -like '*s' | Select @{N='FunctionName';E={$Name}},Name} diff --git a/source/FabricTools.psd1 b/source/FabricTools.psd1 index a9986bde..deafe24d 100644 --- a/source/FabricTools.psd1 +++ b/source/FabricTools.psd1 @@ -18,13 +18,12 @@ ModuleVersion = '0.0.1' # CompatiblePSEditions = @() # ID used to uniquely identify this module -GUID = '0ba3e49a-b47e-4beb-8434-5a34ad41ae72' +GUID = 'f2a0f9e6-fab6-41fc-9e1c-0c94ff38f794' # Author of this module Author = 'The FabricTools Team' -# Company or vendor of this module - CompanyName = 'fabrictools.io' +CompanyName = 'fabrictools.io' # Copyright statement for this module Copyright = 'Copyright (c) 2025 by FabricTools Team' @@ -56,7 +55,7 @@ PowerShellVersion = '5.1' # Modules that must be imported into the global environment prior to importing this module RequiredModules = @( - @{ ModuleName = 'Az.Accounts' ; ModuleVersion = '4.2.0' }, + @{ ModuleName = 'Az.Accounts' ; ModuleVersion = '5.0.0' }, @{ ModuleName = 'MicrosoftPowerBIMgmt.Profile' ; ModuleVersion = '1.2.1111' }, @{ ModuleName = 'Az.Resources' ; ModuleVersion = '6.15.1' } ) @@ -131,10 +130,9 @@ PrivateData = @{ } # End of PrivateData hashtable # HelpInfo URI of this module -# HelpInfoURI = '' +HelpInfoURI = 'https://www.github.com/dataplat/FabricTools' # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. # DefaultCommandPrefix = '' } - diff --git a/source/Private/Test-TokenExpired.ps1 b/source/Private/Confirm-TokenState.ps1 similarity index 57% rename from source/Private/Test-TokenExpired.ps1 rename to source/Private/Confirm-TokenState.ps1 index f1cfa57d..d8a55e84 100644 --- a/source/Private/Test-TokenExpired.ps1 +++ b/source/Private/Confirm-TokenState.ps1 @@ -3,38 +3,34 @@ Checks if the Fabric token is expired and logs appropriate messages. .DESCRIPTION -The `Test-TokenExpired` function checks the expiration status of the Fabric token stored in the `$FabricConfig.TokenExpiresOn` variable. +The `Confirm-TokenState` function checks the expiration status of the Fabric token stored in the `$FabricConfig.TokenExpiresOn` variable. If the token is expired, it logs an error message and provides guidance for refreshing the token. Otherwise, it logs that the token is still valid. -.PARAMETER FabricConfig -The configuration object containing the token expiration details. - .EXAMPLE -Test-TokenExpired -FabricConfig $config +Confirm-TokenState -Checks the token expiration status using the provided `$config` object. +Checks the token expiration status using session's `$FabricConfig` object. .NOTES - Ensure the `FabricConfig` object includes a valid `TokenExpiresOn` property of type `DateTimeOffset`. - Requires the `Write-Message` function for logging. +- Uses EnableTokenRefresh feature flag to determine if the token should be refreshed automatically. .AUTHOR Tiago Balabuch #> -function Test-TokenExpired { +function Confirm-TokenState { [CmdletBinding()] param () - Confirm-FabricAuthToken | Out-Null - - Write-Message -Message "Validating token..." -Level Debug + Write-Message -Message "Validating token..." -Level Verbose try { # Ensure required properties have valid values - if ([string]::IsNullOrWhiteSpace($FabricConfig.TenantIdGlobal) -or + if ([string]::IsNullOrWhiteSpace($FabricConfig.TenantId) -or [string]::IsNullOrWhiteSpace($FabricConfig.TokenExpiresOn)) { - Write-Message -Message "Token details are missing. Please run 'Set-FabricApiHeaders' to configure them." -Level Error + Write-Message -Message "Token details are missing. Please run 'Connect-FabricAccount' to configure the session." -Level Error throw "MissingTokenDetailsException: Token details are missing." } @@ -47,13 +43,18 @@ function Test-TokenExpired { # Check if the token is expired if ($tokenExpiryDate -le [datetimeoffset]::Now) { - Write-Message -Message "Your authentication token has expired. Please sign in again to refresh your session." -Level Warning - #throw "TokenExpiredException: Token has expired." - #Set-FabricApiHeaders -tenantId $FabricConfig.TenantIdGlobal + if ($FabricConfig.FeatureFlags.EnableTokenRefresh) { + Write-Message -Message "Token has expired. Attempting to refresh the token..." -Level Warning + Connect-FabricAccount -reset + } else { + Write-Message -Message "Token has expired and automatic refresh is disabled. Please sign in again using 'Connect-FabricAccount'." -Level Error + throw "TokenExpiredException: Token has expired." + } + } + else { + # Log valid token status + Write-Message -Message "Token is still valid. Expiry time: $($tokenExpiryDate.ToString("u"))" -Level Debug } - - # Log valid token status - Write-Message -Message "Token is still valid. Expiry time: $($tokenExpiryDate.ToString("u"))" -Level Debug } catch [System.FormatException] { Write-Message -Message "Invalid 'TokenExpiresOn' format in the FabricConfig object. Ensure it is a valid datetime string." -Level Error throw "FormatException: Invalid TokenExpiresOn value." @@ -62,5 +63,5 @@ function Test-TokenExpired { Write-Message -Message "An unexpected error occurred: $_" -Level Error throw $_ } - Write-Message -Message "Token validation completed." -Level Debug + Write-Message -Message "Token validation completed." -Level Verbose } diff --git a/source/Private/Set-FabConfig.ps1 b/source/Private/Set-FabConfig.ps1 index 56429327..0324c742 100644 --- a/source/Private/Set-FabConfig.ps1 +++ b/source/Private/Set-FabConfig.ps1 @@ -4,7 +4,6 @@ $script:FabricSession = [ordered]@{ BaseApiUrl = 'https://api.fabric.microsoft.com/v1' ResourceUrl = 'https://api.fabric.microsoft.com' - FabricToken = $null HeaderParams = $null ContentType = @{'Content-Type' = "application/json" } KustoURL = "https://api.kusto.windows.net" @@ -14,7 +13,6 @@ $script:FabricSession = [ordered]@{ $script:AzureSession = [ordered]@{ BaseApiUrl = "https://management.azure.com" AccessToken = $null - Token = $null HeaderParams = $null } @@ -22,16 +20,13 @@ $script:PowerBI = [ordered]@{ BaseApiUrl = "https://api.powerbi.com/v1.0/myorg" } -$FabricTools = @{ - FeatureFlags = @{ - AutoRenewExpiredToken = $true - } -} - $FabricConfig = @{ BaseUrl = "https://api.fabric.microsoft.com/v1" ResourceUrl = "https://api.fabric.microsoft.com" FabricHeaders = @{} - TenantIdGlobal = "" + TenantId = "" TokenExpiresOn = "" + FeatureFlags = @{ + EnableTokenRefresh = $true + } } diff --git a/source/Public/Capacity/Get-FabricCapacities.ps1 b/source/Public/Capacity/Get-FabricCapacities.ps1 index 58daebb7..97c87246 100644 --- a/source/Public/Capacity/Get-FabricCapacities.ps1 +++ b/source/Public/Capacity/Get-FabricCapacities.ps1 @@ -34,7 +34,7 @@ function Get-FabricCapacities { # Initialize an array to store the results $res = @() - Get-FabricAuthToken | Out-Null + Confirm-TokenState # If a subscription ID is provided if ($subscriptionID) { @@ -72,4 +72,3 @@ function Get-FabricCapacities { # Return the results return $res } - diff --git a/source/Public/Capacity/Get-FabricCapacity.ps1 b/source/Public/Capacity/Get-FabricCapacity.ps1 index 8f563083..7879a36e 100644 --- a/source/Public/Capacity/Get-FabricCapacity.ps1 +++ b/source/Public/Capacity/Get-FabricCapacity.ps1 @@ -23,7 +23,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -46,9 +46,7 @@ function Get-FabricCapacity { } # Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Construct the API endpoint URL $apiEndpointURI = "capacities" @@ -58,7 +56,7 @@ function Get-FabricCapacity { Uri = $apiEndpointURI Method = 'Get' } - $capacities = (Invoke-FabricAPIRequest @apiParams).Value + $capacities = (Invoke-FabricRestMethod @apiParams).Value # Filter results based on provided parameters $response = if ($capacityId) { diff --git a/source/Public/Capacity/Get-FabricCapacityRefreshables.ps1 b/source/Public/Capacity/Get-FabricCapacityRefreshables.ps1 index 49888dea..6b244006 100644 --- a/source/Public/Capacity/Get-FabricCapacityRefreshables.ps1 +++ b/source/Public/Capacity/Get-FabricCapacityRefreshables.ps1 @@ -28,9 +28,9 @@ The function retrieves the PowerBI access token and makes a GET request to the P [string]$top = 5 ) - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState # Make a GET request to the PowerBI API to retrieve the top refreshable capacities. # The function returns the 'value' property of the response. return (Invoke-RestMethod -uri "$($PowerBI.BaseApiUrl)/capacities/refreshables?`$top=$top" -Headers $FabricSession.HeaderParams -Method GET).value -} \ No newline at end of file +} diff --git a/source/Public/Capacity/Get-FabricCapacitySkus.ps1 b/source/Public/Capacity/Get-FabricCapacitySkus.ps1 index 713f4ae7..d0301655 100644 --- a/source/Public/Capacity/Get-FabricCapacitySkus.ps1 +++ b/source/Public/Capacity/Get-FabricCapacitySkus.ps1 @@ -31,7 +31,7 @@ Retrieves the fabric capacity information for the specified capacity. [string]$capacity ) - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState #GET https://management.azure.com/subscriptions/548B7FB7-3B2A-4F46-BB02-66473F1FC22C/resourceGroups/TestRG/providers/Microsoft.Fabric/capacities/azsdktest/skus?api-version=2023-11-01 $uri = "$($AzureSession.BaseApiUrl)/subscriptions/$subscriptionID/resourceGroups/$ResourceGroupName/providers/Microsoft.Fabric/capacities/$capacity/skus?api-version=2023-11-01" @@ -39,4 +39,4 @@ Retrieves the fabric capacity information for the specified capacity. return $result.value -} \ No newline at end of file +} diff --git a/source/Public/Capacity/Get-FabricCapacityState.ps1 b/source/Public/Capacity/Get-FabricCapacityState.ps1 index 4f779b34..2c79e8df 100644 --- a/source/Public/Capacity/Get-FabricCapacityState.ps1 +++ b/source/Public/Capacity/Get-FabricCapacityState.ps1 @@ -38,11 +38,11 @@ The function checks if the Azure token is null. If it is, it connects to the Azu [string]$capacity ) - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState # Define the URL for the GET request. $getCapacityState = "$($AzureSession.BaseApiUrl)/subscriptions/$subscriptionID/resourceGroups/$resourcegroup/providers/Microsoft.Fabric/capacities/$capacity/?api-version=2022-07-01-preview" # Make the GET request and return the response. return Invoke-RestMethod -Method GET -Uri $getCapacityState -Headers $script:AzureSession.HeaderParams -ErrorAction Stop -} \ No newline at end of file +} diff --git a/source/Public/Capacity/Get-FabricCapacityTenantOverrides.ps1 b/source/Public/Capacity/Get-FabricCapacityTenantOverrides.ps1 index 311ada92..7cd299fc 100644 --- a/source/Public/Capacity/Get-FabricCapacityTenantOverrides.ps1 +++ b/source/Public/Capacity/Get-FabricCapacityTenantOverrides.ps1 @@ -6,9 +6,6 @@ Retrieves the tenant overrides for all capacities. .DESCRIPTION The Get-FabricCapacityTenantOverrides function retrieves the tenant overrides for all capacities. It supports multiple aliases for flexibility. -.PARAMETER authToken -The authentication token used to authorize the request. If not provided, the function will retrieve the token using the Get-FabricAuthToken function. - .EXAMPLE Get-FabricCapacityTenantOverrides @@ -25,9 +22,9 @@ The function retrieves the PowerBI access token and makes a GET request to the F Param ( ) - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState # Make a GET request to the Fabric API to retrieve the tenant overrides for all capacities. # The function returns the response of the GET request. return Invoke-RestMethod -uri "$($FabricSession.BaseApiUrl)/admin/capacities/delegatedTenantSettingOverrides" -Headers $FabricSession.HeaderParams -Method GET -} \ No newline at end of file +} diff --git a/source/Public/Capacity/Get-FabricCapacityWorkload.ps1 b/source/Public/Capacity/Get-FabricCapacityWorkload.ps1 index 92cacceb..2a8dee78 100644 --- a/source/Public/Capacity/Get-FabricCapacityWorkload.ps1 +++ b/source/Public/Capacity/Get-FabricCapacityWorkload.ps1 @@ -9,11 +9,8 @@ The Get-FabricCapacityWorkload function retrieves the workloads for a specific c .PARAMETER capacityID The ID of the capacity. This is a mandatory parameter. -.PARAMETER authToken -The authentication token to access the PowerBI API. If not provided, the function will retrieve the token using the Get-FabricAuthToken function. - .EXAMPLE -Get-FabricCapacityWorkload -capacityID "your-capacity-id" -authToken "your-auth-token" +Get-FabricCapacityWorkload -capacityID "your-capacity-id" This example retrieves the workloads for a specific capacity given the capacity ID and authentication token. @@ -31,7 +28,7 @@ The function retrieves the PowerBI access token and makes a GET request to the P [string]$capacityID ) - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState # Make a GET request to the PowerBI API to retrieve the workloads for the specified capacity. # The function returns the 'value' property of the response. @@ -39,4 +36,4 @@ The function retrieves the PowerBI access token and makes a GET request to the P } -#https://learn.microsoft.com/en-us/rest/api/power-bi/capacities/get-workloads \ No newline at end of file +#https://learn.microsoft.com/en-us/rest/api/power-bi/capacities/get-workloads diff --git a/source/Public/Capacity/Resume-FabricCapacity.ps1 b/source/Public/Capacity/Resume-FabricCapacity.ps1 index a1ee73ab..716d525a 100644 --- a/source/Public/Capacity/Resume-FabricCapacity.ps1 +++ b/source/Public/Capacity/Resume-FabricCapacity.ps1 @@ -40,7 +40,7 @@ The function defines parameters for the subscription ID, resource group, and cap [string]$capacity ) - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState # Define the URI for the request. $resumeCapacity = "$($AzureSession.BaseApiUrl)/subscriptions/$subscriptionID/resourceGroups/$resourcegroup/providers/Microsoft.Fabric/capacities/$capacity/resume?api-version=2022-07-01-preview" @@ -49,4 +49,4 @@ The function defines parameters for the subscription ID, resource group, and cap if ($PSCmdlet.ShouldProcess("Resume capacity $capacity")) { return Invoke-RestMethod -Method POST -Uri $resumeCapacity -Headers $script:AzureSession.HeaderParams -ErrorAction Stop } -} \ No newline at end of file +} diff --git a/source/Public/Capacity/Suspend-FabricCapacity.ps1 b/source/Public/Capacity/Suspend-FabricCapacity.ps1 index 7461bf5a..40c04ba1 100644 --- a/source/Public/Capacity/Suspend-FabricCapacity.ps1 +++ b/source/Public/Capacity/Suspend-FabricCapacity.ps1 @@ -39,7 +39,7 @@ The function defines parameters for the subscription ID, resource group, and cap [string]$capacity ) - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState # Define the URI for the request. $suspendCapacity = "$($AzureSession.BaseApiUrl)/subscriptions/$subscriptionID/resourceGroups/$resourcegroup/providers/Microsoft.Fabric/capacities/$capacity/suspend?api-version=2023-11-01" @@ -49,4 +49,4 @@ The function defines parameters for the subscription ID, resource group, and cap return Invoke-RestMethod -Method POST -Uri $suspendCapacity -Headers $script:AzureSession.HeaderParams -ErrorAction Stop } -} \ No newline at end of file +} diff --git a/source/Public/Confirm-FabricAuthToken.ps1 b/source/Public/Confirm-FabricAuthToken.ps1 deleted file mode 100644 index 7400251c..00000000 --- a/source/Public/Confirm-FabricAuthToken.ps1 +++ /dev/null @@ -1,50 +0,0 @@ -<# -.SYNOPSIS - Check whether the Fabric API authentication token is set and not expired and reset it if necessary. - -.DESCRIPTION - The Confirm-FabricAuthToken function retrieves the Fabric API authentication token. If the token is not already set, it calls the Set-FabricAuthToken function to set it. It then outputs the token. - -.EXAMPLE - Confirm-FabricAuthToken - - This command retrieves the Fabric API authentication token. - -.INPUTS - None. You cannot pipe inputs to this function. - -.OUTPUTS - Returns object as Get-FabricDebugInfo function - -.NOTES - -#> - -function Confirm-FabricAuthToken { - [CmdletBinding()] - param ( ) - - Write-Verbose "Check if session is established and token not expired." - - # Check if the Fabric token is already set - if (!$FabricSession.FabricToken -or !$AzureSession.AccessToken) { - Write-Output "Confirm-FabricAuthToken::Set-FabricAuthToken" - Set-FabricAuthToken | Out-Null - } - - $now = (Get-Date) - $s = Get-FabricDebugInfo - if ($FabricSession.AccessToken.ExpiresOn -lt $now ) { - Write-Output "Confirm-FabricAuthToken::Set-FabricAuthToken#1" - Set-FabricAuthToken -reset | Out-Null - } - - if ($s.AzureSession.AccessToken.ExpiresOn -lt $now ) { - Write-Output "Confirm-FabricAuthToken::Set-FabricAuthToken#2" - Set-FabricAuthToken -reset | Out-Null - } - - $s = Get-FabricDebugInfo - return $s - -} diff --git a/source/Public/Connect-FabricAccount.ps1 b/source/Public/Connect-FabricAccount.ps1 index 9ffde278..c24c520e 100644 --- a/source/Public/Connect-FabricAccount.ps1 +++ b/source/Public/Connect-FabricAccount.ps1 @@ -19,6 +19,9 @@ function Connect-FabricAccount { .PARAMETER Credential A PSCredential object representing a user credential (username and secure password). +.PARAMETER Reset + A switch parameter. If provided, the function resets the Fabric authentication token. + .EXAMPLE Connect-FabricAccount -TenantId '12345678-1234-1234-1234-123456789012' @@ -35,12 +38,16 @@ function Connect-FabricAccount { Connects as Service Principal using id and secret +.OUTPUTS + None. This function does not return any output. + .NOTES - Revsion History: + Revision History: - 2024-12-22 - FGE: Added Verbose Output - 2025-05-26 - Jojobit: Added Service Principal support, with secure string handling and parameter descriptions, as supported by the original FabTools module + - 2025-06-02 - KNO: Added Reset switch to force re-authentication and token refresh .LINK Connect-AzAccount https://learn.microsoft.com/de-de/powershell/module/az.accounts/connect-azaccount?view=azps-12.4.0 @@ -49,51 +56,89 @@ function Connect-FabricAccount { [CmdletBinding(SupportsShouldProcess)] param ( [Parameter(Mandatory = $false, HelpMessage = "Azure AD Tenant ID.")] - [string]$tenantId, + [string] $TenantId, [Parameter(Mandatory = $false, HelpMessage = "AppId of the service principal.")] - [string]$servicePrincipalId, + [Alias('AppId')] + [string] $ServicePrincipalId, [Parameter(Mandatory = $false, HelpMessage = "Secure secret of the service principal.")] - [SecureString]$servicePrincipalSecret, + [Alias('AppSecret')] + [SecureString] $ServicePrincipalSecret, [Parameter(Mandatory = $false, HelpMessage = "User credential.")] - [PSCredential]$credential + [PSCredential] $Credential, + + [Parameter(Mandatory = $false, HelpMessage = "Refresh current session.")] + [switch] $Reset ) begin { + # Checks if 'AppId' is provided without 'AppSecret' and vice versa. + if ($PSBoundParameters.ContainsKey('AppId') -and -not $PSBoundParameters.ContainsKey('AppSecret')) + { + Write-Message -Message "AppSecret is required when using AppId: $AppId" -Level Error + throw "AppSecret is required when using AppId." + } + if ($PSBoundParameters.ContainsKey('AppSecret') -and -not $PSBoundParameters.ContainsKey('AppId')) + { + Write-Message -Message "AppId is required when using AppSecret." -Level Error + throw "AppId is required when using AppId." + } } process { - Write-Verbose "Connect to Azure Account" - - if ($servicePrincipalId) { - $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $servicePrincipalId, $servicePrincipalSecret - $null = Connect-AzAccount -ServicePrincipal -TenantId $tenantId -Credential $credential - } - elseif ($null -ne $credential) { - $null = Connect-AzAccount -Credential $credential -Tenant $tenantId + if (!$Reset) + { + $azContext = Get-AzContext } - else { - $null = Connect-AzAccount + if (!$azContext) { + if ($ServicePrincipalId) { + Write-Message "Connecting to Azure Account using provided servicePrincipalId..." -Level Verbose + $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ServicePrincipalId, $ServicePrincipalSecret + $null = Connect-AzAccount -ServicePrincipal -TenantId $TenantId -Credential $credential + } + elseif ($null -ne $Credential) { + Write-Message "Connecting to Azure Account using provided credential..." -Level Verbose + $null = Connect-AzAccount -Credential $Credential -Tenant $TenantId + } + else { + Write-Message "Connecting to Azure Account using current user..." -Level Verbose + if ($TenantId) { + $null = Connect-AzAccount -Tenant $TenantId + } + else { + # If no TenantId is provided, connect to the default tenant + Write-Message "No TenantId provided, connecting to default tenant..." -Level Verbose + $null = Connect-AzAccount + } + } + $azContext = Get-AzContext } - $azContext = Get-AzContext - - Write-Verbose "Connected: $($azContext.Account)" + Write-Message "Connected: $($azContext.Account)" -Level Verbose - if ($PSCmdlet.ShouldProcess("Setting Fabric authentication token for $($azContext.Account)")) { + if ($PSCmdlet.ShouldProcess("Setting Fabric authentication token and headers for $($azContext.Account)")) { + Write-Message "Get authentication token from $($FabricSession.ResourceUrl)" -Level Verbose + $FabricSession.AccessToken = (Get-AzAccessToken -ResourceUrl $FabricSession.ResourceUrl) + $plainTextToken = $FabricSession.AccessToken.Token | ConvertFrom-SecureString -AsPlainText + Write-Message "Setup headers for Fabric API calls" -Level Debug + $FabricSession.HeaderParams = @{'Authorization' = "Bearer {0}" -f $plainTextToken } - Write-Verbose "Get authentication token" - $FabricSession.FabricToken = (Get-AzAccessToken -ResourceUrl $FabricSession.ResourceUrl).Token - Write-Verbose "Token: $($FabricSession.FabricToken)" - } + # Copy session values to exposed $FabricConfig + $FabricConfig.TenantId = $FabricSession.AccessToken.TenantId + $FabricConfig.TokenExpiresOn = $FabricSession.AccessToken.ExpiresOn + $FabricConfig.FabricHeaders = $FabricSession.HeaderParams # Remove this; + } - if ($PSCmdlet.ShouldProcess("Setting Fabric headers for $($azContext.Account)")) { - Write-Verbose "Setup headers for API calls" - $FabricSession.HeaderParams = @{'Authorization' = "Bearer {0}" -f $FabricSession.FabricToken } - Write-Verbose "HeaderParams: $($FabricSession.HeaderParams)" + if ($PSCmdlet.ShouldProcess("Setting Azure authentication token and headers for $($azContext.Account)")) { + Write-Message "Get authentication token from $($AzureSession.BaseApiUrl)" -Level Verbose + $AzureSession.AccessToken = (Get-AzAccessToken -ResourceUrl $AzureSession.BaseApiUrl) + $plainTextToken = $AzureSession.AccessToken.Token | ConvertFrom-SecureString -AsPlainText + Write-Message "Setup headers for Azure API calls" -Level Debug + $AzureSession.HeaderParams = @{'Authorization' = "Bearer {0}" -f $plainTextToken } } + } end { } diff --git a/source/Public/Copy Job/Get-FabricCopyJob.ps1 b/source/Public/Copy Job/Get-FabricCopyJob.ps1 index 5d306d65..c1290c94 100644 --- a/source/Public/Copy Job/Get-FabricCopyJob.ps1 +++ b/source/Public/Copy Job/Get-FabricCopyJob.ps1 @@ -26,7 +26,7 @@ function Get-FabricCopyJob { .NOTES Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - Calls `Test-TokenExpired` to ensure token validity before making the API request. + Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -53,9 +53,7 @@ function Get-FabricCopyJob { } # Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Construct the API endpoint URL @@ -66,7 +64,7 @@ function Get-FabricCopyJob { Uri = $apiEndpointURI Method = 'Get' } - $copyJobs = Invoke-FabricAPIRequest @apiParams + $copyJobs = Invoke-FabricRestMethod @apiParams # Filter results based on provided parameters $response = if ($CopyJobId) { diff --git a/source/Public/Copy Job/Get-FabricCopyJobDefinition.ps1 b/source/Public/Copy Job/Get-FabricCopyJobDefinition.ps1 index 96bdbb56..c92d97a6 100644 --- a/source/Public/Copy Job/Get-FabricCopyJobDefinition.ps1 +++ b/source/Public/Copy Job/Get-FabricCopyJobDefinition.ps1 @@ -22,7 +22,7 @@ Retrieves the definition of the Copy Job with ID `67890` from the workspace with .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. - Handles long-running operations asynchronously. - Logs detailed information for debugging purposes. @@ -45,9 +45,7 @@ function Get-FabricCopyJobDefinition { try { # Step 1: Validate authentication token before proceeding. - Write-Message -Message "Validating authentication token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Authentication token is valid." -Level Debug + Confirm-TokenState # Step 2: Construct the API endpoint URL for retrieving the Copy Job definition. $apiEndpointUrl = "workspaces/{0}/copyJobs/{1}/getDefinition" -f $WorkspaceId, $CopyJobId @@ -63,7 +61,7 @@ function Get-FabricCopyJobDefinition { Uri = $apiEndpointUrl Method = 'POST' } - $response = Invoke-FabricAPIRequest @apiParams + $response = Invoke-FabricRestMethod @apiParams # Step 5: Return the API response containing the Copy Job definition. return $response diff --git a/source/Public/Copy Job/New-FabricCopyJob.ps1 b/source/Public/Copy Job/New-FabricCopyJob.ps1 index 73feb86a..d4d12eb7 100644 --- a/source/Public/Copy Job/New-FabricCopyJob.ps1 +++ b/source/Public/Copy Job/New-FabricCopyJob.ps1 @@ -26,7 +26,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -56,9 +56,7 @@ function New-FabricCopyJob { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointURI = "workspaces/{0}/copyJobs" -f $WorkspaceId @@ -131,7 +129,7 @@ function New-FabricCopyJob { Method = 'Post' Body = $bodyJson } - $response = Invoke-FabricAPIRequest @apiParams + $response = Invoke-FabricRestMethod @apiParams } Write-Message -Message "Copy Job created successfully!" -Level Info diff --git a/source/Public/Copy Job/Remove-FabricCopyJob.ps1 b/source/Public/Copy Job/Remove-FabricCopyJob.ps1 index f9a30175..f839bdc8 100644 --- a/source/Public/Copy Job/Remove-FabricCopyJob.ps1 +++ b/source/Public/Copy Job/Remove-FabricCopyJob.ps1 @@ -18,7 +18,7 @@ .NOTES - Requires the `$FabricConfig` global configuration, which must include `BaseUrl` and `FabricHeaders`. - - Ensures token validity by invoking `Test-TokenExpired` before making the API request. + - Ensures token validity by invoking `Confirm-TokenState` before making the API request. Author: Tiago Balabuch #> @@ -35,9 +35,7 @@ function Remove-FabricCopyJob { ) try { # Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Construct the API endpoint URI $apiEndpointURI = "workspaces/{0}/copyJobs/{1}" -f $WorkspaceId, $CopyJobId @@ -50,7 +48,7 @@ function Remove-FabricCopyJob { Uri = $apiEndpointURI Method = 'DELETE' } - $response = Invoke-FabricAPIRequest @apiParams + $response = Invoke-FabricRestMethod @apiParams } Write-Message -Message "Copy Job '$CopyJobId' deleted successfully from workspace '$WorkspaceId'." -Level Info return $response diff --git a/source/Public/Copy Job/Update-FabricCopyJob.ps1 b/source/Public/Copy Job/Update-FabricCopyJob.ps1 index 22cfbcc1..ce730036 100644 --- a/source/Public/Copy Job/Update-FabricCopyJob.ps1 +++ b/source/Public/Copy Job/Update-FabricCopyJob.ps1 @@ -24,7 +24,7 @@ .NOTES - Requires the `$FabricConfig` global configuration, which includes `BaseUrl` and `FabricHeaders`. - - Ensures token validity by calling `Test-TokenExpired` before making the API request. + - Ensures token validity by calling `Confirm-TokenState` before making the API request. Author: Tiago Balabuch #> @@ -52,12 +52,10 @@ function Update-FabricCopyJob try { # Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Construct the API endpoint URI - $apiEndpointURI = "{0}/workspaces/{1}/copyJobs/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $CopyJobId + $apiEndpointURI = "workspaces/{0}/copyJobs/{1}" -f $WorkspaceId, $CopyJobId Write-Message -Message "API Endpoint: $apiEndpointURI" -Level Debug # Construct the request body @@ -77,9 +75,8 @@ function Update-FabricCopyJob if ($PSCmdlet.ShouldProcess($apiEndpointURI, "Update Copy Job")) { # Step 4: Make the API request - $response = Invoke-FabricAPIRequest ` - -Headers $FabricConfig.FabricHeaders ` - -BaseURI $apiEndpointURI ` + $response = Invoke-FabricRestMethod ` + -Uri $apiEndpointURI ` -method Patch ` -body $bodyJson } diff --git a/source/Public/Copy Job/Update-FabricCopyJobDefinition.ps1 b/source/Public/Copy Job/Update-FabricCopyJobDefinition.ps1 index 6a1de71a..fde5a10d 100644 --- a/source/Public/Copy Job/Update-FabricCopyJobDefinition.ps1 +++ b/source/Public/Copy Job/Update-FabricCopyJobDefinition.ps1 @@ -30,7 +30,7 @@ Updates both the content and platform-specific definition of the Copy Job with I .NOTES - Requires the `$FabricConfig` global configuration, which must include `BaseUrl` and `FabricHeaders`. -- Validates token expiration using `Test-TokenExpired` before making the API request. +- Validates token expiration using `Confirm-TokenState` before making the API request. - Encodes file content as Base64 before sending it to the Fabric API. - Logs detailed messages for debugging and error handling. @@ -59,9 +59,7 @@ function Update-FabricCopyJobDefinition { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/copyJobs/{2}/updateDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $CopyJobId @@ -114,9 +112,8 @@ function Update-FabricCopyJobDefinition { if($PSCmdlet.ShouldProcess($apiEndpointUrl, "Update Copy Job Definition")) { # Step 4: Make the API request - $response = Invoke-FabricAPIRequest ` + $response = Invoke-FabricRestMethod ` -BaseURI $apiEndpointUrl ` - -Headers $FabricConfig.FabricHeaders ` -Method Post ` -Body $bodyJson } diff --git a/source/Public/Dashboard/Get-FabricDashboard.ps1 b/source/Public/Dashboard/Get-FabricDashboard.ps1 index b938d89d..1e9b547a 100644 --- a/source/Public/Dashboard/Get-FabricDashboard.ps1 +++ b/source/Public/Dashboard/Get-FabricDashboard.ps1 @@ -10,12 +10,12 @@ The ID of the workspace from which to retrieve dashboards. This parameter is mandatory. .EXAMPLE - Get-FabricDashboard -WorkspaceId "12345" + Get-FabricDashboard -WorkspaceId "12345" This example retrieves all dashboards from the workspace with ID "12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -30,9 +30,7 @@ function Get-FabricDashboard { try { # Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Construct the API endpoint URL $apiEndpointURI = "workspaces/{0}/dashboards" -f $WorkspaceId @@ -42,7 +40,7 @@ function Get-FabricDashboard { Uri = $apiEndpointURI Method = 'Get' } - $Dashboards = Invoke-FabricAPIRequest @apiParams + $Dashboards = Invoke-FabricRestMethod @apiParams return $Dashboards diff --git a/source/Public/Data Pipeline/Get-FabricDataPipeline.ps1 b/source/Public/Data Pipeline/Get-FabricDataPipeline.ps1 index f5a39bcd..931271e1 100644 --- a/source/Public/Data Pipeline/Get-FabricDataPipeline.ps1 +++ b/source/Public/Data Pipeline/Get-FabricDataPipeline.ps1 @@ -17,16 +17,16 @@ function Get-FabricDataPipeline { The name of the Data Pipeline to retrieve. This parameter is optional. .EXAMPLE - Get-FabricData Pipeline -WorkspaceId "workspace-12345" -Data PipelineId "Data Pipeline-67890" + Get-FabricDataPipeline -WorkspaceId "workspace-12345" -Data PipelineId "Data Pipeline-67890" This example retrieves the Data Pipeline details for the Data Pipeline with ID "Data Pipeline-67890" in the workspace with ID "workspace-12345". .EXAMPLE - Get-FabricData Pipeline -WorkspaceId "workspace-12345" -Data PipelineName "My Data Pipeline" + Get-FabricDataPipeline -WorkspaceId "workspace-12345" -Data PipelineName "My Data Pipeline" This example retrieves the Data Pipeline details for the Data Pipeline named "My Data Pipeline" in the workspace with ID "workspace-12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -53,15 +53,13 @@ function Get-FabricDataPipeline { } # Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Construct the API endpoint URL $apiEndpointURI = ("workspaces/{0}/dataPipelines" -f $WorkspaceId) # Invoke the Fabric API to retrieve data pipeline details - $DataPipelines = (Invoke-FabricAPIRequest -uri $apiEndpointURI -Method Get).Value + $DataPipelines = (Invoke-FabricRestMethod -uri $apiEndpointURI -Method Get).Value # Filter results based on provided parameters $response = if ($DataPipelineId) { diff --git a/source/Public/Data Pipeline/New-FabricDataPipeline.ps1 b/source/Public/Data Pipeline/New-FabricDataPipeline.ps1 index 31d67a37..56cf588b 100644 --- a/source/Public/Data Pipeline/New-FabricDataPipeline.ps1 +++ b/source/Public/Data Pipeline/New-FabricDataPipeline.ps1 @@ -22,7 +22,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -47,9 +47,7 @@ function New-FabricDataPipeline try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointURI = ("workspaces/{0}/dataPipelines" -f $WorkspaceId) @@ -77,7 +75,7 @@ function New-FabricDataPipeline method = 'Post' body = $bodyJson } - $response = Invoke-FabricAPIRequest @apiParams + $response = Invoke-FabricRestMethod @apiParams } Write-Message -Message "Data Pipeline created successfully!" -Level Info return $response diff --git a/source/Public/Data Pipeline/Remove-FabricDataPipeline.ps1 b/source/Public/Data Pipeline/Remove-FabricDataPipeline.ps1 index c1b17244..c587c4e6 100644 --- a/source/Public/Data Pipeline/Remove-FabricDataPipeline.ps1 +++ b/source/Public/Data Pipeline/Remove-FabricDataPipeline.ps1 @@ -18,14 +18,14 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> function Remove-FabricDataPipeline { - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -38,22 +38,18 @@ function Remove-FabricDataPipeline try { # Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Construct the API URI - $apiEndpointURI = "{0}/workspaces/{1}/dataPipelines/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $DataPipelineId + $apiEndpointURI = "workspaces/{0}/dataPipelines/{1}" -f $WorkspaceId, $DataPipelineId Write-Message -Message "API Endpoint: $apiEndpointURI" -Level Debug if ($PSCmdlet.ShouldProcess($apiEndpointURI, "Delete DataPipeline")) { - # Make the API request - $response = Invoke-FabricAPIRequest ` - -Headers $FabricConfig.FabricHeaders ` - -BaseURI $apiEndpointURI ` - -method Delete + $response = Invoke-FabricRestMethod ` + -Uri $apiEndpointURI ` + -Method Delete } Write-Message -Message "DataPipeline '$DataPipelineId' deleted successfully from workspace '$WorkspaceId'." -Level Info return $response diff --git a/source/Public/Data Pipeline/Update-FabricDataPipeline.ps1 b/source/Public/Data Pipeline/Update-FabricDataPipeline.ps1 index beac3104..c71893b3 100644 --- a/source/Public/Data Pipeline/Update-FabricDataPipeline.ps1 +++ b/source/Public/Data Pipeline/Update-FabricDataPipeline.ps1 @@ -19,12 +19,12 @@ An optional new description for the DataPipeline. .EXAMPLE - Update-FabricDataPipeline -WorkspaceId "workspace-12345" -DataPipelineId "pipeline-67890" -DataPipelineName "Updated DataPipeline" -DataPipelineDescription "Updated description" + Update-FabricDataPipeline -WorkspaceId "workspace-12345" -DataPipelineId "pipeline-67890" -DataPipelineName "Updated DataPipeline" -DataPipelineDescription "Updated description" This example updates the DataPipeline with ID "pipeline-67890" in the workspace with ID "workspace-12345" with a new name and description. .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -52,12 +52,10 @@ function Update-FabricDataPipeline try { # Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Construct the API URL - $apiEndpointURI = "{0}/workspaces/{1}/dataPipelines/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $DataPipelineId + $apiEndpointURI = "workspaces/{0}/dataPipelines/{1}" -f $WorkspaceId, $DataPipelineId Write-Message -Message "API Endpoint: $apiEndpointURI" -Level Debug # Construct the request body @@ -76,13 +74,11 @@ function Update-FabricDataPipeline if ($PSCmdlet.ShouldProcess($apiEndpointURI, "Update DataPipeline")) { - # Make the API request - $response = Invoke-FabricAPIRequest ` - -Headers $FabricConfig.FabricHeaders ` - -BaseURI $apiEndpointURI ` - -method Patch ` - -body $bodyJson + $response = Invoke-FabricRestMethod ` + -Uri $apiEndpointURI ` + -Method Patch ` + -Body $bodyJson } Write-Message -Message "DataPipeline '$DataPipelineName' updated successfully!" -Level Info diff --git a/source/Public/Datamart/Get-FabricDatamart.ps1 b/source/Public/Datamart/Get-FabricDatamart.ps1 index 4dde6c90..cce12ded 100644 --- a/source/Public/Datamart/Get-FabricDatamart.ps1 +++ b/source/Public/Datamart/Get-FabricDatamart.ps1 @@ -22,7 +22,7 @@ function Get-FabricDatamart { .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -43,9 +43,7 @@ function Get-FabricDatamart { try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $apiEndpointURI = "workspaces/{0}/Datamarts" -f $WorkspaceId @@ -54,7 +52,7 @@ function Get-FabricDatamart { Uri = $apiEndpointURI method = 'Get' } - $Datamarts = Invoke-FabricAPIRequest @apiParams + $Datamarts = Invoke-FabricRestMethod @apiParams # Step 9: Filter results based on provided parameters diff --git a/source/Public/Domain/Add-FabricDomainWorkspaceAssignmentByCapacity.ps1 b/source/Public/Domain/Add-FabricDomainWorkspaceAssignmentByCapacity.ps1 index 84bf2dff..cc2233b7 100644 --- a/source/Public/Domain/Add-FabricDomainWorkspaceAssignmentByCapacity.ps1 +++ b/source/Public/Domain/Add-FabricDomainWorkspaceAssignmentByCapacity.ps1 @@ -18,7 +18,7 @@ Assigns workspaces to the domain with ID "12345" based on the specified capaciti .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -38,9 +38,7 @@ function Add-FabricDomainWorkspaceAssignmentByCapacity { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/admin/domains/{1}/assignWorkspacesByCapacities" -f $FabricConfig.BaseUrl, $DomainId @@ -56,16 +54,10 @@ function Add-FabricDomainWorkspaceAssignmentByCapacity { Write-Message -Message "Request Body: $bodyJson" -Level Debug # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson # Step 5: Handle and log the response switch ($statusCode) { diff --git a/source/Public/Domain/Add-FabricDomainWorkspaceAssignmentById.ps1 b/source/Public/Domain/Add-FabricDomainWorkspaceAssignmentById.ps1 index 118a3f19..7a2fde83 100644 --- a/source/Public/Domain/Add-FabricDomainWorkspaceAssignmentById.ps1 +++ b/source/Public/Domain/Add-FabricDomainWorkspaceAssignmentById.ps1 @@ -18,7 +18,7 @@ Assigns the workspaces with IDs "ws1", "ws2", and "ws3" to the domain with ID "1 .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -38,9 +38,7 @@ function Add-FabricDomainWorkspaceAssignmentById { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/admin/domains/{1}/assignWorkspaces" -f $FabricConfig.BaseUrl, $DomainId @@ -56,16 +54,10 @@ function Add-FabricDomainWorkspaceAssignmentById { Write-Message -Message "Request Body: $bodyJson" -Level Debug # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson # Step 5: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Domain/Add-FabricDomainWorkspaceAssignmentByPrincipal.ps1 b/source/Public/Domain/Add-FabricDomainWorkspaceAssignmentByPrincipal.ps1 index 58a40535..8ace3005 100644 --- a/source/Public/Domain/Add-FabricDomainWorkspaceAssignmentByPrincipal.ps1 +++ b/source/Public/Domain/Add-FabricDomainWorkspaceAssignmentByPrincipal.ps1 @@ -23,7 +23,7 @@ Assigns the workspaces based on the provided principal IDs and types. .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -51,9 +51,7 @@ function Add-FabricDomainWorkspaceAssignmentByPrincipal { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Construct the API URL $apiEndpointUrl = "{0}/admin/domains/{1}/assignWorkspacesByPrincipals" -f $FabricConfig.BaseUrl, $DomainId @@ -69,16 +67,10 @@ function Add-FabricDomainWorkspaceAssignmentByPrincipal { Write-Message -Message "Request Body: $bodyJson" -Level Debug # Step 5: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson # Step 6: Handle and log the response switch ($statusCode) { diff --git a/source/Public/Domain/Add-FabricDomainWorkspaceRoleAssignment.ps1 b/source/Public/Domain/Add-FabricDomainWorkspaceRoleAssignment.ps1 index d39a642a..63fdad33 100644 --- a/source/Public/Domain/Add-FabricDomainWorkspaceRoleAssignment.ps1 +++ b/source/Public/Domain/Add-FabricDomainWorkspaceRoleAssignment.ps1 @@ -25,7 +25,7 @@ Assigns the `Admins` role to the specified principals in the domain with ID "123 .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -57,9 +57,7 @@ function Add-FabricDomainWorkspaceRoleAssignment { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Construct the API URL $apiEndpointUrl = "{0}/admin/domains/{1}/roleAssignments/bulkAssign" -f $FabricConfig.BaseUrl, $DomainId @@ -74,16 +72,10 @@ function Add-FabricDomainWorkspaceRoleAssignment { Write-Message -Message "Request Body: $bodyJson" -Level Debug # Step 5: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson # Step 6: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Domain/Get-FabricDomain.ps1 b/source/Public/Domain/Get-FabricDomain.ps1 index a3122983..7434c604 100644 --- a/source/Public/Domain/Get-FabricDomain.ps1 +++ b/source/Public/Domain/Get-FabricDomain.ps1 @@ -26,7 +26,7 @@ Fetches the domain with the display name "Finance". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -56,9 +56,7 @@ function Get-FabricDomain { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Construct the API URL with filtering logic $apiEndpointUrl = "{0}/admin/domains" -f $FabricConfig.BaseUrl @@ -68,14 +66,9 @@ function Get-FabricDomain { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method 'Get' # Step 5: Validate the response code if ($statusCode -ne 200) { @@ -91,7 +84,6 @@ function Get-FabricDomain { return $null } - # Step 7: Filter results based on provided parameters $domains = if ($DomainId) { $response.domains | Where-Object { $_.Id -eq $DomainId } diff --git a/source/Public/Domain/Get-FabricDomainWorkspace.ps1 b/source/Public/Domain/Get-FabricDomainWorkspace.ps1 index 337ac15e..fdc16d20 100644 --- a/source/Public/Domain/Get-FabricDomainWorkspace.ps1 +++ b/source/Public/Domain/Get-FabricDomainWorkspace.ps1 @@ -15,7 +15,7 @@ Fetches workspaces for the domain with ID "12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -31,23 +31,16 @@ function Get-FabricDomainWorkspace { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/admin/domains/{1}/workspaces" -f $FabricConfig.BaseUrl, $DomainId Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 4: Validate the response code if ($statusCode -ne 200) { @@ -75,4 +68,4 @@ function Get-FabricDomainWorkspace { $errorDetails = Get-ErrorResponse($_.Exception) Write-Message -Message "Failed to retrieve domain workspaces. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Domain/New-FabricDomain.ps1 b/source/Public/Domain/New-FabricDomain.ps1 index ee9207f9..2dae8918 100644 --- a/source/Public/Domain/New-FabricDomain.ps1 +++ b/source/Public/Domain/New-FabricDomain.ps1 @@ -21,7 +21,7 @@ Creates a "Finance" domain under the parent domain with ID "12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -47,9 +47,7 @@ function New-FabricDomain try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Construct the request body $apiEndpointUrl = "{0}/admin/domains" -f $FabricConfig.BaseUrl @@ -78,16 +76,10 @@ function New-FabricDomain { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/Domain/Remove-FabricDomain.ps1 b/source/Public/Domain/Remove-FabricDomain.ps1 index 27fcd905..7e428df6 100644 --- a/source/Public/Domain/Remove-FabricDomain.ps1 +++ b/source/Public/Domain/Remove-FabricDomain.ps1 @@ -15,7 +15,7 @@ Deletes the domain with ID "12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -23,7 +23,7 @@ Author: Tiago Balabuch function Remove-FabricDomain { - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess,ConfirmImpact = 'High')] param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -33,9 +33,7 @@ function Remove-FabricDomain try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/admin/domains/{1}" -f $FabricConfig.BaseUrl, $DomainId @@ -43,14 +41,9 @@ function Remove-FabricDomain if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove Domain")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Validate the response code diff --git a/source/Public/Domain/Remove-FabricDomainWorkspaceAssignment.ps1 b/source/Public/Domain/Remove-FabricDomainWorkspaceAssignment.ps1 index 2dd1c856..c85329fb 100644 --- a/source/Public/Domain/Remove-FabricDomainWorkspaceAssignment.ps1 +++ b/source/Public/Domain/Remove-FabricDomainWorkspaceAssignment.ps1 @@ -25,7 +25,7 @@ Unassigns the specified workspaces from the domain with ID "12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -33,7 +33,7 @@ Author: Tiago Balabuch #> function Remove-FabricDomainWorkspaceAssignment { - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] [Alias("Unassign-FabricDomainWorkspace")] param ( [Parameter(Mandatory = $true)] @@ -48,9 +48,7 @@ function Remove-FabricDomainWorkspaceAssignment try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL # Determine the API endpoint URL based on the presence of WorkspaceIds @@ -82,16 +80,10 @@ function Remove-FabricDomainWorkspaceAssignment if ($PSCmdlet.ShouldProcess($DomainId, "Unassign Workspaces")) { # Step 4: Make the API request to unassign specific workspaces - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code diff --git a/source/Public/Domain/Remove-FabricDomainWorkspaceRoleAssignment.ps1 b/source/Public/Domain/Remove-FabricDomainWorkspaceRoleAssignment.ps1 index 9d61e3c5..b0b352ea 100644 --- a/source/Public/Domain/Remove-FabricDomainWorkspaceRoleAssignment.ps1 +++ b/source/Public/Domain/Remove-FabricDomainWorkspaceRoleAssignment.ps1 @@ -25,7 +25,7 @@ Unassign the `Admins` role to the specified principals in the domain with ID "12 .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -58,9 +58,7 @@ function Remove-FabricDomainWorkspaceRoleAssignment { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Construct the API URL $apiEndpointUrl = "{0}/admin/domains/{1}/roleAssignments/bulkUnassign" -f $FabricConfig.BaseUrl, $DomainId @@ -76,16 +74,10 @@ function Remove-FabricDomainWorkspaceRoleAssignment { if($PSCmdlet.ShouldProcess($DomainId, "Unassign Roles")) { # Step 5: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 6: Validate the response code diff --git a/source/Public/Domain/Update-FabricDomain.ps1 b/source/Public/Domain/Update-FabricDomain.ps1 index 849d70b5..eb541dae 100644 --- a/source/Public/Domain/Update-FabricDomain.ps1 +++ b/source/Public/Domain/Update-FabricDomain.ps1 @@ -24,7 +24,7 @@ Updates the domain with ID "12345" with a new name, description, and contributor .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -55,9 +55,7 @@ function Update-FabricDomain try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/admin/domains/{1}" -f $FabricConfig.BaseUrl, $DomainId @@ -86,16 +84,10 @@ function Update-FabricDomain { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code diff --git a/source/Public/Environment/Get-FabricEnvironment.ps1 b/source/Public/Environment/Get-FabricEnvironment.ps1 index 44a73e7e..46c90b55 100644 --- a/source/Public/Environment/Get-FabricEnvironment.ps1 +++ b/source/Public/Environment/Get-FabricEnvironment.ps1 @@ -27,7 +27,7 @@ Retrieves all environments in workspace "12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. - Returns the matching environment details or all environments if no filter is provided. Author: Tiago Balabuch @@ -57,9 +57,7 @@ Author: Tiago Balabuch } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null @@ -86,14 +84,9 @@ Author: Tiago Balabuch Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Environment/Get-FabricEnvironmentLibrary.ps1 b/source/Public/Environment/Get-FabricEnvironmentLibrary.ps1 index 41f4330d..d7e30b25 100644 --- a/source/Public/Environment/Get-FabricEnvironmentLibrary.ps1 +++ b/source/Public/Environment/Get-FabricEnvironmentLibrary.ps1 @@ -20,7 +20,7 @@ Retrieves the libraries associated with the specified environment in the given w .NOTES - Requires the `$FabricConfig` global object, including `BaseUrl` and `FabricHeaders`. -- Uses `Test-TokenExpired` to validate the token before making API calls. +- Uses `Confirm-TokenState` to validate the token before making API calls. Author: Tiago Balabuch #> @@ -38,23 +38,16 @@ function Get-FabricEnvironmentLibrary { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/environments/{2}/libraries" -f $FabricConfig.BaseUrl, $WorkspaceId, $EnvironmentId Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 4: Validate the response code if ($statusCode -ne 200) { @@ -72,4 +65,4 @@ function Get-FabricEnvironmentLibrary { Write-Message -Message "Failed to retrieve environment libraries. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Environment/Get-FabricEnvironmentSparkCompute.ps1 b/source/Public/Environment/Get-FabricEnvironmentSparkCompute.ps1 index cf60c915..2b9ba4fa 100644 --- a/source/Public/Environment/Get-FabricEnvironmentSparkCompute.ps1 +++ b/source/Public/Environment/Get-FabricEnvironmentSparkCompute.ps1 @@ -20,7 +20,7 @@ Retrieves Spark compute details for the specified environment in the given works .NOTES - Requires the `$FabricConfig` global object, including `BaseUrl` and `FabricHeaders`. -- Uses `Test-TokenExpired` to validate the token before making API calls. +- Uses `Confirm-TokenState` to validate the token before making API calls. Author: Tiago Balabuch #> @@ -38,23 +38,16 @@ function Get-FabricEnvironmentSparkCompute { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/environments/{2}/sparkcompute" -f $FabricConfig.BaseUrl, $WorkspaceId, $EnvironmentId Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 4: Validate the response code if ($statusCode -ne 200) { @@ -72,4 +65,4 @@ function Get-FabricEnvironmentSparkCompute { Write-Message -Message "Failed to retrieve environment Spark compute. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Environment/Get-FabricEnvironmentStagingLibrary.ps1 b/source/Public/Environment/Get-FabricEnvironmentStagingLibrary.ps1 index 1e87be69..639920dc 100644 --- a/source/Public/Environment/Get-FabricEnvironmentStagingLibrary.ps1 +++ b/source/Public/Environment/Get-FabricEnvironmentStagingLibrary.ps1 @@ -13,13 +13,13 @@ The unique identifier of the workspace containing the target environment. The unique identifier of the environment for which staging library details are being retrieved. .EXAMPLE - Get-FabricEnvironmentStagingLibrary -WorkspaceId "workspace-12345" -EnvironmentId "environment-67890" +Get-FabricEnvironmentStagingLibrary -WorkspaceId "workspace-12345" -EnvironmentId "environment-67890" Retrieves the staging libraries for the specified environment in the given workspace. .NOTES - Requires the `$FabricConfig` global object, including `BaseUrl` and `FabricHeaders`. -- Uses `Test-TokenExpired` to validate the token before making API calls. +- Uses `Confirm-TokenState` to validate the token before making API calls. Author: Tiago Balabuch #> @@ -38,23 +38,16 @@ function Get-FabricEnvironmentStagingLibrary { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/environments/{2}/staging/libraries" -f $FabricConfig.BaseUrl, $WorkspaceId, $EnvironmentId Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 4: Validate the response code if ($statusCode -ne 200) { @@ -72,4 +65,4 @@ function Get-FabricEnvironmentStagingLibrary { Write-Message -Message "Failed to retrieve environment spark compute. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Environment/Get-FabricEnvironmentStagingSparkCompute.ps1 b/source/Public/Environment/Get-FabricEnvironmentStagingSparkCompute.ps1 index 49075388..62a4e1c4 100644 --- a/source/Public/Environment/Get-FabricEnvironmentStagingSparkCompute.ps1 +++ b/source/Public/Environment/Get-FabricEnvironmentStagingSparkCompute.ps1 @@ -20,7 +20,7 @@ Retrieves the staging Spark compute configurations for the specified environment .NOTES - Requires the `$FabricConfig` global object, including `BaseUrl` and `FabricHeaders`. -- Uses `Test-TokenExpired` to validate the token before making API calls. +- Uses `Confirm-TokenState` to validate the token before making API calls. Author: Tiago Balabuch #> @@ -38,23 +38,16 @@ Author: Tiago Balabuch try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/environments/{2}/staging/sparkcompute" -f $FabricConfig.BaseUrl, $WorkspaceId, $EnvironmentId Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 4: Validate the response code if ($statusCode -ne 200) { @@ -72,4 +65,4 @@ Author: Tiago Balabuch Write-Message -Message "Failed to retrieve environment spark compute. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Environment/Import-FabricEnvironmentStagingLibrary.ps1 b/source/Public/Environment/Import-FabricEnvironmentStagingLibrary.ps1 index 1c33e533..6b6d65c2 100644 --- a/source/Public/Environment/Import-FabricEnvironmentStagingLibrary.ps1 +++ b/source/Public/Environment/Import-FabricEnvironmentStagingLibrary.ps1 @@ -18,7 +18,7 @@ Import-FabricEnvironmentStagingLibrary -WorkspaceId "workspace-12345" -Environme .NOTES - This is not working code. It is a placeholder for future development. Fabric documentation is missing some important details on how to upload libraries. - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -38,9 +38,7 @@ function Import-FabricEnvironmentStagingLibrary { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/environments/{2}/staging/libraries" -f $FabricConfig.BaseUrl, $WorkspaceId, $EnvironmentId @@ -49,16 +47,10 @@ function Import-FabricEnvironmentStagingLibrary { # Step 3: Construct the request body # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson # Step 5: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Environment/New-FabricEnvironment.ps1 b/source/Public/Environment/New-FabricEnvironment.ps1 index f22a920d..41948fb8 100644 --- a/source/Public/Environment/New-FabricEnvironment.ps1 +++ b/source/Public/Environment/New-FabricEnvironment.ps1 @@ -21,7 +21,7 @@ Creates an environment named "DevEnv" in workspace "12345" with the specified de .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -47,9 +47,7 @@ function New-FabricEnvironment try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/environments" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -70,16 +68,10 @@ function New-FabricEnvironment if ($PSCmdlet.ShouldProcess($EnvironmentName, "Create Environment")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/Environment/Publish-FabricEnvironment.ps1 b/source/Public/Environment/Publish-FabricEnvironment.ps1 index 03ed87fc..58799b4d 100644 --- a/source/Public/Environment/Publish-FabricEnvironment.ps1 +++ b/source/Public/Environment/Publish-FabricEnvironment.ps1 @@ -20,7 +20,7 @@ Initiates the publishing process for the specified staging environment. .NOTES - Requires the `$FabricConfig` global object, including `BaseUrl` and `FabricHeaders`. -- Uses `Test-TokenExpired` to validate the token before making API calls. +- Uses `Confirm-TokenState` to validate the token before making API calls. Author: Tiago Balabuch #> @@ -39,25 +39,17 @@ function Publish-FabricEnvironment { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/environments/{2}/staging/publish" -f $FabricConfig.BaseUrl, $WorkspaceId, $EnvironmentId Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson # Step 4: Handle and log the response switch ($statusCode) { @@ -99,4 +91,4 @@ function Publish-FabricEnvironment { $errorDetails = $_.Exception.Message Write-Message -Message "Failed to create environment. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Environment/Remove-FabricEnvironment.ps1 b/source/Public/Environment/Remove-FabricEnvironment.ps1 index 01719b20..edb1f263 100644 --- a/source/Public/Environment/Remove-FabricEnvironment.ps1 +++ b/source/Public/Environment/Remove-FabricEnvironment.ps1 @@ -40,9 +40,7 @@ function Remove-FabricEnvironment try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/environments/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $EnvironmentId @@ -50,14 +48,9 @@ function Remove-FabricEnvironment if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove Environment")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Validate the response code diff --git a/source/Public/Environment/Remove-FabricEnvironmentStagingLibrary.ps1 b/source/Public/Environment/Remove-FabricEnvironmentStagingLibrary.ps1 index d814aff9..cb5b4cda 100644 --- a/source/Public/Environment/Remove-FabricEnvironmentStagingLibrary.ps1 +++ b/source/Public/Environment/Remove-FabricEnvironmentStagingLibrary.ps1 @@ -29,7 +29,7 @@ Deletes the specified library from the staging environment in the specified work Author: Tiago Balabuch #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -47,11 +47,8 @@ Author: Tiago Balabuch try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState - Write-Message -Message "Token validation completed." -Level Debug # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/environments/{2}/staging/libraries?libraryToDelete={3}" -f $FabricConfig.BaseUrl, $WorkspaceId, $EnvironmentId, $LibraryName @@ -59,14 +56,9 @@ Author: Tiago Balabuch if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove Staging Library")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Validate the response code diff --git a/source/Public/Environment/Stop-FabricEnvironmentPublish.ps1 b/source/Public/Environment/Stop-FabricEnvironmentPublish.ps1 index eb198683..64fed9d5 100644 --- a/source/Public/Environment/Stop-FabricEnvironmentPublish.ps1 +++ b/source/Public/Environment/Stop-FabricEnvironmentPublish.ps1 @@ -40,9 +40,7 @@ function Stop-FabricEnvironmentPublish try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/environments/{2}/staging/cancelPublish" -f $FabricConfig.BaseUrl, $WorkspaceId, $EnvironmentId @@ -50,16 +48,10 @@ function Stop-FabricEnvironmentPublish if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Cancel Publish")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 4: Validate the response code diff --git a/source/Public/Environment/Update-FabricEnvironment.ps1 b/source/Public/Environment/Update-FabricEnvironment.ps1 index c686f310..971a1983 100644 --- a/source/Public/Environment/Update-FabricEnvironment.ps1 +++ b/source/Public/Environment/Update-FabricEnvironment.ps1 @@ -29,7 +29,7 @@ Updates both the name and description of the Environment "Environment123". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -59,9 +59,7 @@ function Update-FabricEnvironment try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/environments/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $EnvironmentId @@ -84,16 +82,10 @@ function Update-FabricEnvironment if ($PSCmdlet.ShouldProcess($EnvironmentId, "Update Environment")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code diff --git a/source/Public/Environment/Update-FabricEnvironmentStagingSparkCompute.ps1 b/source/Public/Environment/Update-FabricEnvironmentStagingSparkCompute.ps1 index bd1c5150..5b3f7af2 100644 --- a/source/Public/Environment/Update-FabricEnvironmentStagingSparkCompute.ps1 +++ b/source/Public/Environment/Update-FabricEnvironmentStagingSparkCompute.ps1 @@ -50,7 +50,7 @@ Update-FabricEnvironmentStagingSparkCompute -WorkspaceId "workspace-12345" -Envi .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -115,9 +115,7 @@ function Update-FabricEnvironmentStagingSparkCompute try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/environments/{2}/staging/sparkcompute" -f $FabricConfig.BaseUrl, $WorkspaceId, $EnvironmentId @@ -149,28 +147,11 @@ function Update-FabricEnvironmentStagingSparkCompute if ($PSCmdlet.ShouldProcess($EnvironmentId, "Update Environment Staging Spark Compute")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } - # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` - -Uri $apiEndpointUrl ` - -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" # Step 5: Validate the response code if ($statusCode -ne 200) diff --git a/source/Public/Eventhouse/Get-FabricEventhouse.ps1 b/source/Public/Eventhouse/Get-FabricEventhouse.ps1 index a9eba8cb..b95f612f 100644 --- a/source/Public/Eventhouse/Get-FabricEventhouse.ps1 +++ b/source/Public/Eventhouse/Get-FabricEventhouse.ps1 @@ -84,9 +84,7 @@ function Get-FabricEventhouse { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null @@ -112,14 +110,9 @@ function Get-FabricEventhouse { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Eventhouse/Get-FabricEventhouseDefinition.ps1 b/source/Public/Eventhouse/Get-FabricEventhouseDefinition.ps1 index 1f8bc72d..79fd575e 100644 --- a/source/Public/Eventhouse/Get-FabricEventhouseDefinition.ps1 +++ b/source/Public/Eventhouse/Get-FabricEventhouseDefinition.ps1 @@ -25,7 +25,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -47,9 +47,7 @@ function Get-FabricEventhouseDefinition { ) try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/eventhouses/{2}/getDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $EventhouseId @@ -61,13 +59,9 @@ function Get-FabricEventhouseDefinition { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post # Step 5: Validate the response code and handle the response switch ($statusCode) { @@ -119,4 +113,4 @@ function Get-FabricEventhouseDefinition { Write-Message -Message "Failed to retrieve Eventhouse. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Eventhouse/New-FabricEventhouse.ps1 b/source/Public/Eventhouse/New-FabricEventhouse.ps1 index 1e346e09..1f2f76e2 100644 --- a/source/Public/Eventhouse/New-FabricEventhouse.ps1 +++ b/source/Public/Eventhouse/New-FabricEventhouse.ps1 @@ -29,7 +29,7 @@ function New-FabricEventhouse .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -60,9 +60,7 @@ function New-FabricEventhouse try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/eventhouses" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -140,16 +138,10 @@ function New-FabricEventhouse if ($PSCmdlet.ShouldProcess($EventhouseName, "Create Eventhouse")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } Write-Message -Message "Response Code: $statusCode" -Level Debug diff --git a/source/Public/Eventhouse/Remove-FabricEventhouse.ps1 b/source/Public/Eventhouse/Remove-FabricEventhouse.ps1 index 2a2756e4..80c80092 100644 --- a/source/Public/Eventhouse/Remove-FabricEventhouse.ps1 +++ b/source/Public/Eventhouse/Remove-FabricEventhouse.ps1 @@ -32,7 +32,7 @@ function Remove-FabricEventhouse https://learn.microsoft.com/en-us/rest/api/fabric/eventhouse/items/delete-eventhouse?tabs=HTTP - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -51,9 +51,7 @@ function Remove-FabricEventhouse try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/eventhouses/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $EventhouseId @@ -61,14 +59,9 @@ function Remove-FabricEventhouse if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove Eventhouse")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Handle response diff --git a/source/Public/Eventhouse/Update-FabricEventhouse.ps1 b/source/Public/Eventhouse/Update-FabricEventhouse.ps1 index 4516ff31..b9bd76bb 100644 --- a/source/Public/Eventhouse/Update-FabricEventhouse.ps1 +++ b/source/Public/Eventhouse/Update-FabricEventhouse.ps1 @@ -24,7 +24,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -52,9 +52,7 @@ function Update-FabricEventhouse try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/eventhouses/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $EventhouseId @@ -77,16 +75,10 @@ function Update-FabricEventhouse if ($PSCmdlet.ShouldProcess("Eventhouse", "Update")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code diff --git a/source/Public/Eventhouse/Update-FabricEventhouseDefinition.ps1 b/source/Public/Eventhouse/Update-FabricEventhouseDefinition.ps1 index d5486e14..491b6672 100644 --- a/source/Public/Eventhouse/Update-FabricEventhouseDefinition.ps1 +++ b/source/Public/Eventhouse/Update-FabricEventhouseDefinition.ps1 @@ -24,7 +24,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -52,9 +52,7 @@ function Update-FabricEventhouseDefinition try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/eventhouses/{2}/updateDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $EventhouseId @@ -117,15 +115,10 @@ function Update-FabricEventhouseDefinition if ($PSCmdlet.ShouldProcess("Eventhouse", "Update")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/Eventstream/Get-FabricEventstream.ps1 b/source/Public/Eventstream/Get-FabricEventstream.ps1 index 05c0d758..31f7a65a 100644 --- a/source/Public/Eventstream/Get-FabricEventstream.ps1 +++ b/source/Public/Eventstream/Get-FabricEventstream.ps1 @@ -13,6 +13,7 @@ Retrieves an Eventstream or a list of Eventstreams from a specified workspace in .PARAMETER EventstreamName (Optional) The name of the specific Eventstream to retrieve. + .PARAMETER EventstreamId The Id of the Eventstream to retrieve. This parameter cannot be used together with EventstreamName. The value for EventstreamId is a GUID. An example of a GUID is '12345678-1234-1234-1234-123456789012'. @@ -29,7 +30,7 @@ Retrieves all Eventstreams in workspace "12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -59,9 +60,7 @@ Author: Tiago Balabuch } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState $continuationToken = $null $eventstreams = @() @@ -90,14 +89,9 @@ Author: Tiago Balabuch Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Eventstream/Get-FabricEventstreamDefinition.ps1 b/source/Public/Eventstream/Get-FabricEventstreamDefinition.ps1 index 411deb41..fea88811 100644 --- a/source/Public/Eventstream/Get-FabricEventstreamDefinition.ps1 +++ b/source/Public/Eventstream/Get-FabricEventstreamDefinition.ps1 @@ -29,7 +29,7 @@ Retrieves the definitions of all Eventstreams in the workspace with ID `12345` i .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. - Handles long-running operations asynchronously. #> @@ -51,9 +51,7 @@ function Get-FabricEventstreamDefinition { try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/Eventstreams/{2}/getDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $EventstreamId @@ -64,13 +62,9 @@ function Get-FabricEventstreamDefinition { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post # Step 5: Validate the response code and handle the response switch ($statusCode) { @@ -116,4 +110,4 @@ function Get-FabricEventstreamDefinition { Write-Message -Message "Failed to retrieve Eventstream. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Eventstream/New-FabricEventstream.ps1 b/source/Public/Eventstream/New-FabricEventstream.ps1 index bc619d33..e671fd67 100644 --- a/source/Public/Eventstream/New-FabricEventstream.ps1 +++ b/source/Public/Eventstream/New-FabricEventstream.ps1 @@ -26,11 +26,11 @@ An optional path to the platform-specific definition (e.g., .platform file) to u .EXAMPLE #TODO Fix example name - Add-FabricEventstream -WorkspaceId "workspace-12345" -EventstreamName "New Eventstream" -EventstreamPathDefinition "C:\Eventstreams\example.ipynb" +Add-FabricEventstream -WorkspaceId "workspace-12345" -EventstreamName "New Eventstream" -EventstreamPathDefinition "C:\Eventstreams\example.ipynb" - .NOTES +.NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -62,9 +62,7 @@ Author: Tiago Balabuch try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/eventstreams" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -144,16 +142,10 @@ Author: Tiago Balabuch if ($PSCmdlet.ShouldProcess($EventstreamName, "Create Eventstream")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/Eventstream/Remove-FabricEventstream.ps1 b/source/Public/Eventstream/Remove-FabricEventstream.ps1 index 0b9da7e3..ebbda0a3 100644 --- a/source/Public/Eventstream/Remove-FabricEventstream.ps1 +++ b/source/Public/Eventstream/Remove-FabricEventstream.ps1 @@ -45,9 +45,7 @@ Author: Tiago Balabuch try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/eventstreams/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $EventstreamId @@ -56,13 +54,9 @@ Author: Tiago Balabuch if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove Eventstream")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Validate the response code diff --git a/source/Public/Eventstream/Update-FabricEventstream.ps1 b/source/Public/Eventstream/Update-FabricEventstream.ps1 index 40655ae6..901d14e6 100644 --- a/source/Public/Eventstream/Update-FabricEventstream.ps1 +++ b/source/Public/Eventstream/Update-FabricEventstream.ps1 @@ -29,7 +29,7 @@ Updates both the name and description of the Eventstream "Eventstream123". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -59,9 +59,7 @@ function Update-FabricEventstream try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/eventstreams/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $EventstreamId @@ -83,15 +81,10 @@ function Update-FabricEventstream if ($PSCmdlet.ShouldProcess($EventstreamId, "Update Eventstream")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code if ($statusCode -ne 200) diff --git a/source/Public/Eventstream/Update-FabricEventstreamDefinition.ps1 b/source/Public/Eventstream/Update-FabricEventstreamDefinition.ps1 index 9ae03b65..2f19fdf3 100644 --- a/source/Public/Eventstream/Update-FabricEventstreamDefinition.ps1 +++ b/source/Public/Eventstream/Update-FabricEventstreamDefinition.ps1 @@ -34,7 +34,7 @@ Updates both the content and metadata of the Eventstream with ID `67890` in the .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. - The Eventstream content is encoded as Base64 before being sent to the Fabric API. - This function handles asynchronous operations and retrieves operation results if required. @@ -66,9 +66,7 @@ function Update-FabricEventstreamDefinition try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/eventstreams/{2}/updateDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $EventstreamId @@ -130,15 +128,10 @@ function Update-FabricEventstreamDefinition if ($PSCmdlet.ShouldProcess($EventstreamId, "Update Eventstream")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/External Data Share/Get-FabricExternalDataShares.ps1 b/source/Public/External Data Share/Get-FabricExternalDataShares.ps1 index c79cf336..b6c115a1 100644 --- a/source/Public/External Data Share/Get-FabricExternalDataShares.ps1 +++ b/source/Public/External Data Share/Get-FabricExternalDataShares.ps1 @@ -7,12 +7,12 @@ It handles token validation, constructs the API URL, makes the API request, and processes the response. .EXAMPLE - Get-FabricExternalDataShares + Get-FabricExternalDataShares This example retrieves the External Data Shares details .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -23,18 +23,15 @@ function Get-FabricExternalDataShares { try { # Validate authentication token before proceeding - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Construct the API endpoint URI for retrieving external data shares Write-Message -Message "Constructing API endpoint URI..." -Level Debug $apiEndpointURI = "{0}/admin/items/externalDataShares" -f $FabricConfig.BaseUrl, $WorkspaceId # Invoke the API request to retrieve external data shares - $externalDataShares = Invoke-FabricAPIRequest ` - -BaseURI $apiEndpointURI ` - -Headers $FabricConfig.FabricHeaders ` + $externalDataShares = Invoke-FabricRestMethod ` + -Uri $apiEndpointURI ` -Method Get # Return the retrieved external data shares @@ -46,4 +43,4 @@ function Get-FabricExternalDataShares { Write-Message -Message "Failed to retrieve External Data Shares. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/External Data Share/Revoke-FabricExternalDataShares.ps1 b/source/Public/External Data Share/Revoke-FabricExternalDataShares.ps1 index 373000df..f056ad0f 100644 --- a/source/Public/External Data Share/Revoke-FabricExternalDataShares.ps1 +++ b/source/Public/External Data Share/Revoke-FabricExternalDataShares.ps1 @@ -17,12 +17,12 @@ function Revoke-FabricExternalDataShares { The unique identifier of the External Data Share to be retrieved. .EXAMPLE - Get-FabricExternalDataShares + Get-FabricExternalDataShares This example retrieves the External Data Shares details .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -45,19 +45,16 @@ function Revoke-FabricExternalDataShares { try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 4: Loop to retrieve all capacities with continuation token Write-Message -Message "Constructing API endpoint URI..." -Level Debug - $apiEndpointURI = "{0}/admin/workspaces/{1}/items/{2}/externalDataShares/{3}/revoke" -f $FabricConfig.BaseUrl, $WorkspaceId, $ItemId, $ExternalDataShareId + $apiEndpointURI = "admin/workspaces/{0}/items/{1}/externalDataShares/{2}/revoke" -f $WorkspaceId, $ItemId, $ExternalDataShareId if ($PSCmdlet.ShouldProcess("$ExternalDataShareId", "revoke")) { - $externalDataShares = Invoke-FabricAPIRequest ` - -BaseURI $apiEndpointURI ` - -Headers $FabricConfig.FabricHeaders ` + $externalDataShares = Invoke-FabricRestMethod ` + -Uri $apiEndpointURI ` -Method Post } diff --git a/source/Public/Get-AllFabricDatasetRefreshes.ps1 b/source/Public/Get-AllFabricDatasetRefreshes.ps1 deleted file mode 100644 index 12a6c81f..00000000 --- a/source/Public/Get-AllFabricDatasetRefreshes.ps1 +++ /dev/null @@ -1,57 +0,0 @@ -function Get-FabricDatasetRefreshes { - <# -.SYNOPSIS -Retrieves all refreshes for all datasets in all PowerBI workspaces. - -.DESCRIPTION -The Get-FabricDatasetRefreshes function retrieves all refreshes for all datasets in all PowerBI workspaces. It supports multiple aliases for flexibility. - -.EXAMPLE -Get-FabricDatasetRefreshes - -This example retrieves all refreshes for all datasets in all PowerBI workspaces. - -.NOTES -The function makes a GET request to the PowerBI API to retrieve the refreshes. It loops through each workspace and each dataset in each workspace. If a dataset is refreshable, it retrieves the refreshes for the dataset and selects the most recent one. It then creates a PSCustomObject with information about the refresh and adds it to an array of refreshes. Finally, it returns the array of refreshes. - #> - - # This function retrieves all refreshes for all datasets in all PowerBI workspaces. - # Define aliases for the function for flexibility. - - Confirm-FabricAuthToken | Out-Null - - # Retrieve all PowerBI workspaces. - $wsps = Get-FabricWorkspace - # Initialize an array to store the refreshes. - $refs = @() - # Loop through each workspace. - foreach ($w in $wsps) { - # Get a list of all the datasets in the workspace. - $d = Get-FabricDataset -workspaceid $w.Id -ErrorAction SilentlyContinue - # Loop through each dataset. - foreach ($di in $d) { - # Check if the dataset is refreshable. - if ($di.isrefreshable ) { - # Get a list of all the refreshes for the dataset. - $results = (Invoke-PowerBIRestMethod -Method get -Url ("datasets/" + $di.id + "/Refreshes") | ConvertFrom-Json) - # Select the most recent refresh. - $results.value[0] - # Create a PSCustomObject with the information about the refresh. - $refresh = [PSCustomObject] @{ - Clock = Get-Date # Current date and time. - Workspace = $w.name # Name of the workspace. - Dataset = $di.Name # Name of the dataset. - refreshtype = $results.value[0].refreshType # Type of the refresh. - startTime = $results.value[0].startTime # Start time of the refresh. - endTime = $results.value[0].endTime # End time of the refresh. - status = $results.value[0].status # Status of the refresh. - ErrorMessage = $results.value[0].serviceExceptionJson # Error message of the refresh, if any. - } - # Add the refresh to the array of refreshes. - $refs += $refresh - } - } - } - # Return the array of refreshes. - return $refs -} \ No newline at end of file diff --git a/source/Public/Get-FabricAPIClusterURI.ps1 b/source/Public/Get-FabricAPIClusterURI.ps1 index ced8ce60..f49eacc3 100644 --- a/source/Public/Get-FabricAPIClusterURI.ps1 +++ b/source/Public/Get-FabricAPIClusterURI.ps1 @@ -24,7 +24,7 @@ function Get-FabricAPIclusterURI { Param ( ) - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState # Make a GET request to the PowerBI API to retrieve the datasets. $reply = Invoke-RestMethod -uri "$($PowerBI.BaseApiUrl)/datasets" -Headers $FabricSession.HeaderParams -Method GET diff --git a/source/Public/Get-FabricAuthToken.ps1 b/source/Public/Get-FabricAuthToken.ps1 index 3bbd3fcb..f6d61bc3 100644 --- a/source/Public/Get-FabricAuthToken.ps1 +++ b/source/Public/Get-FabricAuthToken.ps1 @@ -3,7 +3,8 @@ Retrieves the Fabric API authentication token. .DESCRIPTION - The Get-FabricAuthToken function retrieves the Fabric API authentication token. If the token is not already set, it calls the Set-FabricAuthToken function to set it. It then outputs the token. + The Get-FabricAuthToken function retrieves the Fabric API authentication token. + If the token is not already set, the function fails. .EXAMPLE Get-FabricAuthToken @@ -18,22 +19,21 @@ .NOTES This function was originally written by Rui Romano. - https://github.com/RuiRomano/fabricps-pbip + https://github.com/microsoft/Analysis-Services/tree/master/pbidevmode/fabricps-pbip #> function Get-FabricAuthToken { - [Alias("Get-FabAuthToken")] [CmdletBinding()] param ( ) - # Check if the Fabric token is already set - if (!$FabricSession.FabricToken) { - # If not, set the Fabric token - Set-FabricAuthToken + if ($FabricSession.AccessToken) { + $ssPtr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($FabricSession.AccessToken.Token) + $Token = ([System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($ssPtr)) + return $Token + } else { + Write-Message -Message "AccessToken details are missing. Please run 'Connect-FabricAccount' to configure session." -Level Error } - # Output the Fabric token - return $FabricSession.FabricToken -} \ No newline at end of file +} diff --git a/source/Public/Get-FabricConnection.ps1 b/source/Public/Get-FabricConnection.ps1 index a1056914..3954b23f 100644 --- a/source/Public/Get-FabricConnection.ps1 +++ b/source/Public/Get-FabricConnection.ps1 @@ -31,16 +31,16 @@ https://learn.microsoft.com/en-us/rest/api/fabric/core/connections/list-connecti ) begin { - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState } process { if ($connectionId) { - $result = Invoke-FabricAPIRequest -Uri "/connections/$($connectionId)" -Method GET + $result = Invoke-FabricRestMethod -Uri "/connections/$($connectionId)" -Method GET } else { - $result = Invoke-FabricAPIRequest -Uri "/connections" -Method GET + $result = Invoke-FabricRestMethod -Uri "/connections" -Method GET } return $result.value } -} \ No newline at end of file +} diff --git a/source/Public/Get-FabricDatasetRefreshes.ps1 b/source/Public/Get-FabricDatasetRefreshes.ps1 index dde942ba..ceaa5792 100644 --- a/source/Public/Get-FabricDatasetRefreshes.ps1 +++ b/source/Public/Get-FabricDatasetRefreshes.ps1 @@ -43,12 +43,14 @@ function Get-FabricDatasetRefreshes { # Check if the dataset is refreshable. if ($di.isrefreshable -eq "True") { # Get a list of all the refreshes for the dataset. - $results = (Invoke-PowerBIRestMethod -Method get -Url ("datasets/" + $di.id + "/Refreshes") | ConvertFrom-Json) + $results = Invoke-FabricRestMethod -Method get -PowerBIApi -uri ("datasets/" + $di.id + "/Refreshes") # Create a PSCustomObject with the information about the refresh. $refresh = [PSCustomObject]@{ Clock = Get-Date + WorkspaceId = $workspaceId Workspace = $w.name + DatasetId = $di.Id Dataset = $di.Name refreshtype = $results.value[0].refreshType startTime = $results.value[0].startTime @@ -66,4 +68,4 @@ function Get-FabricDatasetRefreshes { } -} \ No newline at end of file +} diff --git a/source/Public/Get-FabricDebugInfo.ps1 b/source/Public/Get-FabricDebugInfo.ps1 index f51809ef..1b6f3392 100644 --- a/source/Public/Get-FabricDebugInfo.ps1 +++ b/source/Public/Get-FabricDebugInfo.ps1 @@ -2,7 +2,7 @@ function Get-FabricDebugInfo { <# .SYNOPSIS - Shows internal debug information about the current session. + Shows internal debug information about the current Azure & Fabric sessions & Fabric config. .DESCRIPTION Shows internal debug information about the current session. It is useful for troubleshooting purposes. @@ -16,31 +16,16 @@ function Get-FabricDebugInfo { .NOTES - Revsion History: - - - 2024-12-22 - FGE: Added Verbose Output - #> [CmdletBinding()] [OutputType([System.Collections.Hashtable])] - param ( - - ) - - begin { } - - process { - Write-Verbose "Show current session object" - - return @{ - FabricSession = $script:FabricSession - AzureSession = $script:AzureSession - FabricConfig = $script:FabricConfig - } + param ( ) + return @{ + FabricSession = $script:FabricSession + AzureSession = $script:AzureSession + FabricConfig = $script:FabricConfig } - end { } - } diff --git a/source/Public/Get-FabricUsageMetricsQuery.ps1 b/source/Public/Get-FabricUsageMetricsQuery.ps1 index 13b0357d..0263fa4e 100644 --- a/source/Public/Get-FabricUsageMetricsQuery.ps1 +++ b/source/Public/Get-FabricUsageMetricsQuery.ps1 @@ -50,7 +50,7 @@ The function defines the headers and body for a POST request to the PowerBI API ) # Confirm the authentication token. - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState # Define the body of the POST request. if ($ImpersonatedUser -ne "") { @@ -80,4 +80,4 @@ The function defines the headers and body for a POST request to the PowerBI API # Make a POST request to the PowerBI API to retrieve the usage metrics for the specified dataset. # The function returns the response of the POST request. return Invoke-RestMethod -uri "$($PowerBI.BaseApiUrl)/groups/$groupId/datasets/$DatasetID/executeQueries" -Headers $FabricSession.HeaderParams -Body $reportbody -Method Post -} \ No newline at end of file +} diff --git a/source/Public/Invoke-FabricAPIRequest.ps1 b/source/Public/Invoke-FabricAPIRequest.ps1 deleted file mode 100644 index 5ff3ad80..00000000 --- a/source/Public/Invoke-FabricAPIRequest.ps1 +++ /dev/null @@ -1,173 +0,0 @@ -Function Invoke-FabricAPIRequest { - - <# - .SYNOPSIS - Sends an HTTP request to a Fabric API endpoint and retrieves the response. - Takes care of: authentication, 429 throttling, Long-Running-Operation (LRO) response - - .DESCRIPTION - The Invoke-FabricAPIRequest function is used to send an HTTP request to a Fabric API endpoint and retrieve the response. It handles various aspects such as authentication, 429 throttling, and Long-Running-Operation (LRO) response. - - .PARAMETER authToken - The authentication token to be used for the request. If not provided, it will be obtained using the Get-FabricAuthToken function. - - .PARAMETER uri - The URI of the Fabric API endpoint to send the request to. - - .PARAMETER method - The HTTP method to be used for the request. Valid values are 'Get', 'Post', 'Delete', 'Put', and 'Patch'. The default value is 'Get'. - - .PARAMETER body - The body of the request, if applicable. - - .PARAMETER contentType - The content type of the request. The default value is 'application/json; charset=utf-8'. - - .PARAMETER timeoutSec - The timeout duration for the request in seconds. The default value is 240 seconds. - - .PARAMETER outFile - The file path to save the response content to, if applicable. - - .PARAMETER retryCount - The number of times to retry the request in case of a 429 (Too Many Requests) error. The default value is 0. - - .EXAMPLE - Invoke-FabricAPIRequest -uri "/api/resource" -method "Get" - - This example sends a GET request to the "/api/resource" endpoint of the Fabric API. - - .EXAMPLE - Invoke-FabricAPIRequest -authToken "abc123" -uri "/api/resource" -method "Post" -body $requestBody - - This example sends a POST request to the "/api/resource" endpoint of the Fabric API with a request body. - - .NOTES - This function requires the Get-FabricAuthToken function to be defined in the same script or module. - This function was originally written by Rui Romano. - https://github.com/RuiRomano/fabricps-pbip - #> - [CmdletBinding()] - param( - [Parameter(Mandatory = $false)] - [string] $authToken, - - [Parameter(Mandatory = $true)] - [string] $uri, - - [Parameter(Mandatory = $false)] - [ValidateSet('Get', 'Post', 'Delete', 'Put', 'Patch')] - [string] $method = "Get", - - [Parameter(Mandatory = $false)] - $body, - - [Parameter(Mandatory = $false)] - [string] $contentType = "application/json; charset=utf-8", - - [Parameter(Mandatory = $false)] - [int] $timeoutSec = 240, - - [Parameter(Mandatory = $false)] - [int] $retryCount = 0 - ) - - Confirm-FabricAuthToken | Out-Null - $fabricHeaders = $FabricSession.HeaderParams - - try { - - $requestUrl = "$($FabricSession.BaseApiUrl)/$uri" - Write-Verbose "Calling $requestUrl" - $response = Invoke-WebRequest -Headers $fabricHeaders -ContentType $contentType -Method $method -Uri $requestUrl -Body $body -TimeoutSec $timeoutSec - - if ($response.StatusCode -eq 202) { - if ($uri -match "jobType=Pipeline") { - Write-Output "Waiting for pipeline to complete. Please check the status in the Power BI Service." - } else { - do { - $asyncUrl = [string]$response.Headers.Location - - Write-Output "Waiting for request to complete. Sleeping..." - Start-Sleep -Seconds 5 - $response2 = Invoke-WebRequest -Headers $fabricHeaders -Method Get -Uri $asyncUrl - $lroStatusContent = $response2.Content | ConvertFrom-Json - } - while ($lroStatusContent.status -ine "succeeded" -and $lroStatusContent.status -ine "failed") - - try { - $response = Invoke-WebRequest -Headers $fabricHeaders -Method Get -Uri "$asyncUrl/result" - } catch { - Write-Output "No result URL" - } - } - } - - #if ($response.StatusCode -in @(200,201) -and $response.Content) - if ($response.Content) { - $contentBytes = $response.RawContentStream.ToArray() - - if ($contentBytes[0] -eq 0xef -and $contentBytes[1] -eq 0xbb -and $contentBytes[2] -eq 0xbf) { - $contentText = [System.Text.Encoding]::UTF8.GetString($contentBytes[3..$contentBytes.Length]) - } else { - $contentText = $response.Content - } - $jsonResult = $contentText | ConvertFrom-Json - Write-Output $jsonResult -NoEnumerate - } else { - Write-Output $response -NoEnumerate - } - } catch { - $ex = $_.Exception - $message = $null - - if ($null -ne $ex.Response) { - - $responseStatusCode = [int]$ex.Response.StatusCode - - if ($responseStatusCode -in @(429)) { - if ($ex.Response.Headers.RetryAfter) { - $retryAfterSeconds = $ex.Response.Headers.RetryAfter.Delta.TotalSeconds + 5 - } - - if (!$retryAfterSeconds) { - $retryAfterSeconds = 60 - } - - Write-Output "Exceeded the amount of calls (TooManyRequests - 429), sleeping for $retryAfterSeconds seconds." - - Start-Sleep -Seconds $retryAfterSeconds - - $maxRetries = 3 - - if ($retryCount -le $maxRetries) { - Invoke-FabricAPIRequest -authToken $authToken -uri $uri -method $method -body $body -contentType $contentType -timeoutSec $timeoutSec -retryCount ($retryCount + 1) - } else { - throw "Exceeded the amount of retries ($maxRetries) after 429 error." - } - - } else { - $apiErrorObj = $ex.Response.Headers | Where-Object { $_.key -ieq "x-ms-public-api-error-code" } | Select-Object -First 1 - - if ($apiErrorObj) { - $apiError = $apiErrorObj.Value[0] - } - - if ($apiError -ieq "ItemHasProtectedLabel") { - Write-Warning "Item has a protected label." - } else { - throw - } - - # TODO: Investigate why response.Content is empty but powershell can read it on throw - #$errorContent = $ex.Response.Content.ReadAsStringAsync().Result; - #$message = "$($ex.Message) - StatusCode: '$($ex.Response.StatusCode)'; Content: '$errorContent'" - } - } else { - $message = "$($ex.Message)" - } - if ($message) { - throw $message - } - } -} diff --git a/source/Public/Invoke-FabricDatasetRefresh.ps1 b/source/Public/Invoke-FabricDatasetRefresh.ps1 index b34b79b6..c20887ea 100644 --- a/source/Public/Invoke-FabricDatasetRefresh.ps1 +++ b/source/Public/Invoke-FabricDatasetRefresh.ps1 @@ -1,20 +1,20 @@ <# -.SYNOPSIS + .SYNOPSIS This function invokes a refresh of a PowerBI dataset -.DESCRIPTION + .DESCRIPTION The Invoke-FabricDatasetRefresh function is used to refresh a PowerBI dataset. It first checks if the dataset is refreshable. If it is not, it writes an error. If it is, it invokes a PowerBI REST method to refresh the dataset. The URL for the request is constructed using the provided dataset ID. - -.PARAMETER DatasetID + .PARAMETER DatasetID A mandatory parameter that specifies the dataset ID. -.EXAMPLE + .EXAMPLE Invoke-FabricDatasetRefresh -DatasetID "12345678-1234-1234-1234-123456789012" This command invokes a refresh of the dataset with the ID "12345678-1234-1234-1234-123456789012" -.NOTES - Alias: Invoke-FabDatasetRetresh + + .NOTES + Alias: Invoke-FabDatasetRefresh #> function Invoke-FabricDatasetRefresh { # Define aliases for the function for flexibility. @@ -27,7 +27,7 @@ function Invoke-FabricDatasetRefresh { [string]$DatasetID ) - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState # Check if the dataset is refreshable if ((Get-FabricDataset -DatasetId $DatasetID).isrefreshable -eq $false) { @@ -43,4 +43,4 @@ function Invoke-FabricDatasetRefresh { # The URL for the request is constructed using the provided workspace ID and dataset ID. return Invoke-RestMethod -Method POST -uri ("$($PowerBI.BaseApiUrl)/datasets/$datasetid/refreshes") -Headers $FabricSession.HeaderParams } -} \ No newline at end of file +} diff --git a/source/Public/Invoke-FabricRestMethod.ps1 b/source/Public/Invoke-FabricRestMethod.ps1 new file mode 100644 index 00000000..4a5a5f46 --- /dev/null +++ b/source/Public/Invoke-FabricRestMethod.ps1 @@ -0,0 +1,98 @@ +Function Invoke-FabricRestMethod { + +<# +.SYNOPSIS + Sends an HTTP request to a Fabric API endpoint and retrieves the response. + +.DESCRIPTION + The Invoke-FabricRestMethod function is used to send an HTTP request to a Fabric API endpoint and retrieve the response. + +.PARAMETER uri + The URI of the Fabric API endpoint to send the request to. + +.PARAMETER Method + The HTTP method to be used for the request. Valid values are 'GET', 'POST', 'DELETE', 'PUT', and 'PATCH'. The default value is 'GET'. + +.PARAMETER Body + The body of the request, if applicable. This can be a hashtable or a string. If a hashtable is provided, it will be converted to JSON format. + +.PARAMETER TestTokenExpired + A switch parameter to test if the Fabric token is expired before making the request. If the token is expired, it will attempt to refresh it. + +.PARAMETER PowerBIApi + A switch parameter to indicate that the request should be sent to the Power BI API instead of the Fabric API. + +.EXAMPLE + Invoke-FabricRestMethod -uri "/api/resource" -method "GET" + + This example sends a GET request to the "/api/resource" endpoint of the Fabric API. + +.EXAMPLE + Invoke-FabricRestMethod -uri "/api/resource" -method "POST" -body $requestBody + + This example sends a POST request to the "/api/resource" endpoint of the Fabric API with a request body. + +.NOTES + - Requires `$FabricConfig` global configuration, including `BaseUrl`. + + Author: Kamil Nowinski +#> + + [CmdletBinding()] + param( + [Parameter(Mandatory = $true)] + [string] $Uri, + + [Parameter(Mandatory = $false)] + [ValidateSet('GET', 'POST', 'DELETE', 'PUT', 'PATCH')] + [string] $Method = "GET", + + [Parameter(Mandatory = $false)] + $Body, + + [switch] $TestTokenExpired, + + [switch] $PowerBIApi + ) + + if ($TestTokenExpired) { + Confirm-TokenState + } + + $baseUrl = $FabricConfig.BaseUrl + if ($PowerBIApi) { + $baseUrl = $PowerBI.BaseApiUrl + } + + if ($Uri -notmatch '^https?://.*') { + $Uri = "{0}/{1}" -f $baseUrl, $Uri + } elseif ($PowerBIApi) { + Write-Message -Message "PowerBIApi param is ignored when full Uri is provided." -Level Warning + } + Write-Message -Message "Target API Endpoint: $Uri" -Level Verbose + + if ($Body -is [hashtable]) { + $Body = $Body | ConvertTo-Json -Depth 10 + Write-Message -Message "Request Body: $Body" -Level Debug + } elseif ($Body -is [string]) { + Write-Message -Message "Request Body: $Body" -Level Debug + } else { + Write-Message -Message "No request body provided." -Level Debug + } + + $response = Invoke-RestMethod ` + -Headers $FabricSession.HeaderParams ` + -Uri $Uri ` + -Method $Method ` + -Body $Body ` + -ContentType "application/json" ` + -ErrorAction 'Stop' ` + -SkipHttpErrorCheck ` + -ResponseHeadersVariable "responseHeader" ` + -StatusCodeVariable "statusCode" + + $script:statusCode = $statusCode + $script:responseHeader = $responseHeader + + return $response +} diff --git a/source/Public/Invoke-FabricRestMethodExtended.ps1 b/source/Public/Invoke-FabricRestMethodExtended.ps1 new file mode 100644 index 00000000..4714e169 --- /dev/null +++ b/source/Public/Invoke-FabricRestMethodExtended.ps1 @@ -0,0 +1,174 @@ +Function Invoke-FabricRestMethodExtended { + +<# +.SYNOPSIS + Sends an HTTP request to a Fabric API endpoint and retrieves the response. + Takes care of: authentication, 429 throttling, Long-Running-Operation (LRO) response + +.DESCRIPTION + The Invoke-FabricRestMethodExtended function is used to send an HTTP request to a Fabric API endpoint and retrieve the response. It handles various aspects such as authentication, 429 throttling, and Long-Running-Operation (LRO) response. + +.PARAMETER Uri + The URI of the Fabric API endpoint to send the request to. + +.PARAMETER Method + The HTTP method to be used for the request. Valid values are 'GET', 'POST', 'DELETE', 'PUT', and 'PATCH'. The default value is 'GET'. + +.PARAMETER Body + The body of the request, if applicable. + +.PARAMETER RetryCount + The number of times to retry the request in case of a 429 (Too Many Requests) error. The default value is 0. + +.EXAMPLE + Invoke-FabricRestMethodExtended -Uri "/api/resource" -Method "GET" + + This example sends a GET request to the "/api/resource" endpoint of the Fabric API. + +.EXAMPLE + Invoke-FabricRestMethodExtended -Uri "/api/resource" -method "POST" -Body $requestBody + + This example sends a POST request to the "/api/resource" endpoint of the Fabric API with a request body. + +.NOTES + This function based on code that was originally written by Rui Romano (Invoke-FabricAPIRequest) and replaces it. + It's extended version of simple Invoke-FabricRestMethod function. + Requires `$FabricConfig` global configuration, including `BaseUrl`. + + Author: Kamil Nowinski +#> + + [CmdletBinding()] + param( + [Parameter(Mandatory = $true)] + [string] $Uri, + + [Parameter(Mandatory = $false)] + [ValidateSet('GET', 'POST', 'DELETE', 'PUT', 'PATCH')] + [string] $Method = "GET", + + [Parameter(Mandatory = $false)] + $Body, + + [Parameter(Mandatory = $false)] + [int] $RetryCount = 0 + ) + + Confirm-TokenState + if ($Uri -notmatch '^https?://.*') { + $Uri = "{0}/{1}" -f $FabricConfig.BaseUrl, $Uri + } + Write-Message -Message "Fabric API Endpoint: $Uri" -Level Verbose + $fabricHeaders = $FabricSession.HeaderParams + + try { + $requestUrl = "$($FabricConfig.BaseUrl)/$uri" + Write-Message "Calling $requestUrl" -Level Debug + # If need to use -OutFile beware of the following breaking change: https://github.com/PowerShell/PowerShell/issues/20744 + # TODO: use -SkipHttpErrorCheck to read the entire error response, need to find a solution to handle 429 errors: https://stackoverflow.com/questions/75629606/powershell-webrequest-handle-response-code-and-exit + $response = Invoke-WebRequest -Headers $fabricHeaders -Method $method -Uri $requestUrl -Body $body # -TimeoutSec $timeoutSec + $requestId = [string]$response.Headers.requestId + Write-Message "RAID: $requestId" -Level Debug + $lroFailOrNoResultFlag = $false + if ($response.StatusCode -eq 202) { + do { + $asyncUrl = [string]$response.Headers.Location + Write-Log "LRO - Waiting for request to complete in service." + Start-Sleep -Seconds 5 + $response = Invoke-WebRequest -Headers $fabricHeaders -Method Get -Uri $asyncUrl + $lroStatusContent = $response.Content | ConvertFrom-Json + } + while ($lroStatusContent.status -ine "succeeded" -and $lroStatusContent.status -ine "failed") + + if ($lroStatusContent.status -ieq "succeeded") { + # Only calls /result if there is a location header, otherwise 'OperationHasNoResult' error is thrown + $resultUrl = [string]$response.Headers.Location + if ($resultUrl) { + $response = Invoke-WebRequest -Headers $fabricHeaders -Method Get -Uri $resultUrl + } + else { + $lroFailOrNoResultFlag = $true + } + } + else { + $lroFailOrNoResultFlag = $true + if ($lroStatusContent.error) { + throw "LRO API Error: '$($lroStatusContent.error.errorCode)' - $($lroStatusContent.error.message)" + } + } + } + + Write-Message "Request completed." -Level Debug + + #if ($response.StatusCode -in @(200,201) -and $response.Content) + if (!$lroFailOrNoResultFlag -and $response.Content) { + + $contentBytes = $response.RawContentStream.ToArray() + # Test for BOM + if ($contentBytes[0] -eq 0xef -and $contentBytes[1] -eq 0xbb -and $contentBytes[2] -eq 0xbf) { + $contentText = [System.Text.Encoding]::UTF8.GetString($contentBytes[3..$contentBytes.Length]) + } + else { + $contentText = $response.Content + } + + $jsonResult = $contentText | ConvertFrom-Json + if ($jsonResult.value) { + $jsonResult = $jsonResult.value + } + Write-Output $jsonResult -NoEnumerate + } + } + catch { + $ex = $_.Exception + $message = $null + + if ($null -ne $ex.Response) { + + $responseStatusCode = [int]$ex.Response.StatusCode + + if ($responseStatusCode -in @(429)) { + if ($ex.Response.Headers.RetryAfter) { + $retryAfterSeconds = $ex.Response.Headers.RetryAfter.Delta.TotalSeconds + 5 + } + if (!$retryAfterSeconds) { + $retryAfterSeconds = 60 + } + Write-Message "Exceeded the amount of calls (TooManyRequests - 429), sleeping for $retryAfterSeconds seconds." -Level Verbose + Start-Sleep -Seconds $retryAfterSeconds + $maxRetries = 3 + + if ($retryCount -le $maxRetries) { + Invoke-FabricRestMethod -uri $uri -method $method -body $body -retryCount ($retryCount + 1) + } + else { + throw "Exceeded the amount of retries ($maxRetries) after 429 error." + } + } + else { + $apiErrorObj = $ex.Response.Headers | Where-Object { $_.key -ieq "x-ms-public-api-error-code" } | Select-Object -First 1 + + if ($apiErrorObj) { + $apiError = $apiErrorObj.Value[0] + + if ($apiError -ieq "ItemHasProtectedLabel") { + Write-Message "Item has a protected label." -Level Warning + } + else { + $message = "$($ex.Message); API error code: '$apiError'" + + throw $message + } + } + } + } + else { + $message = "$($ex.Message)" + } + + if ($message) { + throw $message + } + + } +} diff --git a/source/Public/Item/Export-FabricItem.ps1 b/source/Public/Item/Export-FabricItem.ps1 index a1ceafe0..1fe13da2 100644 --- a/source/Public/Item/Export-FabricItem.ps1 +++ b/source/Public/Item/Export-FabricItem.ps1 @@ -29,7 +29,7 @@ This example exports the item with the specified ID from the Fabric workspace wi .NOTES This function is based on the Export-FabricItems function written by Rui Romano. -https://github.com/RuiRomano/fabricps-pbip +https://github.com/microsoft/Analysis-Services/tree/master/pbidevmode/fabricps-pbip #> Function Export-FabricItem { @@ -45,7 +45,7 @@ Function Export-FabricItem { if (![string]::IsNullOrEmpty($itemID)) { # Invoke the Fabric API to get the specific item in the workspace - $item = Invoke-FabricAPIRequest -Uri "workspaces/$workspaceId/items/$itemID/getDefinition" -Method POST + $item = Invoke-FabricRestMethod -Uri "workspaces/$workspaceId/items/$itemID/getDefinition" -Method POST # If a filter is provided @@ -65,7 +65,7 @@ Function Export-FabricItem { # Display a message indicating the items were exported Write-Output "Items exported to $path" } else { - $items = Invoke-FabricAPIRequest -Uri "workspaces/$workspaceId/items" -Method Get + $items = Invoke-FabricRestMethod -Uri "workspaces/$workspaceId/items" -Method Get if ($filter) { $items = $items.value | Where-Object $filter @@ -84,7 +84,7 @@ Function Export-FabricItem { if ($itemType -in @("report", "semanticmodel", "notebook", "SparkJobDefinitionV1", "DataPipeline")) { Write-Output "Getting definition of: $itemId / $itemName / $itemType" - $response = Invoke-FabricAPIRequest -Uri "workspaces/$workspaceId/items/$itemId/getDefinition" -Method Post + $response = Invoke-FabricRestMethod -Uri "workspaces/$workspaceId/items/$itemId/getDefinition" -Method Post $partCount = $response.definition.parts.Count @@ -111,4 +111,4 @@ Function Export-FabricItem { } } } -} \ No newline at end of file +} diff --git a/source/Public/Item/Get-FabricItem.ps1 b/source/Public/Item/Get-FabricItem.ps1 index 9fbf0c93..a046a537 100644 --- a/source/Public/Item/Get-FabricItem.ps1 +++ b/source/Public/Item/Get-FabricItem.ps1 @@ -25,7 +25,7 @@ This example retrieves all fabric items of type "file" from the workspace with I .NOTES This function was originally written by Rui Romano. -https://github.com/RuiRomano/fabricps-pbip +https://github.com/microsoft/Analysis-Services/tree/master/pbidevmode/fabricps-pbip #> [CmdletBinding()] @@ -46,7 +46,7 @@ https://github.com/RuiRomano/fabricps-pbip ) begin { - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState } process { @@ -54,16 +54,16 @@ https://github.com/RuiRomano/fabricps-pbip $workspaceID = $Workspace.id } if ($itemID) { - $result = Invoke-FabricAPIRequest -Uri "workspaces/$($workspaceID)/items/$($itemID)" -Method Get + $result = Invoke-FabricRestMethod -Uri "workspaces/$($workspaceID)/items/$($itemID)" -Method Get } else { if ($type) { - $result = Invoke-FabricAPIRequest -Uri "workspaces/$($workspaceID)/items?type=$type" -Method Get + $result = Invoke-FabricRestMethod -Uri "workspaces/$($workspaceID)/items?type=$type" -Method Get } else { # Invoke the Fabric API to get the workspaces - $result = Invoke-FabricAPIRequest -Uri "workspaces/$($workspaceID)/items" -Method Get + $result = Invoke-FabricRestMethod -Uri "workspaces/$($workspaceID)/items" -Method Get } # Output the result return $result.value } } -} \ No newline at end of file +} diff --git a/source/Public/Item/Import-FabricItem.ps1 b/source/Public/Item/Import-FabricItem.ps1 index 1052201f..7ee624d4 100644 --- a/source/Public/Item/Import-FabricItem.ps1 +++ b/source/Public/Item/Import-FabricItem.ps1 @@ -2,6 +2,7 @@ <# .SYNOPSIS Imports items using the Power BI Project format (PBIP) into a Fabric workspace from a specified file system source. + .DESCRIPTION The Import-FabricItem function imports items using the Power BI Project format (PBIP) into a Fabric workspace from a specified file system source. It supports multiple aliases for flexibility. The function handles the import of datasets and reports, ensuring that the correct item type is used and that the items are created or updated as necessary. @@ -24,9 +25,9 @@ This example imports PBIP files from the 'C:\PBIPFiles' folder into the Fabric workspace with ID '12345'. It only searches for PBIP files in the 'C:\PBIPFiles\Reports' folder. .NOTES - This function requires the Invoke-FabricAPIRequest function to be available in the current session. + This function requires the Invoke-FabricRestMethod function to be available in the current session. This function was originally written by Rui Romano. - https://github.com/RuiRomano/fabricps-pbip + https://github.com/microsoft/Analysis-Services/tree/master/pbidevmode/fabricps-pbip #> Function Import-FabricItem { @@ -48,7 +49,7 @@ Function Import-FabricItem { # Search for folders with .pbir and .pbidataset in it - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState $itemsFolders = Get-ChildItem -Path $path -recurse -include *.pbir, *.pbidataset @@ -58,7 +59,7 @@ Function Import-FabricItem { # Get existing items of the workspace - $items = Invoke-FabricAPIRequest -Uri "workspaces/$workspaceId/items" -Method Get + $items = Invoke-FabricRestMethod -Uri "workspaces/$workspaceId/items" -Method Get Write-Output "Existing items: $($items.Count)" @@ -206,7 +207,7 @@ Function Import-FabricItem { } | ConvertTo-Json -Depth 3 if($PSCmdlet.ShouldProcess($itemPath, "Create Item")) { - $createItemResult = Invoke-FabricAPIRequest -uri "workspaces/$workspaceId/items" -method Post -body $itemRequest + $createItemResult = Invoke-FabricRestMethod -uri "workspaces/$workspaceId/items" -method Post -body $itemRequest } $itemId = $createItemResult.id @@ -224,7 +225,7 @@ Function Import-FabricItem { } | ConvertTo-Json -Depth 3 if($PSCmdlet.ShouldProcess($itemPath, "Update Item")) { - Invoke-FabricAPIRequest -Uri "workspaces/$workspaceId/items/$itemId/updateDefinition" -Method Post -Body $itemRequest + Invoke-FabricRestMethod -Uri "workspaces/$workspaceId/items/$itemId/updateDefinition" -Method Post -Body $itemRequest } Write-Output "Updated new item with ID '$itemId' $([datetime]::Now.ToString("s"))" -ForegroundColor Green diff --git a/source/Public/Item/Remove-FabricItem.ps1 b/source/Public/Item/Remove-FabricItem.ps1 index 219d358d..1e180a3b 100644 --- a/source/Public/Item/Remove-FabricItem.ps1 +++ b/source/Public/Item/Remove-FabricItem.ps1 @@ -27,44 +27,44 @@ .NOTES This function was written by Rui Romano. - https://github.com/RuiRomano/fabricps-pbip + https://github.com/microsoft/Analysis-Services/tree/master/pbidevmode/fabricps-pbip #> Function Remove-FabricItem { - [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] - param - ( - [Parameter(Mandatory = $true)] - [string]$workspaceId, - [Parameter(Mandatory = $false)] - [string]$filter, - [Parameter(Mandatory = $false)] - [string]$itemID - ) + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] + param + ( + [Parameter(Mandatory = $true)] + [string]$workspaceId, + [Parameter(Mandatory = $false)] + [string]$filter, + [Parameter(Mandatory = $false)] + [string]$itemID + ) - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState - # Invoke the Fabric API to get the items in the workspace - if ($PSCmdlet.ShouldProcess("Remove items from workspace $workspaceId")) { - if ($itemID) { - Invoke-FabricAPIRequest -Uri "workspaces/$($workspaceID)/items/$($itemID)" -Method Delete - } else { - $items = Invoke-FabricAPIRequest -Uri "workspaces/$workspaceId/items" -Method Get + # Invoke the Fabric API to get the items in the workspace + if ($PSCmdlet.ShouldProcess("Remove items from workspace $workspaceId")) { + if ($itemID) { + Invoke-FabricRestMethod -Uri "workspaces/$($workspaceID)/items/$($itemID)" -Method Delete + } else { + $items = Invoke-FabricRestMethod -Uri "workspaces/$workspaceId/items" -Method Get - # Display the count of existing items - Write-Output "Existing items: $($items.Count)" + # Display the count of existing items + Write-Output "Existing items: $($items.Count)" - # If a filter is provided - if ($filter) { - # Filter the items whose DisplayName matches the filter - $items = $items | Where-Object { $_.DisplayName -like $filter } - } + # If a filter is provided + if ($filter) { + # Filter the items whose DisplayName matches the filter + $items = $items | Where-Object { $_.DisplayName -like $filter } + } - # For each item - foreach ($item in $items) { - # Remove the item - Invoke-FabricAPIRequest -Uri "workspaces/$workspaceId/items/$($item.ID)" -Method Delete - } - } - } + # For each item + foreach ($item in $items) { + # Remove the item + Invoke-FabricRestMethod -Uri "workspaces/$workspaceId/items/$($item.ID)" -Method Delete + } + } + } } diff --git a/source/Public/KQL Dashboard/Get-FabricKQLDashboard.ps1 b/source/Public/KQL Dashboard/Get-FabricKQLDashboard.ps1 index 9390c5a6..193e55b6 100644 --- a/source/Public/KQL Dashboard/Get-FabricKQLDashboard.ps1 +++ b/source/Public/KQL Dashboard/Get-FabricKQLDashboard.ps1 @@ -27,7 +27,7 @@ Retrieves all KQLDashboards in workspace "12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -57,9 +57,7 @@ function Get-FabricKQLDashboard { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null @@ -85,14 +83,9 @@ function Get-FabricKQLDashboard { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/KQL Dashboard/Get-FabricKQLDashboardDefinition.ps1 b/source/Public/KQL Dashboard/Get-FabricKQLDashboardDefinition.ps1 index 48f81469..8de02b5f 100644 --- a/source/Public/KQL Dashboard/Get-FabricKQLDashboardDefinition.ps1 +++ b/source/Public/KQL Dashboard/Get-FabricKQLDashboardDefinition.ps1 @@ -28,7 +28,7 @@ Retrieves the definitions of all KQLDashboards in the workspace with ID `12345` .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. - Handles long-running operations asynchronously. #> @@ -50,9 +50,7 @@ function Get-FabricKQLDashboardDefinition { try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/kqlDashboards/{2}/getDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $KQLDashboardId @@ -63,13 +61,9 @@ function Get-FabricKQLDashboardDefinition { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post # Step 5: Validate the response code and handle the response switch ($statusCode) { @@ -115,4 +109,4 @@ function Get-FabricKQLDashboardDefinition { Write-Message -Message "Failed to retrieve KQLDashboard. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/KQL Dashboard/New-FabricKQLDashboard.ps1 b/source/Public/KQL Dashboard/New-FabricKQLDashboard.ps1 index 202a21fc..00f202f2 100644 --- a/source/Public/KQL Dashboard/New-FabricKQLDashboard.ps1 +++ b/source/Public/KQL Dashboard/New-FabricKQLDashboard.ps1 @@ -23,11 +23,11 @@ An optional path to the KQLDashboard definition file (e.g., .ipynb file) to uplo An optional path to the platform-specific definition (e.g., .platform file) to upload. .EXAMPLE - Add-FabricKQLDashboard -WorkspaceId "workspace-12345" -KQLDashboardName "New KQLDashboard" -KQLDashboardPathDefinition "C:\KQLDashboards\example.ipynb" +Add-FabricKQLDashboard -WorkspaceId "workspace-12345" -KQLDashboardName "New KQLDashboard" -KQLDashboardPathDefinition "C:\KQLDashboards\example.ipynb" - .NOTES +.NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -61,9 +61,7 @@ function New-FabricKQLDashboard try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/kqlDashboards" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -142,16 +140,10 @@ function New-FabricKQLDashboard if ($PSCmdlet.ShouldProcess($KQLDashboardName, "Create KQLDashboard")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/KQL Dashboard/Remove-FabricKQLDashboard.ps1 b/source/Public/KQL Dashboard/Remove-FabricKQLDashboard.ps1 index f76af2fb..76794b09 100644 --- a/source/Public/KQL Dashboard/Remove-FabricKQLDashboard.ps1 +++ b/source/Public/KQL Dashboard/Remove-FabricKQLDashboard.ps1 @@ -26,7 +26,7 @@ Author: Tiago Balabuch function Remove-FabricKQLDashboard { - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]` param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -40,9 +40,7 @@ function Remove-FabricKQLDashboard try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/kqlDashboards/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $KQLDashboardId @@ -51,13 +49,9 @@ function Remove-FabricKQLDashboard if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove KQLDashboard")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Validate the response code diff --git a/source/Public/KQL Dashboard/Update-FabricKQLDashboard.ps1 b/source/Public/KQL Dashboard/Update-FabricKQLDashboard.ps1 index b3a44aef..c61bf958 100644 --- a/source/Public/KQL Dashboard/Update-FabricKQLDashboard.ps1 +++ b/source/Public/KQL Dashboard/Update-FabricKQLDashboard.ps1 @@ -31,7 +31,7 @@ Updates both the name and description of the KQLDashboard "KQLDashboard123". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -58,9 +58,7 @@ Author: Tiago Balabuch try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/kqlDashboards/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $KQLDashboardId @@ -83,15 +81,10 @@ Author: Tiago Balabuch if ($PSCmdlet.ShouldProcess($KQLDashboardId, "Update KQLDashboard")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code diff --git a/source/Public/KQL Dashboard/Update-FabricKQLDashboardDefinition.ps1 b/source/Public/KQL Dashboard/Update-FabricKQLDashboardDefinition.ps1 index 3c8326f2..6502b5d9 100644 --- a/source/Public/KQL Dashboard/Update-FabricKQLDashboardDefinition.ps1 +++ b/source/Public/KQL Dashboard/Update-FabricKQLDashboardDefinition.ps1 @@ -31,7 +31,7 @@ Updates both the content and metadata of the KQLDashboard with ID `67890` in the .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. - The KQLDashboard content is encoded as Base64 before being sent to the Fabric API. - This function handles asynchronous operations and retrieves operation results if required. @@ -63,9 +63,7 @@ function Update-FabricKQLDashboardDefinition try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/KQLDashboards/{2}/updateDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $KQLDashboardId @@ -129,15 +127,10 @@ function Update-FabricKQLDashboardDefinition if ($PSCmdlet.ShouldProcess($KQLDashboardId, "Update KQLDashboard")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/KQL Database/Get-FabricKQLDatabase.ps1 b/source/Public/KQL Database/Get-FabricKQLDatabase.ps1 index 51bb9583..c7189b84 100644 --- a/source/Public/KQL Database/Get-FabricKQLDatabase.ps1 +++ b/source/Public/KQL Database/Get-FabricKQLDatabase.ps1 @@ -27,7 +27,7 @@ Retrieves all KQLDatabases in workspace "12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -55,9 +55,7 @@ Author: Tiago Balabuch } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null $KQLDatabases = @() @@ -82,14 +80,9 @@ Author: Tiago Balabuch Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/KQL Database/Get-FabricKQLDatabaseDefinition.ps1 b/source/Public/KQL Database/Get-FabricKQLDatabaseDefinition.ps1 index 95c016ea..302333b6 100644 --- a/source/Public/KQL Database/Get-FabricKQLDatabaseDefinition.ps1 +++ b/source/Public/KQL Database/Get-FabricKQLDatabaseDefinition.ps1 @@ -17,7 +17,6 @@ Handles both synchronous and asynchronous operations, with detailed logging and .PARAMETER KQLDatabaseFormat Specifies the format of the KQLDatabase definition. Currently, only 'ipynb' is supported. - .EXAMPLE Get-FabricKQLDatabaseDefinition -WorkspaceId "12345" -KQLDatabaseId "67890" @@ -30,7 +29,7 @@ Retrieves the definitions of all KQLDatabases in the workspace with ID `12345` i .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. - Handles long-running operations asynchronously. #> @@ -52,9 +51,7 @@ function Get-FabricKQLDatabaseDefinition { try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/KQLDatabases/{2}/getDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $KQLDatabaseId @@ -66,13 +63,9 @@ function Get-FabricKQLDatabaseDefinition { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post # Step 5: Validate the response code and handle the response switch ($statusCode) { @@ -124,4 +117,4 @@ function Get-FabricKQLDatabaseDefinition { $errorDetails = $_.Exception.Message Write-Message -Message "Failed to retrieve KQLDatabase. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/KQL Database/New-FabricKQLDatabase.ps1 b/source/Public/KQL Database/New-FabricKQLDatabase.ps1 index c4c19906..e62a276a 100644 --- a/source/Public/KQL Database/New-FabricKQLDatabase.ps1 +++ b/source/Public/KQL Database/New-FabricKQLDatabase.ps1 @@ -43,11 +43,11 @@ An optional path to the KQLDatabase definition file (e.g., .ipynb file) to uploa An optional path to the platform-specific definition (e.g., .platform file) to upload. .EXAMPLE - Add-FabricKQLDatabase -WorkspaceId "workspace-12345" -KQLDatabaseName "New KQLDatabase" -KQLDatabasePathDefinition "C:\KQLDatabases\example.ipynb" +Add-FabricKQLDatabase -WorkspaceId "workspace-12345" -KQLDatabaseName "New KQLDatabase" -KQLDatabasePathDefinition "C:\KQLDatabases\example.ipynb" - .NOTES +.NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. - Precedent Request Body - Definition file high priority. - CreationPayload is evaluate only if Definition file is not provided. @@ -107,9 +107,7 @@ Author: Tiago Balabuch try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/kqlDatabases" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -266,16 +264,10 @@ Author: Tiago Balabuch if ($PSCmdlet.ShouldProcess($KQLDatabaseName, "Create KQLDatabase")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/KQL Database/Remove-FabricKQLDatabase.ps1 b/source/Public/KQL Database/Remove-FabricKQLDatabase.ps1 index 568e7f48..136dfa08 100644 --- a/source/Public/KQL Database/Remove-FabricKQLDatabase.ps1 +++ b/source/Public/KQL Database/Remove-FabricKQLDatabase.ps1 @@ -26,7 +26,7 @@ Author: Tiago Balabuch function Remove-FabricKQLDatabase { - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -40,9 +40,7 @@ function Remove-FabricKQLDatabase try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/kqlDatabases/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $KQLDatabaseId @@ -51,13 +49,9 @@ function Remove-FabricKQLDatabase { # Step 3: Check if the API endpoint is valid # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Validate the response code diff --git a/source/Public/KQL Database/Update-FabricKQLDatabase.ps1 b/source/Public/KQL Database/Update-FabricKQLDatabase.ps1 index 67bdcb83..43829b09 100644 --- a/source/Public/KQL Database/Update-FabricKQLDatabase.ps1 +++ b/source/Public/KQL Database/Update-FabricKQLDatabase.ps1 @@ -29,7 +29,7 @@ Updates both the name and description of the KQLDatabase "KQLDatabase123". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -59,9 +59,7 @@ function Update-FabricKQLDatabase try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/kqlDatabases/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $KQLDatabaseId @@ -83,15 +81,10 @@ function Update-FabricKQLDatabase if ($PSCmdlet.ShouldProcess($KQLDatabaseId, "Update KQLDatabase")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code diff --git a/source/Public/KQL Database/Update-FabricKQLDatabaseDefinition.ps1 b/source/Public/KQL Database/Update-FabricKQLDatabaseDefinition.ps1 index 4570ae4d..da1131b2 100644 --- a/source/Public/KQL Database/Update-FabricKQLDatabaseDefinition.ps1 +++ b/source/Public/KQL Database/Update-FabricKQLDatabaseDefinition.ps1 @@ -37,7 +37,7 @@ Updates both the content and metadata of the KQLDatabase with ID `67890` in the .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. - The KQLDatabase content is encoded as Base64 before being sent to the Fabric API. - This function handles asynchronous operations and retrieves operation results if required. @@ -72,9 +72,7 @@ function Update-FabricKQLDatabaseDefinition try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/kqlDatabases/{2}/updateDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $KQLDatabaseId @@ -158,15 +156,10 @@ function Update-FabricKQLDatabaseDefinition if ($PSCmdlet.ShouldProcess($KQLDatabaseId, "Update KQLDatabase")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/KQL Queryset/Get-FabricKQLQueryset.ps1 b/source/Public/KQL Queryset/Get-FabricKQLQueryset.ps1 index 252bce72..46cc1557 100644 --- a/source/Public/KQL Queryset/Get-FabricKQLQueryset.ps1 +++ b/source/Public/KQL Queryset/Get-FabricKQLQueryset.ps1 @@ -27,7 +27,7 @@ Retrieves all KQLQuerysets in workspace "12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -55,9 +55,7 @@ Author: Tiago Balabuch } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null @@ -82,14 +80,9 @@ Author: Tiago Balabuch Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/KQL Queryset/Get-FabricKQLQuerysetDefinition.ps1 b/source/Public/KQL Queryset/Get-FabricKQLQuerysetDefinition.ps1 index d1340167..9e7d9098 100644 --- a/source/Public/KQL Queryset/Get-FabricKQLQuerysetDefinition.ps1 +++ b/source/Public/KQL Queryset/Get-FabricKQLQuerysetDefinition.ps1 @@ -28,7 +28,7 @@ Retrieves the definitions of all KQLQuerysets in the workspace with ID `12345` i .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. - Handles long-running operations asynchronously. #> @@ -50,9 +50,7 @@ function Get-FabricKQLQuerysetDefinition { try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/kqlQuerysets/{2}/getDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $KQLQuerysetId @@ -63,13 +61,9 @@ function Get-FabricKQLQuerysetDefinition { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post # Step 5: Validate the response code and handle the response switch ($statusCode) { @@ -115,4 +109,4 @@ function Get-FabricKQLQuerysetDefinition { Write-Message -Message "Failed to retrieve KQLQueryset. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/KQL Queryset/Invoke-FabricKQLCommand.ps1 b/source/Public/KQL Queryset/Invoke-FabricKQLCommand.ps1 index 00ab9f5c..26b3abf8 100644 --- a/source/Public/KQL Queryset/Invoke-FabricKQLCommand.ps1 +++ b/source/Public/KQL Queryset/Invoke-FabricKQLCommand.ps1 @@ -6,7 +6,6 @@ function Invoke-FabricKQLCommand { .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 Connect-RTISession cmdlet. The cmdlet distinguishes between management commands and query commands. Management commands are executed in the management API, while query commands are executed in the query API. The distinction is made by checking if the KQL command starts with a dot. If it does, it is a management command else it is a query command. If the KQL command is a management command, it is crucial to have the execute database script <| in the beginning, otherwise the Kusto API will not execute the script. This cmdlet will automatically add the .execute database script <| in the beginning of the KQL command if it is a management command and if it is not already present. If the KQL Command is a query command, the result is returned as an array of PowerShell objects by default. If the parameter -ReturnRawResult is used, the raw result of the KQL query is returned which is a JSON object. - .PARAMETER WorkspaceId 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'. @@ -79,7 +78,7 @@ function Invoke-FabricKQLCommand { begin { - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState Write-Verbose "Check if KQLDatabaseName and KQLDatabaseId are used together" if ($PSBoundParameters.ContainsKey("KQLDatabaseName") -and $PSBoundParameters.ContainsKey("KQLDatabaseId")) { @@ -208,4 +207,4 @@ function Invoke-FabricKQLCommand { end { } -} \ No newline at end of file +} diff --git a/source/Public/KQL Queryset/New-FabricKQLQueryset.ps1 b/source/Public/KQL Queryset/New-FabricKQLQueryset.ps1 index 93bde8b7..fd3db242 100644 --- a/source/Public/KQL Queryset/New-FabricKQLQueryset.ps1 +++ b/source/Public/KQL Queryset/New-FabricKQLQueryset.ps1 @@ -23,11 +23,11 @@ An optional path to the KQLQueryset definition file (e.g., .ipynb file) to uploa An optional path to the platform-specific definition (e.g., .platform file) to upload. .EXAMPLE - Add-FabricKQLQueryset -WorkspaceId "workspace-12345" -KQLQuerysetName "New KQLQueryset" -KQLQuerysetPathDefinition "C:\KQLQuerysets\example.ipynb" +Add-FabricKQLQueryset -WorkspaceId "workspace-12345" -KQLQuerysetName "New KQLQueryset" -KQLQuerysetPathDefinition "C:\KQLQuerysets\example.ipynb" - .NOTES +.NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -59,9 +59,7 @@ function New-FabricKQLQueryset { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/kqlQuerysets" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -129,16 +127,10 @@ function New-FabricKQLQueryset { if ($PSCmdlet.ShouldProcess($KQLQuerysetName, "Create KQLQueryset")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/KQL Queryset/Remove-FabricKQLQueryset.ps1 b/source/Public/KQL Queryset/Remove-FabricKQLQueryset.ps1 index c826735b..b768fdf2 100644 --- a/source/Public/KQL Queryset/Remove-FabricKQLQueryset.ps1 +++ b/source/Public/KQL Queryset/Remove-FabricKQLQueryset.ps1 @@ -26,7 +26,7 @@ Author: Tiago Balabuch function Remove-FabricKQLQueryset { - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -40,9 +40,7 @@ function Remove-FabricKQLQueryset try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/kqlQuerysets/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $KQLQuerysetId @@ -50,13 +48,9 @@ function Remove-FabricKQLQueryset if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove KQLQueryset")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Validate the response code if ($statusCode -ne 200) diff --git a/source/Public/KQL Queryset/Update-FabricKQLQueryset.ps1 b/source/Public/KQL Queryset/Update-FabricKQLQueryset.ps1 index b544b501..eafc9240 100644 --- a/source/Public/KQL Queryset/Update-FabricKQLQueryset.ps1 +++ b/source/Public/KQL Queryset/Update-FabricKQLQueryset.ps1 @@ -29,7 +29,7 @@ Updates both the name and description of the KQLQueryset "KQLQueryset123". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -59,9 +59,7 @@ function Update-FabricKQLQueryset try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/kqlQuerysets/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $KQLQuerysetId @@ -83,15 +81,10 @@ function Update-FabricKQLQueryset if ($PSCmdlet.ShouldProcess($KQLQuerysetId, "Update KQLQueryset")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code diff --git a/source/Public/KQL Queryset/Update-FabricKQLQuerysetDefinition.ps1 b/source/Public/KQL Queryset/Update-FabricKQLQuerysetDefinition.ps1 index 1e77c90b..bf86e931 100644 --- a/source/Public/KQL Queryset/Update-FabricKQLQuerysetDefinition.ps1 +++ b/source/Public/KQL Queryset/Update-FabricKQLQuerysetDefinition.ps1 @@ -18,7 +18,6 @@ The KQLQueryset content can be provided as file paths, and metadata updates can .PARAMETER KQLQuerysetPathPlatformDefinition (Optional) The file path to the KQLQueryset's platform-specific definition file. The content will be encoded as Base64 and sent in the request. - .EXAMPLE Update-FabricKQLQuerysetDefinition -WorkspaceId "12345" -KQLQuerysetId "67890" -KQLQuerysetPathDefinition "C:\KQLQuerysets\KQLQueryset.ipynb" @@ -31,7 +30,7 @@ Updates both the content and metadata of the KQLQueryset with ID `67890` in the .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. - The KQLQueryset content is encoded as Base64 before being sent to the Fabric API. - This function handles asynchronous operations and retrieves operation results if required. @@ -61,9 +60,7 @@ function Update-FabricKQLQuerysetDefinition { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/kqlQuerysets/{2}/updateDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $KQLQuerysetId @@ -117,15 +114,10 @@ function Update-FabricKQLQuerysetDefinition { if ($PSCmdlet.ShouldProcess($KQLQuerysetId, "Update KQLQueryset")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/Lakehouse/Get-FabricLakehouse.ps1 b/source/Public/Lakehouse/Get-FabricLakehouse.ps1 index 150be763..25bee82a 100644 --- a/source/Public/Lakehouse/Get-FabricLakehouse.ps1 +++ b/source/Public/Lakehouse/Get-FabricLakehouse.ps1 @@ -27,7 +27,7 @@ Retrieves all Lakehouses in workspace "12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -55,9 +55,7 @@ Author: Tiago Balabuch } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null $lakehouses = @() @@ -82,14 +80,9 @@ Author: Tiago Balabuch Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Lakehouse/Get-FabricLakehouseTable.ps1 b/source/Public/Lakehouse/Get-FabricLakehouseTable.ps1 index f4f4816d..af474cdc 100644 --- a/source/Public/Lakehouse/Get-FabricLakehouseTable.ps1 +++ b/source/Public/Lakehouse/Get-FabricLakehouseTable.ps1 @@ -5,10 +5,13 @@ Retrieves tables from a specified Lakehouse in a Fabric workspace. .DESCRIPTION This function retrieves tables from a specified Lakehouse in a Fabric workspace. It handles pagination using a continuation token to ensure all data is retrieved. + .PARAMETER WorkspaceId The ID of the workspace containing the Lakehouse. + .PARAMETER LakehouseId The ID of the Lakehouse from which to retrieve tables. + .EXAMPLE Get-FabricLakehouseTable -WorkspaceId "your-workspace-id" -LakehouseId "your-lakehouse-id" This example retrieves all tables from the specified Lakehouse in the specified workspace. @@ -28,9 +31,7 @@ This example retrieves all tables from the specified Lakehouse in the specified try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState @@ -59,13 +60,9 @@ This example retrieves all tables from the specified Lakehouse in the specified Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 5: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Method Get Write-Message -Message "API response code: $statusCode" -Level Debug # Step 6: Validate the response code diff --git a/source/Public/Lakehouse/New-FabricLakehouse.ps1 b/source/Public/Lakehouse/New-FabricLakehouse.ps1 index 0ec9e622..4ad8894b 100644 --- a/source/Public/Lakehouse/New-FabricLakehouse.ps1 +++ b/source/Public/Lakehouse/New-FabricLakehouse.ps1 @@ -24,7 +24,7 @@ Add-FabricLakehouse -WorkspaceId "workspace-12345" -LakehouseName "New Lakehouse .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -54,9 +54,7 @@ function New-FabricLakehouse try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/lakehouses" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -83,16 +81,10 @@ function New-FabricLakehouse if ($PSCmdlet.ShouldProcess($LakehouseName, "Create Lakehouse")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response switch ($statusCode) diff --git a/source/Public/Lakehouse/Remove-FabricLakehouse.ps1 b/source/Public/Lakehouse/Remove-FabricLakehouse.ps1 index 4a2b8a8d..1f3ddc35 100644 --- a/source/Public/Lakehouse/Remove-FabricLakehouse.ps1 +++ b/source/Public/Lakehouse/Remove-FabricLakehouse.ps1 @@ -40,9 +40,7 @@ function Remove-FabricLakehouse try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/lakehouses/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $LakehouseId @@ -50,13 +48,9 @@ function Remove-FabricLakehouse if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove Lakehouse")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Validate the response code diff --git a/source/Public/Lakehouse/Start-FabricLakehouseTableMaintenance.ps1 b/source/Public/Lakehouse/Start-FabricLakehouseTableMaintenance.ps1 index a168801f..17b03ef9 100644 --- a/source/Public/Lakehouse/Start-FabricLakehouseTableMaintenance.ps1 +++ b/source/Public/Lakehouse/Start-FabricLakehouseTableMaintenance.ps1 @@ -1,47 +1,58 @@ function Start-FabricLakehouseTableMaintenance { <# -.SYNOPSIS + .SYNOPSIS Initiates a table maintenance job for a specified Lakehouse in a Fabric workspace. -.DESCRIPTION + + .DESCRIPTION This function sends a POST request to the Fabric API to start a table maintenance job for a specified Lakehouse. It allows for optional parameters such as schema name, table name, and Z-ordering columns. The function also handles asynchronous operations and can wait for completion if specified. -.PARAMETER WorkspaceId + + .PARAMETER WorkspaceId The unique identifier of the workspace where the Lakehouse resides. This parameter is mandatory. -.PARAMETER LakehouseId + + .PARAMETER LakehouseId The unique identifier of the Lakehouse for which the table maintenance job is to be initiated. This parameter is mandatory. -.PARAMETER JobType + + .PARAMETER JobType The type of job to be initiated. Default is "TableMaintenance". This parameter is optional. -.PARAMETER SchemaName + + .PARAMETER SchemaName The name of the schema in the Lakehouse. This parameter is optional. -.PARAMETER TableName + + .PARAMETER TableName The name of the table in the Lakehouse. This parameter is optional. -.PARAMETER IsVOrder + + .PARAMETER IsVOrder A boolean flag indicating whether to apply V-ordering. This parameter is optional. -.PARAMETER ColumnsZOrderBy + + .PARAMETER ColumnsZOrderBy An array of columns to be used for Z-ordering. This parameter is optional. -.PARAMETER retentionPeriod + + .PARAMETER retentionPeriod The retention period for the table maintenance job. This parameter is optional. -.PARAMETER waitForCompletion + + .PARAMETER waitForCompletion A boolean flag indicating whether to wait for the job to complete. Default is false. This parameter is optional. -.EXAMPLE + + .EXAMPLE Start-FabricLakehouseTableMaintenance -WorkspaceId "12345" -LakehouseId "67890" -JobType "TableMaintenance" -SchemaName "dbo" -TableName "MyTable" -IsVOrder $true -ColumnsZOrderBy @("Column1", "Column2") -retentionPeriod "7:00:00" -waitForCompletion $true Initiates a table maintenance job for the specified Lakehouse and waits for its completion. -.EXAMPLE + + .EXAMPLE Start-FabricLakehouseTableMaintenance -WorkspaceId "12345" -LakehouseId "67890" -JobType "TableMaintenance" -SchemaName "dbo" -TableName "MyTable" -IsVOrder $false -ColumnsZOrderBy @("Column1", "Column2") -retentionPeriod "7:00:00" Initiates a table maintenance job for the specified Lakehouse without waiting for its completion. -.NOTES + + .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. - This function handles asynchronous operations and retrieves operation results if required. - The function uses the `Write-Message` function for logging and debugging purposes. - The function uses the `Get-FabricLakehouse` function to retrieve Lakehouse details. - The function uses the `Get-FabricLongRunningOperation` function to check the status of long-running operations. - The function uses the `Invoke-RestMethod` cmdlet to make API requests. -.NOTES - #> [CmdletBinding(SupportsShouldProcess)] @@ -89,9 +100,7 @@ function Start-FabricLakehouseTableMaintenance try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState $lakehouse = Get-FabricLakehouse -WorkspaceId $WorkspaceId -LakehouseId $LakehouseId @@ -153,16 +162,10 @@ function Start-FabricLakehouseTableMaintenance if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Start Table Maintenance Job")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } Write-Message -Message "Response Code: $statusCode" -Level Debug diff --git a/source/Public/Lakehouse/Update-FabricLakehouse.ps1 b/source/Public/Lakehouse/Update-FabricLakehouse.ps1 index 6b740f87..255b90c0 100644 --- a/source/Public/Lakehouse/Update-FabricLakehouse.ps1 +++ b/source/Public/Lakehouse/Update-FabricLakehouse.ps1 @@ -29,7 +29,7 @@ Updates both the name and description of the Lakehouse "Lakehouse123". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -59,9 +59,7 @@ function Update-FabricLakehouse try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/lakehouses/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $LakehouseId @@ -83,15 +81,10 @@ function Update-FabricLakehouse if ($PSCmdlet.ShouldProcess($LakehouseId, "Update Lakehouse")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code diff --git a/source/Public/Lakehouse/Write-FabricLakehouseTableData.ps1 b/source/Public/Lakehouse/Write-FabricLakehouseTableData.ps1 index 153e2245..ed7ba2b2 100644 --- a/source/Public/Lakehouse/Write-FabricLakehouseTableData.ps1 +++ b/source/Public/Lakehouse/Write-FabricLakehouseTableData.ps1 @@ -1,37 +1,52 @@ function Write-FabricLakehouseTableData { <# -.SYNOPSIS -Loads data into a specified table in a Lakehouse within a Fabric workspace. -.DESCRIPTION -Loads data into a specified table in a Lakehouse within a Fabric workspace. The function supports loading data from files or folders, with options for file format and CSV settings. -.PARAMETER WorkspaceId -The ID of the workspace containing the Lakehouse. -.PARAMETER LakehouseId -The ID of the Lakehouse where the table resides. -.PARAMETER TableName -The name of the table to load data into. -.PARAMETER PathType -The type of path to load data from (File or Folder). -.PARAMETER RelativePath -The relative path to the file or folder to load data from. -.PARAMETER FileFormat -The format of the file to load data from (CSV or Parquet). -.PARAMETER CsvDelimiter -The delimiter used in the CSV file (default is comma). -.PARAMETER CsvHeader -Indicates whether the CSV file has a header row (default is false). -.PARAMETER Mode -The mode for loading data (append or overwrite). -.PARAMETER Recursive -Indicates whether to load data recursively from subfolders (default is false). -.EXAMPLE -Import-FabricLakehouseTableData -WorkspaceId "your-workspace-id" -LakehouseId "your-lakehouse-id" -TableName "your-table-name" -PathType "File" -RelativePath "path/to/your/file.csv" -FileFormat "CSV" -CsvDelimiter "," -CsvHeader $true -Mode "append" -Recursive $false -This example loads data from a CSV file into the specified table in the Lakehouse. -.EXAMPLE -Import-FabricLakehouseTableData -WorkspaceId "your-workspace-id" -LakehouseId "your-lakehouse-id" -TableName "your-table-name" -PathType "Folder" -RelativePath "path/to/your/folder" -FileFormat "Parquet" -Mode "overwrite" -Recursive $true -This example loads data from a folder into the specified table in the Lakehouse, overwriting any existing data. - #> + + .SYNOPSIS + Loads data into a specified table in a Lakehouse within a Fabric workspace. + + .DESCRIPTION + Loads data into a specified table in a Lakehouse within a Fabric workspace. The function supports loading data from files or folders, with options for file format and CSV settings. + + .PARAMETER WorkspaceId + The ID of the workspace containing the Lakehouse. + + .PARAMETER LakehouseId + The ID of the Lakehouse where the table resides. + + .PARAMETER TableName + The name of the table to load data into. + + .PARAMETER PathType + The type of path to load data from (File or Folder). + + .PARAMETER RelativePath + The relative path to the file or folder to load data from. + + .PARAMETER FileFormat + The format of the file to load data from (CSV or Parquet). + + .PARAMETER CsvDelimiter + The delimiter used in the CSV file (default is comma). + + .PARAMETER CsvHeader + Indicates whether the CSV file has a header row (default is false). + + .PARAMETER Mode + The mode for loading data (append or overwrite). + + .PARAMETER Recursive + Indicates whether to load data recursively from subfolders (default is false). + + .EXAMPLE + Import-FabricLakehouseTableData -WorkspaceId "your-workspace-id" -LakehouseId "your-lakehouse-id" -TableName "your-table-name" -PathType "File" -RelativePath "path/to/your/file.csv" -FileFormat "CSV" -CsvDelimiter "," -CsvHeader $true -Mode "append" -Recursive $false + This example loads data from a CSV file into the specified table in the Lakehouse. + + .EXAMPLE + Import-FabricLakehouseTableData -WorkspaceId "your-workspace-id" -LakehouseId "your-lakehouse-id" -TableName "your-table-name" -PathType "Folder" -RelativePath "path/to/your/folder" -FileFormat "Parquet" -Mode "overwrite" -Recursive $true + This example loads data from a folder into the specified table in the Lakehouse, overwriting any existing data. + +#> [CmdletBinding(SupportsShouldProcess)] [Alias("Import-FabricLakehouseTableData")] param ( @@ -82,9 +97,7 @@ This example loads data from a folder into the specified table in the Lakehouse, try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/lakehouses/{2}/tables/{3}/load" -f $FabricConfig.BaseUrl, $WorkspaceId, $LakehouseId, $TableName @@ -114,16 +127,10 @@ This example loads data from a folder into the specified table in the Lakehouse, if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Load Lakehouse Table Data")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code diff --git a/source/Public/ML Experiment/Get-FabricMLExperiment.ps1 b/source/Public/ML Experiment/Get-FabricMLExperiment.ps1 index 4a9b46fb..0f242e90 100644 --- a/source/Public/ML Experiment/Get-FabricMLExperiment.ps1 +++ b/source/Public/ML Experiment/Get-FabricMLExperiment.ps1 @@ -25,7 +25,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -54,9 +54,7 @@ function Get-FabricMLExperiment { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null $MLExperiments = @() @@ -82,14 +80,9 @@ function Get-FabricMLExperiment { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/ML Experiment/New-FabricMLExperiment.ps1 b/source/Public/ML Experiment/New-FabricMLExperiment.ps1 index d7a1633c..396fe0e7 100644 --- a/source/Public/ML Experiment/New-FabricMLExperiment.ps1 +++ b/source/Public/ML Experiment/New-FabricMLExperiment.ps1 @@ -16,12 +16,12 @@ An optional description for the ML Experiment. .EXAMPLE - New-FabricMLExperiment -WorkspaceId "workspace-12345" -MLExperimentName "New ML Experiment" -MLExperimentDescription "Description of the new ML Experiment" + New-FabricMLExperiment -WorkspaceId "workspace-12345" -MLExperimentName "New ML Experiment" -MLExperimentDescription "Description of the new ML Experiment" This example creates a new ML Experiment named "New ML Experiment" in the workspace with ID "workspace-12345" with the provided description. .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -46,9 +46,7 @@ function New-FabricMLExperiment try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/mlExperiments" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -69,16 +67,10 @@ function New-FabricMLExperiment if ($PSCmdlet.ShouldProcess($MLExperimentName, "Create ML Experiment")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/ML Experiment/Remove-FabricMLExperiment.ps1 b/source/Public/ML Experiment/Remove-FabricMLExperiment.ps1 index 5a1e4652..32bc9288 100644 --- a/source/Public/ML Experiment/Remove-FabricMLExperiment.ps1 +++ b/source/Public/ML Experiment/Remove-FabricMLExperiment.ps1 @@ -13,19 +13,19 @@ The unique identifier of the MLExperiment to be removed. .EXAMPLE - Remove-FabricMLExperiment -WorkspaceId "workspace-12345" -MLExperimentId "experiment-67890" + Remove-FabricMLExperiment -WorkspaceId "workspace-12345" -MLExperimentId "experiment-67890" This example removes the MLExperiment with ID "experiment-67890" from the workspace with ID "workspace-12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> function Remove-FabricMLExperiment { - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = "High")] param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -38,9 +38,7 @@ function Remove-FabricMLExperiment try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/mlExperiments/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $MLExperimentId @@ -48,13 +46,9 @@ function Remove-FabricMLExperiment if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove ML Experiment")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Validate the response code diff --git a/source/Public/ML Experiment/Update-FabricMLExperiment.ps1 b/source/Public/ML Experiment/Update-FabricMLExperiment.ps1 index e24ba6bc..8ba4956e 100644 --- a/source/Public/ML Experiment/Update-FabricMLExperiment.ps1 +++ b/source/Public/ML Experiment/Update-FabricMLExperiment.ps1 @@ -19,12 +19,12 @@ An optional new description for the ML Experiment. .EXAMPLE - Update-FabricMLExperiment -WorkspaceId "workspace-12345" -MLExperimentId "experiment-67890" -MLExperimentName "Updated ML Experiment" -MLExperimentDescription "Updated description" + Update-FabricMLExperiment -WorkspaceId "workspace-12345" -MLExperimentId "experiment-67890" -MLExperimentName "Updated ML Experiment" -MLExperimentDescription "Updated description" This example updates the ML Experiment with ID "experiment-67890" in the workspace with ID "workspace-12345" with a new name and description. .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -53,9 +53,7 @@ function Update-FabricMLExperiment try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/mlExperiments/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $MLExperimentId @@ -77,15 +75,10 @@ function Update-FabricMLExperiment if ($PSCmdlet.ShouldProcess($MLExperimentName, "Update ML Experiment")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code if ($statusCode -ne 200) diff --git a/source/Public/ML Model/Get-FabricMLModel.ps1 b/source/Public/ML Model/Get-FabricMLModel.ps1 index fd8bcc3e..4e55f8ff 100644 --- a/source/Public/ML Model/Get-FabricMLModel.ps1 +++ b/source/Public/ML Model/Get-FabricMLModel.ps1 @@ -25,7 +25,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -54,9 +54,7 @@ function Get-FabricMLModel { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null $MLModels = @() @@ -82,14 +80,9 @@ function Get-FabricMLModel { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/ML Model/New-FabricMLModel.ps1 b/source/Public/ML Model/New-FabricMLModel.ps1 index fb5e4ad1..c4a614e3 100644 --- a/source/Public/ML Model/New-FabricMLModel.ps1 +++ b/source/Public/ML Model/New-FabricMLModel.ps1 @@ -21,7 +21,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -46,9 +46,7 @@ function New-FabricMLModel try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/mlModels" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -69,16 +67,10 @@ function New-FabricMLModel if ($PSCmdlet.ShouldProcess($MLModelName, "Create ML Model")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/ML Model/Remove-FabricMLModel.ps1 b/source/Public/ML Model/Remove-FabricMLModel.ps1 index 6542378a..39c78166 100644 --- a/source/Public/ML Model/Remove-FabricMLModel.ps1 +++ b/source/Public/ML Model/Remove-FabricMLModel.ps1 @@ -13,12 +13,12 @@ The unique identifier of the ML Model to be removed. .EXAMPLE - Remove-FabricMLModel -WorkspaceId "workspace-12345" -MLModelId "model-67890" + Remove-FabricMLModel -WorkspaceId "workspace-12345" -MLModelId "model-67890" This example removes the ML Model with ID "model-67890" from the workspace with ID "workspace-12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -38,9 +38,7 @@ function Remove-FabricMLModel try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/mlModels/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $MLModelId @@ -48,13 +46,9 @@ function Remove-FabricMLModel if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove ML Model")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Validate the response code if ($statusCode -ne 200) diff --git a/source/Public/ML Model/Update-FabricMLModel.ps1 b/source/Public/ML Model/Update-FabricMLModel.ps1 index 2c78a81e..ce408800 100644 --- a/source/Public/ML Model/Update-FabricMLModel.ps1 +++ b/source/Public/ML Model/Update-FabricMLModel.ps1 @@ -21,7 +21,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -46,9 +46,7 @@ function Update-FabricMLModel try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/mlModels/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $MLModelId @@ -65,15 +63,10 @@ function Update-FabricMLModel if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Update ML Model")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code if ($statusCode -ne 200) diff --git a/source/Public/Mirrored Database/Get-FabricMirroredDatabase.ps1 b/source/Public/Mirrored Database/Get-FabricMirroredDatabase.ps1 index 1b036839..e3cd9037 100644 --- a/source/Public/Mirrored Database/Get-FabricMirroredDatabase.ps1 +++ b/source/Public/Mirrored Database/Get-FabricMirroredDatabase.ps1 @@ -27,7 +27,7 @@ Retrieves all MirroredDatabases in workspace "12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -55,9 +55,7 @@ Author: Tiago Balabuch } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState $continuationToken = $null $MirroredDatabases = @() @@ -84,14 +82,9 @@ Author: Tiago Balabuch Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Mirrored Database/Get-FabricMirroredDatabaseDefinition.ps1 b/source/Public/Mirrored Database/Get-FabricMirroredDatabaseDefinition.ps1 index c1df17c8..3c28c9b1 100644 --- a/source/Public/Mirrored Database/Get-FabricMirroredDatabaseDefinition.ps1 +++ b/source/Public/Mirrored Database/Get-FabricMirroredDatabaseDefinition.ps1 @@ -25,7 +25,7 @@ Retrieves the definitions of all MirroredDatabases in the workspace with ID `123 .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. - Handles long-running operations asynchronously. #> @@ -43,22 +43,16 @@ function Get-FabricMirroredDatabaseDefinition { try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/mirroredDatabases/{2}/getDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $MirroredDatabaseId Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post # Step 5: Validate the response code and handle the response switch ($statusCode) { @@ -104,4 +98,4 @@ function Get-FabricMirroredDatabaseDefinition { Write-Message -Message "Failed to retrieve MirroredDatabase. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Mirrored Database/Get-FabricMirroredDatabaseStatus.ps1 b/source/Public/Mirrored Database/Get-FabricMirroredDatabaseStatus.ps1 index c2583190..71eefeea 100644 --- a/source/Public/Mirrored Database/Get-FabricMirroredDatabaseStatus.ps1 +++ b/source/Public/Mirrored Database/Get-FabricMirroredDatabaseStatus.ps1 @@ -1,17 +1,22 @@ function Get-FabricMirroredDatabaseStatus { <# -.SYNOPSIS -Retrieves the status of a mirrored database in a specified workspace. -.DESCRIPTION -Retrieves the status of a mirrored database in a specified workspace. The function validates the authentication token, constructs the API endpoint URL, and makes a POST request to retrieve the mirroring status. -It handles errors and logs messages at various levels (Debug, Error). -.PARAMETER WorkspaceId -The ID of the workspace containing the mirrored database. -.PARAMETER MirroredDatabaseId -the ID of the mirrored database whose status is to be retrieved. -.EXAMPLE -Get-FabricMirroredDatabaseStatus -WorkspaceId "your-workspace-id" -MirroredDatabaseId "your-mirrored-database-id" -This example retrieves the status of a mirrored database with the specified ID in the specified workspace. + + .SYNOPSIS + Retrieves the status of a mirrored database in a specified workspace. + + .DESCRIPTION + Retrieves the status of a mirrored database in a specified workspace. The function validates the authentication token, constructs the API endpoint URL, and makes a POST request to retrieve the mirroring status. + It handles errors and logs messages at various levels (Debug, Error). + + .PARAMETER WorkspaceId + The ID of the workspace containing the mirrored database. + + .PARAMETER MirroredDatabaseId + the ID of the mirrored database whose status is to be retrieved. + + .EXAMPLE + Get-FabricMirroredDatabaseStatus -WorkspaceId "your-workspace-id" -MirroredDatabaseId "your-mirrored-database-id" + This example retrieves the status of a mirrored database with the specified ID in the specified workspace. #> [CmdletBinding()] param ( @@ -26,22 +31,15 @@ This example retrieves the status of a mirrored database with the specified ID i try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState $apiEndpointUrl = "{0}/workspaces/{1}/mirroredDatabases/{2}/getMirroringStatus" -f $FabricConfig.BaseUrl, $WorkspaceId, $MirroredDatabaseId Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post # Step 7: Validate the response code if ($statusCode -ne 200) { @@ -62,4 +60,4 @@ This example retrieves the status of a mirrored database with the specified ID i Write-Message -Message "Failed to retrieve MirroredDatabase. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Mirrored Database/Get-FabricMirroredDatabaseTableStatus.ps1 b/source/Public/Mirrored Database/Get-FabricMirroredDatabaseTableStatus.ps1 index a8a8790f..7e089805 100644 --- a/source/Public/Mirrored Database/Get-FabricMirroredDatabaseTableStatus.ps1 +++ b/source/Public/Mirrored Database/Get-FabricMirroredDatabaseTableStatus.ps1 @@ -1,18 +1,24 @@ function Get-FabricMirroredDatabaseTableStatus { <# -.SYNOPSIS -Retrieves the status of tables in a mirrored database. -.DESCRIPTION -Retrieves the status of tables in a mirrored database. The function validates the authentication token, constructs the API endpoint URL, and makes a POST request to retrieve the mirroring status of tables. It handles errors and logs messages at various levels (Debug, Error). -.PARAMETER WorkspaceId -The ID of the workspace containing the mirrored database. -.PARAMETER MirroredDatabaseId -The ID of the mirrored database whose table status is to be retrieved. -.EXAMPLE -Get-FabricMirroredDatabaseTableStatus -WorkspaceId "your-workspace-id" -MirroredDatabaseId "your-mirrored-database-id" -This example retrieves the status of tables in a mirrored database with the specified ID in the specified workspace. -.NOTES -The function retrieves the PowerBI access token and makes a POST request to the PowerBI API to retrieve the status of tables in the specified mirrored database. It then returns the 'value' property of the response, which contains the table statuses. + + .SYNOPSIS + Retrieves the status of tables in a mirrored database. + + .DESCRIPTION + Retrieves the status of tables in a mirrored database. The function validates the authentication token, constructs the API endpoint URL, and makes a POST request to retrieve the mirroring status of tables. It handles errors and logs messages at various levels (Debug, Error). + + .PARAMETER WorkspaceId + The ID of the workspace containing the mirrored database. + + .PARAMETER MirroredDatabaseId + The ID of the mirrored database whose table status is to be retrieved. + + .EXAMPLE + Get-FabricMirroredDatabaseTableStatus -WorkspaceId "your-workspace-id" -MirroredDatabaseId "your-mirrored-database-id" + This example retrieves the status of tables in a mirrored database with the specified ID in the specified workspace. + + .NOTES + The function retrieves the PowerBI access token and makes a POST request to the PowerBI API to retrieve the status of tables in the specified mirrored database. It then returns the 'value' property of the response, which contains the table statuses. #> [CmdletBinding()] @@ -30,9 +36,7 @@ The function retrieves the PowerBI access token and makes a POST request to the try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState $continuationToken = $null $MirroredDatabaseTableStatus = @() @@ -59,14 +63,9 @@ The function retrieves the PowerBI access token and makes a POST request to the Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Mirrored Database/New-FabricMirroredDatabase.ps1 b/source/Public/Mirrored Database/New-FabricMirroredDatabase.ps1 index daa59eae..fdcf631d 100644 --- a/source/Public/Mirrored Database/New-FabricMirroredDatabase.ps1 +++ b/source/Public/Mirrored Database/New-FabricMirroredDatabase.ps1 @@ -23,11 +23,11 @@ An optional path to the MirroredDatabase definition file to upload. An optional path to the platform-specific definition (e.g., .platform file) to upload. .EXAMPLE - Add-FabricMirroredDatabase -WorkspaceId "workspace-12345" -MirroredDatabaseName "New MirroredDatabase" -MirroredDatabasePathDefinition "C:\MirroredDatabases\example.json" +Add-FabricMirroredDatabase -WorkspaceId "workspace-12345" -MirroredDatabaseName "New MirroredDatabase" -MirroredDatabasePathDefinition "C:\MirroredDatabases\example.json" - .NOTES +.NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -61,9 +61,7 @@ function New-FabricMirroredDatabase try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/mirroredDatabases" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -141,16 +139,10 @@ function New-FabricMirroredDatabase if ($PSCmdlet.ShouldProcess($MirroredDatabaseName, "Create MirroredDatabase")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/Mirrored Database/Remove-FabricMirroredDatabase.ps1 b/source/Public/Mirrored Database/Remove-FabricMirroredDatabase.ps1 index 440cc1c0..49a38836 100644 --- a/source/Public/Mirrored Database/Remove-FabricMirroredDatabase.ps1 +++ b/source/Public/Mirrored Database/Remove-FabricMirroredDatabase.ps1 @@ -25,7 +25,7 @@ Author: Tiago Balabuch function Remove-FabricMirroredDatabase { - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -39,9 +39,7 @@ function Remove-FabricMirroredDatabase try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/mirroredDatabases/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $MirroredDatabaseId @@ -49,13 +47,9 @@ function Remove-FabricMirroredDatabase if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove MirroredDatabase")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Validate the response code diff --git a/source/Public/Mirrored Database/Start-FabricMirroredDatabaseMirroring.ps1 b/source/Public/Mirrored Database/Start-FabricMirroredDatabaseMirroring.ps1 index 5525eb20..1ede6bc6 100644 --- a/source/Public/Mirrored Database/Start-FabricMirroredDatabaseMirroring.ps1 +++ b/source/Public/Mirrored Database/Start-FabricMirroredDatabaseMirroring.ps1 @@ -1,21 +1,27 @@ function Start-FabricMirroredDatabaseMirroring { <# -.SYNOPSIS + + .SYNOPSIS Starts the mirroring of a specified mirrored database in a given workspace. -.DESCRIPTION + + .DESCRIPTION This function sends a POST request to the Microsoft Fabric API to start the mirroring of a specified mirrored database. It requires the workspace ID and the mirrored database ID as parameters. -.PARAMETER WorkspaceId + + .PARAMETER WorkspaceId The unique identifier of the workspace where the mirrored database resides. This parameter is mandatory. -.PARAMETER MirroredDatabaseId + + .PARAMETER MirroredDatabaseId The unique identifier of the mirrored database to be started. This parameter is mandatory. -.EXAMPLE + + .EXAMPLE Start-FabricMirroredDatabaseMirroring -WorkspaceId "12345" -MirroredDatabaseId "67890" Starts the mirroring of the mirrored database with ID `67890` in the workspace `12345`. -.NOTES + + .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. - This function handles asynchronous operations and retrieves operation results if required. #> @@ -33,23 +39,16 @@ function Start-FabricMirroredDatabaseMirroring try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState $apiEndpointUrl = "{0}/workspaces/{1}/mirroredDatabases/{2}/startMirroring" -f $FabricConfig.BaseUrl, $WorkspaceId, $MirroredDatabaseId Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Start MirroredDatabase Mirroring")) { # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post } # Step 7: Validate the response code diff --git a/source/Public/Mirrored Database/Stop-FabricMirroredDatabaseMirroring.ps1 b/source/Public/Mirrored Database/Stop-FabricMirroredDatabaseMirroring.ps1 index eb2b686a..67dc08c8 100644 --- a/source/Public/Mirrored Database/Stop-FabricMirroredDatabaseMirroring.ps1 +++ b/source/Public/Mirrored Database/Stop-FabricMirroredDatabaseMirroring.ps1 @@ -1,25 +1,31 @@ function Stop-FabricMirroredDatabaseMirroring { <# -.SYNOPSIS + + .SYNOPSIS Stops the mirroring of a specified mirrored database in a given workspace. -.DESCRIPTION + + .DESCRIPTION This function sends a POST request to the Microsoft Fabric API to stop the mirroring of a specified mirrored database. It requires the workspace ID and the mirrored database ID as parameters. -.PARAMETER WorkspaceId + + .PARAMETER WorkspaceId The unique identifier of the workspace where the mirrored database resides. This parameter is mandatory. -.PARAMETER MirroredDatabaseId + + .PARAMETER MirroredDatabaseId The unique identifier of the mirrored database to be stopped. This parameter is mandatory. -.EXAMPLE + + .EXAMPLE Stop-FabricMirroredDatabaseMirroring -WorkspaceId "12345" -MirroredDatabaseId "67890" Stops the mirroring of the mirrored database with ID `67890` in the workspace `12345`. -.NOTES + + .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. - This function handles asynchronous operations and retrieves operation results if required. #> @@ -37,23 +43,16 @@ function Stop-FabricMirroredDatabaseMirroring try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState $apiEndpointUrl = "{0}/workspaces/{1}/mirroredDatabases/{2}/stopMirroring" -f $FabricConfig.BaseUrl, $WorkspaceId, $MirroredDatabaseId Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Stop MirroredDatabase Mirroring")) { # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post } # Step 7: Validate the response code diff --git a/source/Public/Mirrored Database/Update-FabricMirroredDatabase.ps1 b/source/Public/Mirrored Database/Update-FabricMirroredDatabase.ps1 index 60a7a381..205ccda3 100644 --- a/source/Public/Mirrored Database/Update-FabricMirroredDatabase.ps1 +++ b/source/Public/Mirrored Database/Update-FabricMirroredDatabase.ps1 @@ -29,7 +29,7 @@ Updates both the name and description of the MirroredDatabase "MirroredDatabase1 .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -59,9 +59,7 @@ function Update-FabricMirroredDatabase try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/mirroredDatabases/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $MirroredDatabaseId @@ -83,15 +81,10 @@ function Update-FabricMirroredDatabase if ($PSCmdlet.ShouldProcess($MirroredDatabaseId, "Update MirroredDatabase")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code diff --git a/source/Public/Mirrored Database/Update-FabricMirroredDatabaseDefinition.ps1 b/source/Public/Mirrored Database/Update-FabricMirroredDatabaseDefinition.ps1 index 5e76ec63..95029abb 100644 --- a/source/Public/Mirrored Database/Update-FabricMirroredDatabaseDefinition.ps1 +++ b/source/Public/Mirrored Database/Update-FabricMirroredDatabaseDefinition.ps1 @@ -34,7 +34,7 @@ Updates both the content and metadata of the MirroredDatabase with ID `67890` in .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. - The MirroredDatabase content is encoded as Base64 before being sent to the Fabric API. - This function handles asynchronous operations and retrieves operation results if required. @@ -66,9 +66,7 @@ function Update-FabricMirroredDatabaseDefinition try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/mirroredDatabases/{2}/updateDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $MirroredDatabaseId @@ -130,15 +128,10 @@ function Update-FabricMirroredDatabaseDefinition if ($PSCmdlet.ShouldProcess($MirroredDatabaseId, "Update MirroredDatabase")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/Mirrored Warehouse/Get-FabricMirroredWarehouse.ps1 b/source/Public/Mirrored Warehouse/Get-FabricMirroredWarehouse.ps1 index 9cec4dfe..407d355c 100644 --- a/source/Public/Mirrored Warehouse/Get-FabricMirroredWarehouse.ps1 +++ b/source/Public/Mirrored Warehouse/Get-FabricMirroredWarehouse.ps1 @@ -27,7 +27,7 @@ Retrieves all MirroredWarehouses in workspace "12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -55,9 +55,7 @@ Author: Tiago Balabuch } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState $continuationToken = $null $MirroredWarehouses = @() @@ -84,14 +82,9 @@ Author: Tiago Balabuch Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Notebook/Get-FabricNotebook.ps1 b/source/Public/Notebook/Get-FabricNotebook.ps1 index 5b970e22..aee9ebf1 100644 --- a/source/Public/Notebook/Get-FabricNotebook.ps1 +++ b/source/Public/Notebook/Get-FabricNotebook.ps1 @@ -27,7 +27,7 @@ Retrieves all Notebooks in workspace "12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -55,9 +55,7 @@ Author: Tiago Balabuch } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null $notebooks = @() @@ -83,14 +81,9 @@ Author: Tiago Balabuch Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Notebook/Get-FabricNotebookDefinition.ps1 b/source/Public/Notebook/Get-FabricNotebookDefinition.ps1 index b7235bbb..1c049299 100644 --- a/source/Public/Notebook/Get-FabricNotebookDefinition.ps1 +++ b/source/Public/Notebook/Get-FabricNotebookDefinition.ps1 @@ -30,7 +30,7 @@ Retrieves the definitions of all notebooks in the workspace with ID `12345` in t .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. - Handles long-running operations asynchronously. #> @@ -53,9 +53,7 @@ function Get-FabricNotebookDefinition { try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/notebooks/{2}/getDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $NotebookId @@ -68,13 +66,9 @@ function Get-FabricNotebookDefinition { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post # Step 5: Validate the response code and handle the response switch ($statusCode) { @@ -126,4 +120,4 @@ function Get-FabricNotebookDefinition { Write-Message -Message "Failed to retrieve Notebook. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Notebook/New-FabricNotebook.ps1 b/source/Public/Notebook/New-FabricNotebook.ps1 index be9ce2b7..7eb1665b 100644 --- a/source/Public/Notebook/New-FabricNotebook.ps1 +++ b/source/Public/Notebook/New-FabricNotebook.ps1 @@ -27,7 +27,7 @@ An optional path to the platform-specific definition (e.g., .platform file) to u .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -61,9 +61,7 @@ function New-FabricNotebook try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/notebooks" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -142,16 +140,10 @@ function New-FabricNotebook if ($PSCmdlet.ShouldProcess($NotebookName, "Create Notebook")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response switch ($statusCode) diff --git a/source/Public/Notebook/New-FabricNotebookNEW.ps1 b/source/Public/Notebook/New-FabricNotebookNEW.ps1 index 9c0e6436..9613b4c1 100644 --- a/source/Public/Notebook/New-FabricNotebookNEW.ps1 +++ b/source/Public/Notebook/New-FabricNotebookNEW.ps1 @@ -27,7 +27,7 @@ An optional path to the platform-specific definition (e.g., .platform file) to u .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -57,9 +57,7 @@ function New-FabricNotebookNEW try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/notebooks" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -103,16 +101,10 @@ function New-FabricNotebookNEW if ($PSCmdlet.ShouldProcess($NotebookName, "Create Notebook")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/Notebook/Remove-FabricNotebook.ps1 b/source/Public/Notebook/Remove-FabricNotebook.ps1 index 78f03b98..deba5593 100644 --- a/source/Public/Notebook/Remove-FabricNotebook.ps1 +++ b/source/Public/Notebook/Remove-FabricNotebook.ps1 @@ -40,9 +40,7 @@ function Remove-FabricNotebook try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/notebooks/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $NotebookId @@ -50,13 +48,9 @@ function Remove-FabricNotebook if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove Notebook")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Validate the response code diff --git a/source/Public/Notebook/Update-FabricNotebook.ps1 b/source/Public/Notebook/Update-FabricNotebook.ps1 index 449e754f..598339bc 100644 --- a/source/Public/Notebook/Update-FabricNotebook.ps1 +++ b/source/Public/Notebook/Update-FabricNotebook.ps1 @@ -29,7 +29,7 @@ Updates both the name and description of the Notebook "Notebook123". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -59,9 +59,7 @@ function Update-FabricNotebook try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/notebooks/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $NotebookId @@ -83,15 +81,10 @@ function Update-FabricNotebook if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Update Notebook")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code if ($statusCode -ne 200) diff --git a/source/Public/Notebook/Update-FabricNotebookDefinition.ps1 b/source/Public/Notebook/Update-FabricNotebookDefinition.ps1 index d867e626..3c5b269d 100644 --- a/source/Public/Notebook/Update-FabricNotebookDefinition.ps1 +++ b/source/Public/Notebook/Update-FabricNotebookDefinition.ps1 @@ -30,7 +30,7 @@ Updates both the content and metadata of the notebook with ID `67890` in the wor .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. - The notebook content is encoded as Base64 before being sent to the Fabric API. - This function handles asynchronous operations and retrieves operation results if required. @@ -62,9 +62,7 @@ function Update-FabricNotebookDefinition try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/notebooks/{2}/updateDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $NotebookId @@ -127,15 +125,10 @@ function Update-FabricNotebookDefinition if ($PSCmdlet.ShouldProcess($NotebookId, "Update Notebook Definition")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/Paginated Reports/Get-FabricPaginatedReport.ps1 b/source/Public/Paginated Reports/Get-FabricPaginatedReport.ps1 index 2f4e2afc..cb959fcf 100644 --- a/source/Public/Paginated Reports/Get-FabricPaginatedReport.ps1 +++ b/source/Public/Paginated Reports/Get-FabricPaginatedReport.ps1 @@ -25,7 +25,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -54,9 +54,7 @@ function Get-FabricPaginatedReport { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null $PaginatedReports = @() @@ -82,14 +80,9 @@ function Get-FabricPaginatedReport { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Paginated Reports/Update-FabricPaginatedReport.ps1 b/source/Public/Paginated Reports/Update-FabricPaginatedReport.ps1 index 398565ae..63cc403e 100644 --- a/source/Public/Paginated Reports/Update-FabricPaginatedReport.ps1 +++ b/source/Public/Paginated Reports/Update-FabricPaginatedReport.ps1 @@ -24,7 +24,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -53,9 +53,7 @@ function Update-FabricPaginatedReport try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/paginatedReports/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $PaginatedReportId @@ -79,15 +77,10 @@ function Update-FabricPaginatedReport { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code if ($statusCode -ne 200) diff --git a/source/Public/Reflex/Get-FabricReflex.ps1 b/source/Public/Reflex/Get-FabricReflex.ps1 index 23966035..cde59399 100644 --- a/source/Public/Reflex/Get-FabricReflex.ps1 +++ b/source/Public/Reflex/Get-FabricReflex.ps1 @@ -25,7 +25,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -54,9 +54,7 @@ function Get-FabricReflex { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null @@ -82,14 +80,9 @@ function Get-FabricReflex { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Reflex/Get-FabricReflexDefinition.ps1 b/source/Public/Reflex/Get-FabricReflexDefinition.ps1 index 4dde23c7..0d7e8a1f 100644 --- a/source/Public/Reflex/Get-FabricReflexDefinition.ps1 +++ b/source/Public/Reflex/Get-FabricReflexDefinition.ps1 @@ -25,7 +25,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -47,9 +47,7 @@ function Get-FabricReflexDefinition { ) try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/reflexes/{2}/getDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $ReflexId @@ -61,13 +59,9 @@ function Get-FabricReflexDefinition { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post # Step 5: Validate the response code and handle the response switch ($statusCode) { @@ -119,4 +113,4 @@ function Get-FabricReflexDefinition { Write-Message -Message "Failed to retrieve Reflex. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Reflex/New-FabricReflex.ps1 b/source/Public/Reflex/New-FabricReflex.ps1 index e7b69bc7..b9713c15 100644 --- a/source/Public/Reflex/New-FabricReflex.ps1 +++ b/source/Public/Reflex/New-FabricReflex.ps1 @@ -27,7 +27,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -59,9 +59,7 @@ function New-FabricReflex try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/reflexes" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -139,16 +137,10 @@ function New-FabricReflex if ($PSCmdlet.ShouldProcess($ReflexName, "Create Reflex")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } Write-Message -Message "Response Code: $statusCode" -Level Debug diff --git a/source/Public/Reflex/Remove-FabricReflex.ps1 b/source/Public/Reflex/Remove-FabricReflex.ps1 index d57a3188..21a6f912 100644 --- a/source/Public/Reflex/Remove-FabricReflex.ps1 +++ b/source/Public/Reflex/Remove-FabricReflex.ps1 @@ -18,7 +18,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -38,9 +38,7 @@ function Remove-FabricReflex try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/reflexes/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $ReflexId @@ -49,14 +47,9 @@ function Remove-FabricReflex if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove Reflex")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Handle response diff --git a/source/Public/Reflex/Update-FabricReflex.ps1 b/source/Public/Reflex/Update-FabricReflex.ps1 index d95ba7ca..3cfa65e5 100644 --- a/source/Public/Reflex/Update-FabricReflex.ps1 +++ b/source/Public/Reflex/Update-FabricReflex.ps1 @@ -24,7 +24,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -52,9 +52,7 @@ function Update-FabricReflex try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/reflexes/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $ReflexId @@ -77,16 +75,10 @@ function Update-FabricReflex if ($PSCmdlet.ShouldProcess("Reflex", "Update")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code diff --git a/source/Public/Reflex/Update-FabricReflexDefinition.ps1 b/source/Public/Reflex/Update-FabricReflexDefinition.ps1 index 8eb8862d..54277b15 100644 --- a/source/Public/Reflex/Update-FabricReflexDefinition.ps1 +++ b/source/Public/Reflex/Update-FabricReflexDefinition.ps1 @@ -24,7 +24,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -52,9 +52,7 @@ function Update-FabricReflexDefinition try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/reflexes/{2}/updateDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $ReflexId @@ -119,15 +117,10 @@ function Update-FabricReflexDefinition { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response switch ($statusCode) diff --git a/source/Public/Report/Get-FabricReport.ps1 b/source/Public/Report/Get-FabricReport.ps1 index 2cd3233f..ab0b165e 100644 --- a/source/Public/Report/Get-FabricReport.ps1 +++ b/source/Public/Report/Get-FabricReport.ps1 @@ -25,7 +25,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -54,9 +54,7 @@ function Get-FabricReport { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null @@ -82,14 +80,9 @@ function Get-FabricReport { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Report/Get-FabricReportDefinition.ps1 b/source/Public/Report/Get-FabricReportDefinition.ps1 index 4e3e8cf9..0b956480 100644 --- a/source/Public/Report/Get-FabricReportDefinition.ps1 +++ b/source/Public/Report/Get-FabricReportDefinition.ps1 @@ -25,7 +25,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -47,9 +47,7 @@ function Get-FabricReportDefinition { ) try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/reports/{2}/getDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $ReportId @@ -61,13 +59,9 @@ function Get-FabricReportDefinition { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post # Step 5: Validate the response code and handle the response switch ($statusCode) { @@ -119,4 +113,4 @@ function Get-FabricReportDefinition { Write-Message -Message "Failed to retrieve Report. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Report/New-FabricReport.ps1 b/source/Public/Report/New-FabricReport.ps1 index 8fbd1bee..70c4b186 100644 --- a/source/Public/Report/New-FabricReport.ps1 +++ b/source/Public/Report/New-FabricReport.ps1 @@ -25,7 +25,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -53,9 +53,7 @@ function New-FabricReport try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/reports" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -89,16 +87,10 @@ function New-FabricReport if ($PSCmdlet.ShouldProcess($ReportName, "Create Report")){ # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } Write-Message -Message "Response Code: $statusCode" -Level Debug diff --git a/source/Public/Report/Remove-FabricReport.ps1 b/source/Public/Report/Remove-FabricReport.ps1 index 130a1762..64dc8d17 100644 --- a/source/Public/Report/Remove-FabricReport.ps1 +++ b/source/Public/Report/Remove-FabricReport.ps1 @@ -18,7 +18,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -38,9 +38,7 @@ function Remove-FabricReport try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/reports/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $ReportId @@ -49,14 +47,9 @@ function Remove-FabricReport if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove Report")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Handle response diff --git a/source/Public/Report/Update-FabricReport.ps1 b/source/Public/Report/Update-FabricReport.ps1 index f8b2ab1c..d6117b0e 100644 --- a/source/Public/Report/Update-FabricReport.ps1 +++ b/source/Public/Report/Update-FabricReport.ps1 @@ -24,7 +24,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -52,9 +52,7 @@ function Update-FabricReport try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/reports/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $ReportId @@ -77,16 +75,10 @@ function Update-FabricReport if ($PSCmdlet.ShouldProcess($ReportName, "Update Report")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code diff --git a/source/Public/Report/Update-FabricReportDefinition.ps1 b/source/Public/Report/Update-FabricReportDefinition.ps1 index 2cb998c1..fadeee9f 100644 --- a/source/Public/Report/Update-FabricReportDefinition.ps1 +++ b/source/Public/Report/Update-FabricReportDefinition.ps1 @@ -21,7 +21,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -45,9 +45,7 @@ function Update-FabricReportDefinition try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/Reports/{2}/updateDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $ReportId @@ -97,15 +95,10 @@ function Update-FabricReportDefinition if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Update Report Definition")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/SQL Database/Get-FabricSQLDatabase.ps1 b/source/Public/SQL Database/Get-FabricSQLDatabase.ps1 index ddbfdbe8..c53c5cd2 100644 --- a/source/Public/SQL Database/Get-FabricSQLDatabase.ps1 +++ b/source/Public/SQL Database/Get-FabricSQLDatabase.ps1 @@ -58,7 +58,7 @@ function Get-FabricSQLDatabase { [string]$SQLDatabaseId ) - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState Write-Verbose "You can either use SQLDatabaseName or SQLDatabaseID not both. If both are used throw error" if ($PSBoundParameters.ContainsKey("SQLDatabaseName") -and $PSBoundParameters.ContainsKey("SQLDatabaseId")) { @@ -75,4 +75,4 @@ function Get-FabricSQLDatabase { return $result.value -} \ No newline at end of file +} diff --git a/source/Public/SQL Database/New-FabricSQLDatabase.ps1 b/source/Public/SQL Database/New-FabricSQLDatabase.ps1 index ae591e07..6b127dd2 100644 --- a/source/Public/SQL Database/New-FabricSQLDatabase.ps1 +++ b/source/Public/SQL Database/New-FabricSQLDatabase.ps1 @@ -22,7 +22,7 @@ An optional description for the SQL Database. .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Kamil Nowinski @@ -48,7 +48,7 @@ function New-FabricSQLDatabase try { # Step 1: Ensure token validity - Test-TokenExpired + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/sqldatabases" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -71,16 +71,10 @@ function New-FabricSQLDatabase { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response Write-Message "RESPONSE: $response" -Level Debug diff --git a/source/Public/SQL Database/Remove-FabricSQLDatabase.ps1 b/source/Public/SQL Database/Remove-FabricSQLDatabase.ps1 index 382d4c98..596bdb5a 100644 --- a/source/Public/SQL Database/Remove-FabricSQLDatabase.ps1 +++ b/source/Public/SQL Database/Remove-FabricSQLDatabase.ps1 @@ -40,8 +40,7 @@ function Remove-FabricSQLDatabase try { # Step 1: Ensure token validity - Confirm-FabricAuthToken | Out-Null - Test-TokenExpired + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/sqldatabases/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $SQLDatabaseId @@ -51,13 +50,9 @@ function Remove-FabricSQLDatabase { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Validate the response code diff --git a/source/Public/SQL Endpoints/Get-FabricSQLEndpoint.ps1 b/source/Public/SQL Endpoints/Get-FabricSQLEndpoint.ps1 index bf3c8335..82443fec 100644 --- a/source/Public/SQL Endpoints/Get-FabricSQLEndpoint.ps1 +++ b/source/Public/SQL Endpoints/Get-FabricSQLEndpoint.ps1 @@ -53,9 +53,7 @@ function Get-FabricSQLEndpoint { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null $SQLEndpoints = @() @@ -81,14 +79,9 @@ function Get-FabricSQLEndpoint { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Semantic Model/Get-FabricSemanticModel.ps1 b/source/Public/Semantic Model/Get-FabricSemanticModel.ps1 index b0bf5155..630c19fc 100644 --- a/source/Public/Semantic Model/Get-FabricSemanticModel.ps1 +++ b/source/Public/Semantic Model/Get-FabricSemanticModel.ps1 @@ -25,7 +25,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -54,9 +54,7 @@ function Get-FabricSemanticModel { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null @@ -82,14 +80,9 @@ function Get-FabricSemanticModel { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Semantic Model/Get-FabricSemanticModelDefinition.ps1 b/source/Public/Semantic Model/Get-FabricSemanticModelDefinition.ps1 index d0083936..0d4b8950 100644 --- a/source/Public/Semantic Model/Get-FabricSemanticModelDefinition.ps1 +++ b/source/Public/Semantic Model/Get-FabricSemanticModelDefinition.ps1 @@ -25,7 +25,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -48,9 +48,7 @@ function Get-FabricSemanticModelDefinition { ) try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/semanticModels/{2}/getDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $SemanticModelId @@ -62,13 +60,9 @@ function Get-FabricSemanticModelDefinition { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post # Step 5: Validate the response code and handle the response switch ($statusCode) { @@ -120,4 +114,4 @@ function Get-FabricSemanticModelDefinition { Write-Message -Message "Failed to retrieve SemanticModel. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Semantic Model/New-FabricSemanticModel.ps1 b/source/Public/Semantic Model/New-FabricSemanticModel.ps1 index 2122447d..2954d8dd 100644 --- a/source/Public/Semantic Model/New-FabricSemanticModel.ps1 +++ b/source/Public/Semantic Model/New-FabricSemanticModel.ps1 @@ -24,7 +24,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -52,9 +52,7 @@ function New-FabricSemanticModel try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/semanticModels" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -84,16 +82,10 @@ function New-FabricSemanticModel if ($PSCmdlet.ShouldProcess("Create SemanticModel", "Creating the SemanticModel '$SemanticModelName' in workspace '$WorkspaceId'.")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } Write-Message -Message "Response Code: $statusCode" -Level Debug diff --git a/source/Public/Semantic Model/Remove-FabricSemanticModel.ps1 b/source/Public/Semantic Model/Remove-FabricSemanticModel.ps1 index 2f165eee..618737c5 100644 --- a/source/Public/Semantic Model/Remove-FabricSemanticModel.ps1 +++ b/source/Public/Semantic Model/Remove-FabricSemanticModel.ps1 @@ -18,7 +18,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -38,9 +38,7 @@ function Remove-FabricSemanticModel try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/semanticModels/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $SemanticModelId @@ -49,14 +47,9 @@ function Remove-FabricSemanticModel if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove SemanticModel")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Handle response diff --git a/source/Public/Semantic Model/Update-FabricSemanticModel.ps1 b/source/Public/Semantic Model/Update-FabricSemanticModel.ps1 index 7d24a52f..1c381e31 100644 --- a/source/Public/Semantic Model/Update-FabricSemanticModel.ps1 +++ b/source/Public/Semantic Model/Update-FabricSemanticModel.ps1 @@ -24,7 +24,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -52,9 +52,7 @@ function Update-FabricSemanticModel try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/semanticModels/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $SemanticModelId @@ -77,16 +75,10 @@ function Update-FabricSemanticModel if ($PSCmdlet.ShouldProcess("Update SemanticModel", "Updating the SemanticModel with ID '$SemanticModelId' in workspace '$WorkspaceId'.")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code diff --git a/source/Public/Semantic Model/Update-FabricSemanticModelDefinition.ps1 b/source/Public/Semantic Model/Update-FabricSemanticModelDefinition.ps1 index 08c0b59b..b03ea578 100644 --- a/source/Public/Semantic Model/Update-FabricSemanticModelDefinition.ps1 +++ b/source/Public/Semantic Model/Update-FabricSemanticModelDefinition.ps1 @@ -21,7 +21,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -45,9 +45,7 @@ function Update-FabricSemanticModelDefinition try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/SemanticModels/{2}/updateDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $SemanticModelId @@ -85,15 +83,10 @@ function Update-FabricSemanticModelDefinition if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Update SemanticModel Definition")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/Set-FabricAuthToken.ps1 b/source/Public/Set-FabricAuthToken.ps1 deleted file mode 100644 index 0781c372..00000000 --- a/source/Public/Set-FabricAuthToken.ps1 +++ /dev/null @@ -1,110 +0,0 @@ -<# -.SYNOPSIS -Sets the Fabric authentication token. - -.DESCRIPTION -The Set-FabricAuthToken function sets the Fabric authentication token. It checks if an Azure context is already available. If not, it connects to the Azure account using either a service principal ID and secret, a provided credential, or interactive login. It then gets the Azure context and sets the Fabric authentication token. - -.PARAMETER azContext -The Azure context. If not provided, the function connects to the Azure account and gets the context. - -.PARAMETER servicePrincipalId -The service principal ID. If provided, the function uses this ID and the service principal secret to connect to the Azure account. - -.PARAMETER servicePrincipalSecret -The service principal secret. Used with the service principal ID to connect to the Azure account. - -.PARAMETER tenantId -The tenant ID. Used with the service principal ID and secret or the credential to connect to the Azure account. - -.PARAMETER credential -The credential. If provided, the function uses this credential to connect to the Azure account. - -.PARAMETER reset -A switch parameter. If provided, the function resets the Fabric authentication token. - -.PARAMETER apiUrl -The API URL. If provided, the function sets the Fabric API URL to this value. - -.EXAMPLE -Set-FabricAuthToken -servicePrincipalId "12345678-90ab-cdef-1234-567890abcdef" -servicePrincipalSecret "secret" -tenantId "12345678-90ab-cdef-1234-567890abcdef" - -This command sets the Fabric authentication token using the provided service principal ID, secret, and tenant ID. - -.INPUTS -String, SecureString, PSCredential. You can pipe a string that contains the service principal ID, a secure string that contains the service principal secret, and a PSCredential object that contains the credential to Set-FabricAuthToken. - -.OUTPUTS -None. This function does not return any output. - -.NOTES -This function was originally written by Rui Romano. -https://github.com/RuiRomano/fabricps-pbip -#> -function Set-FabricAuthToken { - [OutputType([System.Collections.Hashtable])] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification = "To pass current unit tests")] - [CmdletBinding(SupportsShouldProcess)] - param - ( - [string] $servicePrincipalId - , [string] $servicePrincipalSecret - , [PSCredential] $credential - , [string] $tenantId - , [switch] $reset - , [string] $apiUrl - ) - - - if (!$reset) - { - $azContext = Get-AzContext - } - - if ($apiUrl) { - $FabricSession.BaseApiUrl = $apiUrl - } - - if (!$azContext) { - Write-Output "Getting authentication token" - if ($servicePrincipalId) { - $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $servicePrincipalId, ($servicePrincipalSecret | ConvertTo-SecureString -AsPlainText -Force) - - Connect-AzAccount -ServicePrincipal -TenantId $tenantId -Credential $credential | Out-Null - - Set-AzContext -Tenant $tenantId | Out-Null - } - elseif ($null -ne $credential) { - Connect-AzAccount -Credential $credential -Tenant $tenantId | Out-Null - } - else { - Connect-AzAccount | Out-Null - } - $azContext = Get-AzContext - } - if ($PSCmdlet.ShouldProcess("Setting Fabric authentication token for $($azContext.Account)")) - { - Write-Output "Connected: $($azContext.Account)" - Write-Output "Fabric ResourceUrl: $($FabricSession.ResourceUrl)" - - $FabricSession.AccessToken = (Get-AzAccessToken -AsSecureString -ResourceUrl $FabricSession.ResourceUrl) - $ssPtr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($FabricSession.AccessToken.Token) - $FabricSession.FabricToken = ([System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($ssPtr)) - Write-Verbose "Setup headers for API calls" - $FabricSession.HeaderParams = @{ Authorization = $FabricSession.AccessToken.Type + ' ' + $FabricSession.FabricToken } - - Write-Output "Azure BaseApiUrl: $($FabricSession.ResourceUrl)" - $script:AzureSession.AccessToken = (Get-AzAccessToken -AsSecureString -ResourceUrl $AzureSession.BaseApiUrl) - $ssPtr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($AzureSession.AccessToken.Token) - $script:AzureSession.Token = ([System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($ssPtr)) - $AzureSession.HeaderParams = @{ Authorization = $AzureSession.AccessToken.Type + ' ' + $AzureSession.Token } - - # Copy session values to exposed $FabricConfig - $FabricConfig.TenantIdGlobal = $FabricSession.AccessToken.TenantId - $FabricConfig.TokenExpiresOn = $FabricSession.AccessToken.ExpiresOn - $FabricConfig.FabricHeaders = $FabricSession.HeaderParams - - return $($FabricSession.FabricToken) - - } -} diff --git a/source/Public/Spark Job Definition/Get-FabricSparkJobDefinition.ps1 b/source/Public/Spark Job Definition/Get-FabricSparkJobDefinition.ps1 index 6cbcbfe0..a65b2638 100644 --- a/source/Public/Spark Job Definition/Get-FabricSparkJobDefinition.ps1 +++ b/source/Public/Spark Job Definition/Get-FabricSparkJobDefinition.ps1 @@ -25,7 +25,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -54,9 +54,7 @@ function Get-FabricSparkJobDefinition { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null @@ -82,14 +80,9 @@ function Get-FabricSparkJobDefinition { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Spark Job Definition/Get-FabricSparkJobDefinitionDefinition.ps1 b/source/Public/Spark Job Definition/Get-FabricSparkJobDefinitionDefinition.ps1 index 11b2ea17..7a3e380e 100644 --- a/source/Public/Spark Job Definition/Get-FabricSparkJobDefinitionDefinition.ps1 +++ b/source/Public/Spark Job Definition/Get-FabricSparkJobDefinitionDefinition.ps1 @@ -25,7 +25,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -47,9 +47,7 @@ function Get-FabricSparkJobDefinitionDefinition { ) try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/sparkJobDefinitions/{2}/getDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $SparkJobDefinitionId @@ -61,13 +59,9 @@ function Get-FabricSparkJobDefinitionDefinition { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post # Step 5: Validate the response code and handle the response switch ($statusCode) { @@ -119,4 +113,4 @@ function Get-FabricSparkJobDefinitionDefinition { Write-Message -Message "Failed to retrieve Spark Job Definition. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Spark Job Definition/New-FabricSparkJobDefinition.ps1 b/source/Public/Spark Job Definition/New-FabricSparkJobDefinition.ps1 index 1f40185e..49207979 100644 --- a/source/Public/Spark Job Definition/New-FabricSparkJobDefinition.ps1 +++ b/source/Public/Spark Job Definition/New-FabricSparkJobDefinition.ps1 @@ -27,7 +27,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -58,9 +58,7 @@ function New-FabricSparkJobDefinition try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/sparkJobDefinitions" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -140,16 +138,10 @@ function New-FabricSparkJobDefinition if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Create Spark Job Definition")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson Write-Message -Message "Response Code: $statusCode" -Level Debug } diff --git a/source/Public/Spark Job Definition/Remove-FabricSparkJobDefinition.ps1 b/source/Public/Spark Job Definition/Remove-FabricSparkJobDefinition.ps1 index ea9146db..63b0d387 100644 --- a/source/Public/Spark Job Definition/Remove-FabricSparkJobDefinition.ps1 +++ b/source/Public/Spark Job Definition/Remove-FabricSparkJobDefinition.ps1 @@ -18,7 +18,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -37,9 +37,7 @@ function Remove-FabricSparkJobDefinition try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/sparkJobDefinitions/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $SparkJobDefinitionId @@ -47,14 +45,9 @@ function Remove-FabricSparkJobDefinition if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove SparkJobDefinition")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Handle response if ($statusCode -ne 200) diff --git a/source/Public/Spark Job Definition/Start-FabricSparkJobDefinitionOnDemand.ps1 b/source/Public/Spark Job Definition/Start-FabricSparkJobDefinitionOnDemand.ps1 index 5cdd5f61..964eaeef 100644 --- a/source/Public/Spark Job Definition/Start-FabricSparkJobDefinitionOnDemand.ps1 +++ b/source/Public/Spark Job Definition/Start-FabricSparkJobDefinitionOnDemand.ps1 @@ -51,9 +51,7 @@ function Start-FabricSparkJobDefinitionOnDemand try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/SparkJobDefinitions/{2}/jobs/instances?jobType={3}" -f $FabricConfig.BaseUrl, $WorkspaceId , $SparkJobDefinitionId, $JobType @@ -61,15 +59,9 @@ function Start-FabricSparkJobDefinitionOnDemand if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Start Spark Job Definition on demand")){ # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post } Write-Message -Message "Response Code: $statusCode" -Level Debug # Step 5: Handle and log the response diff --git a/source/Public/Spark Job Definition/Update-FabricSparkJobDefinition.ps1 b/source/Public/Spark Job Definition/Update-FabricSparkJobDefinition.ps1 index cff58abf..feae999f 100644 --- a/source/Public/Spark Job Definition/Update-FabricSparkJobDefinition.ps1 +++ b/source/Public/Spark Job Definition/Update-FabricSparkJobDefinition.ps1 @@ -24,7 +24,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -51,9 +51,7 @@ function Update-FabricSparkJobDefinition try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/sparkJobDefinitions/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $SparkJobDefinitionId @@ -77,16 +75,10 @@ function Update-FabricSparkJobDefinition { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code if ($statusCode -ne 200) diff --git a/source/Public/Spark Job Definition/Update-FabricSparkJobDefinitionDefinition.ps1 b/source/Public/Spark Job Definition/Update-FabricSparkJobDefinitionDefinition.ps1 index 1c680b99..6b1a3a04 100644 --- a/source/Public/Spark Job Definition/Update-FabricSparkJobDefinitionDefinition.ps1 +++ b/source/Public/Spark Job Definition/Update-FabricSparkJobDefinitionDefinition.ps1 @@ -24,7 +24,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -51,9 +51,7 @@ function Update-FabricSparkJobDefinitionDefinition try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/SparkJobDefinitions/{2}/updateDefinition" -f $FabricConfig.BaseUrl, $WorkspaceId, $SparkJobDefinitionId @@ -119,15 +117,10 @@ function Update-FabricSparkJobDefinitionDefinition { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/Spark/Get-FabricSparkCustomPool.ps1 b/source/Public/Spark/Get-FabricSparkCustomPool.ps1 index 1bbffe8c..0b931ddc 100644 --- a/source/Public/Spark/Get-FabricSparkCustomPool.ps1 +++ b/source/Public/Spark/Get-FabricSparkCustomPool.ps1 @@ -30,7 +30,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. - Handles continuation tokens to retrieve all Spark custom pools if there are multiple pages of results. Author: Tiago Balabuch @@ -59,9 +59,7 @@ function Get-FabricSparkCustomPool { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null $SparkCustomPools = @() @@ -87,14 +85,9 @@ function Get-FabricSparkCustomPool { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Spark/Get-FabricSparkSettings.ps1 b/source/Public/Spark/Get-FabricSparkSettings.ps1 index e111847c..232537a2 100644 --- a/source/Public/Spark/Get-FabricSparkSettings.ps1 +++ b/source/Public/Spark/Get-FabricSparkSettings.ps1 @@ -15,7 +15,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -32,9 +32,7 @@ function Get-FabricSparkSettings { try { # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null $SparkSettings = @() @@ -59,14 +57,9 @@ function Get-FabricSparkSettings { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Spark/New-FabricSparkCustomPool.ps1 b/source/Public/Spark/New-FabricSparkCustomPool.ps1 index afdf51f2..b107f95e 100644 --- a/source/Public/Spark/New-FabricSparkCustomPool.ps1 +++ b/source/Public/Spark/New-FabricSparkCustomPool.ps1 @@ -42,7 +42,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -98,9 +98,7 @@ function New-FabricSparkCustomPool try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/spark/pools" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -129,16 +127,10 @@ function New-FabricSparkCustomPool if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Create Spark Custom Pool")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/Spark/Remove-FabricSparkCustomPool.ps1 b/source/Public/Spark/Remove-FabricSparkCustomPool.ps1 index cf44ffc1..a8937ad9 100644 --- a/source/Public/Spark/Remove-FabricSparkCustomPool.ps1 +++ b/source/Public/Spark/Remove-FabricSparkCustomPool.ps1 @@ -18,7 +18,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -38,9 +38,7 @@ function Remove-FabricSparkCustomPool try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/spark/pools/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $SparkCustomPoolId @@ -49,13 +47,9 @@ function Remove-FabricSparkCustomPool if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove Spark Custom Pool")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Validate the response code diff --git a/source/Public/Spark/Update-FabricSparkCustomPool.ps1 b/source/Public/Spark/Update-FabricSparkCustomPool.ps1 index e0e58520..73e98bf8 100644 --- a/source/Public/Spark/Update-FabricSparkCustomPool.ps1 +++ b/source/Public/Spark/Update-FabricSparkCustomPool.ps1 @@ -45,7 +45,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -104,9 +104,7 @@ function Update-FabricSparkCustomPool try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/spark/pools/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $SparkCustomPoolId @@ -137,15 +135,10 @@ function Update-FabricSparkCustomPool { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code diff --git a/source/Public/Spark/Update-FabricSparkSettings.ps1 b/source/Public/Spark/Update-FabricSparkSettings.ps1 index 749a2e2b..428543d4 100644 --- a/source/Public/Spark/Update-FabricSparkSettings.ps1 +++ b/source/Public/Spark/Update-FabricSparkSettings.ps1 @@ -72,7 +72,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -127,9 +127,7 @@ function Update-FabricSparkSettings try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/spark/settings" -f $FabricConfig.BaseUrl, $WorkspaceId, $SparkSettingsId @@ -199,15 +197,10 @@ function Update-FabricSparkSettings { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code diff --git a/source/Public/Tenant/Get-FabricCapacityTenantSettingOverrides.ps1 b/source/Public/Tenant/Get-FabricCapacityTenantSettingOverrides.ps1 index d4d50c61..0b700c55 100644 --- a/source/Public/Tenant/Get-FabricCapacityTenantSettingOverrides.ps1 +++ b/source/Public/Tenant/Get-FabricCapacityTenantSettingOverrides.ps1 @@ -20,7 +20,7 @@ Returns tenant setting overrides for the capacity with ID "12345". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -34,24 +34,21 @@ function Get-FabricCapacityTenantSettingOverrides { try { # Step 1: Validate authentication token before making API requests - Write-Message -Message "Validating authentication token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Authentication token is valid." -Level Debug + Confirm-TokenState # Step 2: Construct the API endpoint URL for retrieving capacity tenant setting overrides if ($capacityId) { - $apiEndpointURI = "{0}/admin/capacities/{1}/delegatedTenantSettingOverrides" -f $FabricConfig.BaseUrl, $capacityId + $apiEndpointURI = "admin/capacities/{0}/delegatedTenantSettingOverrides" -f $capacityId $message = "Successfully retrieved tenant setting overrides for capacity ID: $capacityId." } else { - $apiEndpointURI = "{0}/admin/capacities/delegatedTenantSettingOverrides" -f $FabricConfig.BaseUrl + $apiEndpointURI = "admin/capacities/delegatedTenantSettingOverrides" -f $FabricConfig.BaseUrl $message = "Successfully retrieved capacity tenant setting overrides." } Write-Message -Message "Constructed API Endpoint: $apiEndpointURI" -Level Debug # Step 3: Invoke the Fabric API to retrieve capacity tenant setting overrides - $response = Invoke-FabricAPIRequest ` - -BaseURI $apiEndpointURI ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` + -Uri $apiEndpointURI ` -Method Get # Step 4: Check if any capacity tenant setting overrides were retrieved and handle results accordingly @@ -67,4 +64,4 @@ function Get-FabricCapacityTenantSettingOverrides { $errorDetails = $_.Exception.Message Write-Message -Message "Error retrieving capacity tenant setting overrides: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Tenant/Get-FabricDomainTenantSettingOverrides.ps1 b/source/Public/Tenant/Get-FabricDomainTenantSettingOverrides.ps1 index c5fb76b1..a8c50ff3 100644 --- a/source/Public/Tenant/Get-FabricDomainTenantSettingOverrides.ps1 +++ b/source/Public/Tenant/Get-FabricDomainTenantSettingOverrides.ps1 @@ -12,7 +12,7 @@ Fetches tenant setting overrides for all domains in the Fabric tenant. .NOTES - Requires the `$FabricConfig` global configuration, which must include `BaseUrl` and `FabricHeaders`. -- Ensures token validity by invoking `Test-TokenExpired` before making the API request. +- Ensures token validity by invoking `Confirm-TokenState` before making the API request. - Logs detailed messages for debugging and error handling. Author: Tiago Balabuch @@ -23,18 +23,15 @@ function Get-FabricDomainTenantSettingOverrides { try { # Step 1: Validate authentication token before making API requests - Write-Message -Message "Validating authentication token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Authentication token is valid." -Level Debug + Confirm-TokenState # Step 2: Construct the API endpoint URL for retrieving domain tenant setting overrides - $apiEndpointURI = "{0}/admin/domains/delegatedTenantSettingOverrides" -f $FabricConfig.BaseUrl + $apiEndpointURI = "admin/domains/delegatedTenantSettingOverrides" Write-Message -Message "Constructed API Endpoint: $apiEndpointURI" -Level Debug # Step 3: Invoke the Fabric API to retrieve domain tenant setting overrides - $response = Invoke-FabricAPIRequest ` - -BaseURI $apiEndpointURI ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` + -Uri $apiEndpointURI ` -Method Get # Step 4: Check if any domain tenant setting overrides were retrieved and handle results accordingly @@ -50,4 +47,4 @@ function Get-FabricDomainTenantSettingOverrides { $errorDetails = $_.Exception.Message Write-Message -Message "Error retrieving domain tenant setting overrides: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Tenant/Get-FabricTenantSetting.ps1 b/source/Public/Tenant/Get-FabricTenantSetting.ps1 index 7a83a33f..2f423c24 100644 --- a/source/Public/Tenant/Get-FabricTenantSetting.ps1 +++ b/source/Public/Tenant/Get-FabricTenantSetting.ps1 @@ -37,17 +37,16 @@ function Get-FabricTenantSetting { try { # Step 1: Validate authentication token before making API requests Write-Message -Message "Validating authentication token..." -Level Debug - Test-TokenExpired + Confirm-TokenState Write-Message -Message "Authentication token is valid." -Level Debug # Step 2: Construct the API endpoint URL for retrieving tenant settings - $apiEndpointURI = "{0}/admin/tenantsettings" -f $FabricConfig.BaseUrl + $apiEndpointURI = "admin/tenantsettings" Write-Message -Message "Constructed API Endpoint: $apiEndpointURI" -Level Debug # Step 3: Invoke the Fabric API to retrieve tenant settings - $response = Invoke-FabricAPIRequest ` - -BaseURI $apiEndpointURI ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` + -Uri $apiEndpointURI ` -Method Get # Step 4: Filter tenant settings based on the provided SettingTitle parameter (if specified) @@ -72,4 +71,4 @@ function Get-FabricTenantSetting { $errorDetails = $_.Exception.Message Write-Message -Message "Error retrieving tenant settings: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Tenant/Get-FabricWorkspaceTenantSettingOverrides.ps1 b/source/Public/Tenant/Get-FabricWorkspaceTenantSettingOverrides.ps1 index 9ff733b1..2040f9b5 100644 --- a/source/Public/Tenant/Get-FabricWorkspaceTenantSettingOverrides.ps1 +++ b/source/Public/Tenant/Get-FabricWorkspaceTenantSettingOverrides.ps1 @@ -12,7 +12,7 @@ Returns all workspaces tenant setting overrides. .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -22,18 +22,14 @@ function Get-FabricWorkspaceTenantSettingOverrides { try { # Step 1: Validate authentication token before making API requests - Write-Message -Message "Validating authentication token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Authentication token is valid." -Level Debug + Confirm-TokenState # Step 2: Construct the API endpoint URL for retrieving workspaces tenant setting overrides - $apiEndpointURI = "{0}/admin/workspaces/delegatedTenantSettingOverrides" -f $FabricConfig.BaseUrl - Write-Message -Message "Constructed API Endpoint: $apiEndpointURI" -Level Debug + $apiEndpointURI = "admin/workspaces/delegatedTenantSettingOverrides" # Step 3: Invoke the Fabric API to retrieve workspaces tenant setting overrides - $response = Invoke-FabricAPIRequest ` - -BaseURI $apiEndpointURI ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` + -Uri $apiEndpointURI ` -Method Get # Step 4: Check if any workspaces tenant setting overrides were retrieved and handle results accordingly @@ -49,4 +45,4 @@ function Get-FabricWorkspaceTenantSettingOverrides { $errorDetails = $_.Exception.Message Write-Message -Message "Error retrieving workspaces tenant setting overrides: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Tenant/Revoke-FabricCapacityTenantSettingOverrides.ps1 b/source/Public/Tenant/Revoke-FabricCapacityTenantSettingOverrides.ps1 index e47c7d14..bae0e3f0 100644 --- a/source/Public/Tenant/Revoke-FabricCapacityTenantSettingOverrides.ps1 +++ b/source/Public/Tenant/Revoke-FabricCapacityTenantSettingOverrides.ps1 @@ -18,7 +18,7 @@ Removes the tenant setting override named "ExampleSetting" from the capacity wit .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -35,19 +35,16 @@ function Revoke-FabricCapacityTenantSettingOverrides { ) try { # Step 1: Validate authentication token before making API requests - Write-Message -Message "Validating authentication token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Authentication token is valid." -Level Debug + Confirm-TokenState # Step 2: Construct the API endpoint URL for retrieving capacity tenant setting overrides - $apiEndpointURI = "{0}/admin/capacities/{1}/delegatedTenantSettingOverrides/{2}" -f $FabricConfig.BaseUrl, $capacityId, $tenantSettingName + $apiEndpointURI = "admin/capacities/{0}/delegatedTenantSettingOverrides/{1}" -f $capacityId, $tenantSettingName Write-Message -Message "Constructed API Endpoint: $apiEndpointURI" -Level Debug if ($PSCmdlet.ShouldProcess("$tenantSettingName" , "Revoke")) { # Step 3: Invoke the Fabric API to retrieve capacity tenant setting overrides - $response = Invoke-FabricAPIRequest ` - -BaseURI $apiEndpointURI ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` + -Uri $apiEndpointURI ` -Method Delete } Write-Message -Message "Successfully removed the tenant setting override '$tenantSettingName' from the capacity with ID '$capacityId'." -Level Info diff --git a/source/Public/Tenant/Update-FabricCapacityTenantSettingOverrides.ps1 b/source/Public/Tenant/Update-FabricCapacityTenantSettingOverrides.ps1 index 5c6f6fe4..f3504781 100644 --- a/source/Public/Tenant/Update-FabricCapacityTenantSettingOverrides.ps1 +++ b/source/Public/Tenant/Update-FabricCapacityTenantSettingOverrides.ps1 @@ -35,7 +35,7 @@ Updates the tenant setting "SomeSetting" for the capacity with ID "12345", enabl .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -73,9 +73,7 @@ function Update-FabricCapacityTenantSettingOverrides try { # Validate authentication token - Write-Message -Message "Validating authentication token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Authentication token is valid." -Level Debug + Confirm-TokenState # Validate Security Groups if provided if ($EnabledSecurityGroups) @@ -101,8 +99,7 @@ function Update-FabricCapacityTenantSettingOverrides } # Construct API endpoint URL - $apiEndpointURI = "{0}/admin/capacities/{1}/delegatedTenantSettingOverrides" -f $FabricConfig.BaseUrl, $CapacityId - Write-Message -Message "Constructed API Endpoint: $apiEndpointURI" -Level Debug + $apiEndpointURI = "admin/capacities/{0}/delegatedTenantSettingOverrides" -f $CapacityId # Construct request body $body = @{ @@ -130,9 +127,8 @@ function Update-FabricCapacityTenantSettingOverrides Write-Message -Message "Request Body: $bodyJson" -Level Debug if ($PSCmdlet.ShouldProcess($apiEndpointURI, "Update Tenant Setting Overrides")){ # Invoke Fabric API request - $response = Invoke-FabricAPIRequest ` - -BaseURI $apiEndpointURI ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` + -Uri $apiEndpointURI ` -method Post ` -body $bodyJson } diff --git a/source/Public/Tenant/Update-FabricTenantSetting.ps1 b/source/Public/Tenant/Update-FabricTenantSetting.ps1 index 88fd6845..c55bea90 100644 --- a/source/Public/Tenant/Update-FabricTenantSetting.ps1 +++ b/source/Public/Tenant/Update-FabricTenantSetting.ps1 @@ -35,7 +35,7 @@ Updates the tenant setting "SomeSetting" for the capacity with ID "12345", enabl .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -81,9 +81,7 @@ function Update-FabricCapacityTenantSettingOverrides try { # Validate authentication token - Write-Message -Message "Validating authentication token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Authentication token is valid." -Level Debug + Confirm-TokenState # Validate Security Groups if provided if ($EnabledSecurityGroups) @@ -121,7 +119,7 @@ function Update-FabricCapacityTenantSettingOverrides } # Construct API endpoint URL - $apiEndpointURI = "{0}/admin/tenantsettings/{1}/update" -f $FabricConfig.BaseUrl, $TenantSettingName + $apiEndpointURI = "admin/tenantsettings/{0}/update" -f $TenantSettingName Write-Message -Message "Constructed API Endpoint: $apiEndpointURI" -Level Debug # Construct request body @@ -167,9 +165,8 @@ function Update-FabricCapacityTenantSettingOverrides { # Invoke Fabric API request - $response = Invoke-FabricAPIRequest ` - -BaseURI $apiEndpointURI ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` + -Uri $apiEndpointURI ` -method Post ` -body $bodyJson } diff --git a/source/Public/Users/Get-FabricUserListAccessEntities.ps1 b/source/Public/Users/Get-FabricUserListAccessEntities.ps1 index c39956ec..305b4ae1 100644 --- a/source/Public/Users/Get-FabricUserListAccessEntities.ps1 +++ b/source/Public/Users/Get-FabricUserListAccessEntities.ps1 @@ -22,7 +22,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -41,20 +41,16 @@ function Get-FabricUserListAccessEntities { try { - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug - + Confirm-TokenState # Step 4: Loop to retrieve all capacities with continuation token - $apiEndpointURI = "{0}admin/users/{1}/access" -f $FabricConfig.BaseUrl, $UserId + $apiEndpointURI = "admin/users/{0}/access" -f $UserId if ($Type) { $apiEndpointURI += "?type=$Type" } - $response = Invoke-FabricAPIRequest ` - -BaseURI $apiEndpointURI ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` + -Uri $apiEndpointURI ` -Method Get return $response @@ -64,4 +60,4 @@ function Get-FabricUserListAccessEntities { Write-Message -Message "Failed to retrieve Warehouse. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Utils/Get-FabricLongRunningOperation.ps1 b/source/Public/Utils/Get-FabricLongRunningOperation.ps1 index 1238955f..6e90858c 100644 --- a/source/Public/Utils/Get-FabricLongRunningOperation.ps1 +++ b/source/Public/Utils/Get-FabricLongRunningOperation.ps1 @@ -38,12 +38,14 @@ This command polls the status of the operation with the given operationId every [int]$retryAfter = 5 ) + Confirm-TokenState + # Step 1: Construct the API URL if ($location) { # Use the Location header to define the operationUrl $apiEndpointUrl = $location } else { - $apiEndpointUrl = "https://api.fabric.microsoft.com/v1/operations/{0}" -f $operationId + $apiEndpointUrl = "{1}/operations/{1}" -f $FabricConfig.BaseUrl, $operationId } Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug @@ -58,13 +60,9 @@ This command polls the status of the operation with the given operationId every } # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -ResponseHeadersVariable responseHeader ` - -StatusCodeVariable statusCode + -Method Get # Step 3: Parse the response $jsonOperation = $response | ConvertTo-Json @@ -84,4 +82,4 @@ This command polls the status of the operation with the given operationId every Write-Message -Message "An error occurred while checking the operation: $errorDetails" -Level Error throw } -} \ No newline at end of file +} diff --git a/source/Public/Utils/Get-FabricLongRunningOperationResult.ps1 b/source/Public/Utils/Get-FabricLongRunningOperationResult.ps1 index 7e9e81c8..ad1c5a82 100644 --- a/source/Public/Utils/Get-FabricLongRunningOperationResult.ps1 +++ b/source/Public/Utils/Get-FabricLongRunningOperationResult.ps1 @@ -27,20 +27,17 @@ This command fetches the result of the operation with the specified operationId. [string]$operationId ) + Confirm-TokenState + # Step 1: Construct the API URL - $apiEndpointUrl = "https://api.fabric.microsoft.com/v1/operations/{0}/result" -f $operationId + $apiEndpointUrl = "{0}/operations/{1}/result" -f $FabricConfig.BaseUrl, $operationId Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug try { # Step 2: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 3: Return the result @@ -62,4 +59,4 @@ This command fetches the result of the operation with the specified operationId. Write-Message -Message "An error occurred while returning the operation result: $errorDetails" -Level Error throw } -} \ No newline at end of file +} diff --git a/source/Public/Utils/Invoke-FabricAPIRequest_duplicate.ps1 b/source/Public/Utils/Invoke-FabricAPIRequest_duplicate.ps1 index 25632b9d..95bff9b2 100644 --- a/source/Public/Utils/Invoke-FabricAPIRequest_duplicate.ps1 +++ b/source/Public/Utils/Invoke-FabricAPIRequest_duplicate.ps1 @@ -6,7 +6,7 @@ function Invoke-FabricAPIRequest_duplicate { Takes care of: authentication, 429 throttling, Long-Running-Operation (LRO) response .DESCRIPTION - The Invoke-FabricAPIRequest function is used to send an HTTP request to a Fabric API endpoint and retrieve the response. It handles various aspects such as authentication, 429 throttling, and Long-Running-Operation (LRO) response. + The Invoke-RestMethod function is used to send an HTTP request to a Fabric API endpoint and retrieve the response. It handles various aspects such as authentication, 429 throttling, and Long-Running-Operation (LRO) response. .PARAMETER authToken The authentication token to be used for the request. If not provided, it will be obtained using the Get-FabricAuthToken function. @@ -33,19 +33,19 @@ function Invoke-FabricAPIRequest_duplicate { The number of times to retry the request in case of a 429 (Too Many Requests) error. The default value is 0. .EXAMPLE - Invoke-FabricAPIRequest -uri "/api/resource" -method "Get" + Invoke-FabricAPIRequest_duplicate -uri "/api/resource" -method "Get" This example sends a GET request to the "/api/resource" endpoint of the Fabric API. .EXAMPLE - Invoke-FabricAPIRequest -authToken "abc123" -uri "/api/resource" -method "Post" -body $requestBody + Invoke-FabricAPIRequest_duplicate -authToken "abc123" -uri "/api/resource" -method "Post" -body $requestBody This example sends a POST request to the "/api/resource" endpoint of the Fabric API with a request body. .NOTES This function requires the Get-FabricAuthToken function to be defined in the same script or module. This function was originally written by Rui Romano. - https://github.com/RuiRomano/fabricps-pbip + https://github.com/microsoft/Analysis-Services/tree/master/pbidevmode/fabricps-pbip #> param ( [Parameter(Mandatory = $true)] diff --git a/source/Public/Utils/Set-FabricApiHeaders.ps1 b/source/Public/Utils/Set-FabricApiHeaders.ps1 deleted file mode 100644 index ef46e676..00000000 --- a/source/Public/Utils/Set-FabricApiHeaders.ps1 +++ /dev/null @@ -1,126 +0,0 @@ -function Set-FabricApiHeaders -{ - <# -.SYNOPSIS -Sets the Fabric API headers with a valid token for the specified Azure tenant. - -.DESCRIPTION -The `Set-FabricApiHeaders` function logs into the specified Azure tenant, retrieves an access token for the Fabric API, and sets the necessary headers for subsequent API requests. -It also updates the token expiration time and global tenant ID. - -.PARAMETER TenantId -The Azure tenant ID for which the access token is requested. - -.PARAMETER AppId -The Azure app ID for which the service principal access token is requested. - -.PARAMETER AppSecret -The Azure App secret for which the service principal access token is requested. - -.EXAMPLE -Set-FabricApiHeaders -TenantId "your-tenant-id" - -Logs in to Azure with the specified tenant ID, retrieves an access token for the current user, and configures the Fabric headers. - -.EXAMPLE -$tenantId = "999999999-99999-99999-9999-999999999999" -$appId = "888888888-88888-88888-8888-888888888888" -$appSecret = "your-app-secret" -$secureAppSecret = $appSecret | ConvertTo-SecureString -AsPlainText -Force - -Set-FabricApiHeader -TenantId $tenantId -AppId $appId -AppSecret $secureAppSecret -Logs in to Azure with the specified tenant ID, retrieves an access token for the service principal, and configures the Fabric headers. - -.NOTES -- Ensure the `Connect-AzAccount` and `Get-AzAccessToken` commands are available (Azure PowerShell module required). -- Relies on a global `$FabricConfig` object for storing headers and token metadata. - - AUTHOR - Tiago Balabuch - #> - - [CmdletBinding(SupportsShouldProcess)] - param ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [string]$TenantId, - [Parameter(Mandatory = $false)] - [ValidateNotNullOrEmpty()] - [string]$AppId, - [Parameter(Mandatory = $false)] - [ValidateNotNullOrEmpty()] - [System.Security.SecureString]$AppSecret - ) - - try - { - # Step 1: Connect to the Azure account - Write-Message -Message "Logging in to Azure tenant: $TenantId" -Level Info - - # Step 2: Performing validation checks on the parameters passed to a function or script. - # Checks if 'AppId' is provided without 'AppSecret' and vice versa. - if ($PSBoundParameters.ContainsKey('AppId') -and -not $PSBoundParameters.ContainsKey('AppSecret')) - { - Write-Message -Message "AppSecret is required when using AppId: $AppId" -Level Error - throw "AppSecret is required when using AppId." - } - if ($PSBoundParameters.ContainsKey('AppSecret') -and -not $PSBoundParameters.ContainsKey('AppId')) - { - Write-Message -Message "AppId is required when using AppSecret." -Level Error - throw "AppId is required when using AppId." - } - # Step 3: Connect to the Azure account - # Using AppId and AppSecret - if ($PSBoundParameters.ContainsKey('AppId') -and $PSBoundParameters.ContainsKey('AppSecret')) - { - - Write-Message -Message "Logging in using the AppId: $AppId" -Level Debug - Write-Message -Message "Logging in using the AppId: $AppId" -Level Info - $psCredential = [pscredential]::new($AppId, $AppSecret) - Connect-AzAccount -ServicePrincipal -Credential $psCredential -Tenant $tenantId - - } - # Using the current user - else - { - - Write-Message -Message "Logging in using the current user" -Level Debug - Write-Message -Message "Logging in using the current user" -Level Info - Connect-AzAccount -Tenant $TenantId -ErrorAction Stop | Out-Null - } - - ## Step 4: Retrieve the access token for the Fabric API - Write-Message -Message "Retrieve the access token for the Fabric API: $TenantId" -Level Debug - $fabricToken = Get-AzAccessToken -AsSecureString -ResourceUrl $FabricConfig.ResourceUrl -ErrorAction Stop -WarningAction SilentlyContinue - - ## Step 5: Extract the plain token from the secure string - Write-Message -Message "Extract the plain token from the secure string" -Level Debug - $plainToken = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto( - [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($fabricToken.Token) - ) - if ($PSCmdlet.ShouldProcess("Set the headers in the global configuration $($TenantId)")) - { - ## Step 6: Set the headers in the global configuration - $FabricConfig.FabricHeaders = @{ - 'Content-Type' = 'application/json' - 'Authorization' = "Bearer $plainToken" - } - } - ## Step 7: Update token metadata in the global configuration - Write-Message -Message "Update token metadata in the global configuration" -Level Debug - if ($PSCmdlet.ShouldProcess("Update token metadata in the global configuration")) - { - - $FabricConfig.TokenExpiresOn = $fabricToken.ExpiresOn - $FabricConfig.TenantIdGlobal = $TenantId - } - Write-Message -Message "Fabric token successfully configured." -Level Info - } - catch - { - # Step 8: Handle and log errors - $errorDetails = $_.Exception.Message - Write-Message -Message "Failed to set Fabric token: $errorDetails" -Level Error - throw "Unable to configure Fabric token. Ensure tenant and API configurations are correct." - } -} diff --git a/source/Public/Warehouse/Get-FabricWarehouse.ps1 b/source/Public/Warehouse/Get-FabricWarehouse.ps1 index 0e29c35b..a39cf756 100644 --- a/source/Public/Warehouse/Get-FabricWarehouse.ps1 +++ b/source/Public/Warehouse/Get-FabricWarehouse.ps1 @@ -25,7 +25,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -53,9 +53,7 @@ function Get-FabricWarehouse { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables @@ -66,7 +64,7 @@ function Get-FabricWarehouse { Uri = $apiEndpointURI Method = 'Get' } - $Warehouses = (Invoke-FabricAPIRequest @apiParams).Value + $Warehouses = (Invoke-FabricRestMethod @apiParams).Value # Step 8: Filter results based on provided parameters $Warehouse = if ($WarehouseId) { diff --git a/source/Public/Warehouse/New-FabricWarehouse.ps1 b/source/Public/Warehouse/New-FabricWarehouse.ps1 index d71b5436..e460b806 100644 --- a/source/Public/Warehouse/New-FabricWarehouse.ps1 +++ b/source/Public/Warehouse/New-FabricWarehouse.ps1 @@ -21,7 +21,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -45,9 +45,7 @@ function New-FabricWarehouse try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointURI = "workspaces/{0}/warehouses" -f $WorkspaceId @@ -74,7 +72,7 @@ function New-FabricWarehouse Method = 'Post' Body = $bodyJson } - $response = Invoke-FabricAPIRequest @apiParams + $response = Invoke-FabricRestMethod @apiParams } Write-Message -Message "Data Warehouse created successfully!" -Level Info diff --git a/source/Public/Warehouse/Remove-FabricWarehouse.ps1 b/source/Public/Warehouse/Remove-FabricWarehouse.ps1 index 29ddc344..384e6d24 100644 --- a/source/Public/Warehouse/Remove-FabricWarehouse.ps1 +++ b/source/Public/Warehouse/Remove-FabricWarehouse.ps1 @@ -18,7 +18,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -37,25 +37,22 @@ function Remove-FabricWarehouse try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointURI = "workspaces/{0}/warehouses/{1}" -f $WorkspaceId, $WarehouseId - Write-Message -Message "API Endpoint: $apiEndpointURI" -Level Debug if ($PSCmdlet.ShouldProcess($apiEndpointURI, "Delete Warehouse")) { # Step 3: Make the API request - $apiParams = @{ - Uri = $apiEndpointURI - Method = 'Delete' - } - $null = Invoke-FabricAPIRequest @apiParams + $response = Invoke-FabricRestMethod ` + -Uri $apiEndpointURI ` + -method Delete ` } Write-Message -Message "Warehouse '$WarehouseId' deleted successfully from workspace '$WorkspaceId'." -Level Info + return $response + } catch { diff --git a/source/Public/Warehouse/Update-FabricWarehouse.ps1 b/source/Public/Warehouse/Update-FabricWarehouse.ps1 index 6ea42649..55b21af0 100644 --- a/source/Public/Warehouse/Update-FabricWarehouse.ps1 +++ b/source/Public/Warehouse/Update-FabricWarehouse.ps1 @@ -24,7 +24,7 @@ .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. - - Calls `Test-TokenExpired` to ensure token validity before making the API request. + - Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -53,13 +53,10 @@ function Update-FabricWarehouse try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL - $apiEndpointURI = "{0}/workspaces/{1}/warehouses/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $WarehouseId - Write-Message -Message "API Endpoint: $apiEndpointURI" -Level Debug + $apiEndpointURI = "workspaces/{0}/warehouses/{1}" -f $WorkspaceId, $WarehouseId # Step 3: Construct the request body $body = @{ @@ -77,10 +74,8 @@ function Update-FabricWarehouse if ($PSCmdlet.ShouldProcess($apiEndpointURI, "Update Warehouse")) { - - $response = Invoke-FabricAPIRequest ` - -Headers $FabricConfig.FabricHeaders ` - -BaseURI $apiEndpointURI ` + $response = Invoke-FabricRestMethod ` + -Uri $apiEndpointURI ` -method Patch ` -body $bodyJson } diff --git a/source/Public/Workspace/Add-FabricWorkspaceCapacityAssignment.ps1 b/source/Public/Workspace/Add-FabricWorkspaceCapacityAssignment.ps1 index 11e52bf6..ca9611aa 100644 --- a/source/Public/Workspace/Add-FabricWorkspaceCapacityAssignment.ps1 +++ b/source/Public/Workspace/Add-FabricWorkspaceCapacityAssignment.ps1 @@ -18,7 +18,7 @@ Assigns the workspace with ID "workspace123" to the capacity "capacity456". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -38,9 +38,7 @@ function Add-FabricWorkspaceCapacityAssignment { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/assignToCapacity" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -56,16 +54,10 @@ function Add-FabricWorkspaceCapacityAssignment { Write-Message -Message "Request Body: $bodyJson" -Level Debug # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson # Step 5: Validate the response code if ($statusCode -ne 202) { diff --git a/source/Public/Workspace/Add-FabricWorkspaceIdentity.ps1 b/source/Public/Workspace/Add-FabricWorkspaceIdentity.ps1 index 1dba6e27..0b7a1a70 100644 --- a/source/Public/Workspace/Add-FabricWorkspaceIdentity.ps1 +++ b/source/Public/Workspace/Add-FabricWorkspaceIdentity.ps1 @@ -15,7 +15,7 @@ Provisions a Managed Identity for the workspace with ID "workspace123". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -30,24 +30,16 @@ function Add-FabricWorkspaceIdentity { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/provisionIdentity" -f $FabricConfig.BaseUrl, $WorkspaceId Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post # Step 4: Handle and log the response switch ($statusCode) { @@ -96,4 +88,4 @@ function Add-FabricWorkspaceIdentity { $errorDetails = $_.Exception.Message Write-Message -Message "Failed to provision workspace identity. Error: $errorDetails" -Level Error } -} \ No newline at end of file +} diff --git a/source/Public/Workspace/Add-FabricWorkspaceRoleAssignment.ps1 b/source/Public/Workspace/Add-FabricWorkspaceRoleAssignment.ps1 index 82464a4f..82aa9611 100644 --- a/source/Public/Workspace/Add-FabricWorkspaceRoleAssignment.ps1 +++ b/source/Public/Workspace/Add-FabricWorkspaceRoleAssignment.ps1 @@ -24,7 +24,7 @@ Assigns the Admin role to the user with ID "principal123" in the workspace "work .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -54,9 +54,7 @@ function Add-FabricWorkspaceRoleAssignment { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/roleAssignments" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -76,16 +74,10 @@ function Add-FabricWorkspaceRoleAssignment { Write-Message -Message "Request Body: $bodyJson" -Level Debug # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson # Step 5: Validate the response code if ($statusCode -ne 201) { diff --git a/source/Public/Workspace/Get-FabricWorkspace.ps1 b/source/Public/Workspace/Get-FabricWorkspace.ps1 index 3a6ddf73..b4f54c42 100644 --- a/source/Public/Workspace/Get-FabricWorkspace.ps1 +++ b/source/Public/Workspace/Get-FabricWorkspace.ps1 @@ -23,7 +23,7 @@ Fetches details of the workspace with the name "MyWorkspace". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. - Returns the matching workspace details or all workspaces if no filter is provided. Author: Tiago Balabuch @@ -49,9 +49,7 @@ function Get-FabricWorkspace { } # Step 2: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null @@ -76,14 +74,9 @@ function Get-FabricWorkspace { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Workspace/Get-FabricWorkspaceDatasetRefreshes.ps1 b/source/Public/Workspace/Get-FabricWorkspaceDatasetRefreshes.ps1 index 76c040d8..971d36ee 100644 --- a/source/Public/Workspace/Get-FabricWorkspaceDatasetRefreshes.ps1 +++ b/source/Public/Workspace/Get-FabricWorkspaceDatasetRefreshes.ps1 @@ -34,7 +34,7 @@ function Get-FabricWorkspaceDatasetRefreshes { [string]$WorkspaceID ) - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState # Get the workspace using the workspace ID $wsp = Get-FabricWorkspace -workspaceid $WorkspaceID @@ -50,4 +50,4 @@ function Get-FabricWorkspaceDatasetRefreshes { } # Return the refresh history array return $refs -} \ No newline at end of file +} diff --git a/source/Public/Workspace/Get-FabricWorkspaceRoleAssignment.ps1 b/source/Public/Workspace/Get-FabricWorkspaceRoleAssignment.ps1 index dd393868..e85d8e8b 100644 --- a/source/Public/Workspace/Get-FabricWorkspaceRoleAssignment.ps1 +++ b/source/Public/Workspace/Get-FabricWorkspaceRoleAssignment.ps1 @@ -23,7 +23,7 @@ Fetches the role assignment with the ID "role123" for the workspace "workspace12 .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -43,9 +43,7 @@ function Get-FabricWorkspaceRoleAssignment { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 3: Initialize variables $continuationToken = $null @@ -71,14 +69,9 @@ function Get-FabricWorkspaceRoleAssignment { Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug # Step 6: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Get ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Get # Step 7: Validate the response code if ($statusCode -ne 200) { diff --git a/source/Public/Workspace/Get-FabricWorkspaceUsers.ps1 b/source/Public/Workspace/Get-FabricWorkspaceUsers.ps1 index 8f5e90ce..497c7fe5 100644 --- a/source/Public/Workspace/Get-FabricWorkspaceUsers.ps1 +++ b/source/Public/Workspace/Get-FabricWorkspaceUsers.ps1 @@ -40,18 +40,18 @@ The function defines parameters for the workspace ID and workspace object. If th ) begin { - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState } process { - # If the parameter set name is 'WorkspaceId', retrieve the workspace object. - if ($PSCmdlet.ParameterSetName -eq 'WorkspaceId') { - $workspace = Get-PowerBIWorkspace -Id $WorkspaceId + # If the parameter set name is 'WorkspaceObject', retrieve the workspace object. + if ($PSCmdlet.ParameterSetName -eq 'WorkspaceObject') { + $WorkspaceId = $Workspace.id } # Make a GET request to the PowerBI API to retrieve the users of the workspace. # The function returns the 'value' property of the response, which contains the users. - return (Invoke-PowerBIRestMethod -Method get -Url ("groups/$($workspace.Id)/users") | ConvertFrom-Json).value + return (Invoke-FabricRestMethod -Method get -PowerBIApi -uri ("groups/$WorkspaceId/users")).value } -} \ No newline at end of file +} diff --git a/source/Public/Workspace/New-FabricWorkspace.ps1 b/source/Public/Workspace/New-FabricWorkspace.ps1 index 5dc12c8a..d05999af 100644 --- a/source/Public/Workspace/New-FabricWorkspace.ps1 +++ b/source/Public/Workspace/New-FabricWorkspace.ps1 @@ -23,7 +23,7 @@ Creates a workspace named "NewWorkspace". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -45,9 +45,7 @@ Author: Tiago Balabuch try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces" -f $FabricConfig.BaseUrl @@ -76,16 +74,10 @@ Author: Tiago Balabuch { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Post ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Handle and log the response diff --git a/source/Public/Workspace/New-FabricWorkspaceUsageMetricsReport.ps1 b/source/Public/Workspace/New-FabricWorkspaceUsageMetricsReport.ps1 index 893f8387..f7861505 100644 --- a/source/Public/Workspace/New-FabricWorkspaceUsageMetricsReport.ps1 +++ b/source/Public/Workspace/New-FabricWorkspaceUsageMetricsReport.ps1 @@ -29,7 +29,7 @@ The function retrieves the PowerBI access token and the Fabric API cluster URI. [string]$workspaceId ) - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState # Retrieve the Fabric API cluster URI. $url = Get-FabricAPIclusterURI @@ -45,4 +45,4 @@ The function retrieves the PowerBI access token and the Fabric API cluster URI. } else { return $null } -} \ No newline at end of file +} diff --git a/source/Public/Workspace/Register-FabricWorkspaceToCapacity.ps1 b/source/Public/Workspace/Register-FabricWorkspaceToCapacity.ps1 index e7d6d6f1..edfba4e8 100644 --- a/source/Public/Workspace/Register-FabricWorkspaceToCapacity.ps1 +++ b/source/Public/Workspace/Register-FabricWorkspaceToCapacity.ps1 @@ -54,18 +54,20 @@ The function makes a POST request to the PowerBI API to Set the workspace to the $workspaceid = $workspace.id } + Confirm-TokenState + # The body of the request is created. It contains the capacity ID. $body = @{ capacityId = $CapacityId } - Confirm-FabricAuthToken | Out-Null - # The workspace is Seted to the capacity by making a POST request to the PowerBI API. # The function returns the value property of the response. if ($PSCmdlet.ShouldProcess("Set workspace $workspaceid to capacity $CapacityId")) { - #return (Invoke-FabricAPIRequest -Uri "workspaces/$($workspaceID)/assignToCapacity" -Method POST -Body $body).value - return Invoke-WebRequest -Headers $FabricSession.HeaderParams -Method POST -Uri "$($FabricSession.BaseApiUrl)/workspaces/$($workspaceID)/assignToCapacity" -Body $body + Invoke-FabricRestMethod ` + -Uri "workspaces/$($workspaceID)/assignToCapacity" ` + -Method POST ` + -Body $body } } -} \ No newline at end of file +} diff --git a/source/Public/Workspace/Remove-FabricWorkspace.ps1 b/source/Public/Workspace/Remove-FabricWorkspace.ps1 index 5cbfa4d4..18905caa 100644 --- a/source/Public/Workspace/Remove-FabricWorkspace.ps1 +++ b/source/Public/Workspace/Remove-FabricWorkspace.ps1 @@ -15,12 +15,12 @@ Deletes the workspace with the ID "workspace123". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> function Remove-FabricWorkspace { - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -30,9 +30,7 @@ function Remove-FabricWorkspace { try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -41,14 +39,9 @@ function Remove-FabricWorkspace { if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Delete Workspace")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Validate the response code diff --git a/source/Public/Workspace/Remove-FabricWorkspaceCapacityAssignment.ps1 b/source/Public/Workspace/Remove-FabricWorkspaceCapacityAssignment.ps1 index 85e89633..2e34a1a2 100644 --- a/source/Public/Workspace/Remove-FabricWorkspaceCapacityAssignment.ps1 +++ b/source/Public/Workspace/Remove-FabricWorkspaceCapacityAssignment.ps1 @@ -15,14 +15,14 @@ Unassigns the workspace with ID "workspace123" from its capacity. .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> function Remove-FabricWorkspaceCapacityAssignment { - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] [Alias("Unassign-FabricWorkspaceCapacity")] param ( [Parameter(Mandatory = $true)] @@ -32,9 +32,7 @@ function Remove-FabricWorkspaceCapacityAssignment try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/unassignFromCapacity" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -43,15 +41,9 @@ function Remove-FabricWorkspaceCapacityAssignment if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Unassign Workspace from Capacity")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post } # Step 4: Validate the response code if ($statusCode -ne 202) diff --git a/source/Public/Workspace/Remove-FabricWorkspaceIdentity.ps1 b/source/Public/Workspace/Remove-FabricWorkspaceIdentity.ps1 index 9fe5914c..2e7bd0c4 100644 --- a/source/Public/Workspace/Remove-FabricWorkspaceIdentity.ps1 +++ b/source/Public/Workspace/Remove-FabricWorkspaceIdentity.ps1 @@ -15,14 +15,14 @@ Deprovisions the Managed Identity for the workspace with ID "workspace123". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> function Remove-FabricWorkspaceIdentity { - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -32,9 +32,7 @@ function Remove-FabricWorkspaceIdentity try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/deprovisionIdentity" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -44,15 +42,9 @@ function Remove-FabricWorkspaceIdentity { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Post ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Post } # Step 4: Handle and log the response diff --git a/source/Public/Workspace/Remove-FabricWorkspaceRoleAssignment.ps1 b/source/Public/Workspace/Remove-FabricWorkspaceRoleAssignment.ps1 index dd96b1a2..01267a69 100644 --- a/source/Public/Workspace/Remove-FabricWorkspaceRoleAssignment.ps1 +++ b/source/Public/Workspace/Remove-FabricWorkspaceRoleAssignment.ps1 @@ -18,7 +18,7 @@ Removes the role assignment with the ID "role123" from the workspace "workspace1 .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch @@ -26,7 +26,7 @@ Author: Tiago Balabuch function Remove-FabricWorkspaceRoleAssignment { - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -40,9 +40,7 @@ function Remove-FabricWorkspaceRoleAssignment try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/roleAssignments/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $WorkspaceRoleAssignmentId @@ -51,14 +49,9 @@ function Remove-FabricWorkspaceRoleAssignment if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Delete Role Assignment")) { # Step 3: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` - -Method Delete ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Method Delete } # Step 4: Validate the response code if ($statusCode -ne 200) diff --git a/source/Public/Workspace/Unregister-FabricWorkspaceToCapacity.ps1 b/source/Public/Workspace/Unregister-FabricWorkspaceToCapacity.ps1 index f9fad83d..5ab8e9a4 100644 --- a/source/Public/Workspace/Unregister-FabricWorkspaceToCapacity.ps1 +++ b/source/Public/Workspace/Unregister-FabricWorkspaceToCapacity.ps1 @@ -42,7 +42,7 @@ function Unregister-FabricWorkspaceToCapacity { ) begin { - Confirm-FabricAuthToken | Out-Null + Confirm-TokenState } Process { @@ -51,8 +51,7 @@ function Unregister-FabricWorkspaceToCapacity { } if ($PSCmdlet.ShouldProcess("Unassigns workspace $workspaceid from a capacity")) { - return Invoke-WebRequest -Headers $FabricSession.HeaderParams -Method POST -Uri "$($FabricSession.BaseApiUrl)/workspaces/$($workspaceID)/unassignFromCapacity" - #return (Invoke-FabricAPIRequest -Uri "workspaces/$workspaceid/unassignFromCapacity" -Method POST).value + Invoke-FabricRestMethod -Uri "workspaces/$workspaceid/unassignFromCapacity" -Method POST } } -} \ No newline at end of file +} diff --git a/source/Public/Workspace/Update-FabricWorkspace.ps1 b/source/Public/Workspace/Update-FabricWorkspace.ps1 index 87626009..307bcecf 100644 --- a/source/Public/Workspace/Update-FabricWorkspace.ps1 +++ b/source/Public/Workspace/Update-FabricWorkspace.ps1 @@ -26,7 +26,7 @@ Updates both the name and description of the workspace "workspace123". .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -51,9 +51,7 @@ function Update-FabricWorkspace try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}" -f $FabricConfig.BaseUrl, $WorkspaceId @@ -75,18 +73,11 @@ function Update-FabricWorkspace if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Update Workspace")) { - # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code if ($statusCode -ne 200) diff --git a/source/Public/Workspace/Update-FabricWorkspaceRoleAssignment.ps1 b/source/Public/Workspace/Update-FabricWorkspaceRoleAssignment.ps1 index 3c2994fa..3848ce0f 100644 --- a/source/Public/Workspace/Update-FabricWorkspaceRoleAssignment.ps1 +++ b/source/Public/Workspace/Update-FabricWorkspaceRoleAssignment.ps1 @@ -25,7 +25,7 @@ Updates the role assignment to "Admin" for the specified workspace and role assi .NOTES - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. -- Calls `Test-TokenExpired` to ensure token validity before making the API request. +- Calls `Confirm-TokenState` to ensure token validity before making the API request. Author: Tiago Balabuch #> @@ -51,9 +51,7 @@ function Update-FabricWorkspaceRoleAssignment try { # Step 1: Ensure token validity - Write-Message -Message "Validating token..." -Level Debug - Test-TokenExpired - Write-Message -Message "Token validation completed." -Level Debug + Confirm-TokenState # Step 2: Construct the API URL $apiEndpointUrl = "{0}/workspaces/{1}/roleAssignments/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $WorkspaceRoleAssignmentId @@ -71,16 +69,10 @@ function Update-FabricWorkspaceRoleAssignment if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Update Role Assignment")) { # Step 4: Make the API request - $response = Invoke-RestMethod ` - -Headers $FabricConfig.FabricHeaders ` + $response = Invoke-FabricRestMethod ` -Uri $apiEndpointUrl ` -Method Patch ` - -Body $bodyJson ` - -ContentType "application/json" ` - -ErrorAction Stop ` - -SkipHttpErrorCheck ` - -ResponseHeadersVariable "responseHeader" ` - -StatusCodeVariable "statusCode" + -Body $bodyJson } # Step 5: Validate the response code if ($statusCode -ne 200) diff --git a/tests/QA/module.tests.ps1 b/tests/QA/module.tests.ps1 index e1f3847c..0af52252 100644 --- a/tests/QA/module.tests.ps1 +++ b/tests/QA/module.tests.ps1 @@ -88,7 +88,7 @@ BeforeDiscovery { foreach ($function in $allModuleFunctions | Where-Object -FilterScript { $_.Name -notin ( - 'Test-TokenExpired', + 'Confirm-TokenState', 'Get-FabricUri', 'Get-FileDefinitionParts', 'Set-FabConfig', diff --git a/tests/Unit/Connect-FabricAccount.Tests.ps1 b/tests/Unit/Connect-FabricAccount.Tests.ps1 index 254b5ed5..622a6768 100644 --- a/tests/Unit/Connect-FabricAccount.Tests.ps1 +++ b/tests/Unit/Connect-FabricAccount.Tests.ps1 @@ -6,21 +6,21 @@ param( "ServicePrincipalId" "ServicePrincipalSecret" "Credential" - "Verbose" - "Debug" - "ErrorAction" - "WarningAction" - "InformationAction" - "ProgressAction" - "ErrorVariable" - "WarningVariable" - "InformationVariable" - "OutVariable" - "OutBuffer" - "PipelineVariable" - "WhatIf" - "Confirm" - + "Reset" + "Verbose" + "Debug" + "ErrorAction" + "WarningAction" + "InformationAction" + "ProgressAction" + "ErrorVariable" + "WarningVariable" + "InformationVariable" + "OutVariable" + "OutBuffer" + "PipelineVariable" + "WhatIf" + "Confirm" ) ) diff --git a/tests/Unit/Invoke-FabricAPIRequest.Tests.ps1 b/tests/Unit/Invoke-FabricAPIRequest.Tests.ps1 deleted file mode 100644 index 96baaede..00000000 --- a/tests/Unit/Invoke-FabricAPIRequest.Tests.ps1 +++ /dev/null @@ -1,52 +0,0 @@ -#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param( - $ModuleName = "FabricTools", - $expectedParams = @( - "authToken" - "uri" - "method" - "body" - "contentType" - "timeoutSec" - "retryCount" - "Verbose" - "Debug" - "ErrorAction" - "WarningAction" - "InformationAction" - "ProgressAction" - "ErrorVariable" - "WarningVariable" - "InformationVariable" - "OutVariable" - "OutBuffer" - "PipelineVariable" - - ) -) - -Describe "Invoke-FabricAPIRequest" -Tag "UnitTests" { - - BeforeDiscovery { - $command = Get-Command -Name Invoke-FabricAPIRequest - $expected = $expectedParams - } - - Context "Parameter validation" { - BeforeAll { - $command = Get-Command -Name Invoke-FabricAPIRequest - $expected = $expectedParams - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters $($expected.Count)" { - $hasparms = $command.Parameters.Values.Name - #$hasparms.Count | Should -BeExactly $expected.Count - Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty - } - } -} - diff --git a/tests/Unit/Confirm-FabricAuthToken.Tests.ps1 b/tests/Unit/Invoke-FabricRestMethod.Tests.ps1 similarity index 58% rename from tests/Unit/Confirm-FabricAuthToken.Tests.ps1 rename to tests/Unit/Invoke-FabricRestMethod.Tests.ps1 index ac94caf3..eb7b6082 100644 --- a/tests/Unit/Confirm-FabricAuthToken.Tests.ps1 +++ b/tests/Unit/Invoke-FabricRestMethod.Tests.ps1 @@ -2,32 +2,36 @@ param( $ModuleName = "FabricTools", $expectedParams = @( + "Uri" + "Method" + "Body" + "TestTokenExpired" + "PowerBIApi" "Verbose" - "Debug" - "ErrorAction" - "WarningAction" - "InformationAction" - "ProgressAction" - "ErrorVariable" - "WarningVariable" - "InformationVariable" - "OutVariable" - "OutBuffer" - "PipelineVariable" - + "Debug" + "ErrorAction" + "WarningAction" + "InformationAction" + "ProgressAction" + "ErrorVariable" + "WarningVariable" + "InformationVariable" + "OutVariable" + "OutBuffer" + "PipelineVariable" ) ) -Describe "Confirm-FabricAuthToken" -Tag "UnitTests" { +Describe "Invoke-FabricRestMethod" -Tag "UnitTests" { BeforeDiscovery { - $command = Get-Command -Name Confirm-FabricAuthToken + $command = Get-Command -Name Invoke-FabricRestMethod $expected = $expectedParams } Context "Parameter validation" { BeforeAll { - $command = Get-Command -Name Confirm-FabricAuthToken + $command = Get-Command -Name Invoke-FabricRestMethod $expected = $expectedParams } @@ -42,4 +46,3 @@ Describe "Confirm-FabricAuthToken" -Tag "UnitTests" { } } } - diff --git a/tests/Unit/Set-FabricApiHeaders.Tests.ps1 b/tests/Unit/Invoke-FabricRestMethodExtended.Tests.ps1 similarity index 79% rename from tests/Unit/Set-FabricApiHeaders.Tests.ps1 rename to tests/Unit/Invoke-FabricRestMethodExtended.Tests.ps1 index 310ecbc8..63e8d754 100644 --- a/tests/Unit/Set-FabricApiHeaders.Tests.ps1 +++ b/tests/Unit/Invoke-FabricRestMethodExtended.Tests.ps1 @@ -2,9 +2,10 @@ param( $ModuleName = "FabricTools", $expectedParams = @( - "TenantId" - "AppId" - "AppSecret" + "Uri" + "Method" + "Body" + "RetryCount" "Verbose" "Debug" "ErrorAction" @@ -17,21 +18,19 @@ param( "OutVariable" "OutBuffer" "PipelineVariable" - "WhatIf" - "Confirm" ) ) -Describe "Set-FabricApiHeaders" -Tag "UnitTests" { +Describe "Invoke-FabricRestMethodExtended" -Tag "UnitTests" { BeforeDiscovery { - $command = Get-Command -Name Set-FabricApiHeaders + $command = Get-Command -Name Invoke-FabricRestMethodExtended $expected = $expectedParams } Context "Parameter validation" { BeforeAll { - $command = Get-Command -Name Set-FabricApiHeaders + $command = Get-Command -Name Invoke-FabricRestMethodExtended $expected = $expectedParams } diff --git a/tests/Unit/Set-FabricAuthToken.Tests.ps1 b/tests/Unit/Set-FabricAuthToken.Tests.ps1 deleted file mode 100644 index f185f65a..00000000 --- a/tests/Unit/Set-FabricAuthToken.Tests.ps1 +++ /dev/null @@ -1,53 +0,0 @@ -#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param( - $ModuleName = "FabricTools", - $expectedParams = @( - "servicePrincipalId" - "servicePrincipalSecret" - "credential" - "tenantId" - "reset" - "apiUrl" - "Verbose" - "Debug" - "ErrorAction" - "WarningAction" - "InformationAction" - "ProgressAction" - "ErrorVariable" - "WarningVariable" - "InformationVariable" - "OutVariable" - "OutBuffer" - "PipelineVariable" - "WhatIf" - "Confirm" - - ) -) - -Describe "Set-FabricAuthToken" -Tag "UnitTests" { - - BeforeDiscovery { - $command = Get-Command -Name Set-FabricAuthToken - $expected = $expectedParams - } - - Context "Parameter validation" { - BeforeAll { - $command = Get-Command -Name Set-FabricAuthToken - $expected = $expectedParams - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters $($expected.Count)" { - $hasparms = $command.Parameters.Values.Name - #$hasparms.Count | Should -BeExactly $expected.Count - Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty - } - } -} -