Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fixed bug in `Update-FabricSemanticModelDefinition` - Uri was incorrect when a platform file exists
- Name of new SQL database will be shown (#169)
- Logging in with a Service Principal does not work (#164)

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion source/Private/Confirm-TokenState.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function Confirm-TokenState {
param ()

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

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

Expand Down
4 changes: 3 additions & 1 deletion source/Private/Set-FabConfig.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Set-PSFConfig -Name 'FabricTools.FabricApi.BaseApiUrl' -Value 'https://api.fabric.microsoft.com/v1'
Write-Verbose "Setting FabricTools configuration defaults..."

Set-PSFConfig -Name 'FabricTools.FabricApi.BaseUrl' -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'
Expand Down
17 changes: 9 additions & 8 deletions source/Public/Capacity/Get-FabricCapacityState.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ Retrieves the state of a specific capacity.
.DESCRIPTION
The Get-FabricCapacityState function retrieves the state of a specific 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 capacity. This is a mandatory parameter. This is a parameter found in Azure, not Fabric.

.EXAMPLE
This example retrieves the state of a specific capacity given the subscription ID, resource group, and capacity.

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

.NOTES
Expand All @@ -36,20 +36,21 @@ Author: Ioana Bouariu
# Define mandatory 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
)

Confirm-TokenState

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

# Define the URL for the GET request.
$getCapacityState = "$AzureBaseApiUrl/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
return Invoke-RestMethod -Method GET -Uri $getCapacityState -Headers $headers -ErrorAction Stop
}
7 changes: 4 additions & 3 deletions source/Public/Capacity/Resume-FabricCapacity.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ function Resume-FabricCapacity {
.PARAMETER ResourceGroup
The resource group. This is a mandatory parameter. This is a parameter found in Azure, not Fabric.

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

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

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

.NOTES
Expand All @@ -44,12 +44,13 @@ function Resume-FabricCapacity {
Confirm-TokenState

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

# Define the URI for the request.
$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")) {
return Invoke-RestMethod -Method POST -Uri $resumeCapacity -Headers $script:AzureSession.HeaderParams -ErrorAction Stop
return Invoke-RestMethod -Method POST -Uri $resumeCapacity -Headers $headers -ErrorAction Stop
}
}
3 changes: 2 additions & 1 deletion source/Public/Capacity/Suspend-FabricCapacity.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ Author: Ioana Bouariu
Confirm-TokenState

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

# Define the URI for the request.
$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")) {
return Invoke-RestMethod -Method POST -Uri $suspendCapacity -Headers $script:AzureSession.HeaderParams -ErrorAction Stop
return Invoke-RestMethod -Method POST -Uri $suspendCapacity -Headers $headers -ErrorAction Stop
}

}
38 changes: 30 additions & 8 deletions source/Public/Connect-FabricAccount.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,28 @@ function Connect-FabricAccount {
```

.EXAMPLE
Connects as Service Principal using id and secret
Connects as Service Principal using AppId and secret

```powershell
Connect-FabricAccount -TenantId 'xxx' -ServicePrincipalId 'appId' -ServicePrincipalSecret $secret
$TenantID = '12345678-1234-1234-1234-123456789012'
$ServicePrincipalId = '4cbbe76e-1234-1234-0000-ffffffffffff'
$ServicePrincipalSecret = 'xyz'

$ServicePrincipalSecretSecure = ($ServicePrincipalSecret | ConvertTo-SecureString -AsPlainText -Force)
Connect-FabricAccount -TenantId $TenantID -ServicePrincipalId $ServicePrincipalId -ServicePrincipalSecret $ServicePrincipalSecretSecure -Reset
```

.EXAMPLE
Connects as Service Principal using credential object

```powershell
$TenantID = '12345678-1234-1234-1234-123456789012'
$ServicePrincipalId = '4cbbe76e-1234-1234-0000-ffffffffffff'
$ServicePrincipalSecret = 'xyz'

$ServicePrincipalSecretSecure = ($ServicePrincipalSecret | ConvertTo-SecureString -AsPlainText -Force)
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ServicePrincipalId, $ServicePrincipalSecretSecure
Connect-FabricAccount -TenantId $TenantID -Credential $credential -Verbose -Reset
```

.OUTPUTS
Expand Down Expand Up @@ -91,7 +109,12 @@ function Connect-FabricAccount {
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."
throw "AppId is required when using AppSecret."
}
# Warn if both Credential and AppId are provided
if ($PSBoundParameters.ContainsKey('Credential') -and $PSBoundParameters.ContainsKey('AppId'))
{
Write-Message -Message "Provided Credential will be ignored when AppId/ServicePrincipalId is also provided." -Level Warning
}
}

Expand All @@ -102,13 +125,13 @@ function Connect-FabricAccount {
}
if (!$azContext) {
if ($ServicePrincipalId) {
Write-Message "Connecting to Azure Account using provided servicePrincipalId..." -Level Verbose
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
$null = Connect-AzAccount -ServicePrincipal -Credential $Credential -Tenant $TenantId
}
else {
Write-Message "Connecting to Azure Account using current user..." -Level Verbose
Expand All @@ -124,7 +147,7 @@ function Connect-FabricAccount {
$azContext = Get-AzContext
}

Write-Message "Connected: $($azContext.Account)" -Level Verbose
Write-Message "Connected: $($azContext.Account)" -Level Info

if ($PSCmdlet.ShouldProcess("Setting Fabric authentication token and headers for $($azContext.Account)")) {
$ResourceUrl = Get-PSFConfigValue -FullName 'FabricTools.FabricApi.ResourceUrl'
Expand All @@ -151,6 +174,5 @@ function Connect-FabricAccount {
}

}
end {
}
end { }
}
Loading