Skip to content

Commit a326104

Browse files
committed
Add Location parameter to Update-FabricCapacity cmdlet
This change introduces a mandatory Location parameter to the Update-FabricCapacity cmdlet, ensuring that the location is specified when creating or updating a Microsoft Fabric capacity. Additionally, the API request method has been updated from PATCH to PUT for better alignment with RESTful practices.
1 parent a4ff3f7 commit a326104

4 files changed

Lines changed: 27 additions & 9 deletions

File tree

source/Private/Test-FabricApiResponse.ps1

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,19 @@ function Test-FabricApiResponse {
142142
default {
143143
Write-Message -Message "Test-FabricApiResponse::default" -Level Debug
144144
Write-Message -Message "Unexpected response code: $statusCode from the API." -Level Error
145-
Write-Message -Message "Error: $($response.message)" -Level Error
146-
if ($response.moreDetails) {
147-
Write-Message -Message "More Details: $($response.moreDetails)" -Level Error
145+
146+
if ($null -ne $Response.error) {
147+
Write-Message -Message "Error Code: $($Response.error.code)" -Level Error
148+
Write-Message -Message "Error Msg: $($Response.error.message)" -Level Error
149+
$errorJson = $Response.error | ConvertTo-Json -Depth 10
150+
Write-Message -Message "Error Detailed Info:`n$errorJson" -Level Debug
151+
} else {
152+
Write-Message -Message "Error Code: $($Response.errorCode)" -Level Error
153+
Write-Message -Message "Error Msg: $($Response.message)" -Level Error
154+
if ($Response.moreDetails) {
155+
Write-Message -Message "More Details: $($Response.moreDetails)" -Level Error
156+
}
148157
}
149-
Write-Message "Error Code: $($response.errorCode)" -Level Error
150158
throw "API request failed with status code $statusCode."
151159
}
152160
}

source/Public/Capacity/Update-FabricCapacity.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ function Update-FabricCapacity
6969
[ValidateNotNullOrEmpty()]
7070
[string]$SkuName,
7171

72+
[Parameter(Mandatory = $true)]
73+
[ValidateNotNullOrEmpty()]
74+
[string]$Location,
75+
7276
[Parameter(Mandatory = $true)]
7377
[ValidateNotNullOrEmpty()]
7478
[string[]]$AdministrationMembers,
@@ -88,7 +92,6 @@ function Update-FabricCapacity
8892

8993
# Step 2: Construct the API URL
9094
$apiEndpointUrl = "$($AzureSession.BaseApiUrl)/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Fabric/capacities/{2}?api-version=2023-11-01" -f $SubscriptionId, $ResourceGroupName, $CapacityName
91-
Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug
9295

9396
# Step 3: Construct the request body
9497
$body = @{
@@ -101,6 +104,7 @@ function Update-FabricCapacity
101104
name = $SkuName
102105
tier = $SkuTier
103106
}
107+
location = $Location
104108
}
105109

106110
if ($Tags)
@@ -113,7 +117,7 @@ function Update-FabricCapacity
113117
{
114118
$apiParams = @{
115119
Uri = $apiEndpointUrl
116-
Method = 'PATCH'
120+
Method = 'PUT'
117121
Body = $body
118122
TypeName = 'Fabric Capacity'
119123
NoWait = $NoWait

source/Public/Invoke-FabricRestMethod.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ Function Invoke-FabricRestMethod {
133133
Write-Message -Message "PowerBIApi param is ignored when full Uri is provided." -Level Warning
134134
}
135135

136+
$Headers = $FabricSession.HeaderParams
137+
if ($Uri.StartsWith($AzureSession.BaseApiUrl)) {
138+
$Headers = $AzureSession.HeaderParams
139+
Write-Message -Message "Using AzureSession headers for request." -Level Debug
140+
}
141+
136142
if ($Body -is [hashtable]) {
137143
$Body = $Body | ConvertTo-Json -Depth 10
138144
Write-Message -Message "Request Body: $Body" -Level Debug
@@ -154,7 +160,7 @@ Function Invoke-FabricRestMethod {
154160
Write-Message -Message "API Endpoint: $Method $apiEndpointUrl" -Level Verbose
155161

156162
$request = @{
157-
Headers = $FabricSession.HeaderParams
163+
Headers = $Headers
158164
Uri = $Uri
159165
Method = $Method
160166
Body = $Body

tests/Unit/Update-FabricCapacity.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ Describe "Update-FabricCapacity" -Tag "UnitTests" {
4444
}
4545

4646
It "Should have exactly the number of expected parameters $($expected.Count)" {
47-
$hasparms = $command.Parameters.Values.Name
48-
Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty
47+
$hasParams = $command.Parameters.Values.Name
48+
Compare-Object -ReferenceObject $expected -DifferenceObject $hasParams | Should -BeNullOrEmpty
4949
}
5050
}
5151

0 commit comments

Comments
 (0)