Skip to content

Commit 844fd9c

Browse files
committed
CRED-2150: Regenerated client code from templates
1 parent 67c751b commit 844fd9c

File tree

132 files changed

+6608
-13073
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+6608
-13073
lines changed

src/datadog/configuration.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub struct Configuration {
4646
pub(crate) user_agent: String,
4747
pub(crate) unstable_operations: HashMap<String, bool>,
4848
pub(crate) auth_keys: HashMap<String, APIKey>,
49+
pub(crate) pat: Option<String>,
4950
pub server_index: usize,
5051
pub server_variables: HashMap<String, String>,
5152
pub server_operation_index: HashMap<String, usize>,
@@ -109,6 +110,27 @@ impl Configuration {
109110
self.auth_keys.insert(operation_str.to_string(), api_key);
110111
}
111112

113+
/// Set a bearer token for authentication.
114+
pub fn set_pat(&mut self, pat: String) {
115+
self.pat = Some(pat);
116+
}
117+
118+
/// Build authentication headers for an API request.
119+
/// All configured auth credentials are sent; the server decides which to use.
120+
pub fn auth_headers(&self) -> Vec<(String, String)> {
121+
let mut headers = Vec::new();
122+
if let Some(ref pat) = self.pat {
123+
headers.push(("Authorization".to_string(), format!("Bearer {}", pat)));
124+
}
125+
if let Some(key) = self.auth_keys.get("apiKeyAuth") {
126+
headers.push(("DD-API-KEY".to_string(), key.key.clone()));
127+
}
128+
if let Some(key) = self.auth_keys.get("appKeyAuth") {
129+
headers.push(("DD-APPLICATION-KEY".to_string(), key.key.clone()));
130+
}
131+
headers
132+
}
133+
112134
pub fn set_proxy_url(&mut self, proxy_url: Option<String>) {
113135
self.proxy_url = proxy_url;
114136
}
@@ -363,10 +385,14 @@ impl Default for Configuration {
363385
},
364386
);
365387

388+
// DD_BEARER_TOKEN env var enables Bearer token auth (mutually exclusive with API key auth)
389+
let pat = env::var("DD_BEARER_TOKEN").ok().filter(|p| !p.is_empty());
390+
366391
Self {
367392
user_agent: DEFAULT_USER_AGENT.clone(),
368393
unstable_operations,
369394
auth_keys,
395+
pat,
370396
server_index: 0,
371397
server_variables: HashMap::from([(
372398
"site".into(),

src/datadogV1/api/api_authentication.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,14 @@ impl AuthenticationAPI {
143143
};
144144

145145
// build auth
146-
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
146+
for (key, value) in local_configuration.auth_headers() {
147147
headers.insert(
148-
"DD-API-KEY",
149-
HeaderValue::from_str(local_key.key.as_str())
150-
.expect("failed to parse DD-API-KEY header"),
148+
reqwest::header::HeaderName::from_bytes(key.as_bytes())
149+
.expect("failed to parse auth header name"),
150+
HeaderValue::from_str(value.as_str())
151+
.expect("failed to parse auth header value"),
151152
);
152-
};
153+
}
153154

154155
local_req_builder = local_req_builder.headers(headers);
155156
let local_req = local_req_builder.build()?;

src/datadogV1/api/api_aws_integration.rs

Lines changed: 72 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -302,20 +302,14 @@ impl AWSIntegrationAPI {
302302
};
303303

304304
// build auth
305-
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
305+
for (key, value) in local_configuration.auth_headers() {
306306
headers.insert(
307-
"DD-API-KEY",
308-
HeaderValue::from_str(local_key.key.as_str())
309-
.expect("failed to parse DD-API-KEY header"),
307+
reqwest::header::HeaderName::from_bytes(key.as_bytes())
308+
.expect("failed to parse auth header name"),
309+
HeaderValue::from_str(value.as_str())
310+
.expect("failed to parse auth header value"),
310311
);
311-
};
312-
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
313-
headers.insert(
314-
"DD-APPLICATION-KEY",
315-
HeaderValue::from_str(local_key.key.as_str())
316-
.expect("failed to parse DD-APPLICATION-KEY header"),
317-
);
318-
};
312+
}
319313

320314
// build body parameters
321315
let output = Vec::new();
@@ -459,20 +453,14 @@ impl AWSIntegrationAPI {
459453
};
460454

461455
// build auth
462-
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
463-
headers.insert(
464-
"DD-API-KEY",
465-
HeaderValue::from_str(local_key.key.as_str())
466-
.expect("failed to parse DD-API-KEY header"),
467-
);
468-
};
469-
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
456+
for (key, value) in local_configuration.auth_headers() {
470457
headers.insert(
471-
"DD-APPLICATION-KEY",
472-
HeaderValue::from_str(local_key.key.as_str())
473-
.expect("failed to parse DD-APPLICATION-KEY header"),
458+
reqwest::header::HeaderName::from_bytes(key.as_bytes())
459+
.expect("failed to parse auth header name"),
460+
HeaderValue::from_str(value.as_str())
461+
.expect("failed to parse auth header value"),
474462
);
475-
};
463+
}
476464

477465
// build body parameters
478466
let output = Vec::new();
@@ -613,20 +601,14 @@ impl AWSIntegrationAPI {
613601
};
614602

615603
// build auth
616-
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
604+
for (key, value) in local_configuration.auth_headers() {
617605
headers.insert(
618-
"DD-API-KEY",
619-
HeaderValue::from_str(local_key.key.as_str())
620-
.expect("failed to parse DD-API-KEY header"),
606+
reqwest::header::HeaderName::from_bytes(key.as_bytes())
607+
.expect("failed to parse auth header name"),
608+
HeaderValue::from_str(value.as_str())
609+
.expect("failed to parse auth header value"),
621610
);
622-
};
623-
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
624-
headers.insert(
625-
"DD-APPLICATION-KEY",
626-
HeaderValue::from_str(local_key.key.as_str())
627-
.expect("failed to parse DD-APPLICATION-KEY header"),
628-
);
629-
};
611+
}
630612

631613
// build body parameters
632614
let output = Vec::new();
@@ -767,20 +749,14 @@ impl AWSIntegrationAPI {
767749
};
768750

769751
// build auth
770-
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
752+
for (key, value) in local_configuration.auth_headers() {
771753
headers.insert(
772-
"DD-API-KEY",
773-
HeaderValue::from_str(local_key.key.as_str())
774-
.expect("failed to parse DD-API-KEY header"),
754+
reqwest::header::HeaderName::from_bytes(key.as_bytes())
755+
.expect("failed to parse auth header name"),
756+
HeaderValue::from_str(value.as_str())
757+
.expect("failed to parse auth header value"),
775758
);
776-
};
777-
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
778-
headers.insert(
779-
"DD-APPLICATION-KEY",
780-
HeaderValue::from_str(local_key.key.as_str())
781-
.expect("failed to parse DD-APPLICATION-KEY header"),
782-
);
783-
};
759+
}
784760

785761
// build body parameters
786762
let output = Vec::new();
@@ -921,20 +897,14 @@ impl AWSIntegrationAPI {
921897
};
922898

923899
// build auth
924-
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
925-
headers.insert(
926-
"DD-API-KEY",
927-
HeaderValue::from_str(local_key.key.as_str())
928-
.expect("failed to parse DD-API-KEY header"),
929-
);
930-
};
931-
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
900+
for (key, value) in local_configuration.auth_headers() {
932901
headers.insert(
933-
"DD-APPLICATION-KEY",
934-
HeaderValue::from_str(local_key.key.as_str())
935-
.expect("failed to parse DD-APPLICATION-KEY header"),
902+
reqwest::header::HeaderName::from_bytes(key.as_bytes())
903+
.expect("failed to parse auth header name"),
904+
HeaderValue::from_str(value.as_str())
905+
.expect("failed to parse auth header value"),
936906
);
937-
};
907+
}
938908

939909
// build body parameters
940910
let output = Vec::new();
@@ -1078,20 +1048,14 @@ impl AWSIntegrationAPI {
10781048
};
10791049

10801050
// build auth
1081-
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1051+
for (key, value) in local_configuration.auth_headers() {
10821052
headers.insert(
1083-
"DD-API-KEY",
1084-
HeaderValue::from_str(local_key.key.as_str())
1085-
.expect("failed to parse DD-API-KEY header"),
1053+
reqwest::header::HeaderName::from_bytes(key.as_bytes())
1054+
.expect("failed to parse auth header name"),
1055+
HeaderValue::from_str(value.as_str())
1056+
.expect("failed to parse auth header value"),
10861057
);
1087-
};
1088-
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1089-
headers.insert(
1090-
"DD-APPLICATION-KEY",
1091-
HeaderValue::from_str(local_key.key.as_str())
1092-
.expect("failed to parse DD-APPLICATION-KEY header"),
1093-
);
1094-
};
1058+
}
10951059

10961060
// build body parameters
10971061
let output = Vec::new();
@@ -1232,20 +1196,14 @@ impl AWSIntegrationAPI {
12321196
};
12331197

12341198
// build auth
1235-
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1199+
for (key, value) in local_configuration.auth_headers() {
12361200
headers.insert(
1237-
"DD-API-KEY",
1238-
HeaderValue::from_str(local_key.key.as_str())
1239-
.expect("failed to parse DD-API-KEY header"),
1201+
reqwest::header::HeaderName::from_bytes(key.as_bytes())
1202+
.expect("failed to parse auth header name"),
1203+
HeaderValue::from_str(value.as_str())
1204+
.expect("failed to parse auth header value"),
12401205
);
1241-
};
1242-
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1243-
headers.insert(
1244-
"DD-APPLICATION-KEY",
1245-
HeaderValue::from_str(local_key.key.as_str())
1246-
.expect("failed to parse DD-APPLICATION-KEY header"),
1247-
);
1248-
};
1206+
}
12491207

12501208
// build body parameters
12511209
let output = Vec::new();
@@ -1401,20 +1359,14 @@ impl AWSIntegrationAPI {
14011359
};
14021360

14031361
// build auth
1404-
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1405-
headers.insert(
1406-
"DD-API-KEY",
1407-
HeaderValue::from_str(local_key.key.as_str())
1408-
.expect("failed to parse DD-API-KEY header"),
1409-
);
1410-
};
1411-
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1362+
for (key, value) in local_configuration.auth_headers() {
14121363
headers.insert(
1413-
"DD-APPLICATION-KEY",
1414-
HeaderValue::from_str(local_key.key.as_str())
1415-
.expect("failed to parse DD-APPLICATION-KEY header"),
1364+
reqwest::header::HeaderName::from_bytes(key.as_bytes())
1365+
.expect("failed to parse auth header name"),
1366+
HeaderValue::from_str(value.as_str())
1367+
.expect("failed to parse auth header value"),
14161368
);
1417-
};
1369+
}
14181370

14191371
local_req_builder = local_req_builder.headers(headers);
14201372
let local_req = local_req_builder.build()?;
@@ -1507,20 +1459,14 @@ impl AWSIntegrationAPI {
15071459
};
15081460

15091461
// build auth
1510-
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1462+
for (key, value) in local_configuration.auth_headers() {
15111463
headers.insert(
1512-
"DD-API-KEY",
1513-
HeaderValue::from_str(local_key.key.as_str())
1514-
.expect("failed to parse DD-API-KEY header"),
1464+
reqwest::header::HeaderName::from_bytes(key.as_bytes())
1465+
.expect("failed to parse auth header name"),
1466+
HeaderValue::from_str(value.as_str())
1467+
.expect("failed to parse auth header value"),
15151468
);
1516-
};
1517-
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1518-
headers.insert(
1519-
"DD-APPLICATION-KEY",
1520-
HeaderValue::from_str(local_key.key.as_str())
1521-
.expect("failed to parse DD-APPLICATION-KEY header"),
1522-
);
1523-
};
1469+
}
15241470

15251471
local_req_builder = local_req_builder.headers(headers);
15261472
let local_req = local_req_builder.build()?;
@@ -1617,20 +1563,14 @@ impl AWSIntegrationAPI {
16171563
};
16181564

16191565
// build auth
1620-
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1566+
for (key, value) in local_configuration.auth_headers() {
16211567
headers.insert(
1622-
"DD-API-KEY",
1623-
HeaderValue::from_str(local_key.key.as_str())
1624-
.expect("failed to parse DD-API-KEY header"),
1568+
reqwest::header::HeaderName::from_bytes(key.as_bytes())
1569+
.expect("failed to parse auth header name"),
1570+
HeaderValue::from_str(value.as_str())
1571+
.expect("failed to parse auth header value"),
16251572
);
1626-
};
1627-
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1628-
headers.insert(
1629-
"DD-APPLICATION-KEY",
1630-
HeaderValue::from_str(local_key.key.as_str())
1631-
.expect("failed to parse DD-APPLICATION-KEY header"),
1632-
);
1633-
};
1573+
}
16341574

16351575
local_req_builder = local_req_builder.headers(headers);
16361576
let local_req = local_req_builder.build()?;
@@ -1720,20 +1660,14 @@ impl AWSIntegrationAPI {
17201660
};
17211661

17221662
// build auth
1723-
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1724-
headers.insert(
1725-
"DD-API-KEY",
1726-
HeaderValue::from_str(local_key.key.as_str())
1727-
.expect("failed to parse DD-API-KEY header"),
1728-
);
1729-
};
1730-
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1663+
for (key, value) in local_configuration.auth_headers() {
17311664
headers.insert(
1732-
"DD-APPLICATION-KEY",
1733-
HeaderValue::from_str(local_key.key.as_str())
1734-
.expect("failed to parse DD-APPLICATION-KEY header"),
1665+
reqwest::header::HeaderName::from_bytes(key.as_bytes())
1666+
.expect("failed to parse auth header name"),
1667+
HeaderValue::from_str(value.as_str())
1668+
.expect("failed to parse auth header value"),
17351669
);
1736-
};
1670+
}
17371671

17381672
local_req_builder = local_req_builder.headers(headers);
17391673
let local_req = local_req_builder.build()?;
@@ -1847,20 +1781,14 @@ impl AWSIntegrationAPI {
18471781
};
18481782

18491783
// build auth
1850-
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1784+
for (key, value) in local_configuration.auth_headers() {
18511785
headers.insert(
1852-
"DD-API-KEY",
1853-
HeaderValue::from_str(local_key.key.as_str())
1854-
.expect("failed to parse DD-API-KEY header"),
1786+
reqwest::header::HeaderName::from_bytes(key.as_bytes())
1787+
.expect("failed to parse auth header name"),
1788+
HeaderValue::from_str(value.as_str())
1789+
.expect("failed to parse auth header value"),
18551790
);
1856-
};
1857-
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1858-
headers.insert(
1859-
"DD-APPLICATION-KEY",
1860-
HeaderValue::from_str(local_key.key.as_str())
1861-
.expect("failed to parse DD-APPLICATION-KEY header"),
1862-
);
1863-
};
1791+
}
18641792

18651793
// build body parameters
18661794
let output = Vec::new();

0 commit comments

Comments
 (0)