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

Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
288ec95
Adding Authorization for Github api call In KubeLoginInstallerV0
Deekshitha981 Dec 11, 2024
6840c03
Changing minor version
Deekshitha981 Dec 11, 2024
bc37dbe
changing task-loc.json
Deekshitha981 Dec 11, 2024
88e3de8
correcting FF name
Deekshitha981 Dec 11, 2024
9f2816d
changing task-loc.json
Deekshitha981 Dec 11, 2024
4bb651f
modifyng tasloc fle
Deekshitha981 Dec 12, 2024
3b0558e
Merge branch 'master' into users/v-dmerugu/AddingAuthorizationForGith…
Deekshitha981 Dec 12, 2024
742292b
Merge branch 'master' into users/v-dmerugu/AddingAuthorizationForGith…
Deekshitha981 Dec 13, 2024
3f7d244
Merge branch 'master' into users/v-dmerugu/AddingAuthorizationForGith…
Deekshitha981 Dec 16, 2024
d08764c
Merge branch 'master' into users/v-dmerugu/AddingAuthorizationForGith…
Deekshitha981 Dec 16, 2024
e8b1820
Merge branch 'master' into users/v-dmerugu/AddingAuthorizationForGith…
Deekshitha981 Dec 19, 2024
f5bf488
modifying the logic
Deekshitha981 Dec 20, 2024
0eb2680
Merge branch 'users/v-dmerugu/AddingAuthorizationForGithubAPICallInKu…
Deekshitha981 Dec 20, 2024
e7b4f67
Merge branch 'master' into users/v-dmerugu/AddingAuthorizationForGith…
Deekshitha981 Dec 20, 2024
7699b4c
changes in generated folder
Deekshitha981 Dec 20, 2024
13124c2
Merge branch 'master' into users/v-dmerugu/AddingAuthorizationForGith…
Deekshitha981 Dec 24, 2024
2d1d3ef
Merge branch 'master' into users/v-dmerugu/AddingAuthorizationForGith…
Deekshitha981 Dec 27, 2024
582b3b0
Addng Less genric error
Deekshitha981 Dec 30, 2024
c9df2fd
bump tas verson
Deekshitha981 Dec 30, 2024
c89ddf6
addng warnng
Deekshitha981 Dec 30, 2024
c9afc61
addng chld error class
Deekshitha981 Dec 30, 2024
653638a
Merge branch 'master' into users/v-dmerugu/AddingAuthorizationForGith…
Deekshitha981 Jan 3, 2025
c5292fc
Merge branch 'master' into users/v-dmerugu/AddingAuthorizationForGith…
Deekshitha981 Jan 6, 2025
9e2b694
Merge branch 'master' into users/v-dmerugu/AddingAuthorizationForGith…
Deekshitha981 Jan 6, 2025
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
71 changes: 39 additions & 32 deletions Tasks/KubeloginInstallerV0/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion Tasks/KubeloginInstallerV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 247,
"Minor": 251,
"Patch": 0
},
"demands": [],
Expand All @@ -30,6 +30,14 @@
"label": "kubelogin version",
"defaultValue": "latest",
"helpMarkDown": "The version of kubelogin to use"
},
{
"name": "gitHubConnection",
"type": "connectedService:github:OAuth,OAuth2,PersonalAccessToken,InstallationToken,Token",
"label": "GitHub Connection",
"defaultValue": "",
"required": false,
"helpMarkDown": "A GitHub connection is needed to prevent anonymous requests limits to the Github API for [Azure/kubelogin](https://github.com/azure/kubelogin) from impacting the installation. Leaving this empty may cause failures if the request limit is reached. This connection does not require ANY permissions."
}
],
"execution": {
Expand Down
10 changes: 9 additions & 1 deletion Tasks/KubeloginInstallerV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 247,
"Minor": 251,
"Patch": 0
},
"demands": [],
Expand All @@ -30,6 +30,14 @@
"label": "ms-resource:loc.input.label.kubeloginVersion",
"defaultValue": "latest",
"helpMarkDown": "ms-resource:loc.input.help.kubeloginVersion"
},
{
"name": "gitHubConnection",
"type": "connectedService:github:OAuth,OAuth2,PersonalAccessToken,InstallationToken,Token",
"label": "ms-resource:loc.input.label.gitHubConnection",
"defaultValue": "",
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.gitHubConnection"
}
],
"execution": {
Expand Down
47 changes: 47 additions & 0 deletions Tasks/KubeloginInstallerV0/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,23 @@ export function isLatestVersion(version: string): boolean {
return v === 'latest' || v === '*' || v === '';
}

function addAuthorizationHeaderIfEnabled(request: webClient.WebRequest): void {
if (taskLib.getBoolFeatureFlag('USE_AUTHORIZATION_FOR_API_CALL')) {
const token = getGithubEndPointToken();
if (token) {
request.headers['Authorization'] = 'token ' + token;
}
}
}

export async function getLatestVersionTag(): Promise<string> {
let request = new webClient.WebRequest();
request.uri = 'https://api.github.com/repos/' + KUBELOGIN_REPO_OWNER + '/' + KUBELOGIN_REPO + '/releases/latest';
request.method = 'GET';
request.headers = request.headers || {};
request.headers['User-Agent'] = userAgent;

addAuthorizationHeaderIfEnabled(request);
const response = await webClient.sendRequest(request);
return response.body['tag_name'];
}
Expand Down Expand Up @@ -85,6 +95,7 @@ export async function getKubeloginRelease(version: string = 'latest', platform?:
request.headers = request.headers || {};
request.headers['User-Agent'] = userAgent;

addAuthorizationHeaderIfEnabled(request);
const response = await webClient.sendRequest(request);

const releaseUrl: string =
Expand Down Expand Up @@ -134,6 +145,42 @@ export async function unzipRelease(zipPath: string): Promise<string> {
}
}

function getGithubEndPointToken(): string {
const githubEndpoint = taskLib.getInput("gitHubConnection", false);
const githubEndpointObject = taskLib.getEndpointAuthorization(githubEndpoint, true);
let githubEndpointToken: string = null;

if (!githubEndpointObject) {
throw new GitHubEndpointError(taskLib.loc("Failed to retrieve GitHub endpoint object."));
}
taskLib.debug("Endpoint scheme: " + githubEndpointObject.scheme);

switch (githubEndpointObject.scheme) {
case 'PersonalAccessToken':
githubEndpointToken = githubEndpointObject.parameters.accessToken;
break;
case 'OAuth':
githubEndpointToken = githubEndpointObject.parameters.accessToken;
break;
case 'Token':
githubEndpointToken = githubEndpointObject.parameters.accessToken;
break;
default:
throw new Error(
z00sts marked this conversation as resolved.
Show resolved Hide resolved
taskLib.loc("InvalidEndpointAuthScheme", githubEndpointObject.scheme)
);
}
z00sts marked this conversation as resolved.
Show resolved Hide resolved
return githubEndpointToken;
}

class GitHubEndpointError extends Error {
constructor(message: string) {
super(message);
this.name = "GitHubEndpointError";
Object.setPrototypeOf(this, GitHubEndpointError.prototype);
}
}

export function getKubeloginPath(inputPath: string, fileName: string): string | undefined {
const files: string[] = fs.readdirSync(inputPath);
for (const file of files) {
Expand Down
4 changes: 2 additions & 2 deletions _generated/KubeloginInstallerV0.versionmap.txt
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.251.0
Node20_229_3|0.251.1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"loc.instanceNameFormat": "Install Kubelogin $(kubeloginVersion)",
"loc.input.label.kubeloginVersion": "kubelogin version",
"loc.input.help.kubeloginVersion": "The version of kubelogin to use",
"loc.input.label.gitHubConnection": "GitHub Connection",
"loc.input.help.gitHubConnection": "A GitHub connection is needed to prevent anonymous requests limits to the Github API for [Azure/kubelogin](https://github.com/azure/kubelogin) from impacting the installation. Leaving this empty may cause failures if the request limit is reached. This connection does not require ANY permissions.",
"loc.messages.Info_VerifyKubeloginInstallation": "Verifying kubelogin installation...",
"loc.messages.Info_ResolvedToolFromCache": "Resolved from tool cache: %s",
"loc.messages.Info_UsingToolPath": "Using tool path: %s",
Expand Down
71 changes: 39 additions & 32 deletions _generated/KubeloginInstallerV0/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions _generated/KubeloginInstallerV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 247,
"Minor": 251,
"Patch": 0
},
"demands": [],
Expand All @@ -30,6 +30,14 @@
"label": "kubelogin version",
"defaultValue": "latest",
"helpMarkDown": "The version of kubelogin to use"
},
{
"name": "gitHubConnection",
"type": "connectedService:github:OAuth,OAuth2,PersonalAccessToken,InstallationToken,Token",
"label": "GitHub Connection",
"defaultValue": "",
"required": false,
"helpMarkDown": "A GitHub connection is needed to prevent anonymous requests limits to the Github API for [Azure/kubelogin](https://github.com/azure/kubelogin) from impacting the installation. Leaving this empty may cause failures if the request limit is reached. This connection does not require ANY permissions."
}
],
"execution": {
Expand Down Expand Up @@ -59,7 +67,7 @@
"Info_KubeloginDownloading": "Downloading kubelogin"
},
"_buildConfigMapping": {
"Default": "0.247.0",
"Node20_229_3": "0.247.1"
"Default": "0.251.0",
"Node20_229_3": "0.251.1"
}
}
14 changes: 11 additions & 3 deletions _generated/KubeloginInstallerV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 247,
"Minor": 251,
"Patch": 0
},
"demands": [],
Expand All @@ -30,6 +30,14 @@
"label": "ms-resource:loc.input.label.kubeloginVersion",
"defaultValue": "latest",
"helpMarkDown": "ms-resource:loc.input.help.kubeloginVersion"
},
{
"name": "gitHubConnection",
"type": "connectedService:github:OAuth,OAuth2,PersonalAccessToken,InstallationToken,Token",
"label": "ms-resource:loc.input.label.gitHubConnection",
"defaultValue": "",
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.gitHubConnection"
}
],
"execution": {
Expand Down Expand Up @@ -59,7 +67,7 @@
"Info_KubeloginDownloading": "ms-resource:loc.messages.Info_KubeloginDownloading"
},
"_buildConfigMapping": {
"Default": "0.247.0",
"Node20_229_3": "0.247.1"
"Default": "0.251.0",
"Node20_229_3": "0.251.1"
}
}
Loading