From 288ec953b0ea803ccdf56c51db880bd92ad9680d Mon Sep 17 00:00:00 2001 From: "Deeksitha Merugu (LTIMINDTREE LIMITED)" Date: Wed, 11 Dec 2024 14:57:58 +0530 Subject: [PATCH 1/8] Adding Authorization for Github api call In KubeLoginInstallerV0 --- Tasks/KubeloginInstallerV0/package-lock.json | 71 ++++++++++--------- Tasks/KubeloginInstallerV0/task.json | 10 ++- Tasks/KubeloginInstallerV0/task.loc.json | 2 +- Tasks/KubeloginInstallerV0/utils.ts | 42 +++++++++++ .../KubeloginInstallerV0.versionmap.txt | 4 +- .../resources.resjson/en-US/resources.resjson | 2 + .../KubeloginInstallerV0/package-lock.json | 71 ++++++++++--------- _generated/KubeloginInstallerV0/task.json | 14 +++- _generated/KubeloginInstallerV0/task.loc.json | 14 +++- _generated/KubeloginInstallerV0/utils.ts | 42 +++++++++++ .../resources.resjson/en-US/resources.resjson | 2 + .../KubeloginInstallerV0_Node20/task.json | 14 +++- .../KubeloginInstallerV0_Node20/task.loc.json | 14 +++- .../KubeloginInstallerV0_Node20/utils.ts | 42 +++++++++++ 14 files changed, 264 insertions(+), 80 deletions(-) diff --git a/Tasks/KubeloginInstallerV0/package-lock.json b/Tasks/KubeloginInstallerV0/package-lock.json index 70db12877c0e..c2ebfe71b642 100644 --- a/Tasks/KubeloginInstallerV0/package-lock.json +++ b/Tasks/KubeloginInstallerV0/package-lock.json @@ -133,33 +133,6 @@ "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@types/q/-/q-1.5.4.tgz", "integrity": "sha512-1HcDas8SEj4z1Wc696tH56G8OlRaH/sqZOynNNB+HF0WOeXPaxTtbYzJY2oEfiUxjSKjhCKr+MvR7dCHcEelug==" }, - "msalv1": { - "version": "npm:@azure/msal-node@1.18.4", - "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@azure/msal-node/-/msal-node-1.18.4.tgz", - "integrity": "sha1-ySGwRHyS+zsMsev1qadvytLsfCE=", - "requires": { - "@azure/msal-common": "13.3.1", - "jsonwebtoken": "^9.0.0", - "uuid": "^8.3.0" - } - }, - "msalv2": { - "version": "npm:@azure/msal-node@2.15.0", - "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@azure/msal-node/-/msal-node-2.15.0.tgz", - "integrity": "sha1-UL+OaSpmVgJ8Bzp12HeopHiq/f0=", - "requires": { - "@azure/msal-common": "14.15.0", - "jsonwebtoken": "^9.0.0", - "uuid": "^8.3.0" - }, - "dependencies": { - "@azure/msal-common": { - "version": "14.15.0", - "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@azure/msal-common/-/msal-common-14.15.0.tgz", - "integrity": "sha1-DiesC7iP4QD0+NFgW2TVwmhjalU=" - } - } - }, "typed-rest-client": { "version": "2.0.2", "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/typed-rest-client/-/typed-rest-client-2.0.2.tgz", @@ -171,11 +144,6 @@ "tunnel": "0.0.6", "underscore": "^1.12.1" } - }, - "uuid": { - "version": "8.3.2", - "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha1-gNW1ztJxu5r2xEXyGhoExgbO++I=" } } }, @@ -498,6 +466,45 @@ "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, + "msalv1": { + "version": "npm:@azure/msal-node@1.18.4", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@azure/msal-node/-/msal-node-1.18.4.tgz", + "integrity": "sha1-ySGwRHyS+zsMsev1qadvytLsfCE=", + "requires": { + "@azure/msal-common": "13.3.1", + "jsonwebtoken": "^9.0.0", + "uuid": "^8.3.0" + }, + "dependencies": { + "uuid": { + "version": "8.3.2", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha1-gNW1ztJxu5r2xEXyGhoExgbO++I=" + } + } + }, + "msalv2": { + "version": "npm:@azure/msal-node@2.16.2", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@azure/msal-node/-/msal-node-2.16.2.tgz", + "integrity": "sha1-Prdo02iD6m+ak5wLW0Z7UY54//w=", + "requires": { + "@azure/msal-common": "14.16.0", + "jsonwebtoken": "^9.0.0", + "uuid": "^8.3.0" + }, + "dependencies": { + "@azure/msal-common": { + "version": "14.16.0", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@azure/msal-common/-/msal-common-14.16.0.tgz", + "integrity": "sha1-80cPyux4jb5QhZlSzUmTQL2iPXo=" + }, + "uuid": { + "version": "8.3.2", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha1-gNW1ztJxu5r2xEXyGhoExgbO++I=" + } + } + }, "node-addon-api": { "version": "1.7.2", "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/node-addon-api/-/node-addon-api-1.7.2.tgz", diff --git a/Tasks/KubeloginInstallerV0/task.json b/Tasks/KubeloginInstallerV0/task.json index e12220422333..059acd5d4cfc 100644 --- a/Tasks/KubeloginInstallerV0/task.json +++ b/Tasks/KubeloginInstallerV0/task.json @@ -15,7 +15,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 247, + "Minor": 249, "Patch": 0 }, "demands": [], @@ -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": { diff --git a/Tasks/KubeloginInstallerV0/task.loc.json b/Tasks/KubeloginInstallerV0/task.loc.json index e43960d4a41b..3b7ff2f4f67a 100644 --- a/Tasks/KubeloginInstallerV0/task.loc.json +++ b/Tasks/KubeloginInstallerV0/task.loc.json @@ -15,7 +15,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 247, + "Minor": 249, "Patch": 0 }, "demands": [], diff --git a/Tasks/KubeloginInstallerV0/utils.ts b/Tasks/KubeloginInstallerV0/utils.ts index f64238f1ddcb..616015cee502 100644 --- a/Tasks/KubeloginInstallerV0/utils.ts +++ b/Tasks/KubeloginInstallerV0/utils.ts @@ -54,6 +54,12 @@ export async function getLatestVersionTag(): Promise { 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('CUSE_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 { } } +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)); + } + } + + return githubEndpointToken; +} +catch(error) +{ + throw new Error(taskLib.loc("Failed to retrieve GitHub endpoint token:", error.message)); +} +} + export function getKubeloginPath(inputPath: string, fileName: string): string | undefined { const files: string[] = fs.readdirSync(inputPath); for (const file of files) { diff --git a/_generated/KubeloginInstallerV0.versionmap.txt b/_generated/KubeloginInstallerV0.versionmap.txt index 789c1d8a7110..b55ce6d9ec22 100644 --- a/_generated/KubeloginInstallerV0.versionmap.txt +++ b/_generated/KubeloginInstallerV0.versionmap.txt @@ -1,2 +1,2 @@ -Default|0.247.0 -Node20_229_3|0.247.1 +Default|0.249.0 +Node20_229_3|0.249.1 diff --git a/_generated/KubeloginInstallerV0/Strings/resources.resjson/en-US/resources.resjson b/_generated/KubeloginInstallerV0/Strings/resources.resjson/en-US/resources.resjson index aba569a00356..a5b60ea9a2d3 100644 --- a/_generated/KubeloginInstallerV0/Strings/resources.resjson/en-US/resources.resjson +++ b/_generated/KubeloginInstallerV0/Strings/resources.resjson/en-US/resources.resjson @@ -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", diff --git a/_generated/KubeloginInstallerV0/package-lock.json b/_generated/KubeloginInstallerV0/package-lock.json index 70db12877c0e..c2ebfe71b642 100644 --- a/_generated/KubeloginInstallerV0/package-lock.json +++ b/_generated/KubeloginInstallerV0/package-lock.json @@ -133,33 +133,6 @@ "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@types/q/-/q-1.5.4.tgz", "integrity": "sha512-1HcDas8SEj4z1Wc696tH56G8OlRaH/sqZOynNNB+HF0WOeXPaxTtbYzJY2oEfiUxjSKjhCKr+MvR7dCHcEelug==" }, - "msalv1": { - "version": "npm:@azure/msal-node@1.18.4", - "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@azure/msal-node/-/msal-node-1.18.4.tgz", - "integrity": "sha1-ySGwRHyS+zsMsev1qadvytLsfCE=", - "requires": { - "@azure/msal-common": "13.3.1", - "jsonwebtoken": "^9.0.0", - "uuid": "^8.3.0" - } - }, - "msalv2": { - "version": "npm:@azure/msal-node@2.15.0", - "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@azure/msal-node/-/msal-node-2.15.0.tgz", - "integrity": "sha1-UL+OaSpmVgJ8Bzp12HeopHiq/f0=", - "requires": { - "@azure/msal-common": "14.15.0", - "jsonwebtoken": "^9.0.0", - "uuid": "^8.3.0" - }, - "dependencies": { - "@azure/msal-common": { - "version": "14.15.0", - "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@azure/msal-common/-/msal-common-14.15.0.tgz", - "integrity": "sha1-DiesC7iP4QD0+NFgW2TVwmhjalU=" - } - } - }, "typed-rest-client": { "version": "2.0.2", "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/typed-rest-client/-/typed-rest-client-2.0.2.tgz", @@ -171,11 +144,6 @@ "tunnel": "0.0.6", "underscore": "^1.12.1" } - }, - "uuid": { - "version": "8.3.2", - "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha1-gNW1ztJxu5r2xEXyGhoExgbO++I=" } } }, @@ -498,6 +466,45 @@ "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, + "msalv1": { + "version": "npm:@azure/msal-node@1.18.4", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@azure/msal-node/-/msal-node-1.18.4.tgz", + "integrity": "sha1-ySGwRHyS+zsMsev1qadvytLsfCE=", + "requires": { + "@azure/msal-common": "13.3.1", + "jsonwebtoken": "^9.0.0", + "uuid": "^8.3.0" + }, + "dependencies": { + "uuid": { + "version": "8.3.2", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha1-gNW1ztJxu5r2xEXyGhoExgbO++I=" + } + } + }, + "msalv2": { + "version": "npm:@azure/msal-node@2.16.2", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@azure/msal-node/-/msal-node-2.16.2.tgz", + "integrity": "sha1-Prdo02iD6m+ak5wLW0Z7UY54//w=", + "requires": { + "@azure/msal-common": "14.16.0", + "jsonwebtoken": "^9.0.0", + "uuid": "^8.3.0" + }, + "dependencies": { + "@azure/msal-common": { + "version": "14.16.0", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@azure/msal-common/-/msal-common-14.16.0.tgz", + "integrity": "sha1-80cPyux4jb5QhZlSzUmTQL2iPXo=" + }, + "uuid": { + "version": "8.3.2", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha1-gNW1ztJxu5r2xEXyGhoExgbO++I=" + } + } + }, "node-addon-api": { "version": "1.7.2", "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/node-addon-api/-/node-addon-api-1.7.2.tgz", diff --git a/_generated/KubeloginInstallerV0/task.json b/_generated/KubeloginInstallerV0/task.json index 35770ff4dca7..0099cf0b3899 100644 --- a/_generated/KubeloginInstallerV0/task.json +++ b/_generated/KubeloginInstallerV0/task.json @@ -15,7 +15,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 247, + "Minor": 249, "Patch": 0 }, "demands": [], @@ -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": { @@ -59,7 +67,7 @@ "Info_KubeloginDownloading": "Downloading kubelogin" }, "_buildConfigMapping": { - "Default": "0.247.0", - "Node20_229_3": "0.247.1" + "Default": "0.249.0", + "Node20_229_3": "0.249.1" } } \ No newline at end of file diff --git a/_generated/KubeloginInstallerV0/task.loc.json b/_generated/KubeloginInstallerV0/task.loc.json index 8ae47f2c6661..6ff909d3ab4b 100644 --- a/_generated/KubeloginInstallerV0/task.loc.json +++ b/_generated/KubeloginInstallerV0/task.loc.json @@ -15,7 +15,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 247, + "Minor": 249, "Patch": 0 }, "demands": [], @@ -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": { @@ -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.249.0", + "Node20_229_3": "0.249.1" } } \ No newline at end of file diff --git a/_generated/KubeloginInstallerV0/utils.ts b/_generated/KubeloginInstallerV0/utils.ts index f64238f1ddcb..616015cee502 100644 --- a/_generated/KubeloginInstallerV0/utils.ts +++ b/_generated/KubeloginInstallerV0/utils.ts @@ -54,6 +54,12 @@ export async function getLatestVersionTag(): Promise { 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('CUSE_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 { } } +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)); + } + } + + return githubEndpointToken; +} +catch(error) +{ + throw new Error(taskLib.loc("Failed to retrieve GitHub endpoint token:", error.message)); +} +} + export function getKubeloginPath(inputPath: string, fileName: string): string | undefined { const files: string[] = fs.readdirSync(inputPath); for (const file of files) { diff --git a/_generated/KubeloginInstallerV0_Node20/Strings/resources.resjson/en-US/resources.resjson b/_generated/KubeloginInstallerV0_Node20/Strings/resources.resjson/en-US/resources.resjson index aba569a00356..a5b60ea9a2d3 100644 --- a/_generated/KubeloginInstallerV0_Node20/Strings/resources.resjson/en-US/resources.resjson +++ b/_generated/KubeloginInstallerV0_Node20/Strings/resources.resjson/en-US/resources.resjson @@ -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", diff --git a/_generated/KubeloginInstallerV0_Node20/task.json b/_generated/KubeloginInstallerV0_Node20/task.json index 23ced71d304d..9144e4ad6e8d 100644 --- a/_generated/KubeloginInstallerV0_Node20/task.json +++ b/_generated/KubeloginInstallerV0_Node20/task.json @@ -15,7 +15,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 247, + "Minor": 249, "Patch": 1 }, "demands": [], @@ -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": { @@ -63,7 +71,7 @@ "Info_KubeloginDownloading": "Downloading kubelogin" }, "_buildConfigMapping": { - "Default": "0.247.0", - "Node20_229_3": "0.247.1" + "Default": "0.249.0", + "Node20_229_3": "0.249.1" } } \ No newline at end of file diff --git a/_generated/KubeloginInstallerV0_Node20/task.loc.json b/_generated/KubeloginInstallerV0_Node20/task.loc.json index 2a9a2eedfe86..c829343fd8e2 100644 --- a/_generated/KubeloginInstallerV0_Node20/task.loc.json +++ b/_generated/KubeloginInstallerV0_Node20/task.loc.json @@ -15,7 +15,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 247, + "Minor": 249, "Patch": 1 }, "demands": [], @@ -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": { @@ -63,7 +71,7 @@ "Info_KubeloginDownloading": "ms-resource:loc.messages.Info_KubeloginDownloading" }, "_buildConfigMapping": { - "Default": "0.247.0", - "Node20_229_3": "0.247.1" + "Default": "0.249.0", + "Node20_229_3": "0.249.1" } } \ No newline at end of file diff --git a/_generated/KubeloginInstallerV0_Node20/utils.ts b/_generated/KubeloginInstallerV0_Node20/utils.ts index f64238f1ddcb..616015cee502 100644 --- a/_generated/KubeloginInstallerV0_Node20/utils.ts +++ b/_generated/KubeloginInstallerV0_Node20/utils.ts @@ -54,6 +54,12 @@ export async function getLatestVersionTag(): Promise { 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('CUSE_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 { } } +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)); + } + } + + return githubEndpointToken; +} +catch(error) +{ + throw new Error(taskLib.loc("Failed to retrieve GitHub endpoint token:", error.message)); +} +} + export function getKubeloginPath(inputPath: string, fileName: string): string | undefined { const files: string[] = fs.readdirSync(inputPath); for (const file of files) { From 6840c034cfa0c2f29e7b9792134bc06d01ae164e Mon Sep 17 00:00:00 2001 From: "Deeksitha Merugu (LTIMINDTREE LIMITED)" Date: Wed, 11 Dec 2024 15:38:06 +0530 Subject: [PATCH 2/8] Changing minor version --- Tasks/KubeloginInstallerV0/task.json | 2 +- Tasks/KubeloginInstallerV0/task.loc.json | 2 +- _generated/KubeloginInstallerV0.versionmap.txt | 4 ++-- _generated/KubeloginInstallerV0/task.json | 6 +++--- _generated/KubeloginInstallerV0/task.loc.json | 6 +++--- _generated/KubeloginInstallerV0_Node20/.npmrc | 4 ++++ _generated/KubeloginInstallerV0_Node20/task.json | 6 +++--- _generated/KubeloginInstallerV0_Node20/task.loc.json | 6 +++--- 8 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Tasks/KubeloginInstallerV0/task.json b/Tasks/KubeloginInstallerV0/task.json index 059acd5d4cfc..23b04948fffb 100644 --- a/Tasks/KubeloginInstallerV0/task.json +++ b/Tasks/KubeloginInstallerV0/task.json @@ -15,7 +15,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 249, + "Minor": 250, "Patch": 0 }, "demands": [], diff --git a/Tasks/KubeloginInstallerV0/task.loc.json b/Tasks/KubeloginInstallerV0/task.loc.json index 3b7ff2f4f67a..c8e8ee1d1d37 100644 --- a/Tasks/KubeloginInstallerV0/task.loc.json +++ b/Tasks/KubeloginInstallerV0/task.loc.json @@ -15,7 +15,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 249, + "Minor": 250, "Patch": 0 }, "demands": [], diff --git a/_generated/KubeloginInstallerV0.versionmap.txt b/_generated/KubeloginInstallerV0.versionmap.txt index b55ce6d9ec22..c7bfaef441f8 100644 --- a/_generated/KubeloginInstallerV0.versionmap.txt +++ b/_generated/KubeloginInstallerV0.versionmap.txt @@ -1,2 +1,2 @@ -Default|0.249.0 -Node20_229_3|0.249.1 +Default|0.250.0 +Node20_229_3|0.250.1 diff --git a/_generated/KubeloginInstallerV0/task.json b/_generated/KubeloginInstallerV0/task.json index 0099cf0b3899..4075b92b591b 100644 --- a/_generated/KubeloginInstallerV0/task.json +++ b/_generated/KubeloginInstallerV0/task.json @@ -15,7 +15,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 249, + "Minor": 250, "Patch": 0 }, "demands": [], @@ -67,7 +67,7 @@ "Info_KubeloginDownloading": "Downloading kubelogin" }, "_buildConfigMapping": { - "Default": "0.249.0", - "Node20_229_3": "0.249.1" + "Default": "0.250.0", + "Node20_229_3": "0.250.1" } } \ No newline at end of file diff --git a/_generated/KubeloginInstallerV0/task.loc.json b/_generated/KubeloginInstallerV0/task.loc.json index 6ff909d3ab4b..d319a30e11ce 100644 --- a/_generated/KubeloginInstallerV0/task.loc.json +++ b/_generated/KubeloginInstallerV0/task.loc.json @@ -15,7 +15,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 249, + "Minor": 250, "Patch": 0 }, "demands": [], @@ -67,7 +67,7 @@ "Info_KubeloginDownloading": "ms-resource:loc.messages.Info_KubeloginDownloading" }, "_buildConfigMapping": { - "Default": "0.249.0", - "Node20_229_3": "0.249.1" + "Default": "0.250.0", + "Node20_229_3": "0.250.1" } } \ No newline at end of file diff --git a/_generated/KubeloginInstallerV0_Node20/.npmrc b/_generated/KubeloginInstallerV0_Node20/.npmrc index 5fca0d518be7..d5c7fef620a3 100644 --- a/_generated/KubeloginInstallerV0_Node20/.npmrc +++ b/_generated/KubeloginInstallerV0_Node20/.npmrc @@ -1 +1,5 @@ scripts-prepend-node-path=true + +registry=https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/ + +always-auth=true \ No newline at end of file diff --git a/_generated/KubeloginInstallerV0_Node20/task.json b/_generated/KubeloginInstallerV0_Node20/task.json index 9144e4ad6e8d..ead5f2d415e3 100644 --- a/_generated/KubeloginInstallerV0_Node20/task.json +++ b/_generated/KubeloginInstallerV0_Node20/task.json @@ -15,7 +15,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 249, + "Minor": 250, "Patch": 1 }, "demands": [], @@ -71,7 +71,7 @@ "Info_KubeloginDownloading": "Downloading kubelogin" }, "_buildConfigMapping": { - "Default": "0.249.0", - "Node20_229_3": "0.249.1" + "Default": "0.250.0", + "Node20_229_3": "0.250.1" } } \ No newline at end of file diff --git a/_generated/KubeloginInstallerV0_Node20/task.loc.json b/_generated/KubeloginInstallerV0_Node20/task.loc.json index c829343fd8e2..d30c7b557765 100644 --- a/_generated/KubeloginInstallerV0_Node20/task.loc.json +++ b/_generated/KubeloginInstallerV0_Node20/task.loc.json @@ -15,7 +15,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 249, + "Minor": 250, "Patch": 1 }, "demands": [], @@ -71,7 +71,7 @@ "Info_KubeloginDownloading": "ms-resource:loc.messages.Info_KubeloginDownloading" }, "_buildConfigMapping": { - "Default": "0.249.0", - "Node20_229_3": "0.249.1" + "Default": "0.250.0", + "Node20_229_3": "0.250.1" } } \ No newline at end of file From bc37dbeccc809cdbec8b74f2d8fa4a00cb9645bc Mon Sep 17 00:00:00 2001 From: "Deeksitha Merugu (LTIMINDTREE LIMITED)" Date: Wed, 11 Dec 2024 16:49:46 +0530 Subject: [PATCH 3/8] changing task-loc.json --- Tasks/KubeloginInstallerV0/task.loc.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tasks/KubeloginInstallerV0/task.loc.json b/Tasks/KubeloginInstallerV0/task.loc.json index c8e8ee1d1d37..133f42aa928a 100644 --- a/Tasks/KubeloginInstallerV0/task.loc.json +++ b/Tasks/KubeloginInstallerV0/task.loc.json @@ -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": "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": { From 88e3de89712e103858166266eb606e0fc8095069 Mon Sep 17 00:00:00 2001 From: "Deeksitha Merugu (LTIMINDTREE LIMITED)" Date: Wed, 11 Dec 2024 17:12:17 +0530 Subject: [PATCH 4/8] correcting FF name --- Tasks/KubeloginInstallerV0/utils.ts | 2 +- _generated/KubeloginInstallerV0/utils.ts | 2 +- _generated/KubeloginInstallerV0_Node20/utils.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tasks/KubeloginInstallerV0/utils.ts b/Tasks/KubeloginInstallerV0/utils.ts index 616015cee502..02f535badc23 100644 --- a/Tasks/KubeloginInstallerV0/utils.ts +++ b/Tasks/KubeloginInstallerV0/utils.ts @@ -90,7 +90,7 @@ export async function getKubeloginRelease(version: string = 'latest', platform?: request.method = 'GET'; request.headers = request.headers || {}; request.headers['User-Agent'] = userAgent; - if (taskLib.getBoolFeatureFlag('CUSE_AUTHORIZATION_FOR_API_CALL')){ + if (taskLib.getBoolFeatureFlag('USE_AUTHORIZATION_FOR_API_CALL')){ const token = getGithubEndPointToken(); if (token) { request.headers['Authorization'] = 'token ' + token; diff --git a/_generated/KubeloginInstallerV0/utils.ts b/_generated/KubeloginInstallerV0/utils.ts index 616015cee502..02f535badc23 100644 --- a/_generated/KubeloginInstallerV0/utils.ts +++ b/_generated/KubeloginInstallerV0/utils.ts @@ -90,7 +90,7 @@ export async function getKubeloginRelease(version: string = 'latest', platform?: request.method = 'GET'; request.headers = request.headers || {}; request.headers['User-Agent'] = userAgent; - if (taskLib.getBoolFeatureFlag('CUSE_AUTHORIZATION_FOR_API_CALL')){ + if (taskLib.getBoolFeatureFlag('USE_AUTHORIZATION_FOR_API_CALL')){ const token = getGithubEndPointToken(); if (token) { request.headers['Authorization'] = 'token ' + token; diff --git a/_generated/KubeloginInstallerV0_Node20/utils.ts b/_generated/KubeloginInstallerV0_Node20/utils.ts index 616015cee502..02f535badc23 100644 --- a/_generated/KubeloginInstallerV0_Node20/utils.ts +++ b/_generated/KubeloginInstallerV0_Node20/utils.ts @@ -90,7 +90,7 @@ export async function getKubeloginRelease(version: string = 'latest', platform?: request.method = 'GET'; request.headers = request.headers || {}; request.headers['User-Agent'] = userAgent; - if (taskLib.getBoolFeatureFlag('CUSE_AUTHORIZATION_FOR_API_CALL')){ + if (taskLib.getBoolFeatureFlag('USE_AUTHORIZATION_FOR_API_CALL')){ const token = getGithubEndPointToken(); if (token) { request.headers['Authorization'] = 'token ' + token; From 9f2816dadb43486d9f109e9cd8a9a2c4a8e6e3d3 Mon Sep 17 00:00:00 2001 From: "Deeksitha Merugu (LTIMINDTREE LIMITED)" Date: Wed, 11 Dec 2024 18:35:05 +0530 Subject: [PATCH 5/8] changing task-loc.json --- Tasks/KubeloginInstallerV0/task.loc.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tasks/KubeloginInstallerV0/task.loc.json b/Tasks/KubeloginInstallerV0/task.loc.json index 133f42aa928a..99e7b3ec877a 100644 --- a/Tasks/KubeloginInstallerV0/task.loc.json +++ b/Tasks/KubeloginInstallerV0/task.loc.json @@ -32,12 +32,12 @@ "helpMarkDown": "ms-resource:loc.input.help.kubeloginVersion" }, { - "name": "gitHubConnection", - "type": "connectedService:github:OAuth,OAuth2,PersonalAccessToken,InstallationToken,Token", - "label": "GitHub Connection", - "defaultValue": "", + "name": "namespace", + "type": "string", + "label": "ms-resource:loc.input.label.namespace", "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." + "defaultValue": "", + "helpMarkDown": "ms-resource:loc.input.help.namespace" } ], "execution": { From 4bb651fa5ac999b85d85d7be9c90732473d7a8b9 Mon Sep 17 00:00:00 2001 From: "Deeksitha Merugu (LTIMINDTREE LIMITED)" Date: Thu, 12 Dec 2024 11:21:08 +0530 Subject: [PATCH 6/8] modifyng tasloc fle --- Tasks/KubeloginInstallerV0/task.loc.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tasks/KubeloginInstallerV0/task.loc.json b/Tasks/KubeloginInstallerV0/task.loc.json index 99e7b3ec877a..4a7fce0a5776 100644 --- a/Tasks/KubeloginInstallerV0/task.loc.json +++ b/Tasks/KubeloginInstallerV0/task.loc.json @@ -32,12 +32,12 @@ "helpMarkDown": "ms-resource:loc.input.help.kubeloginVersion" }, { - "name": "namespace", - "type": "string", - "label": "ms-resource:loc.input.label.namespace", - "required": false, + "name": "gitHubConnection", + "type": "connectedService:github:OAuth,OAuth2,PersonalAccessToken,InstallationToken,Token", + "label": "ms-resource:loc.input.label.gitHubConnection", "defaultValue": "", - "helpMarkDown": "ms-resource:loc.input.help.namespace" + "required": false, + "helpMarkDown": "ms-resource:loc.input.help.gitHubConnection" } ], "execution": { From f5bf48807e937cfe5add09a12a42dd3b68740383 Mon Sep 17 00:00:00 2001 From: "Deeksitha Merugu (LTIMINDTREE LIMITED)" Date: Fri, 20 Dec 2024 19:57:23 +0530 Subject: [PATCH 7/8] modifying the logic --- Tasks/KubeloginInstallerV0/utils.ts | 67 +++++++++--------- _generated/KubeloginInstallerV0/utils.ts | 69 +++++++++---------- .../KubeloginInstallerV0_Node20/utils.ts | 69 +++++++++---------- 3 files changed, 100 insertions(+), 105 deletions(-) diff --git a/Tasks/KubeloginInstallerV0/utils.ts b/Tasks/KubeloginInstallerV0/utils.ts index 02f535badc23..aeca07f0a3dd 100644 --- a/Tasks/KubeloginInstallerV0/utils.ts +++ b/Tasks/KubeloginInstallerV0/utils.ts @@ -47,6 +47,15 @@ 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 { let request = new webClient.WebRequest(); request.uri = 'https://api.github.com/repos/' + KUBELOGIN_REPO_OWNER + '/' + KUBELOGIN_REPO + '/releases/latest'; @@ -54,12 +63,7 @@ export async function getLatestVersionTag(): Promise { 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; - } - } + addAuthorizationHeaderIfEnabled(request); const response = await webClient.sendRequest(request); return response.body['tag_name']; } @@ -90,13 +94,8 @@ 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; - } - } + addAuthorizationHeaderIfEnabled(request); const response = await webClient.sendRequest(request); const releaseUrl: string = @@ -147,33 +146,31 @@ export async function unzipRelease(zipPath: string): Promise { } function getGithubEndPointToken(): string { - try{ - const githubEndpoint = taskLib.getInput("gitHubConnection", false); - const githubEndpointObject = taskLib.getEndpointAuthorization(githubEndpoint, true); - let githubEndpointToken: string = null; + const githubEndpoint = taskLib.getInput("gitHubConnection", false); + const githubEndpointObject = taskLib.getEndpointAuthorization(githubEndpoint, true); + let githubEndpointToken: string = null; - if (!!githubEndpointObject) { + if (!githubEndpointObject) { + throw new Error(taskLib.loc("Failed to retrieve GitHub endpoint object.")); + } 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)); + 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( + taskLib.loc("InvalidEndpointAuthScheme", githubEndpointObject.scheme) + ); } - } - - return githubEndpointToken; -} -catch(error) -{ - throw new Error(taskLib.loc("Failed to retrieve GitHub endpoint token:", error.message)); -} + return githubEndpointToken; } export function getKubeloginPath(inputPath: string, fileName: string): string | undefined { diff --git a/_generated/KubeloginInstallerV0/utils.ts b/_generated/KubeloginInstallerV0/utils.ts index 02f535badc23..f68dc9fbe003 100644 --- a/_generated/KubeloginInstallerV0/utils.ts +++ b/_generated/KubeloginInstallerV0/utils.ts @@ -47,6 +47,15 @@ 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 { let request = new webClient.WebRequest(); request.uri = 'https://api.github.com/repos/' + KUBELOGIN_REPO_OWNER + '/' + KUBELOGIN_REPO + '/releases/latest'; @@ -54,12 +63,7 @@ export async function getLatestVersionTag(): Promise { 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; - } - } + addAuthorizationHeaderIfEnabled(request); const response = await webClient.sendRequest(request); return response.body['tag_name']; } @@ -90,13 +94,8 @@ 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; - } - } + addAuthorizationHeaderIfEnabled(request); const response = await webClient.sendRequest(request); const releaseUrl: string = @@ -147,33 +146,33 @@ export async function unzipRelease(zipPath: string): Promise { } function getGithubEndPointToken(): string { - try{ - const githubEndpoint = taskLib.getInput("gitHubConnection", false); - const githubEndpointObject = taskLib.getEndpointAuthorization(githubEndpoint, true); - let githubEndpointToken: string = null; + const githubEndpoint = taskLib.getInput("gitHubConnection", false); + const githubEndpointObject = taskLib.getEndpointAuthorization(githubEndpoint, true); + let githubEndpointToken: string = null; - if (!!githubEndpointObject) { + if (!githubEndpointObject) { + throw new Error(taskLib.loc("Failed to retrieve GitHub endpoint object.")); + } 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)); + switch (githubEndpointObject.scheme) { + case 'PersonalAccessToken': + console.log("pat..."); + githubEndpointToken = githubEndpointObject.parameters.accessToken; + break; + case 'OAuth': + console.log("Oauth..."); + githubEndpointToken = githubEndpointObject.parameters.accessToken; + break; + case 'Token': + githubEndpointToken = githubEndpointObject.parameters.accessToken; + break; + default: + throw new Error( + taskLib.loc("InvalidEndpointAuthScheme", githubEndpointObject.scheme) + ); } - } - - return githubEndpointToken; -} -catch(error) -{ - throw new Error(taskLib.loc("Failed to retrieve GitHub endpoint token:", error.message)); -} + return githubEndpointToken; } export function getKubeloginPath(inputPath: string, fileName: string): string | undefined { diff --git a/_generated/KubeloginInstallerV0_Node20/utils.ts b/_generated/KubeloginInstallerV0_Node20/utils.ts index 02f535badc23..f68dc9fbe003 100644 --- a/_generated/KubeloginInstallerV0_Node20/utils.ts +++ b/_generated/KubeloginInstallerV0_Node20/utils.ts @@ -47,6 +47,15 @@ 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 { let request = new webClient.WebRequest(); request.uri = 'https://api.github.com/repos/' + KUBELOGIN_REPO_OWNER + '/' + KUBELOGIN_REPO + '/releases/latest'; @@ -54,12 +63,7 @@ export async function getLatestVersionTag(): Promise { 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; - } - } + addAuthorizationHeaderIfEnabled(request); const response = await webClient.sendRequest(request); return response.body['tag_name']; } @@ -90,13 +94,8 @@ 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; - } - } + addAuthorizationHeaderIfEnabled(request); const response = await webClient.sendRequest(request); const releaseUrl: string = @@ -147,33 +146,33 @@ export async function unzipRelease(zipPath: string): Promise { } function getGithubEndPointToken(): string { - try{ - const githubEndpoint = taskLib.getInput("gitHubConnection", false); - const githubEndpointObject = taskLib.getEndpointAuthorization(githubEndpoint, true); - let githubEndpointToken: string = null; + const githubEndpoint = taskLib.getInput("gitHubConnection", false); + const githubEndpointObject = taskLib.getEndpointAuthorization(githubEndpoint, true); + let githubEndpointToken: string = null; - if (!!githubEndpointObject) { + if (!githubEndpointObject) { + throw new Error(taskLib.loc("Failed to retrieve GitHub endpoint object.")); + } 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)); + switch (githubEndpointObject.scheme) { + case 'PersonalAccessToken': + console.log("pat..."); + githubEndpointToken = githubEndpointObject.parameters.accessToken; + break; + case 'OAuth': + console.log("Oauth..."); + githubEndpointToken = githubEndpointObject.parameters.accessToken; + break; + case 'Token': + githubEndpointToken = githubEndpointObject.parameters.accessToken; + break; + default: + throw new Error( + taskLib.loc("InvalidEndpointAuthScheme", githubEndpointObject.scheme) + ); } - } - - return githubEndpointToken; -} -catch(error) -{ - throw new Error(taskLib.loc("Failed to retrieve GitHub endpoint token:", error.message)); -} + return githubEndpointToken; } export function getKubeloginPath(inputPath: string, fileName: string): string | undefined { From 7699b4c701ba8a7ad40c964f08ac23bfef89af53 Mon Sep 17 00:00:00 2001 From: "Deeksitha Merugu (LTIMINDTREE LIMITED)" Date: Fri, 20 Dec 2024 20:32:36 +0530 Subject: [PATCH 8/8] changes in generated folder --- _generated/KubeloginInstallerV0/utils.ts | 2 -- _generated/KubeloginInstallerV0_Node20/utils.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/_generated/KubeloginInstallerV0/utils.ts b/_generated/KubeloginInstallerV0/utils.ts index f68dc9fbe003..aeca07f0a3dd 100644 --- a/_generated/KubeloginInstallerV0/utils.ts +++ b/_generated/KubeloginInstallerV0/utils.ts @@ -157,11 +157,9 @@ function getGithubEndPointToken(): string { switch (githubEndpointObject.scheme) { case 'PersonalAccessToken': - console.log("pat..."); githubEndpointToken = githubEndpointObject.parameters.accessToken; break; case 'OAuth': - console.log("Oauth..."); githubEndpointToken = githubEndpointObject.parameters.accessToken; break; case 'Token': diff --git a/_generated/KubeloginInstallerV0_Node20/utils.ts b/_generated/KubeloginInstallerV0_Node20/utils.ts index f68dc9fbe003..aeca07f0a3dd 100644 --- a/_generated/KubeloginInstallerV0_Node20/utils.ts +++ b/_generated/KubeloginInstallerV0_Node20/utils.ts @@ -157,11 +157,9 @@ function getGithubEndPointToken(): string { switch (githubEndpointObject.scheme) { case 'PersonalAccessToken': - console.log("pat..."); githubEndpointToken = githubEndpointObject.parameters.accessToken; break; case 'OAuth': - console.log("Oauth..."); githubEndpointToken = githubEndpointObject.parameters.accessToken; break; case 'Token':