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

AzureKeyVault@2: remove duplicate %AZP25 encoding #17566

Merged
merged 7 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Tasks/AzureKeyVaultV2/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Azure Key Vault', function () {
assert(tr.stdout.indexOf("##vso[task.setvariable variable=secret1;isOutput=false;issecret=true;]secret1-value") > 0, "##vso[task.setvariable variable=secret1;isOutput=false;issecret=true;]secret1-value");
assert(tr.stdout.indexOf("##vso[task.setvariable variable=secret2;isOutput=false;issecret=true;]secret2-value") > 0, "##vso[task.setvariable variable=secret2;isOutput=false;issecret=true;]secret2-value");
assert(tr.stdout.indexOf("##vso[task.setvariable variable=secret3;isOutput=false;issecret=true;]secret3-value") > 0, "##vso[task.setvariable variable=secret3;isOutput=false;issecret=true;]secret3-value");
assert(tr.stdout.indexOf("##vso[task.setvariable variable=secret5_%AZP25AZP253B;isOutput=false;issecret=true;]secret5_%AZP25AZP253B-value") > 0, "##vso[task.setvariable variable=secret5_%AZP25AZP253B;isOutput=false;issecret=true;]secret5_%AZP25AZP253B-value");
assert(tr.stdout.indexOf("##vso[task.setvariable variable=secret5_%AZP253B;isOutput=false;issecret=true;]secret5_%AZP253B-value") > 0, "##vso[task.setvariable variable=secret5_%AZP253B;isOutput=false;issecret=true;]secret5_%AZP253B-value");

assert(tr.stdout.indexOf("##vso[task.setvariable variable=secret4;isOutput=false;issecret=true;]secret4-value") < 0, "secret4 value should not be set");

Expand Down
1 change: 0 additions & 1 deletion Tasks/AzureKeyVaultV2/Tests/downloadSelectedSecrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ process.env["ENDPOINT_DATA_AzureRMSpn_AzureKeyVaultServiceEndpointResourceId"] =
process.env["ENDPOINT_URL_AzureRMSpn"] = "https://management.azure.com/";
process.env["SYSTEM_DEFAULTWORKINGDIRECTORY"] = "C:\\a\\w\\";
process.env["AGENT_TEMPDIRECTORY"] = process.cwd();
process.env["DECODE_PERCENTS"] = "false";

tr.registerMock('azure-pipelines-task-lib/toolrunner', require('azure-pipelines-task-lib/mock-toolrunner'));
tr.registerMock('./azure-arm-keyvault', require('./mock_node_modules/azure-arm-keyvault'));
Expand Down
9 changes: 0 additions & 9 deletions Tasks/AzureKeyVaultV2/operations/KeyVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import tl = require("azure-pipelines-task-lib/task");
import * as path from 'path';
import * as fs from 'fs';

const DECODE_PERCENTS = "DECODE_PERCENTS";

export class SecretsToErrorsMapping {
public errorsMap: { [key: string]: string; };

Expand Down Expand Up @@ -186,13 +184,6 @@ export class KeyVault {
return;
}

// Encode percent explicitely as the task lib does not encode % to %AZP25 as of now.
let decodePercents = tl.getVariable(DECODE_PERCENTS);
if (decodePercents && decodePercents.toUpperCase() === "TRUE") {
secretName = secretName.replace(/%/g, '%AZP25');
secretValue = secretValue.replace(/%/g, '%AZP25');
}

// Support multiple stages using different key vaults with the same secret name but with different version identifiers
let secretNameWithoutVersion = secretName.split("/")[0];

Expand Down
9 changes: 0 additions & 9 deletions Tasks/AzureKeyVaultV2/task-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import path = require("path");
import keyVaultTaskParameters = require("./models/KeyVaultTaskParameters");
import keyVault = require("./operations/KeyVault");

const DECODE_PERCENTS = "DECODE_PERCENTS";

export class TaskRunner {
public static async runInContext(isPreJobContext: boolean): Promise<void> {
const runAsPreJob: boolean = tl.getBoolInput('RunAsPreJob', true);
Expand All @@ -22,13 +20,6 @@ export class TaskRunner {
tl.debug("Setting resource path to " + taskManifestPath);
tl.setResourcePath(taskManifestPath);

// Decode percent in agent
let decodePercents = tl.getVariable(DECODE_PERCENTS);
if (!decodePercents) {
tl.debug("Setting DECODE_PERCENTS as true to decode %AZP25 to %");
tl.setVariable(DECODE_PERCENTS, "True", false);
}

const secretsToErrorsMap = new keyVault.SecretsToErrorsMapping();
const vaultParameters = new keyVaultTaskParameters.KeyVaultTaskParameters();
const taskParameters = await vaultParameters.getKeyVaultTaskParameters();
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureKeyVaultV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 2,
"Minor": 216,
"Patch": 1
"Patch": 2
},
"demands": [],
"minimumAgentVersion": "2.182.1",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureKeyVaultV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 2,
"Minor": 216,
"Patch": 1
"Patch": 2
},
"demands": [],
"minimumAgentVersion": "2.182.1",
Expand Down