Skip to content

Commit

Permalink
Move IP Whitelisting configuration middleware into core
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Buhr committed Nov 21, 2014
1 parent 2c18dab commit 67fd772
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions middleware_ip_whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"errors"
"github.com/mitchellh/mapstructure"
"net/http"
"net"
)
Expand All @@ -13,32 +12,17 @@ type IPWhiteListMiddleware struct {
TykMiddleware
}

// IPWhiteListMiddlewareConfig is the configuration element for IPWhiteListMiddleware
type IPWhiteListMiddlewareConfig struct {
EnableIpWhiteListing bool `mapstructure:"enable_ip_whitelisting" bson:"enable_ip_whitelisting" json:"enable_ip_whitelisting"`
AllowedIPs []string `mapstructure:"allowed_ips" bson:"allowed_ips" json:"allowed_ips"`
}

// New lets you do any initialisations for the object can be done here
func (i *IPWhiteListMiddleware) New() {}

// GetConfig retrieves the configuration from the API config - we user mapstructure for this for simplicity
func (i *IPWhiteListMiddleware) GetConfig() (interface{}, error) {
var thisModuleConfig IPWhiteListMiddlewareConfig

err := mapstructure.Decode(i.TykMiddleware.Spec.APIDefinition.RawData, &thisModuleConfig)
if err != nil {
log.Error(err)
return nil, err
}

return thisModuleConfig, nil
return nil, nil
}

// ProcessRequest will run any checks on the request on the way through the system, return an error to have the chain fail
func (i *IPWhiteListMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Request, configuration interface{}) (error, int) {
var ipConfig IPWhiteListMiddlewareConfig
ipConfig = configuration.(IPWhiteListMiddlewareConfig)
ipConfig := i.TykMiddleware.Spec

// Disabled, pass through
if !ipConfig.EnableIpWhiteListing {
Expand Down

0 comments on commit 67fd772

Please sign in to comment.