Skip to content

Commit

Permalink
CargoAuthenticateV0 Register as secret for basic cargo auth (#19905)
Browse files Browse the repository at this point in the history
* set secret on basic cargo auth

* add generated files
  • Loading branch information
embetten authored May 23, 2024
1 parent ce605ef commit 5099bc9
Show file tree
Hide file tree
Showing 14 changed files with 1,922 additions and 1,585 deletions.

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

1,701 changes: 924 additions & 777 deletions Tasks/CargoAuthenticateV0/_buildConfigs/Node20/package-lock.json

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions Tasks/CargoAuthenticateV0/cargoauthenticatemain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function main(): Promise<void> {

const tokenAuthInfo = serviceConnection as TokenServiceConnection;
tl.debug(`Detected token credentials for '${serviceConnection.packageSource.uri}'`);
tl.setVariable("CARGO_REGISTRY_TOKEN", tokenAuthInfo.token);
setSecretEnvVariable("CARGO_REGISTRY_TOKEN", tokenAuthInfo.token);
tl.setVariable("CARGO_REGISTRY_CREDENTIAL_PROVIDER", "cargo:token");
break;
default:
Expand All @@ -87,14 +87,14 @@ async function main(): Promise<void> {
currentRegistry = registry;
tl.debug(`Detected username/password or PAT credentials for '${serviceConnection.packageSource.uri}'`);
tl.debug(tl.loc('AddingAuthExternalRegistry', registry, tokenName));
tl.setVariable(tokenName, `Basic ${base64.encode(utf8.encode(`${usernamePasswordAuthInfo.username}:${usernamePasswordAuthInfo.password}`))}`);
setSecretEnvVariable(tokenName, `Basic ${base64.encode(utf8.encode(`${usernamePasswordAuthInfo.username}:${usernamePasswordAuthInfo.password}`))}`);
tl.setVariable(credProviderName, "cargo:token");
}
}
// Default to internal registry if no token has been set yet
if (!currentRegistry) {
tl.debug(tl.loc('AddingAuthRegistry', registry, tokenName));
tl.setVariable(tokenName, localAccesstoken);
setSecretEnvVariable(tokenName, localAccesstoken);
tl.setVariable(credProviderName, "cargo:token");
}
}
Expand All @@ -108,4 +108,13 @@ async function main(): Promise<void> {
}
}

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

main();
2 changes: 1 addition & 1 deletion Tasks/CargoAuthenticateV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 238,
"Minor": 240,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/CargoAuthenticateV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 238,
"Minor": 240,
"Patch": 0
},
"runsOn": [
Expand Down
4 changes: 2 additions & 2 deletions _generated/CargoAuthenticateV0.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|0.238.0
Node20_229_1|0.238.1
Default|0.240.0
Node20_229_1|0.240.1
15 changes: 12 additions & 3 deletions _generated/CargoAuthenticateV0/cargoauthenticatemain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function main(): Promise<void> {

const tokenAuthInfo = serviceConnection as TokenServiceConnection;
tl.debug(`Detected token credentials for '${serviceConnection.packageSource.uri}'`);
tl.setVariable("CARGO_REGISTRY_TOKEN", tokenAuthInfo.token);
setSecretEnvVariable("CARGO_REGISTRY_TOKEN", tokenAuthInfo.token);
tl.setVariable("CARGO_REGISTRY_CREDENTIAL_PROVIDER", "cargo:token");
break;
default:
Expand All @@ -87,14 +87,14 @@ async function main(): Promise<void> {
currentRegistry = registry;
tl.debug(`Detected username/password or PAT credentials for '${serviceConnection.packageSource.uri}'`);
tl.debug(tl.loc('AddingAuthExternalRegistry', registry, tokenName));
tl.setVariable(tokenName, `Basic ${base64.encode(utf8.encode(`${usernamePasswordAuthInfo.username}:${usernamePasswordAuthInfo.password}`))}`);
setSecretEnvVariable(tokenName, `Basic ${base64.encode(utf8.encode(`${usernamePasswordAuthInfo.username}:${usernamePasswordAuthInfo.password}`))}`);
tl.setVariable(credProviderName, "cargo:token");
}
}
// Default to internal registry if no token has been set yet
if (!currentRegistry) {
tl.debug(tl.loc('AddingAuthRegistry', registry, tokenName));
tl.setVariable(tokenName, localAccesstoken);
setSecretEnvVariable(tokenName, localAccesstoken);
tl.setVariable(credProviderName, "cargo:token");
}
}
Expand All @@ -108,4 +108,13 @@ async function main(): Promise<void> {
}
}

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

main();
6 changes: 3 additions & 3 deletions _generated/CargoAuthenticateV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 238,
"Minor": 240,
"Patch": 0
},
"runsOn": [
Expand Down Expand Up @@ -55,7 +55,7 @@
"AddingAuthExternalRegistry": "Adding auth for external registry: %s with token name: %s"
},
"_buildConfigMapping": {
"Default": "0.238.0",
"Node20_229_1": "0.238.1"
"Default": "0.240.0",
"Node20_229_1": "0.240.1"
}
}
6 changes: 3 additions & 3 deletions _generated/CargoAuthenticateV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 238,
"Minor": 240,
"Patch": 0
},
"runsOn": [
Expand Down Expand Up @@ -55,7 +55,7 @@
"AddingAuthExternalRegistry": "ms-resource:loc.messages.AddingAuthExternalRegistry"
},
"_buildConfigMapping": {
"Default": "0.238.0",
"Node20_229_1": "0.238.1"
"Default": "0.240.0",
"Node20_229_1": "0.240.1"
}
}
14 changes: 11 additions & 3 deletions _generated/CargoAuthenticateV0_Node20/Tests/package-lock.json

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

15 changes: 12 additions & 3 deletions _generated/CargoAuthenticateV0_Node20/cargoauthenticatemain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function main(): Promise<void> {

const tokenAuthInfo = serviceConnection as TokenServiceConnection;
tl.debug(`Detected token credentials for '${serviceConnection.packageSource.uri}'`);
tl.setVariable("CARGO_REGISTRY_TOKEN", tokenAuthInfo.token);
setSecretEnvVariable("CARGO_REGISTRY_TOKEN", tokenAuthInfo.token);
tl.setVariable("CARGO_REGISTRY_CREDENTIAL_PROVIDER", "cargo:token");
break;
default:
Expand All @@ -87,14 +87,14 @@ async function main(): Promise<void> {
currentRegistry = registry;
tl.debug(`Detected username/password or PAT credentials for '${serviceConnection.packageSource.uri}'`);
tl.debug(tl.loc('AddingAuthExternalRegistry', registry, tokenName));
tl.setVariable(tokenName, `Basic ${base64.encode(utf8.encode(`${usernamePasswordAuthInfo.username}:${usernamePasswordAuthInfo.password}`))}`);
setSecretEnvVariable(tokenName, `Basic ${base64.encode(utf8.encode(`${usernamePasswordAuthInfo.username}:${usernamePasswordAuthInfo.password}`))}`);
tl.setVariable(credProviderName, "cargo:token");
}
}
// Default to internal registry if no token has been set yet
if (!currentRegistry) {
tl.debug(tl.loc('AddingAuthRegistry', registry, tokenName));
tl.setVariable(tokenName, localAccesstoken);
setSecretEnvVariable(tokenName, localAccesstoken);
tl.setVariable(credProviderName, "cargo:token");
}
}
Expand All @@ -108,4 +108,13 @@ async function main(): Promise<void> {
}
}

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

main();
Loading

0 comments on commit 5099bc9

Please sign in to comment.