Skip to content

Commit f64424f

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add JWT authentication type for Synthetics HTTP API tests (#1717)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 20af4be commit f64424f

7 files changed

Lines changed: 533 additions & 0 deletions

.generator/schemas/v1/openapi.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17308,6 +17308,7 @@ components:
1730817308
- $ref: "#/components/schemas/SyntheticsBasicAuthDigest"
1730917309
- $ref: "#/components/schemas/SyntheticsBasicAuthOauthClient"
1731017310
- $ref: "#/components/schemas/SyntheticsBasicAuthOauthROP"
17311+
- $ref: "#/components/schemas/SyntheticsBasicAuthJWT"
1731117312
SyntheticsBasicAuthDigest:
1731217313
description: Object to handle digest authentication when performing the test.
1731317314
properties:
@@ -17335,6 +17336,78 @@ components:
1733517336
type: string
1733617337
x-enum-varnames:
1733717338
- DIGEST
17339+
SyntheticsBasicAuthJWT:
17340+
description: Object to handle JWT authentication when performing the test.
17341+
properties:
17342+
addClaims:
17343+
$ref: "#/components/schemas/SyntheticsBasicAuthJWTAddClaims"
17344+
algorithm:
17345+
$ref: "#/components/schemas/SyntheticsBasicAuthJWTAlgorithm"
17346+
expiresIn:
17347+
description: Token time-to-live in seconds.
17348+
example: 3600
17349+
format: int64
17350+
minimum: 1
17351+
type: integer
17352+
header:
17353+
description: Custom JWT header as a JSON string.
17354+
example: '{"kid": "my-key-id"}'
17355+
type: string
17356+
payload:
17357+
description: JWT claims as a JSON string.
17358+
example: '{"sub": "1234567890", "name": "John Doe"}'
17359+
type: string
17360+
secret:
17361+
description: |-
17362+
Signing key for the JWT authentication. Use the shared secret for `HS256`
17363+
or the private key (PEM format) for `RS256` and `ES256`.
17364+
example: "mysecretkey"
17365+
type: string
17366+
tokenPrefix:
17367+
description: Prefix added before the token in the `Authorization` header. Defaults to `Bearer`.
17368+
example: "Bearer"
17369+
type: string
17370+
type:
17371+
$ref: "#/components/schemas/SyntheticsBasicAuthJWTType"
17372+
required:
17373+
- algorithm
17374+
- payload
17375+
- secret
17376+
- type
17377+
type: object
17378+
SyntheticsBasicAuthJWTAddClaims:
17379+
description: Standard JWT claims to automatically inject.
17380+
properties:
17381+
exp:
17382+
description: Whether to inject the `exp` (expiration) claim.
17383+
example: true
17384+
type: boolean
17385+
iat:
17386+
description: Whether to inject the `iat` (issued at) claim.
17387+
example: true
17388+
type: boolean
17389+
type: object
17390+
SyntheticsBasicAuthJWTAlgorithm:
17391+
description: Algorithm to use for the JWT authentication.
17392+
enum:
17393+
- HS256
17394+
- RS256
17395+
- ES256
17396+
example: "HS256"
17397+
type: string
17398+
x-enum-varnames:
17399+
- HS256
17400+
- RS256
17401+
- ES256
17402+
SyntheticsBasicAuthJWTType:
17403+
default: "jwt"
17404+
description: The type of authentication to use when performing the test.
17405+
enum:
17406+
- jwt
17407+
example: "jwt"
17408+
type: string
17409+
x-enum-varnames:
17410+
- JWT
1733817411
SyntheticsBasicAuthNTLM:
1733917412
description: Object to handle `NTLM` authentication when performing the test.
1734017413
properties:

src/datadogV1/model/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,14 @@ pub mod model_synthetics_basic_auth_oauth_rop;
18181818
pub use self::model_synthetics_basic_auth_oauth_rop::SyntheticsBasicAuthOauthROP;
18191819
pub mod model_synthetics_basic_auth_oauth_rop_type;
18201820
pub use self::model_synthetics_basic_auth_oauth_rop_type::SyntheticsBasicAuthOauthROPType;
1821+
pub mod model_synthetics_basic_auth_jwt;
1822+
pub use self::model_synthetics_basic_auth_jwt::SyntheticsBasicAuthJWT;
1823+
pub mod model_synthetics_basic_auth_jwt_add_claims;
1824+
pub use self::model_synthetics_basic_auth_jwt_add_claims::SyntheticsBasicAuthJWTAddClaims;
1825+
pub mod model_synthetics_basic_auth_jwt_algorithm;
1826+
pub use self::model_synthetics_basic_auth_jwt_algorithm::SyntheticsBasicAuthJWTAlgorithm;
1827+
pub mod model_synthetics_basic_auth_jwt_type;
1828+
pub use self::model_synthetics_basic_auth_jwt_type::SyntheticsBasicAuthJWTType;
18211829
pub mod model_synthetics_basic_auth;
18221830
pub use self::model_synthetics_basic_auth::SyntheticsBasicAuth;
18231831
pub mod model_synthetics_test_request_body_type;

src/datadogV1/model/model_synthetics_basic_auth.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub enum SyntheticsBasicAuth {
1414
SyntheticsBasicAuthDigest(Box<crate::datadogV1::model::SyntheticsBasicAuthDigest>),
1515
SyntheticsBasicAuthOauthClient(Box<crate::datadogV1::model::SyntheticsBasicAuthOauthClient>),
1616
SyntheticsBasicAuthOauthROP(Box<crate::datadogV1::model::SyntheticsBasicAuthOauthROP>),
17+
SyntheticsBasicAuthJWT(Box<crate::datadogV1::model::SyntheticsBasicAuthJWT>),
1718
UnparsedObject(crate::datadog::UnparsedObject),
1819
}
1920

@@ -70,6 +71,13 @@ impl<'de> Deserialize<'de> for SyntheticsBasicAuth {
7071
return Ok(SyntheticsBasicAuth::SyntheticsBasicAuthOauthROP(_v));
7172
}
7273
}
74+
if let Ok(_v) = serde_json::from_value::<Box<crate::datadogV1::model::SyntheticsBasicAuthJWT>>(
75+
value.clone(),
76+
) {
77+
if !_v._unparsed {
78+
return Ok(SyntheticsBasicAuth::SyntheticsBasicAuthJWT(_v));
79+
}
80+
}
7381

7482
return Ok(SyntheticsBasicAuth::UnparsedObject(
7583
crate::datadog::UnparsedObject { value },
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
use serde::de::{Error, MapAccess, Visitor};
5+
use serde::{Deserialize, Deserializer, Serialize};
6+
use serde_with::skip_serializing_none;
7+
use std::fmt::{self, Formatter};
8+
9+
/// Object to handle JWT authentication when performing the test.
10+
#[non_exhaustive]
11+
#[skip_serializing_none]
12+
#[derive(Clone, Debug, PartialEq, Serialize)]
13+
pub struct SyntheticsBasicAuthJWT {
14+
/// Standard JWT claims to automatically inject.
15+
#[serde(rename = "addClaims")]
16+
pub add_claims: Option<crate::datadogV1::model::SyntheticsBasicAuthJWTAddClaims>,
17+
/// Algorithm to use for the JWT authentication.
18+
#[serde(rename = "algorithm")]
19+
pub algorithm: crate::datadogV1::model::SyntheticsBasicAuthJWTAlgorithm,
20+
/// Token time-to-live in seconds.
21+
#[serde(rename = "expiresIn")]
22+
pub expires_in: Option<i64>,
23+
/// Custom JWT header as a JSON string.
24+
#[serde(rename = "header")]
25+
pub header: Option<String>,
26+
/// JWT claims as a JSON string.
27+
#[serde(rename = "payload")]
28+
pub payload: String,
29+
/// Signing key for the JWT authentication. Use the shared secret for `HS256`
30+
/// or the private key (PEM format) for `RS256` and `ES256`.
31+
#[serde(rename = "secret")]
32+
pub secret: String,
33+
/// Prefix added before the token in the `Authorization` header. Defaults to `Bearer`.
34+
#[serde(rename = "tokenPrefix")]
35+
pub token_prefix: Option<String>,
36+
/// The type of authentication to use when performing the test.
37+
#[serde(rename = "type")]
38+
pub type_: crate::datadogV1::model::SyntheticsBasicAuthJWTType,
39+
#[serde(flatten)]
40+
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
41+
#[serde(skip)]
42+
#[serde(default)]
43+
pub(crate) _unparsed: bool,
44+
}
45+
46+
impl SyntheticsBasicAuthJWT {
47+
pub fn new(
48+
algorithm: crate::datadogV1::model::SyntheticsBasicAuthJWTAlgorithm,
49+
payload: String,
50+
secret: String,
51+
type_: crate::datadogV1::model::SyntheticsBasicAuthJWTType,
52+
) -> SyntheticsBasicAuthJWT {
53+
SyntheticsBasicAuthJWT {
54+
add_claims: None,
55+
algorithm,
56+
expires_in: None,
57+
header: None,
58+
payload,
59+
secret,
60+
token_prefix: None,
61+
type_,
62+
additional_properties: std::collections::BTreeMap::new(),
63+
_unparsed: false,
64+
}
65+
}
66+
67+
pub fn add_claims(
68+
mut self,
69+
value: crate::datadogV1::model::SyntheticsBasicAuthJWTAddClaims,
70+
) -> Self {
71+
self.add_claims = Some(value);
72+
self
73+
}
74+
75+
pub fn expires_in(mut self, value: i64) -> Self {
76+
self.expires_in = Some(value);
77+
self
78+
}
79+
80+
pub fn header(mut self, value: String) -> Self {
81+
self.header = Some(value);
82+
self
83+
}
84+
85+
pub fn token_prefix(mut self, value: String) -> Self {
86+
self.token_prefix = Some(value);
87+
self
88+
}
89+
90+
pub fn additional_properties(
91+
mut self,
92+
value: std::collections::BTreeMap<String, serde_json::Value>,
93+
) -> Self {
94+
self.additional_properties = value;
95+
self
96+
}
97+
}
98+
99+
impl<'de> Deserialize<'de> for SyntheticsBasicAuthJWT {
100+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
101+
where
102+
D: Deserializer<'de>,
103+
{
104+
struct SyntheticsBasicAuthJWTVisitor;
105+
impl<'a> Visitor<'a> for SyntheticsBasicAuthJWTVisitor {
106+
type Value = SyntheticsBasicAuthJWT;
107+
108+
fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
109+
f.write_str("a mapping")
110+
}
111+
112+
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
113+
where
114+
M: MapAccess<'a>,
115+
{
116+
let mut add_claims: Option<
117+
crate::datadogV1::model::SyntheticsBasicAuthJWTAddClaims,
118+
> = None;
119+
let mut algorithm: Option<
120+
crate::datadogV1::model::SyntheticsBasicAuthJWTAlgorithm,
121+
> = None;
122+
let mut expires_in: Option<i64> = None;
123+
let mut header: Option<String> = None;
124+
let mut payload: Option<String> = None;
125+
let mut secret: Option<String> = None;
126+
let mut token_prefix: Option<String> = None;
127+
let mut type_: Option<crate::datadogV1::model::SyntheticsBasicAuthJWTType> = None;
128+
let mut additional_properties: std::collections::BTreeMap<
129+
String,
130+
serde_json::Value,
131+
> = std::collections::BTreeMap::new();
132+
let mut _unparsed = false;
133+
134+
while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
135+
match k.as_str() {
136+
"addClaims" => {
137+
if v.is_null() {
138+
continue;
139+
}
140+
add_claims = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
141+
}
142+
"algorithm" => {
143+
algorithm = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
144+
if let Some(ref _algorithm) = algorithm {
145+
match _algorithm {
146+
crate::datadogV1::model::SyntheticsBasicAuthJWTAlgorithm::UnparsedObject(_algorithm) => {
147+
_unparsed = true;
148+
},
149+
_ => {}
150+
}
151+
}
152+
}
153+
"expiresIn" => {
154+
if v.is_null() {
155+
continue;
156+
}
157+
expires_in = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
158+
}
159+
"header" => {
160+
if v.is_null() {
161+
continue;
162+
}
163+
header = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
164+
}
165+
"payload" => {
166+
payload = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
167+
}
168+
"secret" => {
169+
secret = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
170+
}
171+
"tokenPrefix" => {
172+
if v.is_null() {
173+
continue;
174+
}
175+
token_prefix =
176+
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
177+
}
178+
"type" => {
179+
type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
180+
if let Some(ref _type_) = type_ {
181+
match _type_ {
182+
crate::datadogV1::model::SyntheticsBasicAuthJWTType::UnparsedObject(_type_) => {
183+
_unparsed = true;
184+
},
185+
_ => {}
186+
}
187+
}
188+
}
189+
&_ => {
190+
if let Ok(value) = serde_json::from_value(v.clone()) {
191+
additional_properties.insert(k, value);
192+
}
193+
}
194+
}
195+
}
196+
let algorithm = algorithm.ok_or_else(|| M::Error::missing_field("algorithm"))?;
197+
let payload = payload.ok_or_else(|| M::Error::missing_field("payload"))?;
198+
let secret = secret.ok_or_else(|| M::Error::missing_field("secret"))?;
199+
let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
200+
201+
let content = SyntheticsBasicAuthJWT {
202+
add_claims,
203+
algorithm,
204+
expires_in,
205+
header,
206+
payload,
207+
secret,
208+
token_prefix,
209+
type_,
210+
additional_properties,
211+
_unparsed,
212+
};
213+
214+
Ok(content)
215+
}
216+
}
217+
218+
deserializer.deserialize_any(SyntheticsBasicAuthJWTVisitor)
219+
}
220+
}

0 commit comments

Comments
 (0)