public static NuGetApiOptions AddUpstreamSource(this NuGetApiOptions options, string name, string serviceIndexUrl, int timeoutInSeconds = 600) { _mirrorsAdded = true; options.Services.AddSingleton <IUpstreamNuGetSource>(sp => { var clientFactory = new NuGetClientFactory(HttpClientFactory(timeoutInSeconds), serviceIndexUrl); return(new UpstreamNuGetSource(name, new NuGetClient(clientFactory))); }); return(options); }
public static NuGetApiOptions AddUpstreamSource(this NuGetApiOptions options, string name, string serviceIndexUrl, string username, string apiToken, int timeoutInSeconds = 600) { _mirrorsAdded = true; options.Services.AddSingleton <IUpstreamNuGetSource>(sp => { var httpClient = HttpClientFactory(timeoutInSeconds); var creds = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{apiToken}")); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", creds); var clientFactory = new NuGetClientFactory(httpClient, serviceIndexUrl); return(new UpstreamNuGetSource(name, new NuGetClient(clientFactory))); }); return(options); }
public static NuGetApiOptions AddUpstreamMirrors(this NuGetApiOptions options) { _mirrorsAdded = true; var feedOptions = options.Configuration.Get <PackageFeedOptions>(); foreach ((var name, var configuration) in feedOptions.Mirror ?? new MirrorOptions()) { if (!string.IsNullOrEmpty(configuration.Username) && !string.IsNullOrEmpty(configuration.ApiToken)) { options.AddUpstreamSource(name, configuration.FeedUrl.ToString(), configuration.Username, configuration.ApiToken, configuration.Timeout); } else { options.AddUpstreamSource(name, configuration.FeedUrl.ToString(), configuration.Timeout); } } return(options); }
public static IServiceCollection AddNuGetApiApplication( this IServiceCollection services, Action <NuGetApiOptions> configureAction) { var options = new NuGetApiOptions(services); services.AddConfiguration(); services.AddNuGetApiServices(); services.AddDefaultProviders(); configureAction(options); if (!_mirrorsAdded) { options.AddUpstreamMirrors(); } services.AddFallbackServices(); return(services); }