diff --git a/app/method.go b/app/method.go index d72053d..ded24fc 100644 --- a/app/method.go +++ b/app/method.go @@ -69,7 +69,7 @@ func initialCaretaker(c *gin.Context, f func(md common.MethodData) common.CodeMe } // requests from hanayo should not be rate limited. - if ip != "127.0.0.1" || c.Request.UserAgent() != "hanayo" { + if !(c.Request.Header.Get("H-Key") == cf.HanayoKey && c.Request.UserAgent() == "hanayo") { perUserRequestLimiter(md.ID(), c.ClientIP()) } diff --git a/app/start.go b/app/start.go index 6806a54..ec44dfc 100644 --- a/app/start.go +++ b/app/start.go @@ -13,11 +13,15 @@ import ( "github.com/gin-gonic/gin" ) -var db *sql.DB +var ( + db *sql.DB + cf common.Conf +) // Start begins taking HTTP connections. func Start(conf common.Conf, dbO *sql.DB) *gin.Engine { db = dbO + cf = conf setUpLimiter() diff --git a/common/conf.go b/common/conf.go index 3afbf5d..2a129f5 100644 --- a/common/conf.go +++ b/common/conf.go @@ -18,6 +18,7 @@ type Conf struct { ListenTo string `description:"The IP/Port combination from which to take connections, e.g. :8080"` Unix bool `description:"Bool indicating whether ListenTo is a UNIX socket or an address."` SentryDSN string `description:"thing for sentry whatever"` + HanayoKey string } var cachedConf *Conf @@ -36,6 +37,7 @@ func Load() (c Conf, halt bool) { DSN: "root@/ripple", ListenTo: ":40001", Unix: false, + HanayoKey: "Potato", }, "api.conf") fmt.Println("Please compile the configuration file (api.conf).") }