http_acl/
error.rs

1//! Error types for the HTTP ACL library.
2
3use crate::acl::HttpRequestMethod;
4use std::net::{IpAddr, SocketAddr};
5use std::ops::RangeInclusive;
6
7use thiserror::Error;
8
9/// Represents an error that can occur when adding a new allowed or denied entity to an ACL.
10#[non_exhaustive]
11#[derive(Clone, Debug, Eq, Hash, PartialEq, Error)]
12pub enum AddError {
13    /// The HTTP method is already allowed.
14    #[error("The HTTP method `{0:?}` is already allowed.")]
15    AlreadyAllowedMethod(HttpRequestMethod),
16    /// The HTTP method is already denied.
17    #[error("The HTTP method `{0:?}` is already denied.")]
18    AlreadyDeniedMethod(HttpRequestMethod),
19    /// The host is already allowed.
20    #[error("The host `{0}` is already allowed.")]
21    AlreadyAllowedHost(String),
22    /// The host is already denied.
23    #[error("The host `{0}` is already denied.")]
24    AlreadyDeniedHost(String),
25    /// The port range is already allowed.
26    #[error("The port range `{0:?}` is already allowed.")]
27    AlreadyAllowedPortRange(RangeInclusive<u16>),
28    /// The port range is already denied.
29    #[error("The port range `{0:?}` is already denied.")]
30    AlreadyDeniedPortRange(RangeInclusive<u16>),
31    /// The IP range is already allowed.
32    #[error("The IP range `{0:?}` is already allowed.")]
33    AlreadyAllowedIpRange(RangeInclusive<IpAddr>),
34    /// The IP range is already denied.
35    #[error("The IP range `{0:?}` is already denied.")]
36    AlreadyDeniedIpRange(RangeInclusive<IpAddr>),
37    /// The header is already allowed.
38    #[error("The header `{0}` is already allowed.")]
39    AlreadyAllowedHeader(String, Option<String>),
40    /// The header is already denied.
41    #[error("The header `{0}` is already denied.")]
42    AlreadyDeniedHeader(String, Option<String>),
43    /// The URL path is already allowed.
44    #[error("The URL path `{0}` is already allowed.")]
45    AlreadyAllowedUrlPath(String),
46    /// The URL path is already denied.
47    #[error("The URL path `{0}` is already denied.")]
48    AlreadyDeniedUrlPath(String),
49    /// The static DNS mapping is already present.
50    #[error("The static DNS mapping for `{0}`-`{1}` is already present.")]
51    AlreadyPresentStaticDnsMapping(String, SocketAddr),
52    /// The entity is not allowed or denied because it is invalid.
53    #[error("The entity `{0}` is not allowed or denied because it is invalid.")]
54    InvalidEntity(String),
55    /// The entity is not unique.
56    #[error("The entity `{0}` is not unique.")]
57    NotUnique(String),
58    /// The entity overlaps with another.
59    #[error("The entity `{0}` overlaps with another.")]
60    Overlaps(String),
61    /// The entity is both allowed and denied.
62    #[error("The entity `{0}` is both allowed and denied.")]
63    BothAllowedAndDenied(String),
64    /// General error with a message.
65    #[error("An error occurred: `{0}`")]
66    Error(String),
67}