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

Fix for Customer Support 1182368: VSTS Azure KEy-Vault task #6489

Merged
merged 4 commits into from
Feb 28, 2018
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
41 changes: 40 additions & 1 deletion Tasks/AzureKeyVault/operations/KeyVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,53 @@ Set-AzureRmKeyVaultAccessPolicy -VaultName %s -ObjectId $spnObjectId -Permission
secretsToErrorsMap.addError(secretName, errorMessage);
}
else {
tl.setVariable(secretName, secretValue, true);
this.setVaultVariable(secretName, secretValue);
}

return resolve();
});
});
}

private tryFlattenJson(jsonString: string): string {
try {
var o = JSON.parse(jsonString);

if (o && typeof o === "object") {
return JSON.stringify(o);
}
}
catch (e) { }

return null;
}

private setVaultVariable(secretName: string, secretValue: string): void {
if (!secretValue) {
return;
}

if (secretValue.indexOf('\n') < 0) {
// single-line case
tl.setVariable(secretName, secretValue, true);
}
else {
// multi-line case
let strVal = this.tryFlattenJson(secretValue);
if (strVal) {
console.log(util.format("Value of secret %s has been converted to single line.", secretName));
tl.setVariable(secretName, strVal, true);
}
else {
let lines = secretValue.split('\n');
lines.forEach((line: string, index: number) => {
console.log("##vso[task.setsecret]" + line);
});
tl.setVariable(secretName, secretValue, true);
}
}
}

private getError(error: any): any {
tl.debug(JSON.stringify(error));

Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureKeyVault/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 14
"Patch": 15
},
"demands": [],
"minimumAgentVersion": "2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureKeyVault/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 14
"Patch": 15
},
"demands": [],
"minimumAgentVersion": "2.0.0",
Expand Down