Skip to content

Commit ee12bf1

Browse files
authored
Support DD_SITE env var and document server variable usage (#306)
1 parent f818550 commit ee12bf1

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

.generator/src/generator/templates/configuration.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ impl Default for Configuration {
161161
unstable_operations,
162162
auth_keys,
163163
server_index: 0,
164-
server_variables: HashMap::new(),
164+
server_variables: HashMap::from([(
165+
"site".into(),
166+
env::var("DD_SITE").unwrap_or("datadoghq.com".into()),
167+
)]),
165168
server_operation_index: HashMap::new(),
166169
server_operation_variables: HashMap::new(),
167170
proxy_url: None,

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ configuration.set_auth_key(
6161
);
6262
```
6363

64+
### Datacenter Selection
65+
66+
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:
67+
68+
```rust
69+
configuration.server_index = 0;
70+
configuration.server_variables.insert("site".into(), "datadoghq.eu".into());
71+
```
72+
73+
Alternatively, you can set the environment variable `DD_SITE=datadoghq.eu` to achieve the same result.
74+
75+
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).
76+
6477
### Unstable Endpoints
6578

6679
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:

src/datadog/configuration.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ impl Default for Configuration {
202202
unstable_operations,
203203
auth_keys,
204204
server_index: 0,
205-
server_variables: HashMap::new(),
205+
server_variables: HashMap::from([(
206+
"site".into(),
207+
env::var("DD_SITE").unwrap_or("datadoghq.com".into()),
208+
)]),
206209
server_operation_index: HashMap::new(),
207210
server_operation_variables: HashMap::new(),
208211
proxy_url: None,

0 commit comments

Comments
 (0)