Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
eae0e84
Removed debug messages for token validation in various scripts (it al…
NowinskiK May 21, 2025
2625e67
Replaced Invoke-PowerBIRestMethod & Invoke-RestMethod by Invoke-Fabri…
NowinskiK May 23, 2025
733b618
Merge branch 'develop' into unification-api-and-tokens
SQLDBAWithABeard May 23, 2025
6b3ce09
Merge branch 'develop' into unification-api-and-tokens
NowinskiK Jun 2, 2025
2475089
Fix: Renamed BaseURI to Uri for all calls of Invoke-FabricRestMethod #44
NowinskiK Jun 2, 2025
ddf939d
Resolved 3 warnings from ScriptAnalyzer
NowinskiK Jun 2, 2025
2384165
Merge branch 'develop' into unification-api-and-tokens
NowinskiK Jun 2, 2025
12c7b64
Added unit test for Invoke-FabricRestMethod #44
NowinskiK Jun 2, 2025
f480462
$Body parameter also should be used, right?
NowinskiK Jun 2, 2025
f202c2d
Removed `Invoke-FabricAPIRequest` and replaced it by `Invoke-FabricRe…
NowinskiK Jun 2, 2025
6355342
changelog
NowinskiK Jun 2, 2025
391e2a0
Removed FabricToken from global FabricSession variable and Token from…
NowinskiK Jun 2, 2025
1a773c8
Added Update-FabricToken function
NowinskiK Jun 2, 2025
a9cf935
Removed Set-FabricAuthToken and replaced it with Connect-FabricAccount
NowinskiK Jun 2, 2025
0d9636c
Get-FabricAuthToken returns token only
NowinskiK Jun 2, 2025
c95dd7d
Renamed TenantIdGlobal to TenantId
NowinskiK Jun 2, 2025
3c52780
- Removed `Confirm-FabricAuthToken` and extended existing `Test-Token…
NowinskiK Jun 2, 2025
9b64035
Fixed warnings from ScriptAnalyzer for Invoke-FabricRestMethodExtended
NowinskiK Jun 2, 2025
c3f5b83
Fixed UnitTest for Connect-FabricAccount
NowinskiK Jun 2, 2025
62d273d
Refactor Update-FabricToken to support ShouldProcess and add missing …
NowinskiK Jun 2, 2025
09a3c31
CodeCoverageThreshold = 0.30 for now
NowinskiK Jun 2, 2025
8821041
Avoid duplicated execution of Test-TokenExpired as it's executed on p…
NowinskiK Jun 3, 2025
4f6edf7
Update Az.Accounts module version to avoid errors
SQLDBAWithABeard Jun 3, 2025
dc77cad
Clarify commit message instructions for Pester tests
SQLDBAWithABeard Jun 3, 2025
e41c361
Add "TestTokenExpired" to expected parameters
SQLDBAWithABeard Jun 3, 2025
13942b5
because 2019 on the runner is deprecated
SQLDBAWithABeard Jun 3, 2025
730a952
Update CONTRIBUTING.md for clearer development guidelines
SQLDBAWithABeard Jun 3, 2025
d86d542
Body parameter - This can be a hashtable or a string. If a hashtable …
NowinskiK Jun 3, 2025
cd5f3c9
Merge branch 'unification-api-and-tokens' of https://github.com/datap…
NowinskiK Jun 3, 2025
3870c54
Added Credits
NowinskiK Jun 3, 2025
5e17dcc
Fixed links to fabricps-pbip
NowinskiK Jun 3, 2025
01e51dd
Set CmdletBinding ConfirmImpact to 'High' for safety
jpomfret Jun 4, 2025
a9e0118
adding Balabuch to the cSpell allowed words
jpomfret Jun 4, 2025
dab6ccf
Set CmdletBinding ConfirmImpact to 'High' for safety
jpomfret Jun 4, 2025
bfc9334
spacing and white space changes
jpomfret Jun 4, 2025
ce32738
Remove unnecessary code (write-Message)
NowinskiK Jun 5, 2025
afedb29
Merge branch 'unification-api-and-tokens' of https://github.com/datap…
NowinskiK Jun 5, 2025
3e68e5c
Update source/Public/Invoke-FabricRestMethod.ps1
NowinskiK Jun 5, 2025
8bfa71f
Update source/FabricTools.psd1
NowinskiK Jun 5, 2025
4f0a996
use `$FabricConfig.BaseUrl` to avoid a hard-coded base URL.
NowinskiK Jun 6, 2025
26b8d96
Fixed comments
NowinskiK Jun 6, 2025
1106839
More elegant way to decode token to plain text needed for request's h…
NowinskiK Jun 6, 2025
8e23ccd
Fixed auto-refresh token feature being used in Test-TokenExpired
NowinskiK Jun 6, 2025
9f4f1e9
Invoke-FabricRestMethod can execute PowerBI API when needed
NowinskiK Jun 6, 2025
103935d
Get-FabricDatasetRefreshes must use PowerBI API
NowinskiK Jun 6, 2025
96f67ef
Fixed test for Invoke-FabricRestMethod (new param)
NowinskiK Jun 6, 2025
3084bd8
Renamed Test-TokenExpired -> Confirm-TokenState and deleted Update-To…
NowinskiK Jun 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/copilot-commit-message-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
11 changes: 6 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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]": {
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 7 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```


Expand All @@ -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.

Expand All @@ -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.
6 changes: 3 additions & 3 deletions RequiredModules.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
3 changes: 1 addition & 2 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -157,4 +157,3 @@ ChangelogConfig:
GitConfig:
UserName: Automation Bot
UserEmail: [email protected]

27 changes: 20 additions & 7 deletions helper/GetFunctionList.ps1
Original file line number Diff line number Diff line change
@@ -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}
10 changes: 4 additions & 6 deletions source/FabricTools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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' }
)
Expand Down Expand Up @@ -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 = ''

}

Original file line number Diff line number Diff line change
Expand Up @@ -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."
}

Expand All @@ -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."
Expand All @@ -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
}
13 changes: 4 additions & 9 deletions source/Private/Set-FabConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -14,24 +13,20 @@ $script:FabricSession = [ordered]@{
$script:AzureSession = [ordered]@{
BaseApiUrl = "https://management.azure.com"
AccessToken = $null
Token = $null
HeaderParams = $null
}

$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
}
}
3 changes: 1 addition & 2 deletions source/Public/Capacity/Get-FabricCapacities.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -72,4 +72,3 @@ function Get-FabricCapacities {
# Return the results
return $res
}

8 changes: 3 additions & 5 deletions source/Public/Capacity/Get-FabricCapacity.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
#>
Expand All @@ -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"
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions source/Public/Capacity/Get-FabricCapacityRefreshables.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Loading
Loading