Skip to content

Commit 0c93cfb

Browse files
authored
Merge pull request #54 from dataplat/unification-api-and-tokens
Unification api and tokens
2 parents c6e9c34 + 3084bd8 commit 0c93cfb

File tree

217 files changed

+1441
-2751
lines changed

Some content is hidden

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

217 files changed

+1441
-2751
lines changed

.github/copilot-commit-message-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ Capitalize the subject/description line
33
Do not end the subject line with a period
44
Separate the subject from the body with a blank line
55
Use the imperative mood in the subject line
6-
The subject line should be a single sentence with an action word and target with some reasoning add "for Pester Help Tests"
6+
The subject line should be a single sentence with an action word and a target with some reasoning for the change
77
Use the body to explain what and why in a friendly kind manner
88
Say thank you at the end of the message

.github/workflows/pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
if: success() || failure()
6868
Test_Stage_test_windows_core:
6969
name: Windows (PowerShell)
70-
runs-on: windows-2019
70+
runs-on: windows-latest
7171
needs:
7272
- Build_Stage_Package_Module
7373
steps:
@@ -94,7 +94,7 @@ jobs:
9494
if: success() || failure()
9595
Test_Stage_test_windows_ps:
9696
name: Windows (Windows PowerShell)
97-
runs-on: windows-2019
97+
runs-on: windows-latest
9898
needs:
9999
- Build_Stage_Package_Module
100100
steps:

.vscode/settings.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@
2020
"*.ps1xml": "xml"
2121
},
2222
"cSpell.words": [
23-
"COMPANYNAME",
24-
"ICONURI",
25-
"LICENSEURI",
26-
"PROJECTURI",
27-
"RELEASENOTES",
23+
"Balabuch",
2824
"buildhelpers",
25+
"COMPANYNAME",
2926
"endregion",
3027
"gitversion",
3128
"icontains",
29+
"ICONURI",
3230
"keepachangelog",
31+
"LICENSEURI",
3332
"notin",
33+
"PROJECTURI",
3434
"pscmdlet",
35+
"RELEASENOTES",
3536
"steppable"
3637
],
3738
"[markdown]": {

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4242

4343
- Removed unnecessary or duplicate functions (e.g., `Get-AllFabricDatasetRefreshes`, `Get-AllFabricCapacities`).
4444
- Removed obsolete scripts and commented-out configuration paths.
45+
- Removed `Invoke-FabricAPIRequest` and replaced it by `Invoke-FabricRestMethodExtended`
46+
- Removed `Confirm-FabricAuthToken`
47+
- Renamed `Test-TokenExpired` to `Confirm-TokenState` and extended it using `EnableTokenRefresh` Feature Flag
48+
- Removed `Set-FabricApiHeaders` and merged the entire logic to `Connect-FabricAccount`
4549

4650
### Security
4751

CONTRIBUTING.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ The workflow for using this and developing the code is shown below.
3232
Install-Module Microsoft.PowerShell.PSResourceGet -Force
3333
```
3434

35-
3. Develop your updates in the source directory
35+
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.
3636

37-
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.
37+
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.
3838

3939
```PowerShell
4040
.\build.ps1 -ResolveDependency -Tasks noop -UsePSResourceGet
@@ -83,7 +83,11 @@ The workflow for using this and developing the code is shown below.
8383
```PowerShell
8484
./build.ps1 -Tasks build,test
8585
```
86-
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.
86+
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.
87+
88+
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.
89+
90+
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.
8791

8892
You can use the [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format for this.
8993

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ Refer to the individual function documentation for detailed usage instructions.
6666

6767
Every now and again the authentication token might time out. Run this to get a new one:
6868
```powershell
69-
Set-FabricAuthToken
69+
Update-FabricToken
7070
```
7171

7272
If you want to change user context run this:
7373
```powershell
74-
Set-FabricAuthToken -reset
74+
Connect-FabricAccount
7575
```
7676

7777

@@ -89,10 +89,14 @@ Contributions to FabricTools are welcome.
8989
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to develop, test and the process for submitting pull requests to us.
9090

9191
## Authors
92+
_(in alphabetical order)_
9293

94+
- **Tiago Balabuch** - *Huge contribution (90% functions)* - [tiagobalabuch](https://github.com/tiagobalabuch)
9395
- **Ioana Bouariu** - *Initial work* - [Jojobit](https://github.com/Jojobit)
9496
- **Frank Geisler** - *Author of RTI functions* - [Frank Geisler](https://github.com/Frank-Geisler)
9597
- **Kamil Nowinski** - *Refactoring, unification, further commands* - [NowinskiK](https://github.com/NowinskiK)
98+
- **Jess Pomfret** - *Automation, great experience with PowerShell* - [jpomfret](https://github.com/jpomfret)
99+
- **Rob Sewell** - *Automation/DevOps, Governance and experience brought from dbatools* - [SQLDBAWithABeard](https://github.com/SQLDBAWithABeard)
96100

97101
See also the list of [contributors](https://github.com/dataplat/FabricTools/contributors) who participated in this project.
98102

@@ -103,4 +107,5 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
103107
## Acknowledgments
104108

105109
- GitHub Copilot and ChatGPT for helping with the documentation
106-
- [**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!
110+
- [**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!
111+
- [**Tiago Balabuch**](https://github.com/tiagobalabuch) and his phenomenal huge work that make this module more robust and very well organised.

RequiredModules.psd1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'Sampler.GitHubTasks' = 'latest'
2222
MarkdownLinkCheck = 'latest'
2323
PSFramework = 'latest'
24-
'Az.Accounts' = '4.2.0'
25-
'Az.Resources' = '6.15.1'
26-
'MicrosoftPowerBIMgmt' = '1.2.1111'
24+
'Az.Accounts' = '5.0.0'
25+
'Az.Resources' = '6.15.1'
26+
'MicrosoftPowerBIMgmt' = '1.2.1111'
2727
}

build.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Pester:
104104
# - FunctionalQuality
105105
# - TestQuality
106106
Tag:
107-
CodeCoverageThreshold: 0.35 # 85 # Set to 0 to bypass
107+
CodeCoverageThreshold: 0.30 # 85 # Set to 0 to bypass
108108
#CodeCoverageOutputFile: JaCoCo_$OsShortName.xml
109109
#CodeCoverageOutputFileEncoding: ascii
110110
# Use this if code coverage should be merged from several pipeline test jobs.
@@ -157,4 +157,3 @@ ChangelogConfig:
157157
GitConfig:
158158
UserName: Automation Bot
159159
UserEmail: automation_bot@fabrictools.io
160-

helper/GetFunctionList.ps1

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
$path = ".\FabricTools\public"
1+
$path = ".\source\public"
22
$op = Get-ChildItem -Path $path -Recurse -Filter *.ps1 | Select-Object -ExpandProperty Name | Sort-Object
33
#$op = $op | ForEach-Object { " ""$_""," }
44
$op | Out-File '.\Output\FunctionList-main-public.txt'
55

6-
$path = ".\FabricTools\tiago\public"
7-
$tp = Get-ChildItem -Path $path -Recurse -Filter *.ps1 | Select-Object -ExpandProperty Name | Sort-Object
8-
$tp | Out-File '.\Output\FunctionList-tiago-public.txt'
6+
# Author Table
7+
# This script generates a table of PowerShell script authors from the specified directory.
8+
$authorTable = @{}
9+
$op | ForEach-Object {
10+
$file = $_.FullName
11+
$name = $_.Name
12+
$content = Get-Content $file
13+
$authorLine = $content | Where-Object { $_ -match 'Author:\s*(.+)' } | Select-Object -First 1
14+
if ($authorLine -match 'Author:\s*(.+)') {
15+
$author = $matches[1].Trim()
16+
$authorTable[$name] = $author
17+
} else {
18+
$authorTable[$name] = $null
19+
}
20+
}
21+
$authorTable
922

10-
$common = Compare-Object -ReferenceObject $op -DifferenceObject $tp -IncludeEqual -ExcludeDifferent | Select-Object -ExpandProperty InputObject
11-
$common
12-
$common | Out-File '.\Output\FunctionList-public-collision.txt'
23+
## Not a singular name option for functions (#26)
24+
Get-Command -Module FabricTools |where Name -like '*s'
25+
Get-Command -Module FabricTools|ForEach-Object { $name = $_.Name; $_.Parameters.Values | Where Name -like '*s' | Select @{N='FunctionName';E={$Name}},Name}

source/FabricTools.psd1

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ ModuleVersion = '0.0.1'
1818
# CompatiblePSEditions = @()
1919

2020
# ID used to uniquely identify this module
21-
GUID = '0ba3e49a-b47e-4beb-8434-5a34ad41ae72'
21+
GUID = 'f2a0f9e6-fab6-41fc-9e1c-0c94ff38f794'
2222

2323
# Author of this module
2424
Author = 'The FabricTools Team'
2525

26-
# Company or vendor of this module
27-
CompanyName = 'fabrictools.io'
26+
CompanyName = 'fabrictools.io'
2827

2928
# Copyright statement for this module
3029
Copyright = 'Copyright (c) 2025 by FabricTools Team'
@@ -56,7 +55,7 @@ PowerShellVersion = '5.1'
5655

5756
# Modules that must be imported into the global environment prior to importing this module
5857
RequiredModules = @(
59-
@{ ModuleName = 'Az.Accounts' ; ModuleVersion = '4.2.0' },
58+
@{ ModuleName = 'Az.Accounts' ; ModuleVersion = '5.0.0' },
6059
@{ ModuleName = 'MicrosoftPowerBIMgmt.Profile' ; ModuleVersion = '1.2.1111' },
6160
@{ ModuleName = 'Az.Resources' ; ModuleVersion = '6.15.1' }
6261
)
@@ -131,10 +130,9 @@ PrivateData = @{
131130
} # End of PrivateData hashtable
132131

133132
# HelpInfo URI of this module
134-
# HelpInfoURI = ''
133+
HelpInfoURI = 'https://www.github.com/dataplat/FabricTools'
135134

136135
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
137136
# DefaultCommandPrefix = ''
138137

139138
}
140-

source/Private/Test-TokenExpired.ps1 renamed to source/Private/Confirm-TokenState.ps1

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,34 @@
33
Checks if the Fabric token is expired and logs appropriate messages.
44
55
.DESCRIPTION
6-
The `Test-TokenExpired` function checks the expiration status of the Fabric token stored in the `$FabricConfig.TokenExpiresOn` variable.
6+
The `Confirm-TokenState` function checks the expiration status of the Fabric token stored in the `$FabricConfig.TokenExpiresOn` variable.
77
If the token is expired, it logs an error message and provides guidance for refreshing the token.
88
Otherwise, it logs that the token is still valid.
99
10-
.PARAMETER FabricConfig
11-
The configuration object containing the token expiration details.
12-
1310
.EXAMPLE
14-
Test-TokenExpired -FabricConfig $config
11+
Confirm-TokenState
1512
16-
Checks the token expiration status using the provided `$config` object.
13+
Checks the token expiration status using session's `$FabricConfig` object.
1714
1815
.NOTES
1916
- Ensure the `FabricConfig` object includes a valid `TokenExpiresOn` property of type `DateTimeOffset`.
2017
- Requires the `Write-Message` function for logging.
18+
- Uses EnableTokenRefresh feature flag to determine if the token should be refreshed automatically.
2119
2220
.AUTHOR
2321
Tiago Balabuch
2422
#>
25-
function Test-TokenExpired {
23+
function Confirm-TokenState {
2624
[CmdletBinding()]
2725
param ()
2826

29-
Confirm-FabricAuthToken | Out-Null
30-
31-
Write-Message -Message "Validating token..." -Level Debug
27+
Write-Message -Message "Validating token..." -Level Verbose
3228

3329
try {
3430
# Ensure required properties have valid values
35-
if ([string]::IsNullOrWhiteSpace($FabricConfig.TenantIdGlobal) -or
31+
if ([string]::IsNullOrWhiteSpace($FabricConfig.TenantId) -or
3632
[string]::IsNullOrWhiteSpace($FabricConfig.TokenExpiresOn)) {
37-
Write-Message -Message "Token details are missing. Please run 'Set-FabricApiHeaders' to configure them." -Level Error
33+
Write-Message -Message "Token details are missing. Please run 'Connect-FabricAccount' to configure the session." -Level Error
3834
throw "MissingTokenDetailsException: Token details are missing."
3935
}
4036

@@ -47,13 +43,18 @@ function Test-TokenExpired {
4743

4844
# Check if the token is expired
4945
if ($tokenExpiryDate -le [datetimeoffset]::Now) {
50-
Write-Message -Message "Your authentication token has expired. Please sign in again to refresh your session." -Level Warning
51-
#throw "TokenExpiredException: Token has expired."
52-
#Set-FabricApiHeaders -tenantId $FabricConfig.TenantIdGlobal
46+
if ($FabricConfig.FeatureFlags.EnableTokenRefresh) {
47+
Write-Message -Message "Token has expired. Attempting to refresh the token..." -Level Warning
48+
Connect-FabricAccount -reset
49+
} else {
50+
Write-Message -Message "Token has expired and automatic refresh is disabled. Please sign in again using 'Connect-FabricAccount'." -Level Error
51+
throw "TokenExpiredException: Token has expired."
52+
}
53+
}
54+
else {
55+
# Log valid token status
56+
Write-Message -Message "Token is still valid. Expiry time: $($tokenExpiryDate.ToString("u"))" -Level Debug
5357
}
54-
55-
# Log valid token status
56-
Write-Message -Message "Token is still valid. Expiry time: $($tokenExpiryDate.ToString("u"))" -Level Debug
5758
} catch [System.FormatException] {
5859
Write-Message -Message "Invalid 'TokenExpiresOn' format in the FabricConfig object. Ensure it is a valid datetime string." -Level Error
5960
throw "FormatException: Invalid TokenExpiresOn value."
@@ -62,5 +63,5 @@ function Test-TokenExpired {
6263
Write-Message -Message "An unexpected error occurred: $_" -Level Error
6364
throw $_
6465
}
65-
Write-Message -Message "Token validation completed." -Level Debug
66+
Write-Message -Message "Token validation completed." -Level Verbose
6667
}

source/Private/Set-FabConfig.ps1

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
$script:FabricSession = [ordered]@{
55
BaseApiUrl = 'https://api.fabric.microsoft.com/v1'
66
ResourceUrl = 'https://api.fabric.microsoft.com'
7-
FabricToken = $null
87
HeaderParams = $null
98
ContentType = @{'Content-Type' = "application/json" }
109
KustoURL = "https://api.kusto.windows.net"
@@ -14,24 +13,20 @@ $script:FabricSession = [ordered]@{
1413
$script:AzureSession = [ordered]@{
1514
BaseApiUrl = "https://management.azure.com"
1615
AccessToken = $null
17-
Token = $null
1816
HeaderParams = $null
1917
}
2018

2119
$script:PowerBI = [ordered]@{
2220
BaseApiUrl = "https://api.powerbi.com/v1.0/myorg"
2321
}
2422

25-
$FabricTools = @{
26-
FeatureFlags = @{
27-
AutoRenewExpiredToken = $true
28-
}
29-
}
30-
3123
$FabricConfig = @{
3224
BaseUrl = "https://api.fabric.microsoft.com/v1"
3325
ResourceUrl = "https://api.fabric.microsoft.com"
3426
FabricHeaders = @{}
35-
TenantIdGlobal = ""
27+
TenantId = ""
3628
TokenExpiresOn = ""
29+
FeatureFlags = @{
30+
EnableTokenRefresh = $true
31+
}
3732
}

source/Public/Capacity/Get-FabricCapacities.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function Get-FabricCapacities {
3434
# Initialize an array to store the results
3535
$res = @()
3636

37-
Get-FabricAuthToken | Out-Null
37+
Confirm-TokenState
3838

3939
# If a subscription ID is provided
4040
if ($subscriptionID) {
@@ -72,4 +72,3 @@ function Get-FabricCapacities {
7272
# Return the results
7373
return $res
7474
}
75-

source/Public/Capacity/Get-FabricCapacity.ps1

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
2424
.NOTES
2525
- Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`.
26-
- Calls `Test-TokenExpired` to ensure token validity before making the API request.
26+
- Calls `Confirm-TokenState` to ensure token validity before making the API request.
2727
2828
Author: Tiago Balabuch
2929
#>
@@ -46,9 +46,7 @@ function Get-FabricCapacity {
4646
}
4747

4848
# Ensure token validity
49-
Write-Message -Message "Validating token..." -Level Debug
50-
Test-TokenExpired
51-
Write-Message -Message "Token validation completed." -Level Debug
49+
Confirm-TokenState
5250

5351
# Construct the API endpoint URL
5452
$apiEndpointURI = "capacities"
@@ -58,7 +56,7 @@ function Get-FabricCapacity {
5856
Uri = $apiEndpointURI
5957
Method = 'Get'
6058
}
61-
$capacities = (Invoke-FabricAPIRequest @apiParams).Value
59+
$capacities = (Invoke-FabricRestMethod @apiParams).Value
6260

6361
# Filter results based on provided parameters
6462
$response = if ($capacityId) {

source/Public/Capacity/Get-FabricCapacityRefreshables.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ The function retrieves the PowerBI access token and makes a GET request to the P
2828
[string]$top = 5
2929
)
3030

31-
Confirm-FabricAuthToken | Out-Null
31+
Confirm-TokenState
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.
3535
return (Invoke-RestMethod -uri "$($PowerBI.BaseApiUrl)/capacities/refreshables?`$top=$top" -Headers $FabricSession.HeaderParams -Method GET).value
36-
}
36+
}

0 commit comments

Comments
 (0)