Skip to content

Commit

Permalink
Merge branch 'pr/MichelZ/240'
Browse files Browse the repository at this point in the history
  • Loading branch information
DarqueWarrior committed Feb 25, 2020
2 parents 65c1516 + 868749c commit 55e39b0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .docs/Invoke-VSTeamRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ Converts the PowerShell object into JSON and displays in the console.
Type: Switch
```
### -AdditionalHeaders
Adds additional headers to the request
```yaml
Type: Hashtable
```
## INPUTS
### System.String
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 6.4.5

Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/240) from [Michel Zehnder](https://github.com/MichelZ) which included the following:

Add option to add additional headers (-AdditionalHeaders) to the request generated by the `Invoke-VSTeamRequest` call

## 6.4.4

Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/257) from [Michel Zehnder](https://github.com/MichelZ) which included the following:
Expand Down
16 changes: 13 additions & 3 deletions Source/Private/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -597,13 +597,14 @@ function _callAPI {
[string]$ProjectName,
[string]$Team,
[string]$Url,
[object]$QueryString
[object]$QueryString,
[hashtable]$AdditionalHeaders
)

# If the caller did not provide a Url build it.
if (-not $Url) {
$buildUriParams = @{ } + $PSBoundParameters;
$extra = 'method', 'body', 'InFile', 'OutFile', 'ContentType'
$extra = 'method', 'body', 'InFile', 'OutFile', 'ContentType', 'AdditionalHeaders'
foreach ($x in $extra) { $buildUriParams.Remove($x) | Out-Null }
$Url = _buildRequestURI @buildUriParams
}
Expand All @@ -625,6 +626,7 @@ function _callAPI {

if (_useWindowsAuthenticationOnPremise) {
$params.Add('UseDefaultCredentials', $true)
$params.Add('Headers', @{})
}
elseif (_useBearerToken) {
$params.Add('Headers', @{Authorization = "Bearer $env:TEAM_TOKEN" })
Expand All @@ -633,8 +635,16 @@ function _callAPI {
$params.Add('Headers', @{Authorization = "Basic $env:TEAM_PAT" })
}

if ($AdditionalHeaders -and $AdditionalHeaders.PSObject.Properties.name -match "Keys")
{
foreach ($key in $AdditionalHeaders.Keys)
{
$params['Headers'].Add($key, $AdditionalHeaders[$key])
}
}

# We have to remove any extra parameters not used by Invoke-RestMethod
$extra = 'Area', 'Resource', 'SubDomain', 'Id', 'Version', 'JSON', 'ProjectName', 'Team', 'Url', 'QueryString'
$extra = 'Area', 'Resource', 'SubDomain', 'Id', 'Version', 'JSON', 'ProjectName', 'Team', 'Url', 'QueryString', 'AdditionalHeaders'
foreach ($e in $extra) { $params.Remove($e) | Out-Null }

try {
Expand Down
3 changes: 2 additions & 1 deletion Source/Public/Invoke-VSTeamRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ function Invoke-VSTeamRequest {
[string]$OutFile,
[switch]$JSON,
[string]$ContentType,
[string]$Url
[string]$Url,
[hashtable]$AdditionalHeaders
)
DynamicParam {
_buildProjectNameDynamicParam -Mandatory $false
Expand Down
13 changes: 13 additions & 0 deletions unit/test/team.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ InModuleScope VSTeam {
Assert-VerifiableMock
}
}

Context 'Invoke-VSTeamRequest AdditionalHeaders' {
[VSTeamVersions]::Account = 'https://dev.azure.com/test'
Mock Invoke-RestMethod { return @() } -Verifiable -ParameterFilter {
$Headers["Test"] -eq 'Test'
}

Invoke-VSTeamRequest -Area release -Resource releases -Id 1 -SubDomain vsrm -Version '4.1-preview' -ProjectName testproject -JSON -AdditionalHeaders @{Test = "Test"}

It 'Should call API' {
Assert-VerifiableMock
}
}
}

Describe 'Team VSTS' {
Expand Down

0 comments on commit 55e39b0

Please sign in to comment.