From b5e18223916577b9b99b4f3de221c704ca23ba35 Mon Sep 17 00:00:00 2001 From: Kevin Zou Date: Tue, 24 Sep 2024 16:29:33 -0400 Subject: [PATCH 1/2] add docs for changing the site url --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index e6027b683..1a864abcd 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,17 @@ configuration.set_auth_key( ); ``` +### Datacenter Selection + +By default the library will use the US1 Datadog datacenter, at `datadoghq.com`. To change this, we expose OpenAPI-style server index and server variable fields. For example, to switch the target datacenter to the EU datacenter, you can set the following values on the configuration object: + +```rust +configuration.server_index = 0; +configuration.server_variables.insert("site".into(), "datadoghq.eu".into()); +``` + +For a list of sites, and alternative server URL schemes, you can refer to the code [here](https://github.com/DataDog/datadog-api-client-rust/blob/1e121063af9e4983a34d1c6185936dda621cad8b/src/datadog/configuration.rs#L223). + ### Unstable Endpoints This client includes access to Datadog API endpoints while they are in an unstable state and may undergo breaking changes. An extra configuration step is required to use these endpoints: From e8157d416303f9c1dcf40315ce96f1828900f19b Mon Sep 17 00:00:00 2001 From: Kevin Zou Date: Tue, 24 Sep 2024 17:26:03 -0400 Subject: [PATCH 2/2] use DD_SITE variable if exists --- .generator/src/generator/templates/configuration.j2 | 5 ++++- README.md | 4 +++- src/datadog/configuration.rs | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.generator/src/generator/templates/configuration.j2 b/.generator/src/generator/templates/configuration.j2 index fa03d72cb..65c260f74 100644 --- a/.generator/src/generator/templates/configuration.j2 +++ b/.generator/src/generator/templates/configuration.j2 @@ -161,7 +161,10 @@ impl Default for Configuration { unstable_operations, auth_keys, server_index: 0, - server_variables: HashMap::new(), + server_variables: HashMap::from([( + "site".into(), + env::var("DD_SITE").unwrap_or("datadoghq.com".into()), + )]), server_operation_index: HashMap::new(), server_operation_variables: HashMap::new(), proxy_url: None, diff --git a/README.md b/README.md index 1a864abcd..6d40f7422 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,9 @@ configuration.server_index = 0; configuration.server_variables.insert("site".into(), "datadoghq.eu".into()); ``` -For a list of sites, and alternative server URL schemes, you can refer to the code [here](https://github.com/DataDog/datadog-api-client-rust/blob/1e121063af9e4983a34d1c6185936dda621cad8b/src/datadog/configuration.rs#L223). +Alternatively, you can set the environment variable `DD_SITE=datadoghq.eu` to achieve the same result. + +For a list of sites and alternative server URL schemes, you can refer to the code [here](https://github.com/DataDog/datadog-api-client-rust/blob/1e121063af9e4983a34d1c6185936dda621cad8b/src/datadog/configuration.rs#L223). ### Unstable Endpoints diff --git a/src/datadog/configuration.rs b/src/datadog/configuration.rs index 58339f9f4..894ddbff1 100644 --- a/src/datadog/configuration.rs +++ b/src/datadog/configuration.rs @@ -202,7 +202,10 @@ impl Default for Configuration { unstable_operations, auth_keys, server_index: 0, - server_variables: HashMap::new(), + server_variables: HashMap::from([( + "site".into(), + env::var("DD_SITE").unwrap_or("datadoghq.com".into()), + )]), server_operation_index: HashMap::new(), server_operation_variables: HashMap::new(), proxy_url: None,