Skip to content

Commit

Permalink
Don't use VstsCredProvider if build task env vars are set (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
satbai committed Jan 16, 2019
1 parent bffa42f commit a7de23f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Build.props
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CredentialProviderVersion>0.1.10</CredentialProviderVersion>
<CredentialProviderVersion>0.1.11</CredentialProviderVersion>
</PropertyGroup>
</Project>
Expand Up @@ -37,6 +37,18 @@ public sealed class VstsCredentialProvider : CredentialProviderBase

public override async Task<bool> 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
Expand Down
Expand Up @@ -68,6 +68,8 @@ public async Task HandleResponseAsync(IConnection connection, Message message, I
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;
Expand All @@ -89,7 +91,7 @@ bool LogExceptionAndReturnFalse(Exception ex)
}

Logger.Verbose(string.Format(Resources.ResponseHandlerException, message.Method, message.RequestId));
Logger.Error(ex.ToString());
Logger.Verbose(ex.ToString());
return false;
}

Expand Down

0 comments on commit a7de23f

Please sign in to comment.