private void Initialize(IEnvironmentVariableReader reader, Lazy <IPluginDiscoverer> pluginDiscoverer, Func <TimeSpan, IPluginFactory> pluginFactoryCreator, Lazy <string> pluginsCacheDirectoryPath) { EnvironmentVariableReader = reader ?? throw new ArgumentNullException(nameof(reader)); _discoverer = pluginDiscoverer ?? throw new ArgumentNullException(nameof(pluginDiscoverer)); _pluginsCacheDirectoryPath = pluginsCacheDirectoryPath ?? throw new ArgumentNullException(nameof(pluginsCacheDirectoryPath)); if (pluginFactoryCreator == null) { throw new ArgumentNullException(nameof(pluginFactoryCreator)); } #if IS_DESKTOP _rawPluginPaths = reader.GetEnvironmentVariable(EnvironmentVariableConstants.DesktopPluginPaths); #else _rawPluginPaths = reader.GetEnvironmentVariable(EnvironmentVariableConstants.CorePluginPaths); #endif if (string.IsNullOrEmpty(_rawPluginPaths)) { _rawPluginPaths = reader.GetEnvironmentVariable(EnvironmentVariableConstants.PluginPaths); } _connectionOptions = ConnectionOptions.CreateDefault(reader); var idleTimeoutInSeconds = EnvironmentVariableReader.GetEnvironmentVariable(EnvironmentVariableConstants.IdleTimeout); var idleTimeout = TimeoutUtilities.GetTimeout(idleTimeoutInSeconds, PluginConstants.IdleTimeout); _pluginFactory = pluginFactoryCreator(idleTimeout); _pluginOperationClaims = new ConcurrentDictionary <PluginRequestKey, Lazy <Task <IReadOnlyList <OperationClaim> > > >(); _pluginUtilities = new ConcurrentDictionary <string, Lazy <IPluginMulticlientUtilities> >( StringComparer.OrdinalIgnoreCase); }
internal PluginLogger(IEnvironmentVariableReader environmentVariableReader) { if (environmentVariableReader == null) { throw new ArgumentNullException(nameof(environmentVariableReader)); } var value = environmentVariableReader.GetEnvironmentVariable(EnvironmentVariableConstants.EnableLog); IsEnabled = bool.TryParse(value, out var enable) && enable; if (IsEnabled) { _logDirectoryPath = environmentVariableReader.GetEnvironmentVariable(EnvironmentVariableConstants.LogDirectoryPath); if (string.IsNullOrWhiteSpace(_logDirectoryPath)) { _logDirectoryPath = Environment.CurrentDirectory; } } _startTime = DateTimeOffset.UtcNow; _stopwatch = Stopwatch.StartNew(); // Created outside of the lambda below to capture the current time. var message = new StopwatchLogMessage(Now, Stopwatch.Frequency); _streamWriter = new Lazy <StreamWriter>(() => CreateStreamWriter(message)); _streamWriterLock = new object(); }
internal NuGetFileLogger(IEnvironmentVariableReader environmentVariableReader) { if (environmentVariableReader == null) { throw new ArgumentNullException(nameof(environmentVariableReader)); } _logDirectoryPath = environmentVariableReader.GetEnvironmentVariable("NUGET_VS_RESTORE_LOGGING_PATH"); if (!string.IsNullOrWhiteSpace(_logDirectoryPath)) { IsEnabled = true; } var formatWithTime = environmentVariableReader.GetEnvironmentVariable("NUGET_VS_RESTORE_FORMAT_WITH_TIME"); if (!string.IsNullOrWhiteSpace(formatWithTime)) { _ = bool.TryParse(formatWithTime, out bool formatWithTimeOverride); ShouldFormatWithTime = formatWithTimeOverride; } _startTime = DateTimeOffset.UtcNow; _stopwatch = Stopwatch.StartNew(); // Created outside of the lambda below to capture the current time. var message = $"The stopwatch frequency is {Stopwatch.Frequency}"; _streamWriter = new Lazy <StreamWriter>(() => CreateStreamWriter(message)); _streamWriterLock = new object(); }
internal HttpFileSystemBasedFindPackageByIdResource( IReadOnlyList <Uri> baseUris, HttpSource httpSource, IEnvironmentVariableReader environmentVariableReader) { if (baseUris == null) { throw new ArgumentNullException(nameof(baseUris)); } if (baseUris.Count < 1) { throw new ArgumentException(Strings.OneOrMoreUrisMustBeSpecified, nameof(baseUris)); } if (httpSource == null) { throw new ArgumentNullException(nameof(httpSource)); } _baseUris = baseUris .Take(DefaultMaxRetries) .Select(uri => uri.OriginalString.EndsWith("/", StringComparison.Ordinal) ? uri : new Uri(uri.OriginalString + "/")) .ToList(); _httpSource = httpSource; _nupkgDownloader = new FindPackagesByIdNupkgDownloader(httpSource); _enhancedHttpRetryHelper = new EnhancedHttpRetryHelper(environmentVariableReader); _maxRetries = _enhancedHttpRetryHelper.IsEnabled ? _enhancedHttpRetryHelper.RetryCount : DefaultMaxRetries; }
// This is non-private only to facilitate testing. internal static IX509ChainBuildPolicy CreateWithoutCaching(IEnvironmentVariableReader reader) { if (reader is null) { throw new ArgumentNullException(nameof(reader)); } if (RuntimeEnvironmentHelper.IsWindows) { string value = reader.GetEnvironmentVariable(EnvironmentVariableName); if (string.IsNullOrWhiteSpace(value)) { return(DefaultX509ChainBuildPolicy.Instance); } string[] parts = value.Split(ValueDelimiter); if (parts.Length == 2 && int.TryParse(parts[0], out int retryCount) && retryCount > 0 && int.TryParse(parts[1], out int sleepIntervalInMilliseconds) && sleepIntervalInMilliseconds >= 0) { TimeSpan sleepInterval = TimeSpan.FromMilliseconds(sleepIntervalInMilliseconds); return(new RetriableX509ChainBuildPolicy(DefaultX509ChainBuildPolicy.Instance, retryCount, sleepInterval)); } } return(DefaultX509ChainBuildPolicy.Instance); }
internal NuGetFeatureFlagService(IEnvironmentVariableReader environmentVariableReader, IAsyncServiceProvider asyncServiceProvider) { _environmentVariableReader = environmentVariableReader ?? throw new ArgumentNullException(nameof(environmentVariableReader)); _asyncServiceProvider = asyncServiceProvider ?? throw new ArgumentNullException(nameof(asyncServiceProvider)); _ivsFeatureFlags = new(() => _asyncServiceProvider.GetServiceAsync <SVsFeatureFlags, IVsFeatureFlags>(), NuGetUIThreadHelper.JoinableTaskFactory); _featureFlagCache = new(); }
/// <summary> /// For testing only /// </summary> /// <param name="ssm"></param> /// <param name="variableReader"></param> /// <param name="injector"></param> public SecretHandler(IAmazonSimpleSystemsManagement ssm, IEnvironmentVariableReader variableReader, SsmInjector injector) { Console.WriteLine("this constructor should only be used for unit testing. It was not designed for production use."); _envreader = variableReader; _injector = injector; Initialize(); }
internal static string GetMSBuild(IEnvironmentVariableReader reader) { var exeNames = new[] { "msbuild.exe" }; if (RuntimeEnvironmentHelper.IsMono) { exeNames = new[] { "msbuild", "xbuild" }; } // Try to find msbuild or xbuild in $Path. var pathDirs = reader.GetEnvironmentVariable("PATH")?.Split(new[] { Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries); if (pathDirs?.Length > 0) { foreach (var exeName in exeNames) { var exePath = pathDirs.Select(dir => Path.Combine(dir.Trim('\"'), exeName)).FirstOrDefault(File.Exists); if (exePath != null) { return(exePath); } } } return(null); }
/// <summary> /// Gets the (first) path of MSBuild to appear in environment variable PATH. /// </summary> /// <returns>The path of MSBuild in PATH environment variable. Returns null if MSBuild location does not exist /// in the variable string.</returns> private static string GetMsBuildPathInPathVar(IEnvironmentVariableReader reader) { var path = reader.GetEnvironmentVariable("PATH"); var paths = path?.Split(new char[] { ';' }); return(paths?.Select(p => { // Strip leading/trailing quotes if (p.Length > 0 && p[0] == '\"') { p = p.Substring(1); } if (p.Length > 0 && p[p.Length - 1] == '\"') { p = p.Substring(0, p.Length - 1); } return p; }).FirstOrDefault(p => { try { return File.Exists(Path.Combine(p, "msbuild.exe")); } catch { return false; } })); }
/// <summary> /// Reinitializes static state. /// </summary> /// <remarks>This is non-private only to facilitate unit testing. /// This should not be called by product code.</remarks> /// <param name="reader">An environment variable reader.</param> /// <param name="pluginDiscoverer">A lazy plugin discoverer.</param> /// <param name="pluginFactory">A plugin factory.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="reader" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="pluginDiscoverer" /> /// is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="pluginFactory" /> /// is <c>null</c>.</exception> public void Reinitialize(IEnvironmentVariableReader reader, Lazy<IPluginDiscoverer> pluginDiscoverer, IPluginFactory pluginFactory) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (pluginDiscoverer == null) { throw new ArgumentNullException(nameof(pluginDiscoverer)); } if (pluginFactory == null) { throw new ArgumentNullException(nameof(pluginFactory)); } EnvironmentVariableReader = reader; _rawPluginPaths = reader.GetEnvironmentVariable(_pluginPathsEnvironmentVariable); var requestTimeoutInSeconds = reader.GetEnvironmentVariable(_pluginRequestTimeoutEnvironmentVariable); _requestTimeout = GetRequestTimeout(requestTimeoutInSeconds); _discoverer = pluginDiscoverer; _pluginFactory = pluginFactory; _pluginOperationClaims = new ConcurrentDictionary<PluginPackageSourceKey, Lazy<Task<IReadOnlyList<OperationClaim>>>>(); _pluginUtilities = new ConcurrentDictionary<string, Lazy<IPluginMulticlientUtilities>>( StringComparer.OrdinalIgnoreCase); }
/// <summary> /// Reinitializes static state. /// </summary> /// <remarks>This is non-private only to facilitate unit testing. /// This should not be called by product code.</remarks> /// <param name="reader">An environment variable reader.</param> /// <param name="pluginDiscoverer">A lazy plugin discoverer.</param> /// <param name="pluginFactoryCreator">A plugin factory creator.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="reader" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="pluginDiscoverer" /> /// is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="pluginFactoryCreator" /> /// is <c>null</c>.</exception> public void Reinitialize(IEnvironmentVariableReader reader, Lazy <IPluginDiscoverer> pluginDiscoverer, Func <TimeSpan, IPluginFactory> pluginFactoryCreator) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (pluginDiscoverer == null) { throw new ArgumentNullException(nameof(pluginDiscoverer)); } if (pluginFactoryCreator == null) { throw new ArgumentNullException(nameof(pluginFactoryCreator)); } EnvironmentVariableReader = reader; _rawPluginPaths = reader.GetEnvironmentVariable(_pluginPathsEnvironmentVariable); _connectionOptions = ConnectionOptions.CreateDefault(reader); var idleTimeoutInSeconds = EnvironmentVariableReader.GetEnvironmentVariable(_idleTimeoutEnvironmentVariable); var idleTimeout = TimeoutUtilities.GetTimeout(idleTimeoutInSeconds, PluginConstants.IdleTimeout); _discoverer = pluginDiscoverer; _pluginFactory = pluginFactoryCreator(idleTimeout); _pluginOperationClaims = new ConcurrentDictionary <PluginPackageSourceKey, Lazy <Task <IReadOnlyList <OperationClaim> > > >(); _pluginUtilities = new ConcurrentDictionary <string, Lazy <IPluginMulticlientUtilities> >( StringComparer.OrdinalIgnoreCase); }
// For testing purposes only internal PackageArchiveReader(Stream stream, IEnvironmentVariableReader environmentVariableReader) : this(stream) { if (environmentVariableReader != null) { _environmentVariableReader = environmentVariableReader; } }
/// <summary> /// Creates a new plugin manager /// </summary> /// <remarks>This is public to facilitate unit testing. This should not be called from product code</remarks> /// <param name="reader">An environment variable reader.</param> /// <param name="pluginDiscoverer">A lazy plugin discoverer.</param> /// <param name="pluginFactoryCreator">A plugin factory creator.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="reader" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="pluginDiscoverer" /> /// is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="pluginFactoryCreator" /> /// is <c>null</c>.</exception> public PluginManager(IEnvironmentVariableReader reader, Lazy <IPluginDiscoverer> pluginDiscoverer, Func <TimeSpan, IPluginFactory> pluginFactoryCreator) { Initialize( reader, pluginDiscoverer, pluginFactoryCreator); }
internal ServiceIndexResourceV3Provider(IEnvironmentVariableReader environmentVariableReader) : base(typeof(ServiceIndexResourceV3), nameof(ServiceIndexResourceV3Provider), NuGetResourceProviderPositions.Last) { _cache = new ConcurrentDictionary <string, ServiceIndexCacheInfo>(StringComparer.OrdinalIgnoreCase); MaxCacheDuration = _defaultCacheDuration; _enhancedHttpRetryHelper = new EnhancedHttpRetryHelper(environmentVariableReader); }
/// <summary> /// Pulls all of the SSM parameters for a given region and path. This package requires running with a role /// or that AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set as environment variables. /// /// Additionally, /// DEFAULT_AWS_REGION (us-east-1 is assumed if none provided) /// and SSM_PARAMETER_PATH ("/" is assumed if none provided) /// should be set as environment variables /// </summary> public SecretHandler() { _envreader = new EnvironmentVariableReader(); _region = _envreader.GetValue("DEFAULT_AWS_REGION") ?? "us-east-1"; _parameterPath = _envreader.GetValue("SSM_PARAMETER_PATH"); _injector = new SsmInjector(); Initialize(); }
public void Init() { _stringValidatorMock = new Mock <IStringValidator>(); _objectValidator = new Mock <IObjectValidator>(); _sut = new Environmentalist.Services.Readers.EnvironmentVariableReader.EnvironmentVariableReader( _stringValidatorMock.Object, _objectValidator.Object); }
internal Testable(IEnvironmentVariableReader environmentVariableReader) { _isMMapEnabled = environmentVariableReader.GetEnvironmentVariable(MMAP_VARIABLE_NAME) switch { "0" => false, "1" => true, _ => RuntimeEnvironmentHelper.IsWindows }; }
internal FindPackagesByIdNupkgDownloader(HttpSource httpSource, IEnvironmentVariableReader environmentVariableReader) { if (httpSource == null) { throw new ArgumentNullException(nameof(httpSource)); } _httpSource = httpSource; _enhancedHttpRetryHelper = new EnhancedHttpRetryHelper(environmentVariableReader); }
internal Testable(IEnvironmentVariableReader environmentVariableReader) { _updateFileTimeFromEntryMaxRetries = 9; string value = environmentVariableReader.GetEnvironmentVariable("NUGET_UPDATEFILETIME_MAXRETRIES"); if (int.TryParse(value, out int maxRetries) && maxRetries > 0) { _updateFileTimeFromEntryMaxRetries = maxRetries; } }
public ProfileRepository( IProfileReader profileReader, IEnvironmentVariableReader environmentVariableReader, IStringValidator stringValidator, IObjectValidator objectValidator) { _profileReader = profileReader; _environmentVariableReader = environmentVariableReader; _stringValidator = stringValidator; _objectValidator = objectValidator; }
private static int?Read(IEnvironmentVariableReader reader, string variableName) { var variableValue = reader.GetEnvironmentVariable(variableName); if (int.TryParse(variableValue, out var value)) { return(value); } return(null); }
public ConfigurationRepository( IConfigurationReader configurationReader, IEnvironmentVariableReader environmentVariableReader, IStringValidator stringValidator, IObjectValidator objectValidator) { _configurationReader = configurationReader; _environmentVariableReader = environmentVariableReader; _stringValidator = stringValidator; _objectValidator = objectValidator; }
public TemplateRepository( ITemplateReader templateReader, IEnvironmentVariableReader environmentVariableReader, IStringValidator stringValidator, IObjectValidator objectValidator) { _templateReader = templateReader; _environmentVariableReader = environmentVariableReader; _stringValidator = stringValidator; _objectValidator = objectValidator; }
private static bool ShouldShowStack(IEnvironmentVariableReader reader) { var rawShowStack = reader.GetEnvironmentVariable("NUGET_SHOW_STACK"); if (rawShowStack == null) { return(false); } return(string.Equals(rawShowStack.Trim(), "true", StringComparison.OrdinalIgnoreCase)); }
public static RevocationMode GetRevocationMode(IEnvironmentVariableReader environmentVariableReader = null) { var reader = environmentVariableReader ?? EnvironmentVariableWrapper.Instance; var revocationModeSetting = reader.GetEnvironmentVariable(RevocationModeEnvironmentKey); if (!string.IsNullOrEmpty(revocationModeSetting) && Enum.TryParse(revocationModeSetting, ignoreCase: true, result: out RevocationMode revocationMode)) { return(revocationMode); } return(RevocationMode.Online); }
public WebService( IEnvironmentVariableReader environmentVariableReader, IHttpFacade httpFacade, IMarketDataRepository marketDataRepository) { _environmentVariableReader = environmentVariableReader ?? throw new ArgumentNullException(nameof(environmentVariableReader)); _httpFacade = httpFacade ?? throw new ArgumentNullException(nameof(httpFacade)); _marketDataCsvFileRepository = marketDataRepository ?? throw new ArgumentNullException(nameof(marketDataRepository)); }
internal PackageSourceProvider(ISettings settingsManager, IEnumerable <PackageSource> providerDefaultSources, IDictionary <PackageSource, PackageSource> migratePackageSources, IEnumerable <PackageSource> configurationDefaultSources, IEnvironmentVariableReader environment) { if (settingsManager == null) { throw new ArgumentNullException("settingsManager"); } this._settingsManager = settingsManager; this._providerDefaultSources = providerDefaultSources ?? Enumerable.Empty <PackageSource>(); this._migratePackageSources = migratePackageSources; this._configurationDefaultSources = configurationDefaultSources ?? Enumerable.Empty <PackageSource>(); this._environment = environment; }
public PluginManager( IEnvironmentVariableReader reader, Lazy <IPluginDiscoverer> pluginDiscoverer, Func <TimeSpan, IPluginFactory> pluginFactoryCreator, Lazy <string> pluginsCacheDirectoryPath) { Initialize( reader, pluginDiscoverer, pluginFactoryCreator, pluginsCacheDirectoryPath); }
public PackageRestoreConsent(ISettings settings, IEnvironmentVariableReader environmentReader) { if (settings == null) { throw new ArgumentNullException("settings"); } if (environmentReader == null) { throw new ArgumentNullException("environmentReader"); } _settings = settings; _environmentReader = environmentReader; }
public App( IRestClient client, IEnvironmentVariableReader envReader, ISlackConnector slack, ISecretHandler secretHandler, int timeout = 5000 ) { _client = client; _envReader = envReader; _slack = slack; _secretHandler = secretHandler; _timeout = timeout; }
internal PackageSourceProvider( ISettings settingsManager, IEnumerable<PackageSource> providerDefaultSources, IDictionary<PackageSource, PackageSource> migratePackageSources, IEnumerable<PackageSource> configurationDefaultSources, IEnvironmentVariableReader environment) { if (settingsManager == null) { throw new ArgumentNullException("settingsManager"); } _settingsManager = settingsManager; _providerDefaultSources = providerDefaultSources ?? Enumerable.Empty<PackageSource>(); _migratePackageSources = migratePackageSources; _configurationDefaultSources = configurationDefaultSources ?? Enumerable.Empty<PackageSource>(); _environment = environment; }
public PackageRestoreConsent(ISettings settings, IEnvironmentVariableReader environmentReader, ConfigurationDefaults configurationDefaults) { if (settings == null) { throw new ArgumentNullException("settings"); } if (environmentReader == null) { throw new ArgumentNullException("environmentReader"); } if (configurationDefaults == null) { throw new ArgumentNullException("configurationDefaults"); } _settings = settings; _environmentReader = environmentReader; _configurationDefaults = configurationDefaults; }
public PackageRestoreConsent(ISettings settings, IEnvironmentVariableReader environmentReader) : this(settings, environmentReader, ConfigurationDefaults.Instance) { }
private IPackageSourceProvider CreatePackageSourceProvider( ISettings settings = null, IEnumerable<PackageSource> providerDefaultSources = null, IDictionary<PackageSource, PackageSource> migratePackageSources = null, IEnumerable<PackageSource> configurationDefaultSources = null, IEnvironmentVariableReader environment = null) { settings = settings ?? new Mock<ISettings>().Object; environment = environment ?? new Mock<IEnvironmentVariableReader>().Object; return new PackageSourceProvider(settings, providerDefaultSources, migratePackageSources, configurationDefaultSources, environment); }