ratelimiting!!!!
This commit is contained in:
@@ -3,7 +3,9 @@ package config
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/netip"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -22,8 +24,10 @@ type Config struct {
|
||||
|
||||
DatabasePath string
|
||||
// public host like "https://bin.zip", NOT the address minbin listens on
|
||||
Host string
|
||||
Addr string
|
||||
Host string
|
||||
Addr string
|
||||
IPAdressSource string
|
||||
TrustedProxies []netip.Prefix
|
||||
}
|
||||
|
||||
func LoadConfig() (Config, error) {
|
||||
@@ -70,6 +74,21 @@ func LoadConfig() (Config, error) {
|
||||
if len(reportOptions) == 0 {
|
||||
return Config{}, fmt.Errorf("no valid report options set")
|
||||
}
|
||||
ipAddressSource := envOrDefault("MINIBIN_IP_ADDRESS_SOURCE", "remote")
|
||||
if !slices.Contains([]string{"remote", "cloudflare", "xff"}, ipAddressSource) {
|
||||
return Config{}, fmt.Errorf("%s is not a valid MINIBIN_IP_ADDRESS_SOURCE option", ipAddressSource)
|
||||
}
|
||||
var trustedProxies []netip.Prefix
|
||||
if rawTrusted := envOrDefault("MINIBIN_TRUSTED_PROXIES", ""); rawTrusted != "" {
|
||||
for entry := range strings.SplitSeq(rawTrusted, ",") {
|
||||
entry = strings.TrimSpace(entry)
|
||||
prefix, err := netip.ParsePrefix(entry)
|
||||
if err != nil {
|
||||
return Config{}, fmt.Errorf("MINIBIN_TRUSTED_PROXIES: invalid cidr %q: %w", entry, err)
|
||||
}
|
||||
trustedProxies = append(trustedProxies, prefix)
|
||||
}
|
||||
}
|
||||
|
||||
return Config{
|
||||
UploadDir: envOrDefault("MINIBIN_UPLOAD_DIR", "uploads"),
|
||||
@@ -81,9 +100,11 @@ func LoadConfig() (Config, error) {
|
||||
PoWDifficulty: powDifficulty,
|
||||
ReportOptions: reportOptions,
|
||||
|
||||
DatabasePath: envOrDefault("MINIBIN_DATABASE_PATH", "minibin.sqlite"),
|
||||
Host: envOrDefault("MINIBIN_HOST", "http://localhost:8080"),
|
||||
Addr: envOrDefault("MINIBIN_ADDR", "localhost:8080"),
|
||||
DatabasePath: envOrDefault("MINIBIN_DATABASE_PATH", "minibin.sqlite"),
|
||||
Host: envOrDefault("MINIBIN_HOST", "http://localhost:8080"),
|
||||
Addr: envOrDefault("MINIBIN_ADDR", "localhost:8080"),
|
||||
IPAdressSource: ipAddressSource,
|
||||
TrustedProxies: trustedProxies,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user