Skip to content
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

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

Deekshitha981
Copy link
Collaborator

@Deekshitha981 Deekshitha981 commented Dec 11, 2024

Task name: KubeLoginInstallerV0

Description: KubeloginInstallerV0 task is calling github API anonymously, so here we are adding authorization using Oauth and pat to access the github API.

Documentation changes required: (Y/N) N

Added unit tests: (Y/N) N

Attached related issue: https://github.com/microsoft/azure-pipelines-tasks/issues/19097

Checklist:

  • Task version was bumped - please check instruction how to do it
  • Checked that applied changes work as expected

@Deekshitha981
Copy link
Collaborator Author

Deekshitha981 commented Dec 12, 2024

/ azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

if (taskLib.getBoolFeatureFlag('USE_AUTHORIZATION_FOR_API_CALL')){
const token = getGithubEndPointToken();
if (token) {
request.headers['Authorization'] = 'token ' + token;
Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Implemented the utlity code

} else if (githubEndpointObject.scheme) {
throw new Error(taskLib.loc("InvalidEndpointAuthScheme", githubEndpointObject.scheme));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's reduce code nesting by inverting if (!!githubEndpointObject) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Used switch block

}
catch(error)
{
throw new Error(taskLib.loc("Failed to retrieve GitHub endpoint token:", error.message));
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's create less generic exception type here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants