src/Private/azuredevops.ps1
function invokeDevOpsAPI{ param([string]$API, [string]$RequestType) $AzureDevOpsAuthenicationHeader = GetDevOpsHeaders $URI = "https://dev.azure.com/$env:AZUREDEVOPS_ORGANIZATION/$env:AZUREDEVOPS_PROJECTNAME/_apis/$API" Return Invoke-RestMethod -Method $RequestType -Uri $URI -Headers $AzureDevOpsAuthenicationHeader -ContentType application/json } function invokeDevOpsAPIPut{ param([string]$API, $Body) $AzureDevOpsAuthenicationHeader = GetDevOpsHeaders $URI = "https://dev.azure.com/$env:AZUREDEVOPS_ORGANIZATION/$env:AZUREDEVOPS_PROJECTNAME/_apis/$API" Return Invoke-RestMethod -Method 'PUT' -Body $Body -Uri $URI -Headers $AzureDevOpsAuthenicationHeader -ContentType application/json } function GetDevOpsHeaders{ $azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile $currentAzContext = Get-AzContext $profileClient = New-Object Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient($azProfile) $token = $profileClient.AcquireAccessToken($currentAzContext.Subscription.TenantId) $AccessToken = $token.AccessToken $Authorization = "{0} {1}" -f ("Bearer" , $AccessToken) $AzureDevOpsAuthenicationHeader = @{"Authorization" = $Authorization; "X-TFS-FedAuthRedirect"= "Suppress"} return $AzureDevOpsAuthenicationHeader } |