diff options
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/config.go | 2 | ||||
| -rw-r--r-- | internal/config/const.go | 20 | ||||
| -rw-r--r-- | internal/config/flags.go | 2 | ||||
| -rw-r--r-- | internal/config/helpers.gen.go | 24 | ||||
| -rw-r--r-- | internal/config/validate.go | 13 |
5 files changed, 43 insertions, 18 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 807d686d5..5c59c47cc 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -90,7 +90,7 @@ type Configuration struct { InstanceLanguages language.Languages `name:"instance-languages" usage:"BCP47 language tags for the instance. Used to indicate the preferred languages of instance residents (in order from most-preferred to least-preferred)."` InstanceSubscriptionsProcessFrom string `name:"instance-subscriptions-process-from" usage:"Time of day from which to start running instance subscriptions processing jobs. Should be in the format 'hh:mm:ss', eg., '15:04:05'."` InstanceSubscriptionsProcessEvery time.Duration `name:"instance-subscriptions-process-every" usage:"Period to elapse between instance subscriptions processing jobs, starting from instance-subscriptions-process-from."` - InstanceStatsRandomize bool `name:"instance-stats-randomize" usage:"Set to true to randomize the stats served at api/v1/instance and api/v2/instance endpoints. Home page stats remain unchanged."` + InstanceStatsMode string `name:"instance-stats-mode" usage:"Allows you to customize the way stats are served to crawlers: one of '', 'serve', 'zero', 'baffle'. Home page stats remain unchanged."` AccountsRegistrationOpen bool `name:"accounts-registration-open" usage:"Allow anyone to submit an account signup request. If false, server will be invite-only."` AccountsReasonRequired bool `name:"accounts-reason-required" usage:"Do new account signups require a reason to be submitted on registration?"` diff --git a/internal/config/const.go b/internal/config/const.go index 48087c4ce..c8e7a9f9d 100644 --- a/internal/config/const.go +++ b/internal/config/const.go @@ -17,16 +17,28 @@ package config +// Instance federation mode determines how this +// instance federates with others (if at all). const ( - // Instance federation mode determines how this - // instance federates with others (if at all). InstanceFederationModeBlocklist = "blocklist" InstanceFederationModeAllowlist = "allowlist" InstanceFederationModeDefault = InstanceFederationModeBlocklist +) - // Request header filter mode determines how - // this instance will perform request filtering. +// Request header filter mode determines how +// this instance will perform request filtering. +const ( RequestHeaderFilterModeAllow = "allow" RequestHeaderFilterModeBlock = "block" RequestHeaderFilterModeDisabled = "" ) + +// Instance stats mode determines if and how +// stats about the instance are served at +// nodeinfo and api/v1|v2/instance endpoints. +const ( + InstanceStatsModeDefault = "" + InstanceStatsModeServe = "serve" + InstanceStatsModeZero = "zero" + InstanceStatsModeBaffle = "baffle" +) diff --git a/internal/config/flags.go b/internal/config/flags.go index b0b530d0b..d67085d6d 100644 --- a/internal/config/flags.go +++ b/internal/config/flags.go @@ -92,7 +92,7 @@ func (s *ConfigState) AddServerFlags(cmd *cobra.Command) { cmd.Flags().StringSlice(InstanceLanguagesFlag(), cfg.InstanceLanguages.TagStrs(), fieldtag("InstanceLanguages", "usage")) cmd.Flags().String(InstanceSubscriptionsProcessFromFlag(), cfg.InstanceSubscriptionsProcessFrom, fieldtag("InstanceSubscriptionsProcessFrom", "usage")) cmd.Flags().Duration(InstanceSubscriptionsProcessEveryFlag(), cfg.InstanceSubscriptionsProcessEvery, fieldtag("InstanceSubscriptionsProcessEvery", "usage")) - cmd.Flags().Bool(InstanceStatsRandomizeFlag(), cfg.InstanceStatsRandomize, fieldtag("InstanceStatsRandomize", "usage")) + cmd.Flags().String(InstanceStatsModeFlag(), cfg.InstanceStatsMode, fieldtag("InstanceStatsMode", "usage")) // Accounts cmd.Flags().Bool(AccountsRegistrationOpenFlag(), cfg.AccountsRegistrationOpen, fieldtag("AccountsRegistrationOpen", "usage")) diff --git a/internal/config/helpers.gen.go b/internal/config/helpers.gen.go index 469c46a7a..54d1b62d9 100644 --- a/internal/config/helpers.gen.go +++ b/internal/config/helpers.gen.go @@ -1057,30 +1057,30 @@ func SetInstanceSubscriptionsProcessEvery(v time.Duration) { global.SetInstanceSubscriptionsProcessEvery(v) } -// GetInstanceStatsRandomize safely fetches the Configuration value for state's 'InstanceStatsRandomize' field -func (st *ConfigState) GetInstanceStatsRandomize() (v bool) { +// GetInstanceStatsMode safely fetches the Configuration value for state's 'InstanceStatsMode' field +func (st *ConfigState) GetInstanceStatsMode() (v string) { st.mutex.RLock() - v = st.config.InstanceStatsRandomize + v = st.config.InstanceStatsMode st.mutex.RUnlock() return } -// SetInstanceStatsRandomize safely sets the Configuration value for state's 'InstanceStatsRandomize' field -func (st *ConfigState) SetInstanceStatsRandomize(v bool) { +// SetInstanceStatsMode safely sets the Configuration value for state's 'InstanceStatsMode' field +func (st *ConfigState) SetInstanceStatsMode(v string) { st.mutex.Lock() defer st.mutex.Unlock() - st.config.InstanceStatsRandomize = v + st.config.InstanceStatsMode = v st.reloadToViper() } -// InstanceStatsRandomizeFlag returns the flag name for the 'InstanceStatsRandomize' field -func InstanceStatsRandomizeFlag() string { return "instance-stats-randomize" } +// InstanceStatsModeFlag returns the flag name for the 'InstanceStatsMode' field +func InstanceStatsModeFlag() string { return "instance-stats-mode" } -// GetInstanceStatsRandomize safely fetches the value for global configuration 'InstanceStatsRandomize' field -func GetInstanceStatsRandomize() bool { return global.GetInstanceStatsRandomize() } +// GetInstanceStatsMode safely fetches the value for global configuration 'InstanceStatsMode' field +func GetInstanceStatsMode() string { return global.GetInstanceStatsMode() } -// SetInstanceStatsRandomize safely sets the value for global configuration 'InstanceStatsRandomize' field -func SetInstanceStatsRandomize(v bool) { global.SetInstanceStatsRandomize(v) } +// SetInstanceStatsMode safely sets the value for global configuration 'InstanceStatsMode' field +func SetInstanceStatsMode(v string) { global.SetInstanceStatsMode(v) } // GetAccountsRegistrationOpen safely fetches the Configuration value for state's 'AccountsRegistrationOpen' field func (st *ConfigState) GetAccountsRegistrationOpen() (v bool) { diff --git a/internal/config/validate.go b/internal/config/validate.go index c8ebd4f2d..a4ed08106 100644 --- a/internal/config/validate.go +++ b/internal/config/validate.go @@ -115,6 +115,19 @@ func Validate() error { SetInstanceLanguages(parsedLangs) } + // `instance-stats-mode` should be + // "", "zero", "serve", or "baffle" + switch statsMode := GetInstanceStatsMode(); statsMode { + case InstanceStatsModeDefault, InstanceStatsModeZero, InstanceStatsModeServe, InstanceStatsModeBaffle: + // No problem. + + default: + errf( + "%s must be set to empty string, zero, serve, or baffle, provided value was %s", + InstanceFederationModeFlag(), statsMode, + ) + } + // `web-assets-base-dir`. webAssetsBaseDir := GetWebAssetBaseDir() if webAssetsBaseDir == "" { |
