Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions eng/common/scripts/Get-MsAlias-FromGithub.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<#
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets name this something like:
Get-AADIdentityFromGithubUser

.DESCRIPTION
Get the corresponding ms alias from github identity
.PARAMETER AadToken
The aad access token.
.PARAMETER GithubName
Github identity. E.g sima-zhu
.PARAMETER ContentType
Content type of http requests.
.PARAMETER AdditionalHeaders
Additional parameters for http request headers in key-value pair format, e.g. @{ key1 = val1; key2 = val2; key3 = val3}
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true)]
[string]$AadToken,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[string]$AadToken,
[string]$opsAuthToken,


[Parameter(Mandatory = $true)]
[string]$GithubName,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[string]$GithubName,
[string]$GithubUser,


[Parameter(Mandatory = $false)]
[string]$ApiVersion = "2019-10-01",

[Parameter(Mandatory = $false)]
[string]$ContentType = "application/json",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to pass in the apiversion or contenttype as parameters?


[Parameter(Mandatory = $false)]
[hashtable]$AdditionalHeaders
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we we have a need to pass extra headers?

)
. "${PSScriptRoot}\logging.ps1"

$OpensourceAPIBaseURI = "https://repos.opensource.microsoft.com/api/people/links/github/$GithubName"

$Headers = @{
"Authorization" = "Bearer $AadToken"
"Content-Type" = $ContentType
"api-version" = $ApiVersion
}

function Load-RequestHeaders() {
if ($AdditionalHeaders) {
return $Headers + $AdditionalHeaders
}
return $Headers
}


try {
$headers = Load-RequestHeaders
Write-Host "Fetching ms alias for github identity: $GithubName."
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Write-Host "Fetching ms alias for github identity: $GithubName."
Write-Host "Fetching aad identity for github user: $GithubName."

$resp = Invoke-RestMethod $OpensourceAPIBaseURI -Method 'GET' -Headers $Headers
}
catch {
LogError $_
exit 1
}

$resp | Write-Verbose

if ($resp.aad) {
return $resp.aad.alias
}

LogError "Failed to retrieve the ms alias from given github identity: $GithubName."
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LogError "Failed to retrieve the ms alias from given github identity: $GithubName."
LogError "Failed to retrieve the aad identity from given github user: $GithubName."

Should we exit 1 here as well, or is what is the expected way to handle the errors from this script?