diff --git a/api/config.go b/api/config.go index 0b1671e15..d0308eb11 100644 --- a/api/config.go +++ b/api/config.go @@ -19,10 +19,28 @@ type WebContact struct { // FeatureFlags is struct to manage feature flags. type FeatureFlags struct { - IsPlottingDefaultOn bool `json:"isPlottingDefaultOn" example:"false"` - IsPlottingAvailable bool `json:"isPlottingAvailable" example:"true"` - IsSubscriptionToAllTagsAvailable bool `json:"isSubscriptionToAllTagsAvailable" example:"false"` - IsReadonlyEnabled bool `json:"isReadonlyEnabled" example:"false"` + IsPlottingDefaultOn bool `json:"isPlottingDefaultOn" example:"false"` + IsPlottingAvailable bool `json:"isPlottingAvailable" example:"true"` + IsSubscriptionToAllTagsAvailable bool `json:"isSubscriptionToAllTagsAvailable" example:"false"` + IsReadonlyEnabled bool `json:"isReadonlyEnabled" example:"false"` + CelebrationMode CelebrationMode `json:"celebrationMode" example:"new_year"` +} + +// CelebrationMode is type for celebrate Moira. +type CelebrationMode string + +const newYear = "new_year" + +// AvailableCelebrationMode map with available celebration mode. +var availableCelebrationMode = map[string]struct{}{ + newYear: {}, +} + +// IsAvailableCelebrationMode return is mode available or not. +func IsAvailableCelebrationMode(mode string) bool { + _, ok := availableCelebrationMode[mode] + + return ok } // Sentry - config for sentry settings. @@ -58,7 +76,7 @@ type MetricSourceCluster struct { ClusterName string `json:"cluster_name" example:"Graphite Remote Prod"` } -func (WebConfig) Render(w http.ResponseWriter, r *http.Request) error { +func (WebConfig) Render(http.ResponseWriter, *http.Request) error { return nil } diff --git a/cmd/api/config.go b/cmd/api/config.go index 41b998b37..0896ed24e 100644 --- a/cmd/api/config.go +++ b/cmd/api/config.go @@ -136,10 +136,11 @@ type webContact struct { } type featureFlags struct { - IsPlottingDefaultOn bool `yaml:"is_plotting_default_on"` - IsPlottingAvailable bool `yaml:"is_plotting_available"` - IsSubscriptionToAllTagsAvailable bool `yaml:"is_subscription_to_all_tags_available"` - IsReadonlyEnabled bool `yaml:"is_readonly_enabled"` + IsPlottingDefaultOn bool `yaml:"is_plotting_default_on"` + IsPlottingAvailable bool `yaml:"is_plotting_available"` + IsSubscriptionToAllTagsAvailable bool `yaml:"is_subscription_to_all_tags_available"` + IsReadonlyEnabled bool `yaml:"is_readonly_enabled"` + CelebrationMode string `yaml:"celebration_mode"` } func (config *apiConfig) getSettings( @@ -247,9 +248,18 @@ func (config *webConfig) getFeatureFlags() api.FeatureFlags { IsPlottingAvailable: config.FeatureFlags.IsPlottingAvailable, IsSubscriptionToAllTagsAvailable: config.FeatureFlags.IsSubscriptionToAllTagsAvailable, IsReadonlyEnabled: config.FeatureFlags.IsReadonlyEnabled, + CelebrationMode: getCelebrationMode(config.FeatureFlags.CelebrationMode), } } +func getCelebrationMode(mode string) api.CelebrationMode { + if api.IsAvailableCelebrationMode(mode) { + return api.CelebrationMode(mode) + } + + return "" +} + func getDefault() config { return config{ Redis: cmd.RedisConfig{ diff --git a/cmd/api/config_test.go b/cmd/api/config_test.go index 2892ab5db..286a316eb 100644 --- a/cmd/api/config_test.go +++ b/cmd/api/config_test.go @@ -258,6 +258,18 @@ func Test_webConfig_getSettings(t *testing.T) { }) } +func Test_webConfig_getCelebrationMode(t *testing.T) { + Convey("Available celebration mode, should return mode", t, func() { + celebrationMode := getCelebrationMode("new_year") + So(celebrationMode, ShouldEqual, api.CelebrationMode("new_year")) + }) + + Convey("Not available celebration mode, should return empty string", t, func() { + celebrationMode := getCelebrationMode("blablabla") + So(celebrationMode, ShouldEqual, "") + }) +} + func Test_webConfig_validate(t *testing.T) { Convey("With empty web config", t, func() { config := webConfig{}