v1_synthetics_CreateGlobalVariable/
v1_synthetics_CreateGlobalVariable.rs

1// Create a global variable returns "OK" response
2use datadog_api_client::datadog;
3use datadog_api_client::datadogV1::api_synthetics::SyntheticsAPI;
4use datadog_api_client::datadogV1::model::SyntheticsGlobalVariableAttributes;
5use datadog_api_client::datadogV1::model::SyntheticsGlobalVariableParseTestOptions;
6use datadog_api_client::datadogV1::model::SyntheticsGlobalVariableParseTestOptionsType;
7use datadog_api_client::datadogV1::model::SyntheticsGlobalVariableParserType;
8use datadog_api_client::datadogV1::model::SyntheticsGlobalVariableRequest;
9use datadog_api_client::datadogV1::model::SyntheticsGlobalVariableValue;
10use datadog_api_client::datadogV1::model::SyntheticsVariableParser;
11
12#[tokio::main]
13async fn main() {
14    let body = SyntheticsGlobalVariableRequest::new(
15        "Example description".to_string(),
16        "MY_VARIABLE".to_string(),
17        vec!["team:front".to_string(), "test:workflow-1".to_string()],
18    )
19    .attributes(
20        SyntheticsGlobalVariableAttributes::new()
21            .restricted_roles(vec!["xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".to_string()]),
22    )
23    .parse_test_options(
24        SyntheticsGlobalVariableParseTestOptions::new(
25            SyntheticsGlobalVariableParseTestOptionsType::HTTP_BODY,
26        )
27        .field("content-type".to_string())
28        .local_variable_name("LOCAL_VARIABLE".to_string())
29        .parser(
30            SyntheticsVariableParser::new(SyntheticsGlobalVariableParserType::REGEX)
31                .value(".*".to_string()),
32        ),
33    )
34    .parse_test_public_id("abc-def-123".to_string())
35    .value(
36        SyntheticsGlobalVariableValue::new()
37            .secure(true)
38            .value("value".to_string()),
39    );
40    let configuration = datadog::Configuration::new();
41    let api = SyntheticsAPI::with_config(configuration);
42    let resp = api.create_global_variable(body).await;
43    if let Ok(value) = resp {
44        println!("{:#?}", value);
45    } else {
46        println!("{:#?}", resp.unwrap_err());
47    }
48}