private void LoadCredentialsSection(IConfigurationSection credentialsSection) { int credentialStarted = 0; int credentialFailed = 0; if (credentialsSection is null || !credentialsSection.GetChildren().Any()) { //this config file contains no credentials section return; } var credentialSections = credentialsSection.GetChildren(); foreach (var credentialSection in credentialSections) { var id = credentialSection[ConfigConstants.ID]; if (_credentialProviders.ContainsKey(id)) { credentialFailed++; continue; } var credentialType = credentialSection[ConfigConstants.CREDENTIAL_TYPE]; var factory = _credentialProviderFactoryCatalog.GetFactory(credentialType); if (factory != null) { try { ICredentialProvider credentialProvider = factory.CreateInstance(credentialType, CreatePlugInContext(credentialSection)); credentialProvider.Id = id; _credentialProviders[id] = credentialProvider; credentialStarted++; _logger.LogDebug($"Created cred provider {credentialType} Id {id}"); } catch (Exception ex) { _logger?.LogError($"Unable to load credential {id}: {ex.ToMinimized()}"); credentialFailed++; } } else { _logger?.LogError("Credential Type {0} is not recognized.", credentialType); credentialFailed++; } _metrics.PublishCounters(string.Empty, MetricsConstants.CATEGORY_PROGRAM, CounterTypeEnum.CurrentValue, new Dictionary <string, MetricValue>() { { MetricsConstants.SINKS_STARTED, new MetricValue(credentialStarted) }, { MetricsConstants.SINKS_FAILED_TO_START, new MetricValue(credentialFailed) } }); } }
private void LoadCredentialProviders() { var credentialsSection = _config.GetSection("Credentials"); var credentialSections = credentialsSection.GetChildren(); int credentialStarted = 0; int credentialFailed = 0; foreach (var credentialSection in credentialSections) { string id = _config.GetChildConfig(credentialSection.Path, ConfigConstants.ID); string credentialType = _config.GetChildConfig(credentialSection.Path, ConfigConstants.CREDENTIAL_TYPE); var factory = _credentialProviderFactoryCatalog.GetFactory(credentialType); if (factory != null) { try { ICredentialProvider credentialProvider = factory.CreateInstance(credentialType, CreatePlugInContext(credentialSection)); credentialProvider.Id = id; _credentialProviders[id] = credentialProvider; credentialStarted++; } catch (Exception ex) { credentialFailed++; _logger?.LogError($"Unable to load event sink {id} exception {ex.ToMinimized()}"); } } else { credentialFailed++; _logger?.LogError("Credential Type {0} is not recognized.", credentialType); } } _metrics.PublishCounters(string.Empty, MetricsConstants.CATEGORY_PROGRAM, CounterTypeEnum.CurrentValue, new Dictionary <string, MetricValue>() { { MetricsConstants.SINKS_STARTED, new MetricValue(credentialStarted) }, { MetricsConstants.SINKS_FAILED_TO_START, new MetricValue(credentialFailed) } }); }