public void IsNuGetOrg(string sourceUrl, bool expected) { // Act var actual = UriUtility.IsNuGetOrg(sourceUrl); // Assert Assert.Equal(expected, actual); }
public void IsNuGetOrg(string sourceUrl, bool expected) { // Arrange var source = new PackageSource(sourceUrl); // Act var actual = UriUtility.IsNuGetOrg(source.Source); // Assert Assert.Equal(expected, actual); }
public static string GetApiKey(ISettings settings, string endpoint, string source) { // try searching API key by endpoint first // needed to support config key mappings like 'https://www.nuget.org/api/v2/package' var apiKey = SettingsUtility.GetDecryptedValueForAddItem(settings, ConfigurationConstants.ApiKeys, endpoint); // if not found try finding it by source url apiKey = apiKey ?? SettingsUtility.GetDecryptedValueForAddItem(settings, ConfigurationConstants.ApiKeys, source); // fallback for a case of nuget.org source // try to retrieve an api key mapped to a default "gallery" url if (apiKey == null && UriUtility.IsNuGetOrg(source)) { var defaultConfigKey = NuGetConstants.DefaultGalleryServerUrl; apiKey = SettingsUtility.GetDecryptedValueForAddItem(settings, ConfigurationConstants.ApiKeys, defaultConfigKey); } // return an API key when found or null when not found return(apiKey); }
/// <summary> /// Create a SourceSummaryEvent event with counts of local vs http and v2 vs v3 feeds. /// </summary> private static TelemetryEvent GetSourceSummaryEvent( string eventName, Guid parentId, IEnumerable <PackageSource> packageSources, PackageSourceTelemetry.Totals protocolDiagnosticTotals) { var local = 0; var httpV2 = 0; var httpV3 = 0; var nugetOrg = HttpStyle.NotPresent; var vsOfflinePackages = false; var dotnetCuratedFeed = false; var httpsV2 = 0; var httpsV3 = 0; if (packageSources != null) { foreach (var source in packageSources) { // Ignore disabled sources if (source.IsEnabled) { if (source.IsHttp) { if (TelemetryUtility.IsHttpV3(source)) { // Http V3 feed httpV3++; if (source.IsHttps) { httpsV3++; } if (UriUtility.IsNuGetOrg(source.Source)) { nugetOrg |= HttpStyle.YesV3; } } else { // Http V2 feed httpV2++; if (source.IsHttps) { httpsV2++; } if (UriUtility.IsNuGetOrg(source.Source)) { if (source.Source.IndexOf( "api/v2/curated-feeds/microsoftdotnet", StringComparison.OrdinalIgnoreCase) >= 0) { dotnetCuratedFeed = true; } else { nugetOrg |= HttpStyle.YesV2; } } } } else { // Local or UNC feed local++; if (TelemetryUtility.IsVsOfflineFeed(source)) { vsOfflinePackages = true; } } } } } return(new SourceSummaryTelemetryEvent( eventName, parentId, local, httpV2, httpV3, nugetOrg.ToString(), vsOfflinePackages, dotnetCuratedFeed, protocolDiagnosticTotals, httpsV2, httpsV3)); }
private void EmitRestoreTelemetryEvent(IEnumerable <NuGetProject> projects, bool forceRestore, RestoreOperationSource source, DateTimeOffset startTime, double duration, PackageSourceTelemetry.Totals protocolDiagnosticTotals, IntervalTracker intervalTimingTracker) { var sortedProjects = projects.OrderBy( project => project.GetMetadata <string>(NuGetProjectMetadataKeys.UniqueName)); var projectIds = sortedProjects.Select( project => project.GetMetadata <string>(NuGetProjectMetadataKeys.ProjectId)).ToArray(); var projectDictionary = sortedProjects .GroupBy(x => x.ProjectStyle) .ToDictionary(x => x.Key, y => y.Count()); var packageSourceMapping = PackageSourceMapping.GetPackageSourceMapping(_settings); bool isPackageSourceMappingEnabled = packageSourceMapping?.IsEnabled ?? false; var packageSources = _sourceRepositoryProvider.PackageSourceProvider.LoadPackageSources().ToList(); int NumHTTPFeeds = 0; int NumLocalFeeds = 0; bool hasVSOfflineFeed = false; bool hasNuGetOrg = false; foreach (var packageSource in packageSources) { if (packageSource.IsEnabled) { if (packageSource.IsHttp) { NumHTTPFeeds++; hasNuGetOrg |= UriUtility.IsNuGetOrg(packageSource.Source); } else { hasVSOfflineFeed |= TelemetryUtility.IsVsOfflineFeed(packageSource); NumLocalFeeds++; } } } var restoreTelemetryEvent = new RestoreTelemetryEvent( _nuGetProjectContext.OperationId.ToString(), projectIds, forceRestore, source, startTime, _status, packageCount: _packageCount, noOpProjectsCount: _noOpProjectsCount, upToDateProjectsCount: _upToDateProjectCount, unknownProjectsCount: projectDictionary.GetValueOrDefault(ProjectStyle.Unknown, 0), // appears in DependencyGraphRestoreUtility projectJsonProjectsCount: projectDictionary.GetValueOrDefault(ProjectStyle.ProjectJson, 0), packageReferenceProjectsCount: projectDictionary.GetValueOrDefault(ProjectStyle.PackageReference, 0), legacyPackageReferenceProjectsCount: sortedProjects.Where(x => x.ProjectStyle == ProjectStyle.PackageReference && x is LegacyPackageReferenceProject).Count(), cpsPackageReferenceProjectsCount: sortedProjects.Where(x => x.ProjectStyle == ProjectStyle.PackageReference && x is CpsPackageReferenceProject).Count(), dotnetCliToolProjectsCount: projectDictionary.GetValueOrDefault(ProjectStyle.DotnetCliTool, 0), // appears in DependencyGraphRestoreUtility packagesConfigProjectsCount: projectDictionary.GetValueOrDefault(ProjectStyle.PackagesConfig, 0), DateTimeOffset.Now, duration, _trackingData, intervalTimingTracker, isPackageSourceMappingEnabled, NumHTTPFeeds, NumLocalFeeds, hasNuGetOrg, hasVSOfflineFeed); TelemetryActivity.EmitTelemetryEvent(restoreTelemetryEvent); var sourceEvent = SourceTelemetry.GetRestoreSourceSummaryEvent(_nuGetProjectContext.OperationId, packageSources, protocolDiagnosticTotals); TelemetryActivity.EmitTelemetryEvent(sourceEvent); }