fastly_api/models/
rate_limiter.rs

1/*
2 * Fastly API
3 *
4 * Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) 
5 *
6 */
7
8
9
10
11#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
12pub struct RateLimiter {
13    /// A human readable name for the rate limiting rule.
14    #[serde(rename = "name", skip_serializing_if = "Option::is_none")]
15    pub name: Option<String>,
16    /// The name of an Edge Dictionary containing URIs as keys. If not defined or `null`, all origin URIs will be rate limited.
17    #[serde(rename = "uri_dictionary_name", skip_serializing_if = "Option::is_none")]
18    pub uri_dictionary_name: Option<String>,
19    /// Array of HTTP methods to apply rate limiting to.
20    #[serde(rename = "http_methods", skip_serializing_if = "Option::is_none")]
21    pub http_methods: Option<std::collections::HashSet<HttpMethods>>,
22    /// Upper limit of requests per second allowed by the rate limiter.
23    #[serde(rename = "rps_limit", skip_serializing_if = "Option::is_none")]
24    pub rps_limit: Option<i32>,
25    /// Number of seconds during which the RPS limit must be exceeded in order to trigger a violation.
26    #[serde(rename = "window_size", skip_serializing_if = "Option::is_none")]
27    pub window_size: Option<WindowSize>,
28    /// Array of VCL variables used to generate a counter key to identify a client. Example variables include `req.http.Fastly-Client-IP`, `req.http.User-Agent`, or a custom header like `req.http.API-Key`.
29    #[serde(rename = "client_key", skip_serializing_if = "Option::is_none")]
30    pub client_key: Option<Vec<String>>,
31    /// Length of time in minutes that the rate limiter is in effect after the initial violation is detected.
32    #[serde(rename = "penalty_box_duration", skip_serializing_if = "Option::is_none")]
33    pub penalty_box_duration: Option<i32>,
34    /// The action to take when a rate limiter violation is detected.
35    #[serde(rename = "action", skip_serializing_if = "Option::is_none")]
36    pub action: Option<Action>,
37    /// Custom response to be sent when the rate limit is exceeded. Required if `action` is `response`.
38    #[serde(rename = "response", skip_serializing_if = "Option::is_none")]
39    pub response: Option<::std::collections::HashMap<String, String>>,
40    /// Name of existing response object. Required if `action` is `response_object`. Note that the rate limiter response is only updated to reflect the response object content when saving the rate limiter configuration.
41    #[serde(rename = "response_object_name", skip_serializing_if = "Option::is_none")]
42    pub response_object_name: Option<String>,
43    /// Name of the type of logging endpoint to be used when action is `log_only`. The logging endpoint type is used to determine the appropriate log format to use when emitting log entries.
44    #[serde(rename = "logger_type", skip_serializing_if = "Option::is_none")]
45    pub logger_type: Option<LoggerType>,
46    /// Revision number of the rate limiting feature implementation. Defaults to the most recent revision.
47    #[serde(rename = "feature_revision", skip_serializing_if = "Option::is_none")]
48    pub feature_revision: Option<i32>,
49}
50
51impl RateLimiter {
52    pub fn new() -> RateLimiter {
53        RateLimiter {
54            name: None,
55            uri_dictionary_name: None,
56            http_methods: None,
57            rps_limit: None,
58            window_size: None,
59            client_key: None,
60            penalty_box_duration: None,
61            action: None,
62            response: None,
63            response_object_name: None,
64            logger_type: None,
65            feature_revision: None,
66        }
67    }
68}
69
70/// Array of HTTP methods to apply rate limiting to.
71#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
72pub enum HttpMethods {
73    #[serde(rename = "HEAD")]
74    HEAD,
75    #[serde(rename = "OPTIONS")]
76    OPTIONS,
77    #[serde(rename = "GET")]
78    GET,
79    #[serde(rename = "POST")]
80    POST,
81    #[serde(rename = "PUT")]
82    PUT,
83    #[serde(rename = "PATCH")]
84    PATCH,
85    #[serde(rename = "DELETE")]
86    DELETE,
87    #[serde(rename = "TRACE")]
88    TRACE,
89}
90
91impl Default for HttpMethods {
92    fn default() -> HttpMethods {
93        Self::HEAD
94    }
95}
96/// Number of seconds during which the RPS limit must be exceeded in order to trigger a violation.
97#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
98pub enum WindowSize {
99    #[serde(rename = "1")]
100    WindowSizeOneSecond,
101    #[serde(rename = "10")]
102    WindowSizeTenSeconds,
103    #[serde(rename = "60")]
104    WindowSizeOneMinute,
105}
106
107impl Default for WindowSize {
108    fn default() -> WindowSize {
109        Self::WindowSizeOneSecond
110    }
111}
112/// The action to take when a rate limiter violation is detected.
113#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
114pub enum Action {
115    #[serde(rename = "response")]
116    Response,
117    #[serde(rename = "response_object")]
118    ResponseObject,
119    #[serde(rename = "log_only")]
120    LogOnly,
121}
122
123impl Default for Action {
124    fn default() -> Action {
125        Self::Response
126    }
127}
128/// Name of the type of logging endpoint to be used when action is `log_only`. The logging endpoint type is used to determine the appropriate log format to use when emitting log entries.
129#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
130pub enum LoggerType {
131    #[serde(rename = "azureblob")]
132    Azureblob,
133    #[serde(rename = "bigquery")]
134    Bigquery,
135    #[serde(rename = "cloudfiles")]
136    Cloudfiles,
137    #[serde(rename = "datadog")]
138    Datadog,
139    #[serde(rename = "digitalocean")]
140    Digitalocean,
141    #[serde(rename = "elasticsearch")]
142    Elasticsearch,
143    #[serde(rename = "ftp")]
144    Ftp,
145    #[serde(rename = "gcs")]
146    Gcs,
147    #[serde(rename = "googleanalytics")]
148    Googleanalytics,
149    #[serde(rename = "heroku")]
150    Heroku,
151    #[serde(rename = "honeycomb")]
152    Honeycomb,
153    #[serde(rename = "http")]
154    Http,
155    #[serde(rename = "https")]
156    Https,
157    #[serde(rename = "kafka")]
158    Kafka,
159    #[serde(rename = "kinesis")]
160    Kinesis,
161    #[serde(rename = "logentries")]
162    Logentries,
163    #[serde(rename = "loggly")]
164    Loggly,
165    #[serde(rename = "logshuttle")]
166    Logshuttle,
167    #[serde(rename = "newrelic")]
168    Newrelic,
169    #[serde(rename = "newrelicotlp")]
170    Newrelicotlp,
171    #[serde(rename = "openstack")]
172    Openstack,
173    #[serde(rename = "papertrail")]
174    Papertrail,
175    #[serde(rename = "pubsub")]
176    Pubsub,
177    #[serde(rename = "s3")]
178    S3,
179    #[serde(rename = "scalyr")]
180    Scalyr,
181    #[serde(rename = "sftp")]
182    Sftp,
183    #[serde(rename = "splunk")]
184    Splunk,
185    #[serde(rename = "stackdriver")]
186    Stackdriver,
187    #[serde(rename = "sumologic")]
188    Sumologic,
189    #[serde(rename = "syslog")]
190    Syslog,
191}
192
193impl Default for LoggerType {
194    fn default() -> LoggerType {
195        Self::Azureblob
196    }
197}
198