Skip to content

Commit d716410

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
and
ci.datadog-api-spec
authored
Support providing files for the file upload feature when creating a Synthetic API test (#67)
Co-authored-by: ci.datadog-api-spec <[email protected]> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com>
1 parent 06d67cd commit d716410

12 files changed

+579
-9
lines changed

.apigentools-info

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.6",
7-
"regenerated": "2024-04-04 19:22:22.135102",
8-
"spec_repo_commit": "fd06108d"
7+
"regenerated": "2024-04-05 17:05:09.050525",
8+
"spec_repo_commit": "9b7c8967"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2024-04-04 19:22:22.154344",
13-
"spec_repo_commit": "fd06108d"
12+
"regenerated": "2024-04-05 17:05:09.094275",
13+
"spec_repo_commit": "9b7c8967"
1414
}
1515
}
1616
}

.generator/schemas/v1/openapi.yaml

+35
Original file line numberDiff line numberDiff line change
@@ -15871,6 +15871,11 @@ components:
1587115871
maximum: 65535
1587215872
minimum: 1
1587315873
type: integer
15874+
files:
15875+
description: Files to be used as part of the request in the test.
15876+
items:
15877+
$ref: '#/components/schemas/SyntheticsTestRequestBodyFile'
15878+
type: array
1587415879
follow_redirects:
1587515880
description: Specifies whether or not the request follows redirects.
1587615881
type: boolean
@@ -15937,6 +15942,32 @@ components:
1593715942
example: https://example.com
1593815943
type: string
1593915944
type: object
15945+
SyntheticsTestRequestBodyFile:
15946+
description: Object describing a file to be used as part of the request in the
15947+
test.
15948+
properties:
15949+
bucketKey:
15950+
description: Bucket key of the file.
15951+
type: string
15952+
content:
15953+
description: Content of the file.
15954+
maxLength: 3145728
15955+
type: string
15956+
name:
15957+
description: Name of the file.
15958+
maxLength: 1500
15959+
type: string
15960+
size:
15961+
description: Size of the file.
15962+
format: int64
15963+
maximum: 3145728
15964+
minimum: 1
15965+
type: integer
15966+
type:
15967+
description: Type of the file.
15968+
maxLength: 1500
15969+
type: string
15970+
type: object
1594015971
SyntheticsTestRequestBodyType:
1594115972
description: Type of the request body.
1594215973
enum:
@@ -15946,6 +15977,8 @@ components:
1594615977
- text/html
1594715978
- application/x-www-form-urlencoded
1594815979
- graphql
15980+
- application/octet-stream
15981+
- multipart/form-data
1594915982
example: text/plain
1595015983
type: string
1595115984
x-enum-varnames:
@@ -15955,6 +15988,8 @@ components:
1595515988
- TEXT_HTML
1595615989
- APPLICATION_X_WWW_FORM_URLENCODED
1595715990
- GRAPHQL
15991+
- APPLICATION_OCTET_STREAM
15992+
- MULTIPART_FORM_DATA
1595815993
SyntheticsTestRequestCertificate:
1595915994
description: Client certificate to use when performing the test request.
1596015995
properties:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
// Create an API test with a file payload returns "OK - Returns the created test
2+
// details." response
3+
use datadog_api_client::datadog::configuration::Configuration;
4+
use datadog_api_client::datadogV1::api::api_synthetics::SyntheticsAPI;
5+
use datadog_api_client::datadogV1::model::SyntheticsAPITest;
6+
use datadog_api_client::datadogV1::model::SyntheticsAPITestConfig;
7+
use datadog_api_client::datadogV1::model::SyntheticsAPITestType;
8+
use datadog_api_client::datadogV1::model::SyntheticsAssertion;
9+
use datadog_api_client::datadogV1::model::SyntheticsAssertionJSONPathOperator;
10+
use datadog_api_client::datadogV1::model::SyntheticsAssertionJSONPathTarget;
11+
use datadog_api_client::datadogV1::model::SyntheticsAssertionJSONPathTargetTarget;
12+
use datadog_api_client::datadogV1::model::SyntheticsAssertionOperator;
13+
use datadog_api_client::datadogV1::model::SyntheticsAssertionTarget;
14+
use datadog_api_client::datadogV1::model::SyntheticsAssertionTimingsScope;
15+
use datadog_api_client::datadogV1::model::SyntheticsAssertionType;
16+
use datadog_api_client::datadogV1::model::SyntheticsAssertionXPathOperator;
17+
use datadog_api_client::datadogV1::model::SyntheticsAssertionXPathTarget;
18+
use datadog_api_client::datadogV1::model::SyntheticsAssertionXPathTargetTarget;
19+
use datadog_api_client::datadogV1::model::SyntheticsBasicAuth;
20+
use datadog_api_client::datadogV1::model::SyntheticsBasicAuthOauthClient;
21+
use datadog_api_client::datadogV1::model::SyntheticsBasicAuthOauthClientType;
22+
use datadog_api_client::datadogV1::model::SyntheticsBasicAuthOauthTokenApiAuthentication;
23+
use datadog_api_client::datadogV1::model::SyntheticsConfigVariable;
24+
use datadog_api_client::datadogV1::model::SyntheticsConfigVariableType;
25+
use datadog_api_client::datadogV1::model::SyntheticsTestDetailsSubType;
26+
use datadog_api_client::datadogV1::model::SyntheticsTestOptions;
27+
use datadog_api_client::datadogV1::model::SyntheticsTestOptionsHTTPVersion;
28+
use datadog_api_client::datadogV1::model::SyntheticsTestOptionsRetry;
29+
use datadog_api_client::datadogV1::model::SyntheticsTestRequest;
30+
use datadog_api_client::datadogV1::model::SyntheticsTestRequestBodyFile;
31+
use datadog_api_client::datadogV1::model::SyntheticsTestRequestBodyType;
32+
use datadog_api_client::datadogV1::model::SyntheticsTestRequestCertificate;
33+
use datadog_api_client::datadogV1::model::SyntheticsTestRequestCertificateItem;
34+
use datadog_api_client::datadogV1::model::SyntheticsTestRequestProxy;
35+
use serde_json::Value;
36+
use std::collections::BTreeMap;
37+
38+
#[tokio::main]
39+
async fn main() {
40+
let body = SyntheticsAPITest::new(
41+
SyntheticsAPITestConfig::new()
42+
.assertions(vec![
43+
SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
44+
SyntheticsAssertionTarget::new(
45+
SyntheticsAssertionOperator::IS,
46+
Value::from("text/html"),
47+
SyntheticsAssertionType::HEADER,
48+
)
49+
.property("{{ PROPERTY }}".to_string()),
50+
)),
51+
SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
52+
SyntheticsAssertionTarget::new(
53+
SyntheticsAssertionOperator::LESS_THAN,
54+
Value::from(2000),
55+
SyntheticsAssertionType::RESPONSE_TIME,
56+
)
57+
.timings_scope(SyntheticsAssertionTimingsScope::WITHOUT_DNS),
58+
)),
59+
SyntheticsAssertion::SyntheticsAssertionJSONPathTarget(Box::new(
60+
SyntheticsAssertionJSONPathTarget::new(
61+
SyntheticsAssertionJSONPathOperator::VALIDATES_JSON_PATH,
62+
SyntheticsAssertionType::BODY,
63+
)
64+
.target(
65+
SyntheticsAssertionJSONPathTargetTarget::new()
66+
.json_path("topKey".to_string())
67+
.operator("isNot".to_string())
68+
.target_value(Value::from("0")),
69+
),
70+
)),
71+
SyntheticsAssertion::SyntheticsAssertionXPathTarget(Box::new(
72+
SyntheticsAssertionXPathTarget::new(
73+
SyntheticsAssertionXPathOperator::VALIDATES_X_PATH,
74+
SyntheticsAssertionType::BODY,
75+
)
76+
.target(
77+
SyntheticsAssertionXPathTargetTarget::new()
78+
.operator("contains".to_string())
79+
.target_value(Value::from("0"))
80+
.x_path("target-xpath".to_string()),
81+
),
82+
)),
83+
])
84+
.config_variables(vec![SyntheticsConfigVariable::new(
85+
"PROPERTY".to_string(),
86+
SyntheticsConfigVariableType::TEXT,
87+
)
88+
.example("content-type".to_string())
89+
.pattern("content-type".to_string())])
90+
.request(
91+
SyntheticsTestRequest::new()
92+
.basic_auth(SyntheticsBasicAuth::SyntheticsBasicAuthOauthClient(
93+
Box::new(
94+
SyntheticsBasicAuthOauthClient::new(
95+
"https://datadog-token.com".to_string(),
96+
"client-id".to_string(),
97+
"client-secret".to_string(),
98+
SyntheticsBasicAuthOauthTokenApiAuthentication::HEADER,
99+
)
100+
.audience("audience".to_string())
101+
.resource("resource".to_string())
102+
.scope("yoyo".to_string())
103+
.type_(SyntheticsBasicAuthOauthClientType::OAUTH_CLIENT),
104+
),
105+
))
106+
.body_type(SyntheticsTestRequestBodyType::APPLICATION_OCTET_STREAM)
107+
.certificate(
108+
SyntheticsTestRequestCertificate::new()
109+
.cert(
110+
SyntheticsTestRequestCertificateItem::new()
111+
.content("cert-content".to_string())
112+
.filename("cert-filename".to_string())
113+
.updated_at("2020-10-16T09:23:24.857Z".to_string()),
114+
)
115+
.key(
116+
SyntheticsTestRequestCertificateItem::new()
117+
.content("key-content".to_string())
118+
.filename("key-filename".to_string())
119+
.updated_at("2020-10-16T09:23:24.857Z".to_string()),
120+
),
121+
)
122+
.files(vec![SyntheticsTestRequestBodyFile::new()
123+
.content("file content".to_string())
124+
.name("file name".to_string())
125+
.type_("file type".to_string())])
126+
.headers(BTreeMap::from([(
127+
"unique".to_string(),
128+
"examplesynthetic".to_string(),
129+
)]))
130+
.method("GET".to_string())
131+
.persist_cookies(true)
132+
.proxy(
133+
SyntheticsTestRequestProxy::new("https://datadoghq.com".to_string())
134+
.headers(BTreeMap::from([])),
135+
)
136+
.timeout(10.0 as f64)
137+
.url("https://datadoghq.com".to_string()),
138+
),
139+
vec!["aws:us-east-2".to_string()],
140+
"BDD test payload: synthetics_api_http_test_payload.json".to_string(),
141+
"Example-Synthetic".to_string(),
142+
SyntheticsTestOptions::new()
143+
.accept_self_signed(false)
144+
.allow_insecure(true)
145+
.follow_redirects(true)
146+
.http_version(SyntheticsTestOptionsHTTPVersion::HTTP2)
147+
.min_failure_duration(10)
148+
.min_location_failed(1)
149+
.monitor_name("Example-Synthetic".to_string())
150+
.monitor_priority(5)
151+
.retry(
152+
SyntheticsTestOptionsRetry::new()
153+
.count(3)
154+
.interval(10.0 as f64),
155+
)
156+
.tick_every(60),
157+
SyntheticsAPITestType::API,
158+
)
159+
.subtype(SyntheticsTestDetailsSubType::HTTP)
160+
.tags(vec!["testing:api".to_string()]);
161+
let configuration = Configuration::new();
162+
let api = SyntheticsAPI::with_config(configuration);
163+
let resp = api.create_synthetics_api_test(body).await;
164+
if let Ok(value) = resp {
165+
println!("{:#?}", value);
166+
} else {
167+
println!("{:#?}", resp.unwrap_err());
168+
}
169+
}

examples/v1_synthetics_update_browser_test.rs

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use datadog_api_client::datadogV1::model::SyntheticsTestOptionsScheduling;
2626
use datadog_api_client::datadogV1::model::SyntheticsTestOptionsSchedulingTimeframe;
2727
use datadog_api_client::datadogV1::model::SyntheticsTestPauseStatus;
2828
use datadog_api_client::datadogV1::model::SyntheticsTestRequest;
29+
use datadog_api_client::datadogV1::model::SyntheticsTestRequestBodyFile;
2930
use datadog_api_client::datadogV1::model::SyntheticsTestRequestBodyType;
3031
use datadog_api_client::datadogV1::model::SyntheticsTestRequestCertificate;
3132
use datadog_api_client::datadogV1::model::SyntheticsTestRequestCertificateItem;
@@ -49,6 +50,7 @@ async fn main() {
4950
.key(SyntheticsTestRequestCertificateItem::new()),
5051
)
5152
.certificate_domains(vec![])
53+
.files(vec![SyntheticsTestRequestBodyFile::new()])
5254
.http_version(SyntheticsTestOptionsHTTPVersion::HTTP1)
5355
.proxy(SyntheticsTestRequestProxy::new(
5456
"https://example.com".to_string(),

src/datadogV1/model/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,8 @@ pub mod model_synthetics_test_request_certificate;
13221322
pub use self::model_synthetics_test_request_certificate::SyntheticsTestRequestCertificate;
13231323
pub mod model_synthetics_test_request_certificate_item;
13241324
pub use self::model_synthetics_test_request_certificate_item::SyntheticsTestRequestCertificateItem;
1325+
pub mod model_synthetics_test_request_body_file;
1326+
pub use self::model_synthetics_test_request_body_file::SyntheticsTestRequestBodyFile;
13251327
pub mod model_synthetics_test_options_http_version;
13261328
pub use self::model_synthetics_test_options_http_version::SyntheticsTestOptionsHTTPVersion;
13271329
pub mod model_synthetics_test_request_proxy;

src/datadogV1/model/model_synthetics_test_request.rs

+21
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ pub struct SyntheticsTestRequest {
4444
/// DNS server port to use for DNS tests.
4545
#[serde(rename = "dnsServerPort")]
4646
pub dns_server_port: Option<i32>,
47+
/// Files to be used as part of the request in the test.
48+
#[serde(rename = "files")]
49+
pub files: Option<Vec<crate::datadogV1::model::SyntheticsTestRequestBodyFile>>,
4750
/// Specifies whether or not the request follows redirects.
4851
#[serde(rename = "follow_redirects")]
4952
pub follow_redirects: Option<bool>,
@@ -119,6 +122,7 @@ impl SyntheticsTestRequest {
119122
compressed_proto_file: None,
120123
dns_server: None,
121124
dns_server_port: None,
125+
files: None,
122126
follow_redirects: None,
123127
headers: None,
124128
host: None,
@@ -202,6 +206,14 @@ impl SyntheticsTestRequest {
202206
self
203207
}
204208

209+
pub fn files(
210+
mut self,
211+
value: Vec<crate::datadogV1::model::SyntheticsTestRequestBodyFile>,
212+
) -> Self {
213+
self.files = Some(value);
214+
self
215+
}
216+
205217
pub fn follow_redirects(mut self, value: bool) -> Self {
206218
self.follow_redirects = Some(value);
207219
self
@@ -333,6 +345,8 @@ impl<'de> Deserialize<'de> for SyntheticsTestRequest {
333345
let mut compressed_proto_file: Option<String> = None;
334346
let mut dns_server: Option<String> = None;
335347
let mut dns_server_port: Option<i32> = None;
348+
let mut files: Option<Vec<crate::datadogV1::model::SyntheticsTestRequestBodyFile>> =
349+
None;
336350
let mut follow_redirects: Option<bool> = None;
337351
let mut headers: Option<std::collections::BTreeMap<String, String>> = None;
338352
let mut host: Option<String> = None;
@@ -453,6 +467,12 @@ impl<'de> Deserialize<'de> for SyntheticsTestRequest {
453467
dns_server_port =
454468
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
455469
}
470+
"files" => {
471+
if v.is_null() {
472+
continue;
473+
}
474+
files = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
475+
}
456476
"follow_redirects" => {
457477
if v.is_null() {
458478
continue;
@@ -591,6 +611,7 @@ impl<'de> Deserialize<'de> for SyntheticsTestRequest {
591611
compressed_proto_file,
592612
dns_server,
593613
dns_server_port,
614+
files,
594615
follow_redirects,
595616
headers,
596617
host,

0 commit comments

Comments
 (0)