plug_ip_whitelist v1.1.0 Plug.IpWhitelist.IpWhitelistEnforcer View Source
Only allow requests from the range of IP addresses specified in the
application config. Assumes the request ip is present in the remote_ip
attribute on the passed in plug.
If the request IP is not whitelisted, the specified response code and body
will be added to the Plug.Conn and it will be halted.
If the request IP is on the whitelist, the plug chain will continue Include this module in your plug chain with required options Options:
ip_whitelist (required): A list of ip range tuples
Example:
```
[
{{1, 1, 1, 1}, {1, 1, 1, 2}},
{{1, 2, 3, 4}, {5, 6, 7, 8}}
]
```
This designates the ranges of IP addresses which are whitelisted
response_code_when_blacklisted: The HTTP status code assigned to the
response when the request's IP address is not in the whitelist. Defaults
to `401` if not specified
response_body_when_blacklisted: The body assigned to the response when the
request's IP address is not in the whitelist. Defaults to
`"Not Authenticated"` if not specified
Example:
```
# Include after a plug which adds the request IP to the remote_ip
# attribute on the Plug.Conn
plug Plug.IpWhitelist.IpWhitelistEnforcer, [
ip_whitelist: [
{{1, 1, 1, 1}, {1, 1, 1, 2}},
{{1, 2, 3, 4}, {5, 6, 7, 8}}
]
]
```
Link to this section Summary
Functions
Initialize the plug with options as described in the module documentation
Returns true or false indicating whether the given request’s remote ip is on the given whitelist
Link to this section Functions
Link to this function
call(conn, options)
View Source
call( Plug.Conn.t(), ip_whitelist: [Plug.IpWhitelist.ip_range(), ...], response_code_when_blacklisted: integer(), response_body_when_blacklisted: String.t() ) :: Plug.Conn.t()
Link to this function
init(options)
View Source
init( ip_whitelist: [Plug.IpWhitelist.ip_range(), ...], response_code_when_blacklisted: integer(), response_body_when_blacklisted: String.t() ) :: [ ip_whitelist: [Plug.IpWhitelist.ip_range(), ...], response_code_when_blacklisted: integer(), response_body_when_blacklisted: String.t() ]
Initialize the plug with options as described in the module documentation
Link to this function
is_whitelisted?(conn, ip_whitelist)
View Source
is_whitelisted?(Plug.Conn.t(), [Plug.IpWhitelist.ip_range(), ...]) :: boolean()
Returns true or false indicating whether the given request’s remote ip is on the given whitelist