Skip to content

Commit

Permalink
Support providing files for the file upload feature when creating a S…
Browse files Browse the repository at this point in the history
…ynthetic 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>
  • Loading branch information
api-clients-generation-pipeline[bot] and ci.datadog-api-spec authored Apr 5, 2024
1 parent 06d67cd commit d716410
Show file tree
Hide file tree
Showing 12 changed files with 579 additions and 9 deletions.
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2024-04-04 19:22:22.135102",
"spec_repo_commit": "fd06108d"
"regenerated": "2024-04-05 17:05:09.050525",
"spec_repo_commit": "9b7c8967"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-04-04 19:22:22.154344",
"spec_repo_commit": "fd06108d"
"regenerated": "2024-04-05 17:05:09.094275",
"spec_repo_commit": "9b7c8967"
}
}
}
35 changes: 35 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15871,6 +15871,11 @@ components:
maximum: 65535
minimum: 1
type: integer
files:
description: Files to be used as part of the request in the test.
items:
$ref: '#/components/schemas/SyntheticsTestRequestBodyFile'
type: array
follow_redirects:
description: Specifies whether or not the request follows redirects.
type: boolean
Expand Down Expand Up @@ -15937,6 +15942,32 @@ components:
example: https://example.com
type: string
type: object
SyntheticsTestRequestBodyFile:
description: Object describing a file to be used as part of the request in the
test.
properties:
bucketKey:
description: Bucket key of the file.
type: string
content:
description: Content of the file.
maxLength: 3145728
type: string
name:
description: Name of the file.
maxLength: 1500
type: string
size:
description: Size of the file.
format: int64
maximum: 3145728
minimum: 1
type: integer
type:
description: Type of the file.
maxLength: 1500
type: string
type: object
SyntheticsTestRequestBodyType:
description: Type of the request body.
enum:
Expand All @@ -15946,6 +15977,8 @@ components:
- text/html
- application/x-www-form-urlencoded
- graphql
- application/octet-stream
- multipart/form-data
example: text/plain
type: string
x-enum-varnames:
Expand All @@ -15955,6 +15988,8 @@ components:
- TEXT_HTML
- APPLICATION_X_WWW_FORM_URLENCODED
- GRAPHQL
- APPLICATION_OCTET_STREAM
- MULTIPART_FORM_DATA
SyntheticsTestRequestCertificate:
description: Client certificate to use when performing the test request.
properties:
Expand Down
169 changes: 169 additions & 0 deletions examples/v1_synthetics_create_synthetics_api_test_1241981394.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
// Create an API test with a file payload returns "OK - Returns the created test
// details." response
use datadog_api_client::datadog::configuration::Configuration;
use datadog_api_client::datadogV1::api::api_synthetics::SyntheticsAPI;
use datadog_api_client::datadogV1::model::SyntheticsAPITest;
use datadog_api_client::datadogV1::model::SyntheticsAPITestConfig;
use datadog_api_client::datadogV1::model::SyntheticsAPITestType;
use datadog_api_client::datadogV1::model::SyntheticsAssertion;
use datadog_api_client::datadogV1::model::SyntheticsAssertionJSONPathOperator;
use datadog_api_client::datadogV1::model::SyntheticsAssertionJSONPathTarget;
use datadog_api_client::datadogV1::model::SyntheticsAssertionJSONPathTargetTarget;
use datadog_api_client::datadogV1::model::SyntheticsAssertionOperator;
use datadog_api_client::datadogV1::model::SyntheticsAssertionTarget;
use datadog_api_client::datadogV1::model::SyntheticsAssertionTimingsScope;
use datadog_api_client::datadogV1::model::SyntheticsAssertionType;
use datadog_api_client::datadogV1::model::SyntheticsAssertionXPathOperator;
use datadog_api_client::datadogV1::model::SyntheticsAssertionXPathTarget;
use datadog_api_client::datadogV1::model::SyntheticsAssertionXPathTargetTarget;
use datadog_api_client::datadogV1::model::SyntheticsBasicAuth;
use datadog_api_client::datadogV1::model::SyntheticsBasicAuthOauthClient;
use datadog_api_client::datadogV1::model::SyntheticsBasicAuthOauthClientType;
use datadog_api_client::datadogV1::model::SyntheticsBasicAuthOauthTokenApiAuthentication;
use datadog_api_client::datadogV1::model::SyntheticsConfigVariable;
use datadog_api_client::datadogV1::model::SyntheticsConfigVariableType;
use datadog_api_client::datadogV1::model::SyntheticsTestDetailsSubType;
use datadog_api_client::datadogV1::model::SyntheticsTestOptions;
use datadog_api_client::datadogV1::model::SyntheticsTestOptionsHTTPVersion;
use datadog_api_client::datadogV1::model::SyntheticsTestOptionsRetry;
use datadog_api_client::datadogV1::model::SyntheticsTestRequest;
use datadog_api_client::datadogV1::model::SyntheticsTestRequestBodyFile;
use datadog_api_client::datadogV1::model::SyntheticsTestRequestBodyType;
use datadog_api_client::datadogV1::model::SyntheticsTestRequestCertificate;
use datadog_api_client::datadogV1::model::SyntheticsTestRequestCertificateItem;
use datadog_api_client::datadogV1::model::SyntheticsTestRequestProxy;
use serde_json::Value;
use std::collections::BTreeMap;

#[tokio::main]
async fn main() {
let body = SyntheticsAPITest::new(
SyntheticsAPITestConfig::new()
.assertions(vec![
SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
SyntheticsAssertionTarget::new(
SyntheticsAssertionOperator::IS,
Value::from("text/html"),
SyntheticsAssertionType::HEADER,
)
.property("{{ PROPERTY }}".to_string()),
)),
SyntheticsAssertion::SyntheticsAssertionTarget(Box::new(
SyntheticsAssertionTarget::new(
SyntheticsAssertionOperator::LESS_THAN,
Value::from(2000),
SyntheticsAssertionType::RESPONSE_TIME,
)
.timings_scope(SyntheticsAssertionTimingsScope::WITHOUT_DNS),
)),
SyntheticsAssertion::SyntheticsAssertionJSONPathTarget(Box::new(
SyntheticsAssertionJSONPathTarget::new(
SyntheticsAssertionJSONPathOperator::VALIDATES_JSON_PATH,
SyntheticsAssertionType::BODY,
)
.target(
SyntheticsAssertionJSONPathTargetTarget::new()
.json_path("topKey".to_string())
.operator("isNot".to_string())
.target_value(Value::from("0")),
),
)),
SyntheticsAssertion::SyntheticsAssertionXPathTarget(Box::new(
SyntheticsAssertionXPathTarget::new(
SyntheticsAssertionXPathOperator::VALIDATES_X_PATH,
SyntheticsAssertionType::BODY,
)
.target(
SyntheticsAssertionXPathTargetTarget::new()
.operator("contains".to_string())
.target_value(Value::from("0"))
.x_path("target-xpath".to_string()),
),
)),
])
.config_variables(vec![SyntheticsConfigVariable::new(
"PROPERTY".to_string(),
SyntheticsConfigVariableType::TEXT,
)
.example("content-type".to_string())
.pattern("content-type".to_string())])
.request(
SyntheticsTestRequest::new()
.basic_auth(SyntheticsBasicAuth::SyntheticsBasicAuthOauthClient(
Box::new(
SyntheticsBasicAuthOauthClient::new(
"https://datadog-token.com".to_string(),
"client-id".to_string(),
"client-secret".to_string(),
SyntheticsBasicAuthOauthTokenApiAuthentication::HEADER,
)
.audience("audience".to_string())
.resource("resource".to_string())
.scope("yoyo".to_string())
.type_(SyntheticsBasicAuthOauthClientType::OAUTH_CLIENT),
),
))
.body_type(SyntheticsTestRequestBodyType::APPLICATION_OCTET_STREAM)
.certificate(
SyntheticsTestRequestCertificate::new()
.cert(
SyntheticsTestRequestCertificateItem::new()
.content("cert-content".to_string())
.filename("cert-filename".to_string())
.updated_at("2020-10-16T09:23:24.857Z".to_string()),
)
.key(
SyntheticsTestRequestCertificateItem::new()
.content("key-content".to_string())
.filename("key-filename".to_string())
.updated_at("2020-10-16T09:23:24.857Z".to_string()),
),
)
.files(vec![SyntheticsTestRequestBodyFile::new()
.content("file content".to_string())
.name("file name".to_string())
.type_("file type".to_string())])
.headers(BTreeMap::from([(
"unique".to_string(),
"examplesynthetic".to_string(),
)]))
.method("GET".to_string())
.persist_cookies(true)
.proxy(
SyntheticsTestRequestProxy::new("https://datadoghq.com".to_string())
.headers(BTreeMap::from([])),
)
.timeout(10.0 as f64)
.url("https://datadoghq.com".to_string()),
),
vec!["aws:us-east-2".to_string()],
"BDD test payload: synthetics_api_http_test_payload.json".to_string(),
"Example-Synthetic".to_string(),
SyntheticsTestOptions::new()
.accept_self_signed(false)
.allow_insecure(true)
.follow_redirects(true)
.http_version(SyntheticsTestOptionsHTTPVersion::HTTP2)
.min_failure_duration(10)
.min_location_failed(1)
.monitor_name("Example-Synthetic".to_string())
.monitor_priority(5)
.retry(
SyntheticsTestOptionsRetry::new()
.count(3)
.interval(10.0 as f64),
)
.tick_every(60),
SyntheticsAPITestType::API,
)
.subtype(SyntheticsTestDetailsSubType::HTTP)
.tags(vec!["testing:api".to_string()]);
let configuration = Configuration::new();
let api = SyntheticsAPI::with_config(configuration);
let resp = api.create_synthetics_api_test(body).await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
2 changes: 2 additions & 0 deletions examples/v1_synthetics_update_browser_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use datadog_api_client::datadogV1::model::SyntheticsTestOptionsScheduling;
use datadog_api_client::datadogV1::model::SyntheticsTestOptionsSchedulingTimeframe;
use datadog_api_client::datadogV1::model::SyntheticsTestPauseStatus;
use datadog_api_client::datadogV1::model::SyntheticsTestRequest;
use datadog_api_client::datadogV1::model::SyntheticsTestRequestBodyFile;
use datadog_api_client::datadogV1::model::SyntheticsTestRequestBodyType;
use datadog_api_client::datadogV1::model::SyntheticsTestRequestCertificate;
use datadog_api_client::datadogV1::model::SyntheticsTestRequestCertificateItem;
Expand All @@ -49,6 +50,7 @@ async fn main() {
.key(SyntheticsTestRequestCertificateItem::new()),
)
.certificate_domains(vec![])
.files(vec![SyntheticsTestRequestBodyFile::new()])
.http_version(SyntheticsTestOptionsHTTPVersion::HTTP1)
.proxy(SyntheticsTestRequestProxy::new(
"https://example.com".to_string(),
Expand Down
2 changes: 2 additions & 0 deletions src/datadogV1/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,8 @@ pub mod model_synthetics_test_request_certificate;
pub use self::model_synthetics_test_request_certificate::SyntheticsTestRequestCertificate;
pub mod model_synthetics_test_request_certificate_item;
pub use self::model_synthetics_test_request_certificate_item::SyntheticsTestRequestCertificateItem;
pub mod model_synthetics_test_request_body_file;
pub use self::model_synthetics_test_request_body_file::SyntheticsTestRequestBodyFile;
pub mod model_synthetics_test_options_http_version;
pub use self::model_synthetics_test_options_http_version::SyntheticsTestOptionsHTTPVersion;
pub mod model_synthetics_test_request_proxy;
Expand Down
21 changes: 21 additions & 0 deletions src/datadogV1/model/model_synthetics_test_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ pub struct SyntheticsTestRequest {
/// DNS server port to use for DNS tests.
#[serde(rename = "dnsServerPort")]
pub dns_server_port: Option<i32>,
/// Files to be used as part of the request in the test.
#[serde(rename = "files")]
pub files: Option<Vec<crate::datadogV1::model::SyntheticsTestRequestBodyFile>>,
/// Specifies whether or not the request follows redirects.
#[serde(rename = "follow_redirects")]
pub follow_redirects: Option<bool>,
Expand Down Expand Up @@ -119,6 +122,7 @@ impl SyntheticsTestRequest {
compressed_proto_file: None,
dns_server: None,
dns_server_port: None,
files: None,
follow_redirects: None,
headers: None,
host: None,
Expand Down Expand Up @@ -202,6 +206,14 @@ impl SyntheticsTestRequest {
self
}

pub fn files(
mut self,
value: Vec<crate::datadogV1::model::SyntheticsTestRequestBodyFile>,
) -> Self {
self.files = Some(value);
self
}

pub fn follow_redirects(mut self, value: bool) -> Self {
self.follow_redirects = Some(value);
self
Expand Down Expand Up @@ -333,6 +345,8 @@ impl<'de> Deserialize<'de> for SyntheticsTestRequest {
let mut compressed_proto_file: Option<String> = None;
let mut dns_server: Option<String> = None;
let mut dns_server_port: Option<i32> = None;
let mut files: Option<Vec<crate::datadogV1::model::SyntheticsTestRequestBodyFile>> =
None;
let mut follow_redirects: Option<bool> = None;
let mut headers: Option<std::collections::BTreeMap<String, String>> = None;
let mut host: Option<String> = None;
Expand Down Expand Up @@ -453,6 +467,12 @@ impl<'de> Deserialize<'de> for SyntheticsTestRequest {
dns_server_port =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"files" => {
if v.is_null() {
continue;
}
files = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"follow_redirects" => {
if v.is_null() {
continue;
Expand Down Expand Up @@ -591,6 +611,7 @@ impl<'de> Deserialize<'de> for SyntheticsTestRequest {
compressed_proto_file,
dns_server,
dns_server_port,
files,
follow_redirects,
headers,
host,
Expand Down
Loading

0 comments on commit d716410

Please sign in to comment.