summaryrefslogtreecommitdiff
path: root/internal/config
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-11-06 10:47:48 +0100
committerLibravatar GitHub <noreply@github.com>2022-11-06 09:47:48 +0000
commit4d66fb9603ada9b04f642576bbc541189876a3f3 (patch)
tree7f9b4f3a5ab95b20eb1ad4ceaf2e6779c1e02630 /internal/config
parent[bugfix] Check `media-description-min-chars` on submission of new status (#960) (diff)
downloadgotosocial-4d66fb9603ada9b04f642576bbc541189876a3f3.tar.xz
[feature] Make rate limit requests amount configurable (#966)
* update rate limit documentation * regenerate landingpage config helpers * make rate limit rate configurable
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/config.go3
-rw-r--r--internal/config/defaults.go3
-rw-r--r--internal/config/flags.go1
-rw-r--r--internal/config/helpers.gen.go50
4 files changed, 42 insertions, 15 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 98114dea3..313e6ab05 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -129,7 +129,8 @@ type Configuration struct {
AdminAccountPassword string `name:"password" usage:"the password to set for this account"`
AdminTransPath string `name:"path" usage:"the path of the file to import from/export to"`
- AdvancedCookiesSamesite string `name:"advanced-cookies-samesite" usage:"'strict' or 'lax', see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite"`
+ AdvancedCookiesSamesite string `name:"advanced-cookies-samesite" usage:"'strict' or 'lax', see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite"`
+ AdvancedRateLimitRequests int `name:"advanced-rate-limit-requests" usage:"Amount of HTTP requests to permit within a 5 minute window. 0 or less turns rate limiting off."`
}
// MarshalMap will marshal current Configuration into a map structure (useful for JSON).
diff --git a/internal/config/defaults.go b/internal/config/defaults.go
index 37ca5e31d..058b3efb1 100644
--- a/internal/config/defaults.go
+++ b/internal/config/defaults.go
@@ -97,5 +97,6 @@ var Defaults = Configuration{
SyslogProtocol: "udp",
SyslogAddress: "localhost:514",
- AdvancedCookiesSamesite: "lax",
+ AdvancedCookiesSamesite: "lax",
+ AdvancedRateLimitRequests: 1000, // per 5 minutes
}
diff --git a/internal/config/flags.go b/internal/config/flags.go
index 38d4cd51a..bb3f67732 100644
--- a/internal/config/flags.go
+++ b/internal/config/flags.go
@@ -121,6 +121,7 @@ func AddServerFlags(cmd *cobra.Command) {
// Advanced flags
cmd.Flags().String(AdvancedCookiesSamesiteFlag(), cfg.AdvancedCookiesSamesite, fieldtag("AdvancedCookiesSamesite", "usage"))
+ cmd.Flags().Int(AdvancedRateLimitRequestsFlag(), cfg.AdvancedRateLimitRequests, fieldtag("AdvancedRateLimitRequests", "usage"))
})
}
diff --git a/internal/config/helpers.gen.go b/internal/config/helpers.gen.go
index f42593a54..45a56e796 100644
--- a/internal/config/helpers.gen.go
+++ b/internal/config/helpers.gen.go
@@ -95,6 +95,31 @@ func GetApplicationName() string { return global.GetApplicationName() }
// SetApplicationName safely sets the value for global configuration 'ApplicationName' field
func SetApplicationName(v string) { global.SetApplicationName(v) }
+// GetLandingPageUser safely fetches the Configuration value for state's 'LandingPageUser' field
+func (st *ConfigState) GetLandingPageUser() (v string) {
+ st.mutex.Lock()
+ v = st.config.LandingPageUser
+ st.mutex.Unlock()
+ return
+}
+
+// SetLandingPageUser safely sets the Configuration value for state's 'LandingPageUser' field
+func (st *ConfigState) SetLandingPageUser(v string) {
+ st.mutex.Lock()
+ defer st.mutex.Unlock()
+ st.config.LandingPageUser = v
+ st.reloadToViper()
+}
+
+// LandingPageUserFlag returns the flag name for the 'LandingPageUser' field
+func LandingPageUserFlag() string { return "landing-page-user" }
+
+// GetLandingPageUser safely fetches the value for global configuration 'LandingPageUser' field
+func GetLandingPageUser() string { return global.GetLandingPageUser() }
+
+// SetLandingPageUser safely sets the value for global configuration 'LandingPageUser' field
+func SetLandingPageUser(v string) { global.SetLandingPageUser(v) }
+
// GetConfigPath safely fetches the Configuration value for state's 'ConfigPath' field
func (st *ConfigState) GetConfigPath() (v string) {
st.mutex.Lock()
@@ -1795,28 +1820,27 @@ func GetAdvancedCookiesSamesite() string { return global.GetAdvancedCookiesSames
// SetAdvancedCookiesSamesite safely sets the value for global configuration 'AdvancedCookiesSamesite' field
func SetAdvancedCookiesSamesite(v string) { global.SetAdvancedCookiesSamesite(v) }
-// GetLandingPageUser safely fetches the Configuration value for state's 'LandingPageUser' field
-func (st *ConfigState) GetLandingPageUser() (v string) {
+// GetAdvancedRateLimitRequests safely fetches the Configuration value for state's 'AdvancedRateLimitRequests' field
+func (st *ConfigState) GetAdvancedRateLimitRequests() (v int) {
st.mutex.Lock()
- v = st.config.LandingPageUser
+ v = st.config.AdvancedRateLimitRequests
st.mutex.Unlock()
return
}
-// SetLandingPageUser safely sets the Configuration value for state's 'LandingPageUser' field
-func (st *ConfigState) SetLandingPageUser(v string) {
+// SetAdvancedRateLimitRequests safely sets the Configuration value for state's 'AdvancedRateLimitRequests' field
+func (st *ConfigState) SetAdvancedRateLimitRequests(v int) {
st.mutex.Lock()
defer st.mutex.Unlock()
- st.config.LandingPageUser = v
+ st.config.AdvancedRateLimitRequests = v
st.reloadToViper()
}
-// LandingPageUserFlag returns the flag name for the 'LandingPageUser' field
-func LandingPageUserFlag() string { return "landing-page-user" }
+// AdvancedRateLimitRequestsFlag returns the flag name for the 'AdvancedRateLimitRequests' field
+func AdvancedRateLimitRequestsFlag() string { return "advanced-rate-limit-requests" }
-// GetLandingPageUser safely fetches the value for global configuration 'LandingPageUser' field
-func GetLandingPageUser() string { return global.GetLandingPageUser() }
-
-// SetLandingPageUser safely sets the value for global configuration 'LandingPageUser' field
-func SetLandingPageUser(v string) { global.SetLandingPageUser(v) }
+// GetAdvancedRateLimitRequests safely fetches the value for global configuration 'AdvancedRateLimitRequests' field
+func GetAdvancedRateLimitRequests() int { return global.GetAdvancedRateLimitRequests() }
+// SetAdvancedRateLimitRequests safely sets the value for global configuration 'AdvancedRateLimitRequests' field
+func SetAdvancedRateLimitRequests(v int) { global.SetAdvancedRateLimitRequests(v) }