From a7de23f53e8d066829ee50620ea055e45838f4fd Mon Sep 17 00:00:00 2001 From: Satu Bailey Date: Wed, 16 Jan 2019 12:42:22 -0800 Subject: [PATCH] Don't use VstsCredProvider if build task env vars are set (#56) --- Build.props | 2 +- .../Vsts/VstsCredentialProvider.cs | 12 ++++++++++++ .../RequestHandlers/RequestHandlerBase.cs | 4 +++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Build.props b/Build.props index 4db02f6..ebefaaf 100644 --- a/Build.props +++ b/Build.props @@ -1,6 +1,6 @@ - 0.1.10 + 0.1.11 \ No newline at end of file diff --git a/CredentialProvider.Microsoft/CredentialProviders/Vsts/VstsCredentialProvider.cs b/CredentialProvider.Microsoft/CredentialProviders/Vsts/VstsCredentialProvider.cs index 51850c5..2b35dfc 100644 --- a/CredentialProvider.Microsoft/CredentialProviders/Vsts/VstsCredentialProvider.cs +++ b/CredentialProvider.Microsoft/CredentialProviders/Vsts/VstsCredentialProvider.cs @@ -37,6 +37,18 @@ namespace NuGetCredentialProvider.CredentialProviders.Vsts public override async Task CanProvideCredentialsAsync(Uri uri) { + // If for any reason we reach this point and any of the three build task env vars are set, + // we should not try get credentials with this cred provider. + string feedEndPointsJsonEnvVar = Environment.GetEnvironmentVariable(EnvUtil.BuildTaskExternalEndpoints); + string uriPrefixesStringEnvVar = Environment.GetEnvironmentVariable(EnvUtil.BuildTaskUriPrefixes); + string accessTokenEnvVar = Environment.GetEnvironmentVariable(EnvUtil.BuildTaskAccessToken); + + if (string.IsNullOrWhiteSpace(feedEndPointsJsonEnvVar) == false || string.IsNullOrWhiteSpace(uriPrefixesStringEnvVar) == false || string.IsNullOrWhiteSpace(accessTokenEnvVar) == false) + { + Verbose(Resources.BuildTaskCredProviderIsUsedError); + return false; + } + var validHosts = EnvUtil.GetHostsFromEnvironment(Logger, EnvUtil.SupportedHostsEnvVar, new[] { ".pkgs.vsts.me", // DevFabric diff --git a/CredentialProvider.Microsoft/RequestHandlers/RequestHandlerBase.cs b/CredentialProvider.Microsoft/RequestHandlers/RequestHandlerBase.cs index 42bde0f..4847964 100644 --- a/CredentialProvider.Microsoft/RequestHandlers/RequestHandlerBase.cs +++ b/CredentialProvider.Microsoft/RequestHandlers/RequestHandlerBase.cs @@ -68,6 +68,8 @@ namespace NuGetCredentialProvider.RequestHandlers var cancelMessage = MessageUtilities.Create(message.RequestId, MessageType.Cancel, message.Method); await connection.SendAsync(cancelMessage, CancellationToken.None); + Logger.Verbose(ex.ToString()); + // We must guarantee that exactly one terminating message is sent, so do not fall through to send // the normal response, but also do not rethrow. return; @@ -89,7 +91,7 @@ namespace NuGetCredentialProvider.RequestHandlers } Logger.Verbose(string.Format(Resources.ResponseHandlerException, message.Method, message.RequestId)); - Logger.Error(ex.ToString()); + Logger.Verbose(ex.ToString()); return false; }