-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathFeatureFlags.cs
More file actions
66 lines (55 loc) · 1.73 KB
/
FeatureFlags.cs
File metadata and controls
66 lines (55 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information
namespace Elastic.Documentation.Configuration.Builder;
public class FeatureFlags(Dictionary<string, bool> initFeatureFlags)
{
private readonly Dictionary<string, bool> _featureFlags = new(initFeatureFlags);
public void Set(string key, bool value)
{
var normalizedKey = key.ToLowerInvariant().Replace('_', '-');
_featureFlags[normalizedKey] = value;
}
public bool PrimaryNavEnabled
{
get => IsEnabled("primary-nav");
set => _featureFlags["primary-nav"] = value;
}
public bool DisableGitHubEditLink
{
get => IsEnabled("disable-github-edit-link");
set => _featureFlags["disable-github-edit-link"] = value;
}
public bool SearchOrAskAiEnabled
{
get => IsEnabled("search-or-ask-ai");
set => _featureFlags["search-or-ask-ai"] = value;
}
public bool StagingElasticNavEnabled
{
get => IsEnabled("staging-elastic-nav");
set => _featureFlags["staging-elastic-nav"] = value;
}
public bool AirGappedEnabled
{
get => IsEnabled("air-gapped");
set => _featureFlags["air-gapped"] = value;
}
public bool DiagnosticsPanelEnabled
{
get => IsEnabled("diagnostics-panel");
set => _featureFlags["diagnostics-panel"] = value;
}
private bool IsEnabled(string key)
{
var envKey = $"FEATURE_{key.ToUpperInvariant().Replace('-', '_')}";
if (Environment.GetEnvironmentVariable(envKey) is { } envValue)
{
if (bool.TryParse(envValue, out var envBool))
return envBool;
// if the env var is set but not a bool, we treat it as enabled
return true;
}
return _featureFlags.TryGetValue(key, out var value) && value;
}
}