Skip to content

Commit 340bbf0

Browse files
committed
We want Test-FabricApiResponse to be executed after Invoke-FabricRestMethod #143
1 parent 0abbd41 commit 340bbf0

13 files changed

+207
-83
lines changed

source/Private/Get-FabricContinuationToken.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Author: Kamil Nowinski
2323
function Get-FabricContinuationToken {
2424
[CmdletBinding()]
2525
param (
26-
[Parameter(Mandatory = $true)]
26+
[Parameter(Mandatory = $false)]
2727
[object]$Response
2828
)
2929

source/Private/Test-FabricApiResponse.ps1

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ function Test-FabricApiResponse {
1010
.PARAMETER Response
1111
The response body from the API call.
1212
13+
.PARAMETER Operation
14+
The operation being performed by parent function (e.g., 'New', 'Update', 'Remove', 'Get'). It helps in logging appropriate messages.
15+
1316
.PARAMETER ObjectIdOrName
1417
The name or ID of the resource being operated.
1518
@@ -40,37 +43,53 @@ function Test-FabricApiResponse {
4043

4144
[CmdletBinding()]
4245
param (
43-
[Parameter(Mandatory = $false)]
46+
[Parameter(Mandatory = $false)] # Response is $null when Response Code is 202
4447
$Response,
4548

49+
[Parameter(Mandatory = $true)]
50+
$ResponseHeader,
51+
52+
[Parameter(Mandatory = $true)]
53+
$StatusCode,
54+
55+
[Parameter(Mandatory = $false)]
56+
$Operation,
57+
4658
[Parameter(Mandatory = $false)]
4759
[string] $ObjectIdOrName,
4860

4961
[Parameter(Mandatory = $false)]
5062
[string] $TypeName = 'Fabric Item',
5163

5264
[Parameter(Mandatory = $false)]
53-
[switch] $NoWait = $false
65+
[string] $SuccessMessage,
66+
67+
[Parameter(Mandatory = $false)]
68+
[switch] $NoWait = $false,
69+
70+
[Parameter(Mandatory = $false)]
71+
[switch] $ExtractValue = $false
5472
)
5573

5674
Write-Message -Message "[Test-FabricApiResponse]::Begin" -Level Debug
5775

58-
$responseHeader = $script:responseHeader
59-
$statusCode = $script:statusCode
76+
#$responseHeader = $script:responseHeader
77+
#$statusCode = $script:statusCode
6078
$result = $null
6179

62-
$verb = (Get-PSCallStack)[1].Command.Split('-')[0]
63-
Write-Message -Message "Testing API response for '$verb' operation. StatusCode: $statusCode." -Level Debug
80+
Write-Message -Message "Testing API response for '$Operation' operation. StatusCode: $statusCode." -Level Debug
6481

6582
switch ($statusCode) {
6683
200 {
67-
$result = $null
84+
if ($Operation -eq 'Get') {
85+
$result = $Response
86+
}
6887
}
6988
201 {
7089
$result = $Response
7190
}
7291
202 {
73-
Write-Message -Message "$verb Request for $TypeName '$ObjectIdOrName' accepted. Provisioning in progress!" -Level Info
92+
Write-Message -Message "$Operation Request for $TypeName '$ObjectIdOrName' accepted. Provisioning in progress!" -Level Info
7493
[string]$operationId = $responseHeader["x-ms-operation-id"]
7594

7695
if ($NoWait) {
@@ -91,14 +110,14 @@ function Test-FabricApiResponse {
91110
# Handle operation result
92111
if ($operationStatus.status -eq "Succeeded") {
93112
Write-Message -Message "Operation Succeeded" -Level Debug
94-
Write-Message -Message "Getting Long Running Operation result" -Level Debug
113+
Write-Message -Message "Getting Long Running Operation result" -Level Verbose
95114

96115
$operationResult = Get-FabricLongRunningOperationResult -operationId $operationId
97-
Write-Message -Message "Long Running Operation status: $operationResult" -Level Debug
116+
#Write-Message -Message "Long Running Operation status: $operationResult" -Level Debug
98117

99118
return $operationResult
100119
} else {
101-
Write-Message -Message "Operation failed. Status: $($operationStatus)" -Level Debug
120+
#Write-Message -Message "Operation failed. Status: $($operationStatus)" -Level Debug
102121
Write-Message -Message "Operation failed. Status: $($operationStatus)" -Level Error
103122
return $operationStatus
104123
}
@@ -115,16 +134,41 @@ function Test-FabricApiResponse {
115134
}
116135
}
117136

118-
switch ($verb) {
137+
# if (FeatureFlag.IsEnabled('FabricToolsVerboseLogging')) { # This is placeholder for verbose logging feature flag being implemented soon
138+
$TypeName= $TypeName.Substring(0, 1).ToUpper() + $TypeName.Substring(1)
139+
140+
if ($SuccessMessage) {
141+
$Operation = "Custom"
142+
}
143+
144+
# Try to get Name of Id from the response when new item is created
145+
if ($Operation -eq 'New' -and -not $ObjectIdOrName) {
146+
$ObjectIdOrName = $Response.DisplayName ? $Response.DisplayName : $Response.id
147+
}
148+
switch ($Operation) {
119149
'New' { $msg = "$TypeName '$ObjectIdOrName' created successfully."; $level = 'Info' }
120150
'Update' { $msg = "$TypeName '$ObjectIdOrName' updated successfully."; $level = 'Info' }
121151
'Remove' { $msg = "$TypeName '$ObjectIdOrName' deleted successfully."; $level = 'Info' }
122-
'Get' { $msg = "Successfully retrieved $TypeName details."; $level = 'Debug' }
123-
default { $msg = "Received $statusCode status code for $verb operation on $TypeName '$ObjectIdOrName'."; $level = 'Info' }
152+
'Get' { $msg = "Successfully retrieved $TypeName details."; $level = 'Debug' }
153+
'Custom' { $msg = "$SuccessMessage"; $level = 'Info' }
154+
default { $msg = "Received $statusCode status code for $Operation operation on $TypeName '$ObjectIdOrName'."; $level = 'Info' }
124155
}
125156
Write-Message -Message $msg -Level $level
157+
# }
158+
126159
Write-Message -Message "[Test-FabricApiResponse]::End" -Level Debug
127160

128-
$result
161+
# Return the "value" object if exists, otherwise return the response directly
162+
if ($result -and $ExtractValue) {
163+
Write-Message -Message "Extracting 'value' property from the response as requested." -Level Debug
164+
if (-not $result.value) {
165+
Write-Message -Message "No 'value' property found in the response." -Level Warning
166+
return $result
167+
}
168+
$result | ForEach-Object { $result.value }
169+
}
170+
else {
171+
$result
172+
}
129173

130174
}

source/Public/Deployment Pipeline/Add-FabricWorkspaceToStage.ps1

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,21 @@ function Add-FabricWorkspaceToStage {
6464
}
6565

6666
# Step 4: Make the API request and validate response
67-
$response = Invoke-FabricRestMethod -Uri $apiEndpointUrl -Method Post -Body $requestBody
68-
Test-FabricApiResponse -Response $response
67+
$apiParameters = @{
68+
Uri = $apiEndpointUrl
69+
Method = 'POST'
70+
Body = $requestBody
71+
HandleResponse = $true
72+
TypeName = "deployment pipeline stage"
73+
ObjectIdOrName = $StageId
74+
SuccessMessage = "Successfully assigned workspace to deployment pipeline stage."
75+
}
76+
$response = Invoke-FabricRestMethod @apiParameters
6977

7078
# Step 5: Return results
71-
Write-Message -Message "Successfully assigned workspace to deployment pipeline stage." -Level Info
79+
#Write-Message -Message "??? Successfully assigned workspace to deployment pipeline stage." -Level Info
7280
$response
81+
7382
} catch {
7483
# Step 6: Error handling
7584
$errorDetails = $_.Exception.Message

source/Public/Deployment Pipeline/Get-FabricDeploymentPipeline.ps1

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,19 @@ function Get-FabricDeploymentPipeline {
5959
Write-Message -Message "Retrieving specific deployment pipeline with ID: $DeploymentPipelineId" -Level Debug
6060
$apiEndpointUrl = "deploymentPipelines/$DeploymentPipelineId"
6161

62-
$response = Invoke-FabricRestMethod -Uri $apiEndpointUrl -Method Get
62+
$response = Invoke-FabricRestMethod -Uri $apiEndpointUrl -Method Get -HandleResponse -TypeName "deployment pipeline"
63+
return $response
6364

6465
# Validate response
65-
Test-FabricApiResponse -response $response -ObjectIdOrName $DeploymentPipelineId -typeName "deployment pipeline"
66-
67-
if ($response) {
68-
Write-Message -Message "Successfully retrieved deployment pipeline." -Level Debug
69-
return $response
70-
} else {
71-
Write-Message -Message "No deployment pipeline found with the specified ID." -Level Warning
72-
return $null
73-
}
66+
#Test-FabricApiResponse -response $response -ObjectIdOrName $DeploymentPipelineId -typeName "deployment pipeline"
67+
68+
# if ($response) {
69+
# Write-Message -Message "Successfully retrieved deployment pipeline." -Level Debug
70+
# return $response
71+
# } else {
72+
# Write-Message -Message "No deployment pipeline found with the specified ID." -Level Warning
73+
# return $null
74+
# }
7475
}
7576

7677
# Step 2: Initialize variables for listing all pipelines
@@ -97,10 +98,13 @@ function Get-FabricDeploymentPipeline {
9798
Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug
9899

99100
# Step 5: Make the API request
100-
$response = Invoke-FabricRestMethod -Uri $apiEndpointUrl -Method Get
101-
102-
# Validate response
103-
Test-FabricApiResponse -response $response -typeName "deployment pipeline"
101+
$apiParameters = @{
102+
Uri = $apiEndpointUrl
103+
Method = 'GET'
104+
HandleResponse = $true
105+
TypeName = "deployment pipeline"
106+
}
107+
$response = Invoke-FabricRestMethod @apiParameters
104108

105109
# Step 6: Process response and update continuation token
106110
if ($null -ne $response) {

source/Public/Deployment Pipeline/Get-FabricDeploymentPipelineOperation.ps1

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,16 @@ function Get-FabricDeploymentPipelineOperation {
5252
Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug
5353

5454
# Step 3: Make the API request
55-
$response = Invoke-FabricRestMethod -Uri $apiEndpointUrl -Method Get
56-
57-
# Step 4: Validate response
58-
Test-FabricApiResponse -response $response -ObjectIdOrName $DeploymentPipelineId -typeName "deployment pipeline operation"
59-
60-
# Step 5: Handle results
55+
$apiParameters = @{
56+
Uri = $apiEndpointUrl
57+
Method = 'GET'
58+
HandleResponse = $true
59+
TypeName = "deployment pipeline operation"
60+
ObjectIdOrName = $DeploymentPipelineId
61+
}
62+
$response = Invoke-FabricRestMethod @apiParameters
6163
$response
62-
# if ($response) {
63-
# Write-Message -Message "Successfully retrieved deployment pipeline operation details." -Level Debug
64-
# return $response
65-
# } else {
66-
# Write-Message -Message "No deployment pipeline operation found with the specified IDs." -Level Warning
67-
# return $null
68-
# }
64+
6965
} catch {
7066
# Step 6: Error handling
7167
$errorDetails = $_.Exception.Message

source/Public/Deployment Pipeline/Get-FabricDeploymentPipelineRoleAssignments.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ function Get-FabricDeploymentPipelineRoleAssignments {
4848
Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug
4949

5050
# Step 4: Make the API request and validate response
51-
$response = Invoke-FabricRestMethod -Uri $apiEndpointUrl -Method Get
52-
Test-FabricApiResponse -Response $response -ObjectIdOrName $DeploymentPipelineId -TypeName "Deployment Pipeline Role Assignments"
51+
$apiParameters = @{
52+
Uri = $apiEndpointUrl
53+
Method = 'GET'
54+
HandleResponse = $true
55+
TypeName = "deployment pipeline role assignments"
56+
ObjectIdOrName = $DeploymentPipelineId
57+
}
58+
$response = Invoke-FabricRestMethod @apiParameters
5359

5460
# Step 5: Process response and update continuation token
5561
if ($response.value) {
@@ -61,7 +67,7 @@ function Get-FabricDeploymentPipelineRoleAssignments {
6167
} while ($continuationToken)
6268

6369
# Step 7: Return results
64-
Write-Message -Message "Successfully retrieved $($roleAssignments.Count) role assignments." -Level Debug
70+
Write-Message -Message "??? Successfully retrieved $($roleAssignments.Count) role assignments." -Level Info
6571
$roleAssignments
6672

6773
} catch {

source/Public/Deployment Pipeline/Get-FabricDeploymentPipelineStage.ps1

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ function Get-FabricDeploymentPipelineStage {
6161
Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug
6262

6363
# Step 3: Make the API request
64-
$response = Invoke-FabricRestMethod -Uri $apiEndpointUrl -Method Get
65-
66-
# Step 4: Validate response
67-
Test-FabricApiResponse -response $response -ObjectIdOrName $DeploymentPipelineId -typeName "deployment pipeline stage"
68-
69-
# Step 5: Handle results
70-
$response
64+
$apiParameters = @{
65+
Uri = $apiEndpointUrl
66+
Method = 'GET'
67+
HandleResponse = $true
68+
TypeName = "deployment pipeline stage"
69+
ObjectIdOrName = $StageId ? $StageId : $DeploymentPipelineId
70+
}
71+
$response = Invoke-FabricRestMethod @apiParameters
72+
$response.value
7173

7274
} catch {
7375
# Step 6: Error handling

source/Public/Deployment Pipeline/Get-FabricDeploymentPipelineStageItem.ps1

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ function Get-FabricDeploymentPipelineStageItem {
6363
Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug
6464

6565
# Step 4: Make the API request
66-
$response = Invoke-FabricRestMethod -Uri $apiEndpointUrl -Method Get
67-
68-
# Step 5: Validate response
69-
Test-FabricApiResponse -response $response -ObjectIdOrName $StageId -typeName "deployment pipeline stage items"
66+
$apiParameters = @{
67+
Uri = $apiEndpointUrl
68+
Method = 'GET'
69+
HandleResponse = $true
70+
TypeName = "deployment pipeline stage items"
71+
ObjectIdOrName = $StageId
72+
}
73+
$response = Invoke-FabricRestMethod @apiParameters
7074

7175
# Step 6: Process results
7276
if ($response.value) {
@@ -76,15 +80,8 @@ function Get-FabricDeploymentPipelineStageItem {
7680
$continuationToken = Get-FabricContinuationToken -Response $response
7781
} while ($continuationToken)
7882

79-
# Step 7: Return all items
8083
$allItems
81-
# if ($allItems.Count -gt 0) {
82-
# Write-Message -Message "Successfully retrieved $($allItems.Count) items in total." -Level Debug
83-
# return $allItems
84-
# } else {
85-
# Write-Message -Message "No items found in the deployment pipeline stage." -Level Warning
86-
# return $null
87-
# }
84+
8885
} catch {
8986
# Step 8: Error handling
9087
$errorDetails = $_.Exception.Message

source/Public/Deployment Pipeline/New-FabricDeploymentPipeline.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,15 @@ function New-FabricDeploymentPipeline {
9191
}
9292

9393
# Step 4: Make the API request and Validate response
94-
if ($PSCmdlet.ShouldProcess($requestBody, "Create new Deployment Pipeline")) {
95-
$response = Invoke-FabricRestMethod -Uri "deploymentPipelines" -Method Post -Body $requestBody
96-
$response = Test-FabricApiResponse -response $response -ObjectIdOrName $DisplayName -typeName "deployment pipeline"
94+
if ($PSCmdlet.ShouldProcess("Create new Deployment Pipeline")) {
95+
$apiParameters = @{
96+
Uri = "deploymentPipelines"
97+
Method = "Post"
98+
Body = $requestBody
99+
HandleResponse = $true
100+
TypeName = "deployment pipeline"
101+
}
102+
$response = Invoke-FabricRestMethod @apiParameters
97103
}
98104

99105
# Step 5: Handle results

source/Public/Deployment Pipeline/Remove-FabricDeploymentPipeline.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,18 @@ function Remove-FabricDeploymentPipeline {
4242
# Step 3: Make the API request & validate response
4343
if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Delete Deployment Pipeline"))
4444
{
45-
$response = Invoke-FabricRestMethod -Uri $apiEndpointUrl -Method Delete
46-
Test-FabricApiResponse -response $response -ObjectIdOrName $DeploymentPipelineId -typeName "deployment pipeline"
45+
$apiParameters = @{
46+
Uri = $apiEndpointUrl
47+
Method = 'DELETE'
48+
HandleResponse = $true
49+
TypeName = "deployment pipeline"
50+
ObjectIdOrName = $DeploymentPipelineId
51+
}
52+
$response = Invoke-FabricRestMethod @apiParameters
4753
}
4854

4955
# Step 4: Handle results
50-
Write-Message -Message "Deployment pipeline $DeploymentPipelineId deleted successfully." -Level Info
56+
$response
5157

5258
} catch {
5359
# Step 5: Error handling

0 commit comments

Comments
 (0)