v2_service_definition_CreateOrUpdateServiceDefinitions/
v2_service-definition_CreateOrUpdateServiceDefinitions.rs

1// Create or update service definition returns "CREATED" response
2use datadog_api_client::datadog;
3use datadog_api_client::datadogV2::api_service_definition::ServiceDefinitionAPI;
4use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot2;
5use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot2Contact;
6use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot2Integrations;
7use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot2Link;
8use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot2Opsgenie;
9use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot2OpsgenieRegion;
10use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot2Pagerduty;
11use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot2Version;
12use datadog_api_client::datadogV2::model::ServiceDefinitionsCreateRequest;
13use serde_json::Value;
14use std::collections::BTreeMap;
15
16#[tokio::main]
17async fn main() {
18    let body = ServiceDefinitionsCreateRequest::ServiceDefinitionV2Dot2(Box::new(
19        ServiceDefinitionV2Dot2::new(
20            "my-service".to_string(),
21            ServiceDefinitionV2Dot2Version::V2_2,
22        )
23        .application("my-app".to_string())
24        .ci_pipeline_fingerprints(vec!["j88xdEy0J5lc".to_string(), "eZ7LMljCk8vo".to_string()])
25        .contacts(vec![ServiceDefinitionV2Dot2Contact::new(
26            "https://teams.microsoft.com/myteam".to_string(),
27            "slack".to_string(),
28        )
29        .name("My team channel".to_string())])
30        .description("My service description".to_string())
31        .extensions(BTreeMap::from([(
32            "myorg/extension".to_string(),
33            Value::from("extensionValue"),
34        )]))
35        .integrations(
36            ServiceDefinitionV2Dot2Integrations::new()
37                .opsgenie(
38                    ServiceDefinitionV2Dot2Opsgenie::new(
39                        "https://my-org.opsgenie.com/service/123e4567-e89b-12d3-a456-426614174000"
40                            .to_string(),
41                    )
42                    .region(ServiceDefinitionV2Dot2OpsgenieRegion::US),
43                )
44                .pagerduty(ServiceDefinitionV2Dot2Pagerduty::new().service_url(
45                    "https://my-org.pagerduty.com/service-directory/PMyService".to_string(),
46                )),
47        )
48        .languages(vec![
49            "dotnet".to_string(),
50            "go".to_string(),
51            "java".to_string(),
52            "js".to_string(),
53            "php".to_string(),
54            "python".to_string(),
55            "ruby".to_string(),
56            "c++".to_string(),
57        ])
58        .lifecycle("sandbox".to_string())
59        .links(vec![ServiceDefinitionV2Dot2Link::new(
60            "Runbook".to_string(),
61            "runbook".to_string(),
62            "https://my-runbook".to_string(),
63        )
64        .provider("Github".to_string())])
65        .tags(vec!["my:tag".to_string(), "service:tag".to_string()])
66        .team("my-team".to_string())
67        .tier("High".to_string())
68        .type_("web".to_string()),
69    ));
70    let configuration = datadog::Configuration::new();
71    let api = ServiceDefinitionAPI::with_config(configuration);
72    let resp = api.create_or_update_service_definitions(body).await;
73    if let Ok(value) = resp {
74        println!("{:#?}", value);
75    } else {
76        println!("{:#?}", resp.unwrap_err());
77    }
78}