Skip to content

Commit

Permalink
Prepare cred provider utils in packaging-common for NuGetAuthenticate…
Browse files Browse the repository at this point in the history
…V1 (#16065)
  • Loading branch information
satbai authored Mar 23, 2022
1 parent 1fe93c4 commit 882833f
Show file tree
Hide file tree
Showing 4 changed files with 521 additions and 510 deletions.
52 changes: 31 additions & 21 deletions common-npm-packages/artifacts-common/credentialProviderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,43 @@ interface EndpointCredentialsContainer {
endpointCredentials: EndpointCredentials[];
}

/**
* Get the task-provided credential provider plugins directory (containing netcore and netfx folders)
*/
export function getTaskCredProviderPluginsDir(): string {
let taskRootPath: string = path.dirname(path.dirname(__dirname));
return path.join(taskRootPath, "CredentialProviderV2", "plugins");
}

async function installFromLocation(
taskPluginsDir: string,
folderName: string,
logString: string,
overwrite: boolean) {
const source = path.join(taskPluginsDir, folderName, 'CredentialProvider.Microsoft');
const userPluginsDir = getUserProfileNuGetPluginsDir();
const dest = path.join(userPluginsDir, folderName, 'CredentialProvider.Microsoft');

console.log(tl.loc(logString, dest));
await copyCredProviderFiles(source, dest, overwrite);
console.log();
}

/**
* Copy the credential provider (netcore and netfx) to the user profile directory
* This function is only used by the NuGet Authenticate task
*/
export async function installCredProviderToUserProfile(overwrite: boolean) {
const taskPluginsPir = getTaskCredProviderPluginsDir();
const userPluginsDir = getUserProfileNuGetPluginsDir();

const netCoreSource = path.join(taskPluginsPir, 'netcore', 'CredentialProvider.Microsoft');
const netCoreDest = path.join(userPluginsDir, 'netcore', 'CredentialProvider.Microsoft');
console.log(tl.loc("CredProvider_InstallingNetCoreTo", netCoreDest));
await copyCredProviderFiles(netCoreSource, netCoreDest, overwrite);
console.log();
export async function installCredProviderToUserProfile(overwrite: boolean, isNuGetAuthenticateV0: boolean = false) {
let taskRootPath: string = path.dirname(path.dirname(__dirname));
const netfx = "netfx";
const netcore = "netcore";

if (isNuGetAuthenticateV0) {
const pluginsDir = path.join(taskRootPath, "CredentialProviderV2", "plugins");
// install netfx and netcore
await installFromLocation(pluginsDir, netfx, "CredProvider_InstallingNetFxTo", overwrite);
await installFromLocation(pluginsDir, netcore, "CredProvider_InstallingNetCoreTo_NuGetAuthenticateV0", overwrite);
return;
}

const netFxSource = path.join(taskPluginsPir, 'netfx', 'CredentialProvider.Microsoft');
const netFxDest = path.join(userPluginsDir, 'netfx', 'CredentialProvider.Microsoft');
console.log(tl.loc("CredProvider_InstallingNetFxTo", netFxDest));
await copyCredProviderFiles(netFxSource, netFxDest, overwrite);
console.log();
// install netfx and netcore
let pluginsDir = path.join(taskRootPath, "ArtifactsCredProvider", "plugins");
await installFromLocation(pluginsDir, netfx, "CredProvider_InstallingNetFxTo", overwrite);
pluginsDir = path.join(taskRootPath, "ArtifactsCredProviderNet6", "plugins");
await installFromLocation(pluginsDir, netcore, "CredProvider_InstallingNetCoreTo_NuGetAuthenticateV1", overwrite);
}

async function copyCredProviderFiles(source, dest, overwrite) {
Expand Down
3 changes: 2 additions & 1 deletion common-npm-packages/artifacts-common/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"CredProvider_Error_FailedRemoveDir": "Failed to remove the directory '%s' while installing the credential provider. Ensure that this directory is not in use and that the agent account has permission to delete this directory.",
"CredProvider_Error_InvalidServiceConnection": "The service connection for '%s' is not valid.",
"CredProvider_Error_InvalidServiceConnection_ApiKey": "The service connection for '%s' is not valid. ApiKey service connections are not supported in this task. Instead, use -ApiKey (NuGet) or --api-key (dotnet) when invoking the tool itself. See the task documentation for more details.",
"CredProvider_InstallingNetCoreTo": "Installing the Azure Artifacts Credential Provider (.NET Core) to '%s'. This credential provider is compatible with dotnet SDK 2.1.400 or later.",
"CredProvider_InstallingNetCoreTo_NuGetAuthenticateV0": "Installing the Azure Artifacts Credential Provider (.NET Core) to '%s'. This credential provider is compatible with dotnet SDK 2.1 or later.",
"CredProvider_InstallingNetCoreTo_NuGetAuthenticateV1": "Installing the Azure Artifacts Credential Provider (.NET Core) to '%s'. This credential provider is compatible with .NET SDK 6 or later.",
"CredProvider_InstallingNetFxTo": "Installing the Azure Artifacts Credential Provider (.NET Framework) to '%s'. This credential provider is compatible with nuget.exe 4.8.0.5385 or later, and MSBuild 15.8.166.59604 or later.",
"CredProvider_SettingUpForOrgFeeds": "Setting up the credential provider to use the identity '%s' for feeds in your organization/collection starting with:",
"CredProvider_SettingUpForServiceConnections": "Setting up the credential provider for these service connections:",
Expand Down
Loading

0 comments on commit 882833f

Please sign in to comment.