1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Create or update entities returns "ACCEPTED" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_software_catalog::SoftwareCatalogAPI;
use datadog_api_client::datadogV2::model::EntityV3;
use datadog_api_client::datadogV2::model::EntityV3APIVersion;
use datadog_api_client::datadogV2::model::EntityV3DatadogCodeLocationItem;
use datadog_api_client::datadogV2::model::EntityV3DatadogEventItem;
use datadog_api_client::datadogV2::model::EntityV3DatadogIntegrationOpsgenie;
use datadog_api_client::datadogV2::model::EntityV3DatadogIntegrationPagerduty;
use datadog_api_client::datadogV2::model::EntityV3DatadogLogItem;
use datadog_api_client::datadogV2::model::EntityV3DatadogPerformance;
use datadog_api_client::datadogV2::model::EntityV3DatadogPipelines;
use datadog_api_client::datadogV2::model::EntityV3Integrations;
use datadog_api_client::datadogV2::model::EntityV3Metadata;
use datadog_api_client::datadogV2::model::EntityV3MetadataContactsItems;
use datadog_api_client::datadogV2::model::EntityV3MetadataLinksItems;
use datadog_api_client::datadogV2::model::EntityV3Service;
use datadog_api_client::datadogV2::model::EntityV3ServiceDatadog;
use datadog_api_client::datadogV2::model::EntityV3ServiceKind;
use datadog_api_client::datadogV2::model::EntityV3ServiceSpec;
use datadog_api_client::datadogV2::model::UpsertCatalogEntityRequest;

#[tokio::main]
async fn main() {
    let body = UpsertCatalogEntityRequest::EntityV3(Box::new(EntityV3::EntityV3Service(Box::new(
        EntityV3Service::new(
            EntityV3APIVersion::V3,
            EntityV3ServiceKind::SERVICE,
            EntityV3Metadata::new("myService".to_string())
                .additional_owners(vec![])
                .contacts(vec![EntityV3MetadataContactsItems::new(
                    "https://slack/".to_string(),
                    "slack".to_string(),
                )])
                .id("4b163705-23c0-4573-b2fb-f6cea2163fcb".to_string())
                .inherit_from("application:default/myapp".to_string())
                .links(vec![EntityV3MetadataLinksItems::new(
                    "mylink".to_string(),
                    "link".to_string(),
                    "https://mylink".to_string(),
                )])
                .namespace("default".to_string())
                .tags(vec!["this:tag".to_string(), "that:tag".to_string()]),
        )
        .datadog(
            EntityV3ServiceDatadog::new()
                .code_locations(vec![EntityV3DatadogCodeLocationItem::new().paths(vec![])])
                .events(vec![EntityV3DatadogEventItem::new()])
                .logs(vec![EntityV3DatadogLogItem::new()])
                .performance_data(EntityV3DatadogPerformance::new().tags(vec![]))
                .pipelines(EntityV3DatadogPipelines::new().fingerprints(vec![])),
        )
        .integrations(
            EntityV3Integrations::new()
                .opsgenie(EntityV3DatadogIntegrationOpsgenie::new(
                    "https://www.opsgenie.com/service/shopping-cart".to_string(),
                ))
                .pagerduty(EntityV3DatadogIntegrationPagerduty::new(
                    "https://www.pagerduty.com/service-directory/Pshopping-cart".to_string(),
                )),
        )
        .spec(
            EntityV3ServiceSpec::new()
                .depends_on(vec![])
                .languages(vec![]),
        ),
    ))));
    let configuration = datadog::Configuration::new();
    let api = SoftwareCatalogAPI::with_config(configuration);
    let resp = api.upsert_catalog_entity(body).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}