Skip to content

Commit 491e4c6

Browse files
committed
Unified global variables & usage of Confirm-FabricAuthToken everywhere
1 parent f9420a1 commit 491e4c6

File tree

55 files changed

+141
-201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+141
-201
lines changed

FabricTools/FabricTools.psm1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
#>
2424

2525
$script:FabricSession = [ordered]@{
26-
BaseFabricUrl = 'https://api.fabric.microsoft.com'
27-
ApiUrl = 'https://api.fabric.microsoft.com/v1'
26+
BaseApiUrl = 'https://api.fabric.microsoft.com/v1'
2827
FabricToken = $null
2928
HeaderParams = $null
3029
ContentType = @{'Content-Type' = "application/json"}
@@ -33,12 +32,16 @@ $script:FabricSession = [ordered]@{
3332
}
3433

3534
$script:AzureSession = [ordered]@{
36-
BaseUrl = "https://management.azure.com"
35+
BaseApiUrl = "https://management.azure.com"
3736
AccessToken = $null
3837
Token = $null
3938
HeaderParams = $null
4039
}
4140

41+
$script:PowerBI = [ordered]@{
42+
BaseApiUrl = "https://api.powerbi.com/v1.0/myorg"
43+
}
44+
4245
# Get all .ps1 files in the (public) Functions folder
4346
$functions = Get-ChildItem -Path "$PSScriptRoot\public" -Filter *.ps1
4447

FabricTools/public/Add-FabricWorkspaceRoleAssignment.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ begin {
7171
-Depth 1
7272

7373
# Create Workspace API URL
74-
$workspaceApiUrl = "$($FabricSession.BaseFabricUrl)/v1/admin/workspaces/$WorkspaceId/roleassignments"
74+
$workspaceApiUrl = "$($FabricSession.BaseApiUrl)/admin/workspaces/$WorkspaceId/roleassignments"
7575
}
7676

7777
process {

FabricTools/public/Confirm-FabricAuthToken.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function Confirm-FabricAuthToken {
2424
[CmdletBinding()]
2525
param ( )
2626

27+
Write-Verbose "Check if session is established and token not expired."
28+
2729
# Check if the Fabric token is already set
2830
if (!$FabricSession.FabricToken -or !$AzureSession.AccessToken) {
2931
Write-Output "Confirm-FabricAuthToken::Set-FabricAuthToken"
@@ -32,7 +34,7 @@ function Confirm-FabricAuthToken {
3234

3335
$now = (Get-Date)
3436
$s = Get-FabricDebugInfo
35-
if ($s.FabricSession.AccessToken.ExpiresOn -lt $now ) {
37+
if ($FabricSession.AccessToken.ExpiresOn -lt $now ) {
3638
Write-Output "Confirm-FabricAuthToken::Set-FabricAuthToken#1"
3739
Set-FabricAuthToken -reset | Out-Null
3840
}

FabricTools/public/Connect-FabricAccount.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ begin {
3939

4040
process {
4141
Write-Verbose "Connect to Azure Account"
42-
Connect-AzAccount `
43-
-TenantId $TenantId | `
44-
Out-Null
42+
Connect-AzAccount -TenantId $TenantId | Out-Null
4543

4644
Write-Verbose "Get authentication token"
47-
$FabricSession.FabricToken = (Get-AzAccessToken -ResourceUrl $FabricSession.BaseFabricUrl).Token
45+
$FabricSession.FabricToken = (Get-AzAccessToken -ResourceUrl $FabricSession.BaseApiUrl).Token
4846
Write-Verbose "Token: $($FabricSession.FabricToken)"
4947

5048
Write-Verbose "Setup headers for API calls"

FabricTools/public/Get-AllFabricDatasetRefreshes.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ function Get-AllFabricDatasetRefreshes {
1919
# Define aliases for the function for flexibility.
2020
[Alias("Get-AllFabDatasetRefreshes")]
2121

22+
Confirm-FabricAuthToken | Out-Null
23+
2224
# Retrieve all PowerBI workspaces.
2325
$wsps = Get-FabricWorkspace
2426
# Initialize an array to store the refreshes.

FabricTools/public/Get-FabricAPIClusterURI.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ function Get-FabricAPIclusterURI {
2424
Param (
2525
)
2626

27-
$s = Confirm-FabricAuthToken
27+
Confirm-FabricAuthToken | Out-Null
2828

2929
# Make a GET request to the PowerBI API to retrieve the datasets.
30-
$reply = Invoke-RestMethod -uri "https://api.powerbi.com/v1.0/myorg/datasets" -Headers $s.FabricSession.HeaderParams -Method GET
30+
$reply = Invoke-RestMethod -uri "$($PowerBI.BaseApiUrl)/datasets" -Headers $FabricSession.HeaderParams -Method GET
3131

3232
# Extract the '@odata.context' property from the response.
3333
$unaltered = $reply.'@odata.context'

FabricTools/public/Get-FabricCapacityRefreshables.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ function Get-FabricCapacityRefreshables {
2828
[string]$top = 5
2929
)
3030

31-
$s = Confirm-FabricAuthToken
31+
Confirm-FabricAuthToken | Out-Null
3232

3333
# Make a GET request to the PowerBI API to retrieve the top refreshable capacities.
3434
# The function returns the 'value' property of the response.
35-
return (Invoke-RestMethod -uri "https://api.powerbi.com/v1.0/myorg/capacities/refreshables?`$top=$top" -Headers $s.FabricSession.HeaderParams -Method GET).value
35+
return (Invoke-RestMethod -uri "$($PowerBI.BaseApiUrl)/capacities/refreshables?`$top=$top" -Headers $FabricSession.HeaderParams -Method GET).value
3636
}

FabricTools/public/Get-FabricCapacitySkus.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function Get-FabricCapacitySkus {
2929
Confirm-FabricAuthToken | Out-Null
3030

3131
#GET https://management.azure.com/subscriptions/548B7FB7-3B2A-4F46-BB02-66473F1FC22C/resourceGroups/TestRG/providers/Microsoft.Fabric/capacities/azsdktest/skus?api-version=2023-11-01
32-
$uri = "$($AzureSession.BaseUrl)/subscriptions/$subscriptionID/resourceGroups/$ResourceGroupName/providers/Microsoft.Fabric/capacities/$capacity/skus?api-version=2023-11-01"
32+
$uri = "$($AzureSession.BaseApiUrl)/subscriptions/$subscriptionID/resourceGroups/$ResourceGroupName/providers/Microsoft.Fabric/capacities/$capacity/skus?api-version=2023-11-01"
3333
$result = Invoke-RestMethod -Headers $AzureSession.HeaderParams -Uri $uri -Method GET
3434

3535
return $result.value

FabricTools/public/Get-FabricCapacityState.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function Get-FabricCapacityState {
4141
Confirm-FabricAuthToken | Out-Null
4242

4343
# Define the URL for the GET request.
44-
$getCapacityState = "$($AzureSession.BaseUrl)/subscriptions/$subscriptionID/resourceGroups/$resourcegroup/providers/Microsoft.Fabric/capacities/$capacity/?api-version=2022-07-01-preview"
44+
$getCapacityState = "$($AzureSession.BaseApiUrl)/subscriptions/$subscriptionID/resourceGroups/$resourcegroup/providers/Microsoft.Fabric/capacities/$capacity/?api-version=2022-07-01-preview"
4545

4646
# Make the GET request and return the response.
4747
return Invoke-RestMethod -Method GET -Uri $getCapacityState -Headers $script:AzureSession.HeaderParams -ErrorAction Stop

FabricTools/public/Get-FabricCapacityTenantOverrides.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ function Get-FabricCapacityTenantOverrides {
2525
Param (
2626
)
2727

28-
$s = Confirm-FabricAuthToken
28+
Confirm-FabricAuthToken | Out-Null
2929

3030
# Make a GET request to the Fabric API to retrieve the tenant overrides for all capacities.
3131
# The function returns the response of the GET request.
32-
return Invoke-RestMethod -uri "$($FabricSession.ApiUrl)/admin/capacities/delegatedTenantSettingOverrides" -Headers $s.FabricSession.HeaderParams -Method GET
32+
return Invoke-RestMethod -uri "$($FabricSession.BaseApiUrl)/admin/capacities/delegatedTenantSettingOverrides" -Headers $FabricSession.HeaderParams -Method GET
3333
}

0 commit comments

Comments
 (0)