Skip to content

Commit aae11c4

Browse files
authored
Merge branch 'main' into fix/New-AzDoServiceConnection
2 parents 70b1967 + 5286ff5 commit aae11c4

4 files changed

Lines changed: 34 additions & 25 deletions

File tree

AzureDevOpsPowerShell/Private/Invoke-AzDoRestMethod.ps1

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ function Invoke-AzDoRestMethod {
3131
[string]
3232
$Method,
3333

34-
[Parameter()]
35-
[string]
36-
$Pat,
37-
3834
[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)]
3935
[PSCustomObject[]]
4036
$Body
@@ -47,7 +43,7 @@ function Invoke-AzDoRestMethod {
4743
Write-Debug "method: $Method"
4844
Write-Debug "body: $($body | ConvertTo-Json -Depth 10)"
4945

50-
if (-not($Pat) -and $script:header) {
46+
if ($script:header.Authorization -match "Bearer") {
5147
$params = @{
5248
Uri = "https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=6.0"
5349
Method = 'GET'
@@ -62,13 +58,13 @@ function Invoke-AzDoRestMethod {
6258
}
6359
} catch {
6460
Write-Verbose "Refreshing authentication header"
65-
Clear-AzDoAuthHeader
61+
$script:header = $null
6662
}
6763
}
6864

6965
if (-not($script:header)) {
7066
try {
71-
New-AzDoAuthHeader -PAT $Pat -ErrorAction Stop
67+
New-AzDoAuthHeader -ErrorAction Stop
7268
} catch {
7369
throw $_
7470
}

AzureDevOpsPowerShell/Public/Api/Pipelines/Pipelines/New-AzDoPipeline.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ function New-AzDoPipeline {
6565
RepoName = $RepoName
6666
}
6767

68-
Write-Debug "Calling Get-AzDoRepo with"
69-
$RepoId = (Get-AzDoRepo @getAzDoRepoSplat).RepoId
68+
Write-Debug "Calling Get-AzDoRepo with $($getAzDoRepoSplat| ConvertTo-Json -Depth 10)"
69+
$RepoId = (Get-AzDoRepo @getAzDoRepoSplat -ErrorAction Stop).RepoId
7070

7171
$body = @{
7272
name = $PipelineName

AzureDevOpsPowerShell/Public/Helpers/Clear-AzDoAuthHeader.ps1

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function Set-AzDoPAT {
2+
<#
3+
.SYNOPSIS
4+
This script sets the header variable with a PAT.
5+
.DESCRIPTION
6+
This script sets the header variable with a PAT.
7+
.NOTES
8+
This function can be used to use a PAT for authentication instead of an Azure PowerShell access token.
9+
.EXAMPLE
10+
Set-AzDoPAT -Pat '***'
11+
12+
This example sets the header variable used for authentication with a PAT.
13+
#>
14+
[CmdletBinding(SupportsShouldProcess)]
15+
param (
16+
# PAT used for authentication
17+
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)]
18+
[string]
19+
$Pat
20+
)
21+
22+
process {
23+
if ($PSCmdlet.ShouldProcess()) {
24+
New-AzDoAuthHeader -Pat $Pat
25+
} else {
26+
Write-Verbose "Calling New-AzDoAuthHeader with pat"
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)