acl
fastly::acl
Compute ACLs.
Management
Management of ACLs is done via api.fastly.com. See ACLs in Compute.
One or more ACLs can be linked to a Compute service. Once linked, an ACL can be accessed from within a Compute application via its linked name.
Usage
The following example opens an ACL by its linked name and then performs a lookup within the ACL of the client's IP. Different responses are returned depending on the result of the lookup (allow or block):
123456789101112131415161718192021222324use fastly::{Error, Request, Response};
#[fastly::main]fn main(req: Request) -> Result<Response, Error> { let acl = fastly::Acl::open("my_acl").expect("can open acl");
let ip = req.get_client_ip_addr().expect("request has an ip");
let lookup = acl.try_lookup(ip)?; match lookup { Some(lookup_match) if lookup_match.is_allow() => { // IP is allowed. Ok(Response::from_body("allowed!")) } Some(_) => { // IP is not allowed. Ok(Response::from_status(403).with_body("blocked!")) } None => { // No prefixes matched the IP. Ok(Response::from_body("no match")) } }}Structs
| Acl | A Compute ACL. |
| LookupMatch | LookupMatch is the result of an ACL lookup which found a matching prefix. |
Enums
| LookupError | Errors thrown on lookup failure. |
| MatchAction | MatchAction represents an action associated with an ACL prefix. |
| OpenError | Errors thrown when calling open. |