in CredentialProvider.Microsoft/Util/FeedEndpointCredentialsParser.cs [51:110]
public static Dictionary<string, EndpointCredentials> ParseFeedEndpointsJsonToDictionary(ILogger logger)
{
string feedEndpointsJson = Environment.GetEnvironmentVariable(EnvUtil.EndpointCredentials);
if (string.IsNullOrWhiteSpace(feedEndpointsJson))
{
return new Dictionary<string, EndpointCredentials>(StringComparer.OrdinalIgnoreCase);
}
try
{
logger.Verbose(Resources.ParsingJson);
Dictionary<string, EndpointCredentials> credsResult = new Dictionary<string, EndpointCredentials>(StringComparer.OrdinalIgnoreCase);
EndpointCredentialsContainer endpointCredentials = System.Text.Json.JsonSerializer.Deserialize<EndpointCredentialsContainer>(feedEndpointsJson, options);
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.ClientId == null)
{
logger.Verbose(Resources.EndpointParseFailure);
break;
}
if (credentials.CertificateSubjectName != null && credentials.CertificateFilePath != null)
{
logger.Verbose(Resources.EndpointParseFailure);
break;
}
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, EndpointCredentials>(StringComparer.OrdinalIgnoreCase); ;
}
}