Skip to content

Commit 1eb7ce8

Browse files
authored
Set Cargo credential-provider setting alongside auth setting (#19086)
1 parent e5c6fac commit 1eb7ce8

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Tasks/CargoAuthenticateV0/cargoauthenticatemain.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ 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+
tl.setVariable("CARGO_REGISTRY_TOKEN", tokenAuthInfo.token);
70+
tl.setVariable("CARGO_REGISTRY_CREDENTIAL_PROVIDER", "cargo:token");
7071
break;
7172
default:
7273
throw Error(tl.loc('Error_InvalidServiceConnection', serviceConnection.packageSource.uri));
@@ -75,7 +76,9 @@ async function main(): Promise<void> {
7576

7677
for (let registry of Object.keys(result.registries)) {
7778
const registryUrl = url.parse(result.registries[registry].index);
78-
let tokenName = `CARGO_REGISTRIES_${registry.toLocaleUpperCase().replace(/-/g, "_")}_TOKEN`;
79+
const registryConfigName = registry.toLocaleUpperCase().replace(/-/g, "_");
80+
const tokenName = `CARGO_REGISTRIES_${registryConfigName}_TOKEN`;
81+
const credProviderName = `CARGO_REGISTRIES_${registryConfigName}_CREDENTIAL_PROVIDER`;
7982
if (registryUrl && registryUrl.host && collectionHosts.indexOf(registryUrl.host.toLowerCase()) >= 0) {
8083
let currentRegistry : string;
8184
for (let serviceConnection of externalServiceConnections) {
@@ -85,12 +88,14 @@ async function main(): Promise<void> {
8588
tl.debug(`Detected username/password or PAT credentials for '${serviceConnection.packageSource.uri}'`);
8689
tl.debug(tl.loc('AddingAuthExternalRegistry', registry, tokenName));
8790
tl.setVariable(tokenName, `Basic ${base64.encode(utf8.encode(`${usernamePasswordAuthInfo.username}:${usernamePasswordAuthInfo.password}`))}`);
91+
tl.setVariable(credProviderName, "cargo:token");
8892
}
8993
}
9094
// Default to internal registry if no token has been set yet
9195
if (!currentRegistry) {
9296
tl.debug(tl.loc('AddingAuthRegistry', registry, tokenName));
9397
tl.setVariable(tokenName, localAccesstoken);
98+
tl.setVariable(credProviderName, "cargo:token");
9499
}
95100
}
96101
}

Tasks/CargoAuthenticateV0/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"author": "Microsoft Corporation",
1010
"version": {
1111
"Major": 0,
12-
"Minor": 227,
12+
"Minor": 229,
1313
"Patch": 0
1414
},
1515
"runsOn": [

Tasks/CargoAuthenticateV0/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"author": "Microsoft Corporation",
1010
"version": {
1111
"Major": 0,
12-
"Minor": 227,
12+
"Minor": 229,
1313
"Patch": 0
1414
},
1515
"runsOn": [

0 commit comments

Comments
 (0)