v2_service_accounts_CreateServiceAccountApplicationKey_3480494373/
v2_service-accounts_CreateServiceAccountApplicationKey_3480494373.rs

1// Create an application key with scopes for this service account returns
2// "Created" response
3use datadog_api_client::datadog;
4use datadog_api_client::datadogV2::api_service_accounts::ServiceAccountsAPI;
5use datadog_api_client::datadogV2::model::ApplicationKeyCreateAttributes;
6use datadog_api_client::datadogV2::model::ApplicationKeyCreateData;
7use datadog_api_client::datadogV2::model::ApplicationKeyCreateRequest;
8use datadog_api_client::datadogV2::model::ApplicationKeysType;
9
10#[tokio::main]
11async fn main() {
12    // there is a valid "service_account_user" in the system
13    let service_account_user_data_id = std::env::var("SERVICE_ACCOUNT_USER_DATA_ID").unwrap();
14    let body = ApplicationKeyCreateRequest::new(ApplicationKeyCreateData::new(
15        ApplicationKeyCreateAttributes::new("Example-Service-Account".to_string()).scopes(Some(
16            vec![
17                "dashboards_read".to_string(),
18                "dashboards_write".to_string(),
19                "dashboards_public_share".to_string(),
20            ],
21        )),
22        ApplicationKeysType::APPLICATION_KEYS,
23    ));
24    let configuration = datadog::Configuration::new();
25    let api = ServiceAccountsAPI::with_config(configuration);
26    let resp = api
27        .create_service_account_application_key(service_account_user_data_id.clone(), body)
28        .await;
29    if let Ok(value) = resp {
30        println!("{:#?}", value);
31    } else {
32        println!("{:#?}", resp.unwrap_err());
33    }
34}