generated from brevdev/seed
-
Notifications
You must be signed in to change notification settings - Fork 9
/
featureflag.go
65 lines (53 loc) · 1.57 KB
/
featureflag.go
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
package featureflag
import (
"strings"
"github.com/brevdev/brev-cli/pkg/cmd/version"
"github.com/brevdev/brev-cli/pkg/entity"
"github.com/spf13/viper"
)
func IsDev() bool {
if viper.IsSet("feature.dev") {
return viper.GetBool("feature.dev")
} else {
return strings.HasPrefix(version.Version, "dev")
}
}
func IsAdmin(userType entity.GlobalUserType) bool {
if viper.IsSet("feature.not_admin") && viper.GetBool("feature.not_admin") {
return false
} else {
return userType == "Admin"
}
}
// use feature flag if not provided default true for admin but not others
func ServiceMeshSSH(userType entity.GlobalUserType) bool {
if viper.IsSet("feature.service_mesh_ssh") {
return viper.GetBool("feature.service_mesh_ssh")
}
return IsAdmin(userType)
}
func DisableSSHProxyVersionCheck() bool {
return viper.GetBool("feature.disable_ssh_proxy_version_check")
}
func DisableErrorReporting() bool {
return viper.GetBool("feature.disable_error_reporting")
}
func ShowVersionOnRun() bool {
return viper.GetBool("feature.show_version_on_run")
}
// todo set me via cli flag? this was meant to sort of like verbose but could be
// removed in favor of something like that
func Debug() bool {
return viper.GetBool("feature.debug")
}
func LoadFeatureFlags(path string) error {
viper.SetConfigName("config")
viper.AddConfigPath("/etc/brev/")
viper.AddConfigPath(path)
viper.SetEnvPrefix("brev")
viper.SetConfigType("yaml")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
_ = viper.ReadInConfig() // do not need to fail if can't find config file
return nil
}