public static Func <string, string> Create(IConfiguration bootstrapConfiguration) { string appConfigurationUri = bootstrapConfiguration[ConfigurationConstants.AppConfigurationUriConfigurationKey]; if (appConfigurationUri == null) { return(value => value); } TokenCredential credentials = ServiceConfigurationExtensions.GetAzureTokenCredential(bootstrapConfiguration); var client = new ConfigurationClient(new Uri(appConfigurationUri), credentials); return(RegexConfigMapper.Create(ConfigReferenceRegex, key => { try { const string featureManagementPrefix = "FeatureManagement:"; if (key.StartsWith(featureManagementPrefix)) { key = key.Substring(featureManagementPrefix.Length); var featureFlagData = JObject.Parse(client.GetConfigurationSetting(".appconfig.featureflag/" + key).Value.Value); if (featureFlagData.Value <bool>("enabled")) { return "true"; } return "false"; } return client.GetConfigurationSetting(key).Value.Value; } catch (RequestFailedException) { return ""; } })); }
public static Func <string, string> Create(IConfiguration bootstrapConfiguration) { string appConfigurationUri = bootstrapConfiguration[ConfigurationConstants.AppConfigurationUriConfigurationKey]; if (appConfigurationUri == null) { return(value => value); } TelemetryClient telemetry = ConfigMapper.GetTelemetryClient(bootstrapConfiguration); TokenCredential credentials = ServiceConfigurationExtensions.GetAzureTokenCredential(bootstrapConfiguration); var client = new ConfigurationClient(new Uri(appConfigurationUri), credentials); void TrackEvent(string name, string key, Exception?error) { telemetry.TrackEvent(name, new Dictionary <string, string> { ["name"] = key, ["appConfigurationUri"] = appConfigurationUri, ["success"] = error == null ? "true" : "false", }); if (error != null) { telemetry.TrackException(error); } } return(RegexConfigMapper.Create(ConfigReferenceRegex, key => { const string featureManagementPrefix = "FeatureManagement:"; if (key.StartsWith(featureManagementPrefix)) { key = key.Substring(featureManagementPrefix.Length); var(result, error) = GetFeatureFlagValue(client, key); TrackEvent("AppConfigurationFeatureFlagAccess", key, error); return result; } else { var(result, error) = GetConfigurationSetting(client, key); TrackEvent("AppConfigurationSettingAccess", key, error); return result; } })); }
public static Func <string, string> Create(IConfiguration bootstrapConfiguration) { var keyVaultUri = bootstrapConfiguration[ConfigurationConstants.KeyVaultUriConfigurationKey]; var credentials = ServiceConfigurationExtensions.GetAzureTokenCredential(bootstrapConfiguration); var client = new SecretClient(new Uri(keyVaultUri), credentials); return(RegexConfigMapper.Create(VaultReferenceRegex, key => { try { return client.GetSecret(key).Value.Value; } catch (RequestFailedException) { return ""; } })); }
public static Func <string, string> Create(IConfiguration bootstrapConfiguration) { TelemetryClient telemetry = ConfigMapper.GetTelemetryClient(bootstrapConfiguration); string keyVaultUri = bootstrapConfiguration[ConfigurationConstants.KeyVaultUriConfigurationKey]; var credentials = ServiceConfigurationExtensions.GetAzureTokenCredential(bootstrapConfiguration); var client = new SecretClient(new Uri(keyVaultUri), credentials); void TrackEvent(string key, Exception?error) { telemetry.TrackEvent("KeyVaultSecretAccess", new Dictionary <string, string> { ["secretKey"] = key, ["keyVaultUri"] = keyVaultUri, ["success"] = error == null ? "true" : "false", }); if (error != null) { telemetry.TrackException(error); } } return(RegexConfigMapper.Create(VaultReferenceRegex, key => { try { var value = client.GetSecret(key).Value.Value; TrackEvent(key, null); return value; } catch (RequestFailedException ex) { TrackEvent(key, ex); return ""; } })); }