in CredentialProvider.Microsoft/Util/FeedEndpointCredentialsParser.cs [112:169]
public static Dictionary<string, ExternalEndpointCredentials> ParseExternalFeedEndpointsJsonToDictionary(ILogger logger)
{
string feedEndpointsJson = Environment.GetEnvironmentVariable(EnvUtil.BuildTaskExternalEndpoints);
if (string.IsNullOrWhiteSpace(feedEndpointsJson))
{
return new Dictionary<string, ExternalEndpointCredentials>(StringComparer.OrdinalIgnoreCase);
}
try
{
logger.Verbose(Resources.ParsingJson);
if (feedEndpointsJson.Contains("':"))
{
logger.Warning(Resources.InvalidJsonWarning);
}
Dictionary<string, ExternalEndpointCredentials> credsResult = new Dictionary<string, ExternalEndpointCredentials>(StringComparer.OrdinalIgnoreCase);
ExternalEndpointCredentialsContainer endpointCredentials = JsonConvert.DeserializeObject<ExternalEndpointCredentialsContainer>(feedEndpointsJson);
if (endpointCredentials == null)
{
logger.Verbose(Resources.NoEndpointsFound);
return credsResult;
}
foreach (var credentials in endpointCredentials.EndpointCredentials)
{
if (credentials == null)
{
logger.Verbose(Resources.EndpointParseFailure);
break;
}
if (credentials.Username == null)
{
credentials.Username = "VssSessionToken";
}
if (!Uri.TryCreate(credentials.Endpoint, UriKind.Absolute, out var endpointUri))
{
logger.Verbose(Resources.EndpointParseFailure);
break;
}
var urlEncodedEndpoint = endpointUri.AbsoluteUri;
if (!credsResult.ContainsKey(urlEncodedEndpoint))
{
credsResult.Add(urlEncodedEndpoint, credentials);
}
}
return credsResult;
}
catch (Exception ex)
{
logger.Verbose(string.Format(Resources.VstsBuildTaskExternalCredentialCredentialProviderError, ex));
return new Dictionary<string, ExternalEndpointCredentials>(StringComparer.OrdinalIgnoreCase);
}
}