v2_service_definition_CreateOrUpdateServiceDefinitions_2619874414/
v2_service-definition_CreateOrUpdateServiceDefinitions_2619874414.rs

1// Create or update service definition using schema v2-1 returns "CREATED" response
2use datadog_api_client::datadog;
3use datadog_api_client::datadogV2::api_service_definition::ServiceDefinitionAPI;
4use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot1;
5use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot1Contact;
6use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot1Email;
7use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot1EmailType;
8use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot1Integrations;
9use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot1Link;
10use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot1LinkType;
11use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot1Opsgenie;
12use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot1OpsgenieRegion;
13use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot1Pagerduty;
14use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot1Version;
15use datadog_api_client::datadogV2::model::ServiceDefinitionsCreateRequest;
16use serde_json::Value;
17use std::collections::BTreeMap;
18
19#[tokio::main]
20async fn main() {
21    let body = ServiceDefinitionsCreateRequest::ServiceDefinitionV2Dot1(Box::new(
22        ServiceDefinitionV2Dot1::new(
23            "service-exampleservicedefinition".to_string(),
24            ServiceDefinitionV2Dot1Version::V2_1,
25        )
26        .contacts(vec![
27            ServiceDefinitionV2Dot1Contact::ServiceDefinitionV2Dot1Email(Box::new(
28                ServiceDefinitionV2Dot1Email::new(
29                    "contact@datadoghq.com".to_string(),
30                    ServiceDefinitionV2Dot1EmailType::EMAIL,
31                )
32                .name("Team Email".to_string()),
33            )),
34        ])
35        .extensions(BTreeMap::from([(
36            "myorgextension".to_string(),
37            Value::from("extensionvalue"),
38        )]))
39        .integrations(
40            ServiceDefinitionV2Dot1Integrations::new()
41                .opsgenie(
42                    ServiceDefinitionV2Dot1Opsgenie::new(
43                        "https://my-org.opsgenie.com/service/123e4567-e89b-12d3-a456-426614174000"
44                            .to_string(),
45                    )
46                    .region(ServiceDefinitionV2Dot1OpsgenieRegion::US),
47                )
48                .pagerduty(ServiceDefinitionV2Dot1Pagerduty::new().service_url(
49                    "https://my-org.pagerduty.com/service-directory/PMyService".to_string(),
50                )),
51        )
52        .links(vec![
53            ServiceDefinitionV2Dot1Link::new(
54                "Runbook".to_string(),
55                ServiceDefinitionV2Dot1LinkType::RUNBOOK,
56                "https://my-runbook".to_string(),
57            ),
58            ServiceDefinitionV2Dot1Link::new(
59                "Source Code".to_string(),
60                ServiceDefinitionV2Dot1LinkType::REPO,
61                "https://github.com/DataDog/schema".to_string(),
62            )
63            .provider("GitHub".to_string()),
64            ServiceDefinitionV2Dot1Link::new(
65                "Architecture".to_string(),
66                ServiceDefinitionV2Dot1LinkType::DOC,
67                "https://my-runbook".to_string(),
68            )
69            .provider("Gigoogle drivetHub".to_string()),
70        ])
71        .tags(vec!["my:tag".to_string(), "service:tag".to_string()])
72        .team("my-team".to_string()),
73    ));
74    let configuration = datadog::Configuration::new();
75    let api = ServiceDefinitionAPI::with_config(configuration);
76    let resp = api.create_or_update_service_definitions(body).await;
77    if let Ok(value) = resp {
78        println!("{:#?}", value);
79    } else {
80        println!("{:#?}", resp.unwrap_err());
81    }
82}