Skip to content

Commit

Permalink
feat(api): add celebration mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kissken committed Dec 4, 2024
1 parent 520c968 commit f22f795
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
28 changes: 23 additions & 5 deletions api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand Down
18 changes: 14 additions & 4 deletions cmd/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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{
Expand Down
12 changes: 12 additions & 0 deletions cmd/api/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit f22f795

Please sign in to comment.