diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..3e09564 --- /dev/null +++ b/build.sh @@ -0,0 +1,4 @@ +#! /bin/bash + +psql -U postgres -f sql/initialize_database.sql +psql -U postgres -d gorm -c "GRANT USAGE ON SCHEMA public TO gorm;" \ No newline at end of file diff --git a/config.json b/config.json index 7b3986b..3098453 100644 --- a/config.json +++ b/config.json @@ -1,50 +1,64 @@ { "database": { "host": "localhost", - "port": "5432", + "port": "5433", "user": "gorm", "password": "gorm", "dbname": "gorm" }, "host": "http://localhost", "port": ":8081", - "endpoints": [{ - "plugins": [{ - "type": "monitor", - "settings": { - "active_mode": false, - "verbose": true, - "publishers": [{ - "type": "file", - "name": "monitor-log", - "directory": "." - }] - } - }, + "endpoints": [ { - "type":"ratelimiter", - "settings":{ - "active_mode": true, - "rate": 1, - "publishers": [{ - "type": "slack", - "token": "xoxb-198202255696-5682091092327-m8IHyjQEnO6FdIIslpzjq2nz", - "channelID": "C5UTW0J6N" - }] - } - }, - { - "type": "requestfilter", - "settings":{ - "active_mode": true, - "ip-blacklist":[], - "ip-whitelist": [], - "region-whitelist": ["US", "IN"], - "region-blacklist": [] - } - }], - "methods": ["GET", "POST"], - "external": "/their-client-api", - "internal": "/our-customers-api" - }] -} + "plugins": [ + { + "type": "monitor", + "settings": { + "active_mode": false, + "verbose": true, + "publishers": [ + { + "type": "file", + "name": "monitor-log", + "directory": "." + } + ] + } + }, + { + "type": "ratelimiter", + "settings": { + "active_mode": true, + "rate": 1, + "publishers": [ + { + "type": "slack", + "token": "xoxb-198202255696-5682091092327-m8IHyjQEnO6FdIIslpzjq2nz", + "channelID": "C5UTW0J6N" + } + ] + } + }, + { + "type": "requestfilter", + "settings": { + "active_mode": true, + "ip-blacklist": [], + "ip-whitelist": [], + "region-whitelist": [ + "US", + "IN" + ], + "region-blacklist": [] + } + } + ], + "methods": [ + "GET", + "POST" + ], + "external": "/their-client-api", + "internal": "/our-customers-api" + } + ] +} \ No newline at end of file diff --git a/plugins/ipfilter/requestfilter.go b/plugins/ipfilter/requestfilter.go index a0900a5..0982c2e 100644 --- a/plugins/ipfilter/requestfilter.go +++ b/plugins/ipfilter/requestfilter.go @@ -113,8 +113,11 @@ func (p *RequestFilterPlugin) Handle(r *http.Request) error { // Handle region-based restrictions region := getRegionForIP(ip) - if len(p.regionBlacklist) > 0 { + if region == "" { + return nil + } + if len(p.regionBlacklist) > 0 { for _, restrictedRegion := range p.regionBlacklist { if region == restrictedRegion { req, err := database.NewRequest(r, "regionblacklist")