Skip to content
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Version of `Microsoft.PowerShell.PSResourceGet` and `Microsoft.PowerShell.PlatyPS` updated
- Replace the repo's configuration approach with PSFramework (move config handling to PSFramework) #85
- Applied `Invoke-FabricRestMethod` to several public cmdlets #85

### Fixed

Expand Down
8 changes: 4 additions & 4 deletions RequiredModules.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
#}
Assert = "0.9.6"
InvokeBuild = 'latest'
PSScriptAnalyzer = '1.19.1'
PSScriptAnalyzer = '1.24.0'
Pester = 'latest'
ModuleBuilder = 'latest'
ChangelogManagement = 'latest'
Sampler = 'latest'
'Sampler.GitHubTasks' = 'latest'
MarkdownLinkCheck = 'latest'
PSFramework = 'latest'
'Az.Accounts' = '5.0.0'
'Az.Resources' = '6.15.1'
'PSFramework' = 'latest'
'Az.Accounts' = '5.3.0'
'Az.Resources' = '8.1.1'
'MicrosoftPowerBIMgmt' = '1.2.1111'
'Microsoft.PowerShell.PlatyPS' = 'latest'
}
2 changes: 1 addition & 1 deletion build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Pester:
# - FunctionalQuality
# - TestQuality
Tag:
CodeCoverageThreshold: 0.30 # 85 # Set to 0 to bypass
CodeCoverageThreshold: 0.10 # 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.
Expand Down
5 changes: 2 additions & 3 deletions docs/en-US/FabricTools.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Retrieves the workloads for a specific capacity.

### [Get-FabricConfig](Get-FabricConfig.md)

Gets the configuration for use with all functions in the PSFabricTools module.
Gets the configuration for use with all functions in the FabricTools module.

### [Get-FabricConnection](Get-FabricConnection.md)

Expand Down Expand Up @@ -686,7 +686,7 @@ Retrieves External Data Shares details from a specified Microsoft Fabric.

### [Set-FabricConfig](Set-FabricConfig.md)

Register the configuration for use with all functions in the PSFabricTools module.
Register the configuration for use with all functions in the FabricTools module.

### [Start-FabricDeploymentPipelineStage](Start-FabricDeploymentPipelineStage.md)

Expand Down Expand Up @@ -875,4 +875,3 @@ Updates the role assignment for a specific principal in a Fabric workspace.
### [Write-FabricLakehouseTableData](Write-FabricLakehouseTableData.md)

Loads data into a specified table in a Lakehouse within a Fabric workspace.

9 changes: 4 additions & 5 deletions docs/en-US/Get-FabricConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ title: Get-FabricConfig

## SYNOPSIS

Gets the configuration for use with all functions in the PSFabricTools module.
Gets the configuration for use with all functions in the FabricTools module.

## SYNTAX

Expand All @@ -27,21 +27,21 @@ Get-FabricConfig [[-ConfigName] <string>]

## DESCRIPTION

Gets the configuration for use with all functions in the PSFabricTools module.
Gets the configuration for use with all functions in the FabricTools module.

## EXAMPLES

### EXAMPLE 1

Gets all configuration values for the PSFabricTools module and outputs them.
Gets all configuration values for the FabricTools module and outputs them.

```powershell
Get-FabricConfig
```

### EXAMPLE 2

Gets the BaseUrl configuration value for the PSFabricTools module.
Gets the BaseUrl configuration value for the FabricTools module.

```powershell
Get-FabricConfig -ConfigName BaseUrl
Expand Down Expand Up @@ -81,4 +81,3 @@ Author: Jess Pomfret
## RELATED LINKS

{{ Fill in the related links here }}

9 changes: 4 additions & 5 deletions docs/en-US/Set-FabricConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ title: Set-FabricConfig

## SYNOPSIS

Register the configuration for use with all functions in the PSFabricTools module.
Register the configuration for use with all functions in the FabricTools module.

## SYNTAX

Expand All @@ -28,21 +28,21 @@ Set-FabricConfig [[-WorkspaceGUID] <guid>] [[-DataWarehouseGUID] <guid>] [[-Base

## DESCRIPTION

Register the configuration for use with all functions in the PSFabricTools module.
Register the configuration for use with all functions in the FabricTools module.

## EXAMPLES

### EXAMPLE 1

Registers the specified Fabric Data Warehouse configuration for use with all functions in the PSFabricTools module.
Registers the specified Fabric Data Warehouse configuration for use with all functions in the FabricTools module.

```powershell
Set-FabricConfig -WorkspaceGUID 'GUID-GUID-GUID-GUID' -DataWarehouseGUID 'GUID-GUID-GUID-GUID'
```

### EXAMPLE 2

Registers the specified Fabric Data Warehouse configuration for use with all functions in the PSFabricTools module, but does not persist the values.
Registers the specified Fabric Data Warehouse configuration for use with all functions in the FabricTools module, but does not persist the values.

```powershell
Set-FabricConfig -WorkspaceGUID 'GUID-GUID-GUID-GUID' -DataWarehouseGUID 'GUID-GUID-GUID-GUID' -SkipPersist
Expand Down Expand Up @@ -196,4 +196,3 @@ Author: Jess Pomfret
## RELATED LINKS

{{ Fill in the related links here }}

20 changes: 13 additions & 7 deletions source/Private/Confirm-TokenState.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,32 @@ function Confirm-TokenState {
[CmdletBinding()]
param ()

# Refresh the global FabricConfig variable to be backwards compatible
$script:FabricConfig = Get-PSFConfigValue 'FabricTools.FabricApi.BaseApiUrl'

Write-Message -Message "Validating token..." -Level Verbose

try {
# Ensure required properties have valid values
if ([string]::IsNullOrWhiteSpace($FabricConfig.TenantId) -or
[string]::IsNullOrWhiteSpace($FabricConfig.TokenExpiresOn)) {
$tenantId = Get-PSFConfigValue FabricTools.FabricApi.TenantId
$tokenExpiresOn = Get-PSFConfigValue FabricTools.FabricSession.TokenExpiresOn

if ([string]::IsNullOrWhiteSpace($tenantId) -or
[string]::IsNullOrWhiteSpace($tokenExpiresOn)) {
Write-Message -Message "Token details are missing. Please run 'Connect-FabricAccount' to configure the session." -Level Error
throw "MissingTokenDetailsException: Token details are missing."
}

# Convert the TokenExpiresOn value to a DateTime object
if ($FabricConfig.TokenExpiresOn.GetType() -eq [datetimeoffset]) {
$tokenExpiryDate = $FabricConfig.TokenExpiresOn
if ($tokenExpiresOn.GetType() -eq [DateTimeOffset]) {
$tokenExpiryDate = $tokenExpiresOn
} else {
$tokenExpiryDate = [datetimeoffset]::Parse($FabricConfig.TokenExpiresOn)
$tokenExpiryDate = [DateTimeOffset]::Parse($tokenExpiresOn)
}

# Check if the token is expired
if ($tokenExpiryDate -le [datetimeoffset]::Now) {
if ($FabricConfig.FeatureFlags.EnableTokenRefresh) {
if ($tokenExpiryDate -le [DateTimeOffset]::Now) {
if (Get-PSFConfigValue -FullName 'FabricTools.FeatureFlags.EnableTokenRefresh') {
Write-Message -Message "Token has expired. Attempting to refresh the token..." -Level Warning
Connect-FabricAccount -reset
} else {
Expand Down
44 changes: 18 additions & 26 deletions source/Private/Set-FabConfig.ps1
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
# this is a workaround to get the variables set for now
# TODO: change to use PSFConfig?
Set-PSFConfig -Name 'FabricTools.FabricApi.BaseApiUrl' -Value 'https://api.fabric.microsoft.com/v1'
Set-PSFConfig -Name 'FabricTools.FabricApi.ResourceUrl' -Value 'https://api.fabric.microsoft.com'
Set-PSFConfig -Name 'FabricTools.FabricApi.TenantId'
Set-PSFConfig -Name 'FabricTools.FabricApi.ContentType' -Value 'application/json; charset=utf-8'

$script:FabricSession = [ordered]@{
BaseApiUrl = 'https://api.fabric.microsoft.com/v1'
ResourceUrl = 'https://api.fabric.microsoft.com'
HeaderParams = $null
ContentType = @{'Content-Type' = "application/json" }
KustoURL = "https://api.kusto.windows.net"
AccessToken = $null
}
Set-PSFConfig -Name 'FabricTools.FabricSession.Headers' -Value @{}
Set-PSFConfig -Name 'FabricTools.FabricSession.TokenExpiresOn' -Value $null
Set-PSFConfig -Name 'FabricTools.FabricSession.AccessToken' -Value $null

$script:AzureSession = [ordered]@{
BaseApiUrl = "https://management.azure.com"
AccessToken = $null
HeaderParams = $null
}
Set-PSFConfig -Name 'FabricTools.KustoApi.BaseUrl' -Value 'https://api.kusto.windows.net'
Set-PSFConfig -Name 'FabricTools.AzureApi.BaseUrl' -Value "https://management.azure.com"

$script:PowerBI = [ordered]@{
BaseApiUrl = "https://api.powerbi.com/v1.0/myorg"
}
Set-PSFConfig -Name 'FabricTools.AzureSession.AccessToken' -Value $null
Set-PSFConfig -Name 'FabricTools.AzureSession.Headers' -Value @{}

$FabricConfig = @{
Set-PSFConfig -Name 'FabricTools.PowerBiApi.BaseUrl' -Value "https://api.powerbi.com/v1.0/myorg"

# Remain backwards compatible with scripts relying on $FabricConfig variable
$script:FabricConfig = @{
BaseUrl = "https://api.fabric.microsoft.com/v1"
ResourceUrl = "https://api.fabric.microsoft.com"
FabricHeaders = @{}
TenantId = ""
TokenExpiresOn = ""
FeatureFlags = @{
EnableTokenRefresh = $true
}
}

# Feature Flags
Set-PSFConfig -Name 'FabricTools.FeatureFlags.EnableTokenRefresh' -Value $true -Validation bool
3 changes: 2 additions & 1 deletion source/Public/Capacity/Get-FabricCapacityRefreshables.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ Author: Ioana Bouariu

# 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
$result = Invoke-FabricRestMethod -Method GET -PowerBIApi -Uri "capacities/refreshables?`$top=$top"
$result.value
}
7 changes: 5 additions & 2 deletions source/Public/Capacity/Get-FabricCapacitySkus.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ Author: Kamil Nowinski

Confirm-TokenState

$AzureBaseApiUrl = Get-PSFConfigValue 'FabricTools.AzureApi.BaseUrl'
$AzureSessionHeaderParams = Get-PSFConfigValue 'FabricTools.AzureSession.Headers'

#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"
$result = Invoke-RestMethod -Headers $AzureSession.HeaderParams -Uri $uri -Method GET
$uri = "$AzureBaseApiUrl/subscriptions/$subscriptionID/resourceGroups/$ResourceGroupName/providers/Microsoft.Fabric/capacities/$capacity/skus?api-version=2023-11-01"
$result = Invoke-RestMethod -Headers $AzureSessionHeaderParams -Uri $uri -Method GET

return $result.value

Expand Down
4 changes: 3 additions & 1 deletion source/Public/Capacity/Get-FabricCapacityState.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ Author: Ioana Bouariu

Confirm-TokenState

$AzureBaseApiUrl = Get-PSFConfigValue 'FabricTools.AzureApi.BaseUrl'

# 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"
$getCapacityState = "$AzureBaseApiUrl/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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ Author: Ioana Bouariu

# 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
return Invoke-FabricRestMethod -uri "admin/capacities/delegatedTenantSettingOverrides" -Method GET
}
3 changes: 2 additions & 1 deletion source/Public/Capacity/Get-FabricCapacityWorkload.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Author: Ioana Bouariu

# 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.
return (Invoke-RestMethod -uri "$($PowerBI.BaseApiUrl)/capacities/$capacityID/Workloads" -Headers $FabricSession.HeaderParams -Method GET).value
$result = Invoke-FabricRestMethod -Method GET -PowerBIApi -Uri "capacities/$capacityID/Workloads"
$result.value
}


Expand Down
18 changes: 10 additions & 8 deletions source/Public/Capacity/Resume-FabricCapacity.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ function Resume-FabricCapacity {
.DESCRIPTION
The Resume-FabricCapacity function resumes a capacity. It supports multiple aliases for flexibility.

.PARAMETER subscriptionID
.PARAMETER SubscriptionID
The the ID of the subscription. This is a mandatory parameter. This is a parameter found in Azure, not Fabric.

.PARAMETER resourcegroup
.PARAMETER ResourceGroup
The resource group. This is a mandatory parameter. This is a parameter found in Azure, not Fabric.

.PARAMETER capacity
Expand All @@ -19,7 +19,7 @@ function Resume-FabricCapacity {
This example resumes a capacity given the subscription ID, resource group, and capacity.

```powershell
Resume-FabricCapacity -subscriptionID "your-subscription-id" -resourcegroupID "your-resource-group" -capacityID "your-capacity"
Resume-FabricCapacity -subscriptionID "your-subscription-id" -ResourceGroup "your-resource-group" -capacityID "your-capacity"
```

.NOTES
Expand All @@ -34,20 +34,22 @@ function Resume-FabricCapacity {
# Define parameters for the subscription ID, resource group, and capacity.
Param (
[Parameter(Mandatory = $true)]
[guid]$subscriptionID,
[guid]$SubscriptionID,
[Parameter(Mandatory = $true)]
[string]$resourcegroup,
[string]$ResourceGroup,
[Parameter(Mandatory = $true)]
[string]$capacity
[string]$Capacity
)

Confirm-TokenState

$AzureBaseApiUrl = Get-PSFConfigValue 'FabricTools.AzureApi.BaseUrl'

# 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"
$resumeCapacity = "$AzureBaseApiUrl/subscriptions/$SubscriptionID/resourceGroups/$ResourceGroup/providers/Microsoft.Fabric/capacities/$Capacity/resume?api-version=2022-07-01-preview"

# Make a GET request to the URI and return the response.
if ($PSCmdlet.ShouldProcess("Resume capacity $capacity")) {
if ($PSCmdlet.ShouldProcess("Resume capacity $Capacity")) {
return Invoke-RestMethod -Method POST -Uri $resumeCapacity -Headers $script:AzureSession.HeaderParams -ErrorAction Stop
}
}
18 changes: 10 additions & 8 deletions source/Public/Capacity/Suspend-FabricCapacity.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ Suspends a capacity.
.DESCRIPTION
The Suspend-FabricCapacity function suspends a capacity. It supports multiple aliases for flexibility.

.PARAMETER subscriptionID
.PARAMETER SubscriptionID
The ID of the subscription. This is a mandatory parameter. This is a parameter found in Azure, not Fabric.

.PARAMETER resourcegroup
.PARAMETER ResourceGroup
The resource group. This is a mandatory parameter. This is a parameter found in Azure, not Fabric.

.PARAMETER capacity
.PARAMETER Capacity
The the capacity. This is a mandatory parameter. This is a parameter found in Azure, not Fabric.

.EXAMPLE
This example suspends a capacity given the subscription ID, resource group, and capacity.

```powershell
Suspend-FabricCapacity -subscriptionID "your-subscription-id" -resourcegroupID "your-resource-group" -capacityID "your-capacity"
Suspend-FabricCapacity -SubscriptionID "your-subscription-id" -ResourceGroup "your-resource-group" -Capacity "your-capacity"
```

.NOTES
Expand All @@ -35,17 +35,19 @@ Author: Ioana Bouariu
# Define parameters for the subscription ID, resource group, and capacity.
Param (
[Parameter(Mandatory = $true)]
[guid]$subscriptionID,
[guid]$SubscriptionID,
[Parameter(Mandatory = $true)]
[string]$resourcegroup,
[string]$ResourceGroup,
[Parameter(Mandatory = $true)]
[string]$capacity
[string]$Capacity
)

Confirm-TokenState

$AzureBaseApiUrl = Get-PSFConfigValue 'FabricTools.AzureApi.BaseUrl'

# Define the URI for the request.
$suspendCapacity = "$($AzureSession.BaseApiUrl)/subscriptions/$subscriptionID/resourceGroups/$resourcegroup/providers/Microsoft.Fabric/capacities/$capacity/suspend?api-version=2023-11-01"
$suspendCapacity = "$AzureBaseApiUrl/subscriptions/$SubscriptionID/resourceGroups/$ResourceGroup/providers/Microsoft.Fabric/capacities/$Capacity/suspend?api-version=2023-11-01"

# Make a GET request to the URI and return the response.
if ($PSCmdlet.ShouldProcess("Suspend capacity $capacity")) {
Expand Down
Loading
Loading