public E2ESecretConfigurationReader(IConfigurationRoot config, ISecretReaderFactory secretReaderFactory) { _configuration = config; _secretReaderFactory = secretReaderFactory; _secretInjector = new Lazy <ISecretInjector>(InitSecretInjector, isThreadSafe: false); }
public ConfigurationService(ISecretReaderFactory secretReaderFactory) { if (secretReaderFactory == null) { throw new ArgumentNullException(nameof(secretReaderFactory)); } _secretReaderFactory = secretReaderFactory; _secretInjector = new Lazy <ISecretInjector>(InitSecretInjector, isThreadSafe: false); }
public ConfigurationService(ISecretReaderFactory secretReaderFactory) { if (secretReaderFactory == null) { throw new ArgumentNullException(nameof(secretReaderFactory)); } _secretReaderFactory = secretReaderFactory; _secretInjector = new Lazy<ISecretInjector>(InitSecretInjector, isThreadSafe: false); }
public CommandLineParser(ICommandManager manager, ISecretReaderFactory secretReaderFactory) { _commandManager = manager; if (secretReaderFactory == null) { throw new ArgumentNullException(nameof(secretReaderFactory)); } _secretReaderFactory = secretReaderFactory; _secretInjector = new Lazy <ISecretInjector>(InitSecretInjector, isThreadSafe: false); }
public ConfigurationService(ISecretReaderFactory secretReaderFactory) { _secretReaderFactory = secretReaderFactory ?? throw new ArgumentNullException(nameof(secretReaderFactory)); _secretInjector = new Lazy <ISecretInjector>(InitSecretInjector, isThreadSafe: false); _httpSiteRootThunk = new Lazy <string>(GetHttpSiteRoot); _httpsSiteRootThunk = new Lazy <string>(GetHttpsSiteRoot); _lazyAppConfiguration = new Lazy <IAppConfiguration>(() => ResolveSettings().Result); _lazyFeatureConfiguration = new Lazy <FeatureConfiguration>(() => ResolveFeatures().Result); _lazyServiceBusConfiguration = new Lazy <IServiceBusConfiguration>(() => ResolveServiceBus().Result); }
private static IDictionary <string, string> InjectSecrets(ISecretReaderFactory secretReaderFactory, Dictionary <string, string> argsDictionary) { var secretReader = secretReaderFactory.CreateSecretReader(argsDictionary); var secretInjector = secretReaderFactory.CreateSecretInjector(secretReader); if (secretReader == null) { throw new ApplicationException("Could not create a secret reader. Please check your configuration."); } return(new SecretDictionary(secretInjector, argsDictionary)); }
/// <summary> /// Parses the string[] of <c>args</c> passed into the job into a dictionary of string, string. /// Expects the string[] to be set of pairs of argumentName and argumentValue, where, argumentName start with a hyphen /// </summary> /// <param name="commandLineArgs">Arguments passed to the job via commandline or environment variable settings</param> /// <param name="jobName">Jobname to be used to infer environment variable settings</param> /// <param name="secretReaderFactory">Creates a secret reader.</param> /// <returns>Returns a dictionary of arguments</returns> public static IDictionary <string, string> GetJobArgsDictionary(ILogger logger, string[] commandLineArgs, string jobName, ISecretReaderFactory secretReaderFactory) { if (secretReaderFactory == null) { throw new ArgumentNullException(nameof(secretReaderFactory)); } Dictionary <string, string> argsDictionary = ReadCommandLineArguments(logger, commandLineArgs); return(InjectSecrets(secretReaderFactory, argsDictionary)); }
public ConfigurationProcessor(ISecretReaderFactory secretReaderFactory) { _secretReaderFactory = secretReaderFactory; }
public RefreshableSecretReaderFactory(ISecretReaderFactory underlyingFactory, RefreshableSecretReaderSettings settings) { _underlyingFactory = underlyingFactory ?? throw new ArgumentNullException(nameof(underlyingFactory)); _cache = new ConcurrentDictionary <string, ISecret>(); _settings = settings ?? throw new ArgumentNullException(nameof(settings)); }
public TestableConfigurationService(ISecretReaderFactory secretReaderFactory = null) : base(secretReaderFactory ?? new EmptySecretReaderFactory()) { }
/// <summary> /// Parses the string[] of <c>args</c> passed into the job into a dictionary of string, string. /// Expects the string[] to be set of pairs of argumentName and argumentValue, where, argumentName start with a hyphen /// </summary> /// <param name="commandLineArgs">Arguments passed to the job via commandline or environment variable settings</param> /// <param name="jobName">Jobname to be used to infer environment variable settings</param> /// <param name="secretReaderFactory">Creates a secret reader.</param> /// <returns>Returns a dictionary of arguments</returns> public static IDictionary <string, string> GetJobArgsDictionary(string[] commandLineArgs, string jobName, ISecretReaderFactory secretReaderFactory) { if (secretReaderFactory == null) { throw new ArgumentNullException(nameof(secretReaderFactory)); } var argsDictionary = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var allArgsList = commandLineArgs.ToList(); if (allArgsList.Count == 0) { Trace.TraceInformation("No command-line arguments provided."); } else { Trace.TraceInformation("Total number of arguments : " + allArgsList.Count); // Arguments are expected to be a set of pairs, where each pair is of the form '-<argName> <argValue>' // Or, in singles as a switch '-<switch>' for (int i = 0; i < allArgsList.Count; i++) { if (!allArgsList[i].StartsWith("-")) { throw new ArgumentException("Argument Name does not start with a hyphen ('-')"); } var argName = allArgsList[i].Substring(1); if (string.IsNullOrEmpty(argName)) { throw new ArgumentException("Argument Name is null or empty"); } var nextString = allArgsList.Count > i + 1 ? allArgsList[i + 1] : null; if (string.IsNullOrEmpty(nextString) || nextString.StartsWith("-")) { // If the key already exists, don't add. This means that first added value is preferred // Since command line args are added before args from environment variable, this is the desired behavior if (!argsDictionary.ContainsKey(argName)) { // nextString startWith hyphen, the current one is a switch argsDictionary.Add(argName, bool.TrueString); } } else { var argValue = nextString; if (string.IsNullOrEmpty(argValue)) { throw new ArgumentException("Argument Value is null or empty"); } // If the key already exists, don't add. This means that first added value is preferred // Since command line args are added before args from environment variable, this is the desired behavior if (!argsDictionary.ContainsKey(argName)) { argsDictionary.Add(argName, argValue); } i++; // skip next string since it was added as an argument value } } } return(InjectSecrets(secretReaderFactory, argsDictionary)); }
/// <summary> /// Initializes the instance. /// </summary> /// <param name="underlyingFactory">Actual factory we are wrapping</param> /// <param name="cachingTimeout">The max caching time for secrets</param> public CachingSecretReaderFactory(ISecretReaderFactory underlyingFactory, TimeSpan cachingTimeout) { _underlyingFactory = underlyingFactory ?? throw new ArgumentNullException(nameof(underlyingFactory)); _cachingTimeout = cachingTimeout; }