Skip to content

Commit 260e9b3

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add OpenAPI spec for OAuth2 well-known sites endpoint (#1700)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent fabdcd7 commit 260e9b3

11 files changed

Lines changed: 629 additions & 0 deletions

.generator/schemas/v2/openapi.yaml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57840,6 +57840,59 @@ components:
5784057840
- id
5784157841
- type
5784257842
type: object
57843+
OAuth2WellKnownSitesAttributes:
57844+
description: Attributes containing the list of public OAuth2 sites.
57845+
properties:
57846+
sites:
57847+
description: Array of public OAuth2 site URLs for the environment.
57848+
example:
57849+
- datadoghq.com
57850+
- datadoghq.eu
57851+
- us5.datadoghq.com
57852+
- us3.datadoghq.com
57853+
- ap1.datadoghq.com
57854+
- ap2.datadoghq.com
57855+
items:
57856+
description: Public OAuth2 site URL.
57857+
example: app.datadoghq.com
57858+
type: string
57859+
type: array
57860+
required:
57861+
- sites
57862+
type: object
57863+
OAuth2WellKnownSitesData:
57864+
description: Data object containing OAuth2 well-known sites information.
57865+
properties:
57866+
attributes:
57867+
$ref: "#/components/schemas/OAuth2WellKnownSitesAttributes"
57868+
id:
57869+
description: Environment identifier.
57870+
example: prod
57871+
type: string
57872+
type:
57873+
$ref: "#/components/schemas/OAuth2WellKnownSitesEnvType"
57874+
required:
57875+
- id
57876+
- type
57877+
- attributes
57878+
type: object
57879+
OAuth2WellKnownSitesEnvType:
57880+
default: env
57881+
description: JSON:API resource type for OAuth2 well-known sites environment.
57882+
enum:
57883+
- env
57884+
example: env
57885+
type: string
57886+
x-enum-varnames:
57887+
- ENV
57888+
OAuth2WellKnownSitesResponse:
57889+
description: Response payload containing the list of public OAuth2 sites for discovery.
57890+
properties:
57891+
data:
57892+
$ref: "#/components/schemas/OAuth2WellKnownSitesData"
57893+
required:
57894+
- data
57895+
type: object
5784357896
OAuthClientRegistrationError:
5784457897
description: Error payload returned by OAuth2 dynamic client registration as defined by RFC 7591.
5784557898
properties:
@@ -142472,6 +142525,40 @@ paths:
142472142525
summary: Get all aggregated DNS traffic
142473142526
tags:
142474142527
- Cloud Network Monitoring
142528+
/api/v2/oauth2/.well-known/sites:
142529+
get:
142530+
description: Retrieve the list of public OAuth2 sites available for the current environment. This endpoint is used for OAuth2 discovery and returns sites where users can authenticate.
142531+
operationId: GetOAuth2WellKnownSites
142532+
responses:
142533+
"200":
142534+
content:
142535+
application/json:
142536+
examples:
142537+
default:
142538+
value:
142539+
data:
142540+
attributes:
142541+
sites:
142542+
- datadoghq.com
142543+
- datadoghq.eu
142544+
- us5.datadoghq.com
142545+
- us3.datadoghq.com
142546+
- ap1.datadoghq.com
142547+
- ap2.datadoghq.com
142548+
id: prod
142549+
type: env
142550+
schema:
142551+
$ref: "#/components/schemas/OAuth2WellKnownSitesResponse"
142552+
description: OK
142553+
"429":
142554+
$ref: "#/components/responses/TooManyRequestsResponse"
142555+
security: []
142556+
summary: Get OAuth2 well-known sites
142557+
tags:
142558+
- OAuth2 Client Public
142559+
x-unstable: |-
142560+
**Note**: This endpoint is in preview and is subject to change.
142561+
If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).
142475142562
/api/v2/oauth2/clients/{client_uuid}/scopes_restriction:
142476142563
delete:
142477142564
description: Delete the scopes restriction configured for the OAuth2 client.

src/datadog/configuration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ impl Default for Configuration {
556556
),
557557
("v2.validate_monitor_user_template".to_owned(), false),
558558
("v2.delete_scopes_restriction".to_owned(), false),
559+
("v2.get_o_auth2_well_known_sites".to_owned(), false),
559560
("v2.get_scopes_restriction".to_owned(), false),
560561
("v2.register_o_auth_client".to_owned(), false),
561562
("v2.upsert_scopes_restriction".to_owned(), false),

src/datadogV2/api/api_o_auth2_client_public.rs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ pub enum DeleteScopesRestrictionError {
2020
UnknownValue(serde_json::Value),
2121
}
2222

23+
/// GetOAuth2WellKnownSitesError is a struct for typed errors of method [`OAuth2ClientPublicAPI::get_o_auth2_well_known_sites`]
24+
#[derive(Debug, Clone, Serialize, Deserialize)]
25+
#[serde(untagged)]
26+
pub enum GetOAuth2WellKnownSitesError {
27+
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
28+
UnknownValue(serde_json::Value),
29+
}
30+
2331
/// GetScopesRestrictionError is a struct for typed errors of method [`OAuth2ClientPublicAPI::get_scopes_restriction`]
2432
#[derive(Debug, Clone, Serialize, Deserialize)]
2533
#[serde(untagged)]
@@ -221,6 +229,106 @@ impl OAuth2ClientPublicAPI {
221229
}
222230
}
223231

232+
/// Retrieve the list of public OAuth2 sites available for the current environment. This endpoint is used for OAuth2 discovery and returns sites where users can authenticate.
233+
pub async fn get_o_auth2_well_known_sites(
234+
&self,
235+
) -> Result<
236+
crate::datadogV2::model::OAuth2WellKnownSitesResponse,
237+
datadog::Error<GetOAuth2WellKnownSitesError>,
238+
> {
239+
match self.get_o_auth2_well_known_sites_with_http_info().await {
240+
Ok(response_content) => {
241+
if let Some(e) = response_content.entity {
242+
Ok(e)
243+
} else {
244+
Err(datadog::Error::Serde(serde::de::Error::custom(
245+
"response content was None",
246+
)))
247+
}
248+
}
249+
Err(err) => Err(err),
250+
}
251+
}
252+
253+
/// Retrieve the list of public OAuth2 sites available for the current environment. This endpoint is used for OAuth2 discovery and returns sites where users can authenticate.
254+
pub async fn get_o_auth2_well_known_sites_with_http_info(
255+
&self,
256+
) -> Result<
257+
datadog::ResponseContent<crate::datadogV2::model::OAuth2WellKnownSitesResponse>,
258+
datadog::Error<GetOAuth2WellKnownSitesError>,
259+
> {
260+
let local_configuration = &self.config;
261+
let operation_id = "v2.get_o_auth2_well_known_sites";
262+
if local_configuration.is_unstable_operation_enabled(operation_id) {
263+
warn!("Using unstable operation {operation_id}");
264+
} else {
265+
let local_error = datadog::UnstableOperationDisabledError {
266+
msg: "Operation 'v2.get_o_auth2_well_known_sites' is not enabled".to_string(),
267+
};
268+
return Err(datadog::Error::UnstableOperationDisabledError(local_error));
269+
}
270+
271+
let local_client = &self.client;
272+
273+
let local_uri_str = format!(
274+
"{}/api/v2/oauth2/.well-known/sites",
275+
local_configuration.get_operation_host(operation_id)
276+
);
277+
let mut local_req_builder =
278+
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
279+
280+
// build headers
281+
let mut headers = HeaderMap::new();
282+
headers.insert("Accept", HeaderValue::from_static("application/json"));
283+
284+
// build user agent
285+
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
286+
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
287+
Err(e) => {
288+
log::warn!("Failed to parse user agent header: {e}, falling back to default");
289+
headers.insert(
290+
reqwest::header::USER_AGENT,
291+
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
292+
)
293+
}
294+
};
295+
296+
// build auth
297+
298+
local_req_builder = local_req_builder.headers(headers);
299+
let local_req = local_req_builder.build()?;
300+
log::debug!("request content: {:?}", local_req.body());
301+
let local_resp = local_client.execute(local_req).await?;
302+
303+
let local_status = local_resp.status();
304+
let local_content = local_resp.text().await?;
305+
log::debug!("response content: {}", local_content);
306+
307+
if !local_status.is_client_error() && !local_status.is_server_error() {
308+
match serde_json::from_str::<crate::datadogV2::model::OAuth2WellKnownSitesResponse>(
309+
&local_content,
310+
) {
311+
Ok(e) => {
312+
return Ok(datadog::ResponseContent {
313+
status: local_status,
314+
content: local_content,
315+
entity: Some(e),
316+
})
317+
}
318+
Err(e) => return Err(datadog::Error::Serde(e)),
319+
};
320+
} else {
321+
let local_entity: Option<GetOAuth2WellKnownSitesError> =
322+
serde_json::from_str(&local_content).ok();
323+
let local_error = datadog::ResponseContent {
324+
status: local_status,
325+
content: local_content,
326+
entity: local_entity,
327+
};
328+
Err(datadog::Error::ResponseError(local_error))
329+
}
330+
}
331+
224332
/// Get the scopes restriction configured for the OAuth2 client.
225333
pub async fn get_scopes_restriction(
226334
&self,

src/datadogV2/model/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6380,6 +6380,14 @@ pub mod model_dns_metric_key;
63806380
pub use self::model_dns_metric_key::DnsMetricKey;
63816381
pub mod model_single_aggregated_dns_response_data_type;
63826382
pub use self::model_single_aggregated_dns_response_data_type::SingleAggregatedDnsResponseDataType;
6383+
pub mod model_o_auth2_well_known_sites_response;
6384+
pub use self::model_o_auth2_well_known_sites_response::OAuth2WellKnownSitesResponse;
6385+
pub mod model_o_auth2_well_known_sites_data;
6386+
pub use self::model_o_auth2_well_known_sites_data::OAuth2WellKnownSitesData;
6387+
pub mod model_o_auth2_well_known_sites_attributes;
6388+
pub use self::model_o_auth2_well_known_sites_attributes::OAuth2WellKnownSitesAttributes;
6389+
pub mod model_o_auth2_well_known_sites_env_type;
6390+
pub use self::model_o_auth2_well_known_sites_env_type::OAuth2WellKnownSitesEnvType;
63836391
pub mod model_o_auth_scopes_restriction_response;
63846392
pub use self::model_o_auth_scopes_restriction_response::OAuthScopesRestrictionResponse;
63856393
pub mod model_o_auth_scopes_restriction_response_data;
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
/// Attributes containing the list of public OAuth2 sites.
10+
#[non_exhaustive]
11+
#[skip_serializing_none]
12+
#[derive(Clone, Debug, PartialEq, Serialize)]
13+
pub struct OAuth2WellKnownSitesAttributes {
14+
/// Array of public OAuth2 site URLs for the environment.
15+
#[serde(rename = "sites")]
16+
pub sites: Vec<String>,
17+
#[serde(flatten)]
18+
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
19+
#[serde(skip)]
20+
#[serde(default)]
21+
pub(crate) _unparsed: bool,
22+
}
23+
24+
impl OAuth2WellKnownSitesAttributes {
25+
pub fn new(sites: Vec<String>) -> OAuth2WellKnownSitesAttributes {
26+
OAuth2WellKnownSitesAttributes {
27+
sites,
28+
additional_properties: std::collections::BTreeMap::new(),
29+
_unparsed: false,
30+
}
31+
}
32+
33+
pub fn additional_properties(
34+
mut self,
35+
value: std::collections::BTreeMap<String, serde_json::Value>,
36+
) -> Self {
37+
self.additional_properties = value;
38+
self
39+
}
40+
}
41+
42+
impl<'de> Deserialize<'de> for OAuth2WellKnownSitesAttributes {
43+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
44+
where
45+
D: Deserializer<'de>,
46+
{
47+
struct OAuth2WellKnownSitesAttributesVisitor;
48+
impl<'a> Visitor<'a> for OAuth2WellKnownSitesAttributesVisitor {
49+
type Value = OAuth2WellKnownSitesAttributes;
50+
51+
fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
52+
f.write_str("a mapping")
53+
}
54+
55+
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
56+
where
57+
M: MapAccess<'a>,
58+
{
59+
let mut sites: Option<Vec<String>> = None;
60+
let mut additional_properties: std::collections::BTreeMap<
61+
String,
62+
serde_json::Value,
63+
> = std::collections::BTreeMap::new();
64+
let mut _unparsed = false;
65+
66+
while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
67+
match k.as_str() {
68+
"sites" => {
69+
sites = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
70+
}
71+
&_ => {
72+
if let Ok(value) = serde_json::from_value(v.clone()) {
73+
additional_properties.insert(k, value);
74+
}
75+
}
76+
}
77+
}
78+
let sites = sites.ok_or_else(|| M::Error::missing_field("sites"))?;
79+
80+
let content = OAuth2WellKnownSitesAttributes {
81+
sites,
82+
additional_properties,
83+
_unparsed,
84+
};
85+
86+
Ok(content)
87+
}
88+
}
89+
90+
deserializer.deserialize_any(OAuth2WellKnownSitesAttributesVisitor)
91+
}
92+
}

0 commit comments

Comments
 (0)