-
Notifications
You must be signed in to change notification settings - Fork 234
Get ms alias from github identity #2582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,64 @@ | ||||||
| <# | ||||||
| .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, | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| [Parameter(Mandatory = $true)] | ||||||
| [string]$GithubName, | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| [Parameter(Mandatory = $false)] | ||||||
| [string]$ApiVersion = "2019-10-01", | ||||||
|
|
||||||
| [Parameter(Mandatory = $false)] | ||||||
| [string]$ContentType = "application/json", | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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." | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| $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." | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Should we exit 1 here as well, or is what is the expected way to handle the errors from this script? |
||||||
There was a problem hiding this comment.
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