v1_synthetics_CreateSyntheticsAPITest_1717840259/
v1_synthetics_CreateSyntheticsAPITest_1717840259.rs

1// Create a multi-step api test with every type of basicAuth returns "OK - Returns
2// the created test details." response
3use datadog_api_client::datadog;
4use datadog_api_client::datadogV1::api_synthetics::SyntheticsAPI;
5use datadog_api_client::datadogV1::model::SyntheticsAPIStep;
6use datadog_api_client::datadogV1::model::SyntheticsAPITest;
7use datadog_api_client::datadogV1::model::SyntheticsAPITestConfig;
8use datadog_api_client::datadogV1::model::SyntheticsAPITestStep;
9use datadog_api_client::datadogV1::model::SyntheticsAPITestStepSubtype;
10use datadog_api_client::datadogV1::model::SyntheticsAPITestType;
11use datadog_api_client::datadogV1::model::SyntheticsAssertion;
12use datadog_api_client::datadogV1::model::SyntheticsAssertionOperator;
13use datadog_api_client::datadogV1::model::SyntheticsAssertionTarget;
14use datadog_api_client::datadogV1::model::SyntheticsAssertionTargetValue;
15use datadog_api_client::datadogV1::model::SyntheticsAssertionType;
16use datadog_api_client::datadogV1::model::SyntheticsBasicAuth;
17use datadog_api_client::datadogV1::model::SyntheticsBasicAuthDigest;
18use datadog_api_client::datadogV1::model::SyntheticsBasicAuthDigestType;
19use datadog_api_client::datadogV1::model::SyntheticsBasicAuthNTLM;
20use datadog_api_client::datadogV1::model::SyntheticsBasicAuthNTLMType;
21use datadog_api_client::datadogV1::model::SyntheticsBasicAuthOauthClient;
22use datadog_api_client::datadogV1::model::SyntheticsBasicAuthOauthClientType;
23use datadog_api_client::datadogV1::model::SyntheticsBasicAuthOauthROP;
24use datadog_api_client::datadogV1::model::SyntheticsBasicAuthOauthROPType;
25use datadog_api_client::datadogV1::model::SyntheticsBasicAuthOauthTokenApiAuthentication;
26use datadog_api_client::datadogV1::model::SyntheticsBasicAuthSigv4;
27use datadog_api_client::datadogV1::model::SyntheticsBasicAuthSigv4Type;
28use datadog_api_client::datadogV1::model::SyntheticsBasicAuthWeb;
29use datadog_api_client::datadogV1::model::SyntheticsBasicAuthWebType;
30use datadog_api_client::datadogV1::model::SyntheticsTestDetailsSubType;
31use datadog_api_client::datadogV1::model::SyntheticsTestOptions;
32use datadog_api_client::datadogV1::model::SyntheticsTestRequest;
33
34#[tokio::main]
35async fn main() {
36    let body = SyntheticsAPITest::new(
37        SyntheticsAPITestConfig::new().steps(vec![
38            SyntheticsAPIStep::SyntheticsAPITestStep(Box::new(SyntheticsAPITestStep::new(
39                vec![SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
40                    SyntheticsAssertionTarget::new(
41                        SyntheticsAssertionOperator::IS,
42                        SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueNumber(
43                            200.0 as f64,
44                        ),
45                        SyntheticsAssertionType::STATUS_CODE,
46                    ),
47                ))],
48                "request is sent".to_string(),
49                SyntheticsTestRequest::new()
50                    .basic_auth(SyntheticsBasicAuth::SyntheticsBasicAuthWeb(Box::new(
51                        SyntheticsBasicAuthWeb::new()
52                            .password("password".to_string())
53                            .username("username".to_string()),
54                    )))
55                    .method("GET".to_string())
56                    .url("https://httpbin.org/status/200".to_string()),
57                SyntheticsAPITestStepSubtype::HTTP,
58            ))),
59            SyntheticsAPIStep::SyntheticsAPITestStep(Box::new(SyntheticsAPITestStep::new(
60                vec![SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
61                    SyntheticsAssertionTarget::new(
62                        SyntheticsAssertionOperator::IS,
63                        SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueNumber(
64                            200.0 as f64,
65                        ),
66                        SyntheticsAssertionType::STATUS_CODE,
67                    ),
68                ))],
69                "request is sent".to_string(),
70                SyntheticsTestRequest::new()
71                    .basic_auth(SyntheticsBasicAuth::SyntheticsBasicAuthWeb(Box::new(
72                        SyntheticsBasicAuthWeb::new()
73                            .password("password".to_string())
74                            .type_(SyntheticsBasicAuthWebType::WEB)
75                            .username("username".to_string()),
76                    )))
77                    .method("GET".to_string())
78                    .url("https://httpbin.org/status/200".to_string()),
79                SyntheticsAPITestStepSubtype::HTTP,
80            ))),
81            SyntheticsAPIStep::SyntheticsAPITestStep(Box::new(SyntheticsAPITestStep::new(
82                vec![SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
83                    SyntheticsAssertionTarget::new(
84                        SyntheticsAssertionOperator::IS,
85                        SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueNumber(
86                            200.0 as f64,
87                        ),
88                        SyntheticsAssertionType::STATUS_CODE,
89                    ),
90                ))],
91                "request is sent".to_string(),
92                SyntheticsTestRequest::new()
93                    .basic_auth(SyntheticsBasicAuth::SyntheticsBasicAuthSigv4(Box::new(
94                        SyntheticsBasicAuthSigv4::new(
95                            "accessKey".to_string(),
96                            "secretKey".to_string(),
97                            SyntheticsBasicAuthSigv4Type::SIGV4,
98                        ),
99                    )))
100                    .method("GET".to_string())
101                    .url("https://httpbin.org/status/200".to_string()),
102                SyntheticsAPITestStepSubtype::HTTP,
103            ))),
104            SyntheticsAPIStep::SyntheticsAPITestStep(Box::new(SyntheticsAPITestStep::new(
105                vec![SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
106                    SyntheticsAssertionTarget::new(
107                        SyntheticsAssertionOperator::IS,
108                        SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueNumber(
109                            200.0 as f64,
110                        ),
111                        SyntheticsAssertionType::STATUS_CODE,
112                    ),
113                ))],
114                "request is sent".to_string(),
115                SyntheticsTestRequest::new()
116                    .basic_auth(SyntheticsBasicAuth::SyntheticsBasicAuthNTLM(Box::new(
117                        SyntheticsBasicAuthNTLM::new(SyntheticsBasicAuthNTLMType::NTLM),
118                    )))
119                    .method("GET".to_string())
120                    .url("https://httpbin.org/status/200".to_string()),
121                SyntheticsAPITestStepSubtype::HTTP,
122            ))),
123            SyntheticsAPIStep::SyntheticsAPITestStep(Box::new(SyntheticsAPITestStep::new(
124                vec![SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
125                    SyntheticsAssertionTarget::new(
126                        SyntheticsAssertionOperator::IS,
127                        SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueNumber(
128                            200.0 as f64,
129                        ),
130                        SyntheticsAssertionType::STATUS_CODE,
131                    ),
132                ))],
133                "request is sent".to_string(),
134                SyntheticsTestRequest::new()
135                    .basic_auth(SyntheticsBasicAuth::SyntheticsBasicAuthDigest(Box::new(
136                        SyntheticsBasicAuthDigest::new(
137                            "password".to_string(),
138                            SyntheticsBasicAuthDigestType::DIGEST,
139                            "username".to_string(),
140                        ),
141                    )))
142                    .method("GET".to_string())
143                    .url("https://httpbin.org/status/200".to_string()),
144                SyntheticsAPITestStepSubtype::HTTP,
145            ))),
146            SyntheticsAPIStep::SyntheticsAPITestStep(Box::new(SyntheticsAPITestStep::new(
147                vec![SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
148                    SyntheticsAssertionTarget::new(
149                        SyntheticsAssertionOperator::IS,
150                        SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueNumber(
151                            200.0 as f64,
152                        ),
153                        SyntheticsAssertionType::STATUS_CODE,
154                    ),
155                ))],
156                "request is sent".to_string(),
157                SyntheticsTestRequest::new()
158                    .basic_auth(SyntheticsBasicAuth::SyntheticsBasicAuthOauthClient(
159                        Box::new(SyntheticsBasicAuthOauthClient::new(
160                            "accessTokenUrl".to_string(),
161                            "clientId".to_string(),
162                            "clientSecret".to_string(),
163                            SyntheticsBasicAuthOauthTokenApiAuthentication::HEADER,
164                            SyntheticsBasicAuthOauthClientType::OAUTH_CLIENT,
165                        )),
166                    ))
167                    .method("GET".to_string())
168                    .url("https://httpbin.org/status/200".to_string()),
169                SyntheticsAPITestStepSubtype::HTTP,
170            ))),
171            SyntheticsAPIStep::SyntheticsAPITestStep(Box::new(SyntheticsAPITestStep::new(
172                vec![SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
173                    SyntheticsAssertionTarget::new(
174                        SyntheticsAssertionOperator::IS,
175                        SyntheticsAssertionTargetValue::SyntheticsAssertionTargetValueNumber(
176                            200.0 as f64,
177                        ),
178                        SyntheticsAssertionType::STATUS_CODE,
179                    ),
180                ))],
181                "request is sent".to_string(),
182                SyntheticsTestRequest::new()
183                    .basic_auth(SyntheticsBasicAuth::SyntheticsBasicAuthOauthROP(Box::new(
184                        SyntheticsBasicAuthOauthROP::new(
185                            "accessTokenUrl".to_string(),
186                            "password".to_string(),
187                            SyntheticsBasicAuthOauthTokenApiAuthentication::HEADER,
188                            SyntheticsBasicAuthOauthROPType::OAUTH_ROP,
189                            "username".to_string(),
190                        ),
191                    )))
192                    .method("GET".to_string())
193                    .url("https://httpbin.org/status/200".to_string()),
194                SyntheticsAPITestStepSubtype::HTTP,
195            ))),
196        ]),
197        vec!["aws:us-east-2".to_string()],
198        "BDD test payload: synthetics_api_test_multi_step_with_every_type_of_basic_auth.json"
199            .to_string(),
200        "Example-Synthetic".to_string(),
201        SyntheticsTestOptions::new().tick_every(60),
202        SyntheticsAPITestType::API,
203    )
204    .subtype(SyntheticsTestDetailsSubType::MULTI);
205    let configuration = datadog::Configuration::new();
206    let api = SyntheticsAPI::with_config(configuration);
207    let resp = api.create_synthetics_api_test(body).await;
208    if let Ok(value) = resp {
209        println!("{:#?}", value);
210    } else {
211        println!("{:#?}", resp.unwrap_err());
212    }
213}