-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Adding Authorization for Github api call In KubeLoginInstallerV0 #20725
base: master
Are you sure you want to change the base?
Changes from 10 commits
288ec95
6840c03
bc37dbe
88e3de8
9f2816d
4bb651f
3b0558e
742292b
3f7d244
d08764c
e8b1820
f5bf488
0eb2680
e7b4f67
7699b4c
13124c2
2d1d3ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,12 @@ export async function getLatestVersionTag(): Promise<string> { | |
request.headers = request.headers || {}; | ||
request.headers['User-Agent'] = userAgent; | ||
|
||
if (taskLib.getBoolFeatureFlag('USE_AUTHORIZATION_FOR_API_CALL')){ | ||
const token = getGithubEndPointToken(); | ||
if (token) { | ||
request.headers['Authorization'] = 'token ' + token; | ||
} | ||
} | ||
const response = await webClient.sendRequest(request); | ||
return response.body['tag_name']; | ||
} | ||
|
@@ -84,6 +90,12 @@ export async function getKubeloginRelease(version: string = 'latest', platform?: | |
request.method = 'GET'; | ||
request.headers = request.headers || {}; | ||
request.headers['User-Agent'] = userAgent; | ||
if (taskLib.getBoolFeatureFlag('USE_AUTHORIZATION_FOR_API_CALL')){ | ||
const token = getGithubEndPointToken(); | ||
if (token) { | ||
request.headers['Authorization'] = 'token ' + token; | ||
} | ||
} | ||
|
||
const response = await webClient.sendRequest(request); | ||
|
||
|
@@ -134,6 +146,36 @@ export async function unzipRelease(zipPath: string): Promise<string> { | |
} | ||
} | ||
|
||
function getGithubEndPointToken(): string { | ||
try{ | ||
const githubEndpoint = taskLib.getInput("gitHubConnection", false); | ||
const githubEndpointObject = taskLib.getEndpointAuthorization(githubEndpoint, true); | ||
let githubEndpointToken: string = null; | ||
|
||
if (!!githubEndpointObject) { | ||
taskLib.debug("Endpoint scheme: " + githubEndpointObject.scheme); | ||
|
||
if (githubEndpointObject.scheme === 'PersonalAccessToken') { | ||
githubEndpointToken = githubEndpointObject.parameters.accessToken | ||
} else if (githubEndpointObject.scheme === 'OAuth'){ | ||
// scheme: 'OAuth' | ||
githubEndpointToken = githubEndpointObject.parameters.AccessToken | ||
} else if (githubEndpointObject.scheme === 'Token'){ | ||
// scheme: 'Token' | ||
githubEndpointToken = githubEndpointObject.parameters.AccessToken | ||
} else if (githubEndpointObject.scheme) { | ||
throw new Error(taskLib.loc("InvalidEndpointAuthScheme", githubEndpointObject.scheme)); | ||
} | ||
} | ||
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. Let's reduce code nesting by inverting 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. Used switch block |
||
|
||
return githubEndpointToken; | ||
} | ||
catch(error) | ||
{ | ||
throw new Error(taskLib.loc("Failed to retrieve GitHub endpoint token:", error.message)); | ||
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. Let's create less generic exception type here. |
||
} | ||
} | ||
|
||
export function getKubeloginPath(inputPath: string, fileName: string): string | undefined { | ||
const files: string[] = fs.readdirSync(inputPath); | ||
for (const file of files) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Default|0.247.0 | ||
Node20_229_3|0.247.1 | ||
Default|0.250.0 | ||
Node20_229_3|0.250.1 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Let's extract explicit utility method to reduce code duplication
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.
Implemented the utlity code