Skip to content

Commit 5099bc9

Browse files
authored
CargoAuthenticateV0 Register as secret for basic cargo auth (#19905)
* set secret on basic cargo auth * add generated files
1 parent ce605ef commit 5099bc9

File tree

14 files changed

+1922
-1585
lines changed

14 files changed

+1922
-1585
lines changed

Tasks/CargoAuthenticateV0/_buildConfigs/Node20/Tests/package-lock.json

+11-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tasks/CargoAuthenticateV0/_buildConfigs/Node20/package-lock.json

+924-777
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tasks/CargoAuthenticateV0/cargoauthenticatemain.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async function main(): Promise<void> {
6666

6767
const tokenAuthInfo = serviceConnection as TokenServiceConnection;
6868
tl.debug(`Detected token credentials for '${serviceConnection.packageSource.uri}'`);
69-
tl.setVariable("CARGO_REGISTRY_TOKEN", tokenAuthInfo.token);
69+
setSecretEnvVariable("CARGO_REGISTRY_TOKEN", tokenAuthInfo.token);
7070
tl.setVariable("CARGO_REGISTRY_CREDENTIAL_PROVIDER", "cargo:token");
7171
break;
7272
default:
@@ -87,14 +87,14 @@ async function main(): Promise<void> {
8787
currentRegistry = registry;
8888
tl.debug(`Detected username/password or PAT credentials for '${serviceConnection.packageSource.uri}'`);
8989
tl.debug(tl.loc('AddingAuthExternalRegistry', registry, tokenName));
90-
tl.setVariable(tokenName, `Basic ${base64.encode(utf8.encode(`${usernamePasswordAuthInfo.username}:${usernamePasswordAuthInfo.password}`))}`);
90+
setSecretEnvVariable(tokenName, `Basic ${base64.encode(utf8.encode(`${usernamePasswordAuthInfo.username}:${usernamePasswordAuthInfo.password}`))}`);
9191
tl.setVariable(credProviderName, "cargo:token");
9292
}
9393
}
9494
// Default to internal registry if no token has been set yet
9595
if (!currentRegistry) {
9696
tl.debug(tl.loc('AddingAuthRegistry', registry, tokenName));
97-
tl.setVariable(tokenName, localAccesstoken);
97+
setSecretEnvVariable(tokenName, localAccesstoken);
9898
tl.setVariable(credProviderName, "cargo:token");
9999
}
100100
}
@@ -108,4 +108,13 @@ async function main(): Promise<void> {
108108
}
109109
}
110110

111+
// Register the value as a secret to the logger before setting the value in an enviornment variable.
112+
// Use when needed to set a specific enviornment variable whose value is a secret. We cannot use
113+
// setVariable(_, , isSecret=true) because it adds SECRET_ as a prefix to the env variable.
114+
// TODO: Move to a common location
115+
function setSecretEnvVariable(variableName: string, value: string){
116+
tl.setSecret(value);
117+
tl.setVariable(variableName, value);
118+
}
119+
111120
main();

Tasks/CargoAuthenticateV0/task.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"author": "Microsoft Corporation",
1010
"version": {
1111
"Major": 0,
12-
"Minor": 238,
12+
"Minor": 240,
1313
"Patch": 0
1414
},
1515
"runsOn": [

Tasks/CargoAuthenticateV0/task.loc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"author": "Microsoft Corporation",
1010
"version": {
1111
"Major": 0,
12-
"Minor": 238,
12+
"Minor": 240,
1313
"Patch": 0
1414
},
1515
"runsOn": [
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Default|0.238.0
2-
Node20_229_1|0.238.1
1+
Default|0.240.0
2+
Node20_229_1|0.240.1

_generated/CargoAuthenticateV0/cargoauthenticatemain.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async function main(): Promise<void> {
6666

6767
const tokenAuthInfo = serviceConnection as TokenServiceConnection;
6868
tl.debug(`Detected token credentials for '${serviceConnection.packageSource.uri}'`);
69-
tl.setVariable("CARGO_REGISTRY_TOKEN", tokenAuthInfo.token);
69+
setSecretEnvVariable("CARGO_REGISTRY_TOKEN", tokenAuthInfo.token);
7070
tl.setVariable("CARGO_REGISTRY_CREDENTIAL_PROVIDER", "cargo:token");
7171
break;
7272
default:
@@ -87,14 +87,14 @@ async function main(): Promise<void> {
8787
currentRegistry = registry;
8888
tl.debug(`Detected username/password or PAT credentials for '${serviceConnection.packageSource.uri}'`);
8989
tl.debug(tl.loc('AddingAuthExternalRegistry', registry, tokenName));
90-
tl.setVariable(tokenName, `Basic ${base64.encode(utf8.encode(`${usernamePasswordAuthInfo.username}:${usernamePasswordAuthInfo.password}`))}`);
90+
setSecretEnvVariable(tokenName, `Basic ${base64.encode(utf8.encode(`${usernamePasswordAuthInfo.username}:${usernamePasswordAuthInfo.password}`))}`);
9191
tl.setVariable(credProviderName, "cargo:token");
9292
}
9393
}
9494
// Default to internal registry if no token has been set yet
9595
if (!currentRegistry) {
9696
tl.debug(tl.loc('AddingAuthRegistry', registry, tokenName));
97-
tl.setVariable(tokenName, localAccesstoken);
97+
setSecretEnvVariable(tokenName, localAccesstoken);
9898
tl.setVariable(credProviderName, "cargo:token");
9999
}
100100
}
@@ -108,4 +108,13 @@ async function main(): Promise<void> {
108108
}
109109
}
110110

111+
// Register the value as a secret to the logger before setting the value in an enviornment variable.
112+
// Use when needed to set a specific enviornment variable whose value is a secret. We cannot use
113+
// setVariable(_, , isSecret=true) because it adds SECRET_ as a prefix to the env variable.
114+
// TODO: Move to a common location
115+
function setSecretEnvVariable(variableName: string, value: string){
116+
tl.setSecret(value);
117+
tl.setVariable(variableName, value);
118+
}
119+
111120
main();

_generated/CargoAuthenticateV0/task.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"author": "Microsoft Corporation",
1010
"version": {
1111
"Major": 0,
12-
"Minor": 238,
12+
"Minor": 240,
1313
"Patch": 0
1414
},
1515
"runsOn": [
@@ -55,7 +55,7 @@
5555
"AddingAuthExternalRegistry": "Adding auth for external registry: %s with token name: %s"
5656
},
5757
"_buildConfigMapping": {
58-
"Default": "0.238.0",
59-
"Node20_229_1": "0.238.1"
58+
"Default": "0.240.0",
59+
"Node20_229_1": "0.240.1"
6060
}
6161
}

_generated/CargoAuthenticateV0/task.loc.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"author": "Microsoft Corporation",
1010
"version": {
1111
"Major": 0,
12-
"Minor": 238,
12+
"Minor": 240,
1313
"Patch": 0
1414
},
1515
"runsOn": [
@@ -55,7 +55,7 @@
5555
"AddingAuthExternalRegistry": "ms-resource:loc.messages.AddingAuthExternalRegistry"
5656
},
5757
"_buildConfigMapping": {
58-
"Default": "0.238.0",
59-
"Node20_229_1": "0.238.1"
58+
"Default": "0.240.0",
59+
"Node20_229_1": "0.240.1"
6060
}
6161
}

_generated/CargoAuthenticateV0_Node20/Tests/package-lock.json

+11-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_generated/CargoAuthenticateV0_Node20/cargoauthenticatemain.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async function main(): Promise<void> {
6666

6767
const tokenAuthInfo = serviceConnection as TokenServiceConnection;
6868
tl.debug(`Detected token credentials for '${serviceConnection.packageSource.uri}'`);
69-
tl.setVariable("CARGO_REGISTRY_TOKEN", tokenAuthInfo.token);
69+
setSecretEnvVariable("CARGO_REGISTRY_TOKEN", tokenAuthInfo.token);
7070
tl.setVariable("CARGO_REGISTRY_CREDENTIAL_PROVIDER", "cargo:token");
7171
break;
7272
default:
@@ -87,14 +87,14 @@ async function main(): Promise<void> {
8787
currentRegistry = registry;
8888
tl.debug(`Detected username/password or PAT credentials for '${serviceConnection.packageSource.uri}'`);
8989
tl.debug(tl.loc('AddingAuthExternalRegistry', registry, tokenName));
90-
tl.setVariable(tokenName, `Basic ${base64.encode(utf8.encode(`${usernamePasswordAuthInfo.username}:${usernamePasswordAuthInfo.password}`))}`);
90+
setSecretEnvVariable(tokenName, `Basic ${base64.encode(utf8.encode(`${usernamePasswordAuthInfo.username}:${usernamePasswordAuthInfo.password}`))}`);
9191
tl.setVariable(credProviderName, "cargo:token");
9292
}
9393
}
9494
// Default to internal registry if no token has been set yet
9595
if (!currentRegistry) {
9696
tl.debug(tl.loc('AddingAuthRegistry', registry, tokenName));
97-
tl.setVariable(tokenName, localAccesstoken);
97+
setSecretEnvVariable(tokenName, localAccesstoken);
9898
tl.setVariable(credProviderName, "cargo:token");
9999
}
100100
}
@@ -108,4 +108,13 @@ async function main(): Promise<void> {
108108
}
109109
}
110110

111+
// Register the value as a secret to the logger before setting the value in an enviornment variable.
112+
// Use when needed to set a specific enviornment variable whose value is a secret. We cannot use
113+
// setVariable(_, , isSecret=true) because it adds SECRET_ as a prefix to the env variable.
114+
// TODO: Move to a common location
115+
function setSecretEnvVariable(variableName: string, value: string){
116+
tl.setSecret(value);
117+
tl.setVariable(variableName, value);
118+
}
119+
111120
main();

0 commit comments

Comments
 (0)