Skip to main content

ossify/ops/service/
init_user_anti_ddos_info.rs

1//! InitUserAntiDDosInfo.
2//!
3//! Official document: <https://www.alibabacloud.com/help/en/oss/developer-reference/inituserantiddosinfo>
4
5use std::future::Future;
6
7use http::Method;
8use serde::{Deserialize, Serialize};
9
10use crate::body::ZeroBody;
11use crate::error::Result;
12use crate::response::HeaderResponseProcessor;
13use crate::ser::OnlyKeyField;
14use crate::{Client, Ops, Prepared, Request};
15
16#[derive(Debug, Clone, Default, Serialize)]
17pub struct InitUserAntiDDosInfoParams {
18    #[serde(rename = "antiDDos")]
19    anti_ddos: OnlyKeyField,
20}
21
22/// Parsed from the `x-oss-defender-instance` response header.
23#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
24pub struct InitUserAntiDDosInfoResponse {
25    #[serde(rename = "x-oss-defender-instance")]
26    pub defender_instance: String,
27}
28
29pub struct InitUserAntiDDosInfo;
30
31impl Ops for InitUserAntiDDosInfo {
32    const USE_BUCKET: bool = false;
33
34    type Response = HeaderResponseProcessor<InitUserAntiDDosInfoResponse>;
35    type Body = ZeroBody;
36    type Query = InitUserAntiDDosInfoParams;
37
38    fn prepare(self) -> Result<Prepared<InitUserAntiDDosInfoParams>> {
39        Ok(Prepared {
40            method: Method::PUT,
41            query: Some(InitUserAntiDDosInfoParams::default()),
42            body: Some(()),
43            ..Default::default()
44        })
45    }
46}
47
48pub trait InitUserAntiDDosInfoOps {
49    /// Create an OSS Anti-DDoS instance for the current account.
50    ///
51    /// Official document: <https://www.alibabacloud.com/help/en/oss/developer-reference/inituserantiddosinfo>
52    fn init_user_anti_ddos_info(&self) -> impl Future<Output = Result<InitUserAntiDDosInfoResponse>>;
53}
54
55impl InitUserAntiDDosInfoOps for Client {
56    async fn init_user_anti_ddos_info(&self) -> Result<InitUserAntiDDosInfoResponse> {
57        self.request(InitUserAntiDDosInfo).await
58    }
59}
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64
65    #[test]
66    fn params_serialize() {
67        let q = crate::ser::to_string(&InitUserAntiDDosInfoParams::default()).unwrap();
68        assert_eq!(q, "antiDDos");
69    }
70
71    #[test]
72    fn use_bucket_is_false() {
73        const _: () = assert!(!<InitUserAntiDDosInfo as Ops>::USE_BUCKET);
74    }
75
76    #[test]
77    fn method_is_put() {
78        let p = InitUserAntiDDosInfo.prepare().unwrap();
79        assert_eq!(p.method, Method::PUT);
80    }
81}