Skip to content

Commit c7a82a3

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Support provisioning teams from external sources (#1027)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent ed8392b commit c7a82a3

File tree

14 files changed

+521
-13
lines changed

14 files changed

+521
-13
lines changed

.generator/schemas/v2/openapi.yaml

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52263,14 +52263,31 @@ components:
5226352263
TeamSyncAttributes:
5226452264
description: Team sync attributes.
5226552265
properties:
52266+
frequency:
52267+
$ref: '#/components/schemas/TeamSyncAttributesFrequency'
5226652268
source:
5226752269
$ref: '#/components/schemas/TeamSyncAttributesSource'
52270+
sync_membership:
52271+
$ref: '#/components/schemas/TeamSyncAttributesSyncMembership'
5226852272
type:
5226952273
$ref: '#/components/schemas/TeamSyncAttributesType'
5227052274
required:
5227152275
- source
5227252276
- type
5227352277
type: object
52278+
TeamSyncAttributesFrequency:
52279+
description: How often the sync process should be run. Defaults to `once` when
52280+
not provided.
52281+
enum:
52282+
- once
52283+
- continuously
52284+
- paused
52285+
example: once
52286+
type: string
52287+
x-enum-varnames:
52288+
- ONCE
52289+
- CONTINUOUSLY
52290+
- PAUSED
5227452291
TeamSyncAttributesSource:
5227552292
description: The external source platform for team synchronization. Only "github"
5227652293
is supported.
@@ -52280,15 +52297,22 @@ components:
5228052297
type: string
5228152298
x-enum-varnames:
5228252299
- GITHUB
52300+
TeamSyncAttributesSyncMembership:
52301+
description: Whether to sync members from the external team to the Datadog team.
52302+
Defaults to `false` when not provided.
52303+
example: true
52304+
type: boolean
5228352305
TeamSyncAttributesType:
52284-
description: The type of synchronization operation. Only "link" is supported,
52285-
which links existing teams by matching names.
52306+
description: The type of synchronization operation. "link" connects teams by
52307+
matching names. "provision" creates new teams when no match is found.
5228652308
enum:
5228752309
- link
52310+
- provision
5228852311
example: link
5228952312
type: string
5229052313
x-enum-varnames:
5229152314
- LINK
52315+
- PROVISION
5229252316
TeamSyncBulkType:
5229352317
description: Team sync bulk type.
5229452318
enum:
@@ -52298,10 +52322,15 @@ components:
5229852322
x-enum-varnames:
5229952323
- TEAM_SYNC_BULK
5230052324
TeamSyncData:
52301-
description: Team sync data.
52325+
description: A configuration governing syncing between Datadog teams and teams
52326+
from an external system.
5230252327
properties:
5230352328
attributes:
5230452329
$ref: '#/components/schemas/TeamSyncAttributes'
52330+
id:
52331+
description: The sync's identifier
52332+
example: aeadc05e-98a8-11ec-ac2c-da7ad0900001
52333+
type: string
5230552334
type:
5230652335
$ref: '#/components/schemas/TeamSyncBulkType'
5230752336
required:
@@ -52322,6 +52351,15 @@ components:
5232252351
required:
5232352352
- data
5232452353
type: object
52354+
TeamSyncResponse:
52355+
description: Team sync configurations response.
52356+
properties:
52357+
data:
52358+
description: List of team sync configurations
52359+
items:
52360+
$ref: '#/components/schemas/TeamSyncData'
52361+
type: array
52362+
type: object
5232552363
TeamTarget:
5232652364
description: Represents a team target for an escalation policy step, including
5232752365
the team's ID and resource type.
@@ -81182,6 +81220,52 @@ paths:
8118281220

8118381221
If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).'
8118481222
/api/v2/team/sync:
81223+
get:
81224+
description: 'Get all team synchronization configurations.
81225+
81226+
Returns a list of configurations used for linking or provisioning teams with
81227+
external sources like GitHub.'
81228+
operationId: GetTeamSync
81229+
parameters:
81230+
- description: Filter by the external source platform for team synchronization
81231+
in: query
81232+
name: filter[source]
81233+
required: true
81234+
schema:
81235+
$ref: '#/components/schemas/TeamSyncAttributesSource'
81236+
responses:
81237+
'200':
81238+
content:
81239+
application/json:
81240+
schema:
81241+
$ref: '#/components/schemas/TeamSyncResponse'
81242+
description: OK
81243+
'403':
81244+
$ref: '#/components/responses/ForbiddenResponse'
81245+
'404':
81246+
content:
81247+
application/json:
81248+
schema:
81249+
$ref: '#/components/schemas/APIErrorResponse'
81250+
description: Team sync configurations not found
81251+
'429':
81252+
$ref: '#/components/responses/TooManyRequestsResponse'
81253+
security:
81254+
- apiKeyAuth: []
81255+
appKeyAuth: []
81256+
- AuthZ:
81257+
- teams_read
81258+
summary: Get team sync configurations
81259+
tags:
81260+
- Teams
81261+
x-permission:
81262+
operator: OR
81263+
permissions:
81264+
- teams_read
81265+
x-unstable: '**Note**: This endpoint is in Preview. To request access, fill
81266+
out this [form](https://www.datadoghq.com/product-preview/github-integration-for-teams/).
81267+
81268+
If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).'
8118581269
post:
8118681270
description: 'This endpoint attempts to link your existing Datadog teams with
8118781271
GitHub teams by matching their names.
@@ -81208,7 +81292,8 @@ paths:
8120881292
using a normalized exact match; case is ignored and spaces are removed. No
8120981293
modifications are made
8121081294

81211-
to teams in GitHub. This will not create new Teams in Datadog.'
81295+
to teams in GitHub. This only creates new teams in Datadog when type is set
81296+
to `provision`.'
8121281297
operationId: SyncTeams
8121381298
requestBody:
8121481299
content:

examples/v2_teams_GetTeamSync.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Get team sync configurations returns "OK" response
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV2::api_teams::TeamsAPI;
4+
use datadog_api_client::datadogV2::model::TeamSyncAttributesSource;
5+
6+
#[tokio::main]
7+
async fn main() {
8+
let mut configuration = datadog::Configuration::new();
9+
configuration.set_unstable_operation_enabled("v2.GetTeamSync", true);
10+
let api = TeamsAPI::with_config(configuration);
11+
let resp = api.get_team_sync(TeamSyncAttributesSource::GITHUB).await;
12+
if let Ok(value) = resp {
13+
println!("{:#?}", value);
14+
} else {
15+
println!("{:#?}", resp.unwrap_err());
16+
}
17+
}

src/datadog/configuration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ impl Default for Configuration {
256256
("v2.create_sca_resolve_vulnerable_symbols".to_owned(), false),
257257
("v2.create_sca_result".to_owned(), false),
258258
("v2.add_member_team".to_owned(), false),
259+
("v2.get_team_sync".to_owned(), false),
259260
("v2.list_member_teams".to_owned(), false),
260261
("v2.remove_member_team".to_owned(), false),
261262
("v2.sync_teams".to_owned(), false),

src/datadogV2/api/api_teams.rs

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ pub enum GetTeamPermissionSettingsError {
234234
UnknownValue(serde_json::Value),
235235
}
236236

237+
/// GetTeamSyncError is a struct for typed errors of method [`TeamsAPI::get_team_sync`]
238+
#[derive(Debug, Clone, Serialize, Deserialize)]
239+
#[serde(untagged)]
240+
pub enum GetTeamSyncError {
241+
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
242+
UnknownValue(serde_json::Value),
243+
}
244+
237245
/// GetUserMembershipsError is a struct for typed errors of method [`TeamsAPI::get_user_memberships`]
238246
#[derive(Debug, Clone, Serialize, Deserialize)]
239247
#[serde(untagged)]
@@ -1848,6 +1856,122 @@ impl TeamsAPI {
18481856
}
18491857
}
18501858

1859+
/// Get all team synchronization configurations.
1860+
/// Returns a list of configurations used for linking or provisioning teams with external sources like GitHub.
1861+
pub async fn get_team_sync(
1862+
&self,
1863+
filter_source: crate::datadogV2::model::TeamSyncAttributesSource,
1864+
) -> Result<crate::datadogV2::model::TeamSyncResponse, datadog::Error<GetTeamSyncError>> {
1865+
match self.get_team_sync_with_http_info(filter_source).await {
1866+
Ok(response_content) => {
1867+
if let Some(e) = response_content.entity {
1868+
Ok(e)
1869+
} else {
1870+
Err(datadog::Error::Serde(serde::de::Error::custom(
1871+
"response content was None",
1872+
)))
1873+
}
1874+
}
1875+
Err(err) => Err(err),
1876+
}
1877+
}
1878+
1879+
/// Get all team synchronization configurations.
1880+
/// Returns a list of configurations used for linking or provisioning teams with external sources like GitHub.
1881+
pub async fn get_team_sync_with_http_info(
1882+
&self,
1883+
filter_source: crate::datadogV2::model::TeamSyncAttributesSource,
1884+
) -> Result<
1885+
datadog::ResponseContent<crate::datadogV2::model::TeamSyncResponse>,
1886+
datadog::Error<GetTeamSyncError>,
1887+
> {
1888+
let local_configuration = &self.config;
1889+
let operation_id = "v2.get_team_sync";
1890+
if local_configuration.is_unstable_operation_enabled(operation_id) {
1891+
warn!("Using unstable operation {operation_id}");
1892+
} else {
1893+
let local_error = datadog::UnstableOperationDisabledError {
1894+
msg: "Operation 'v2.get_team_sync' is not enabled".to_string(),
1895+
};
1896+
return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1897+
}
1898+
1899+
let local_client = &self.client;
1900+
1901+
let local_uri_str = format!(
1902+
"{}/api/v2/team/sync",
1903+
local_configuration.get_operation_host(operation_id)
1904+
);
1905+
let mut local_req_builder =
1906+
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1907+
1908+
local_req_builder =
1909+
local_req_builder.query(&[("filter[source]", &filter_source.to_string())]);
1910+
1911+
// build headers
1912+
let mut headers = HeaderMap::new();
1913+
headers.insert("Accept", HeaderValue::from_static("application/json"));
1914+
1915+
// build user agent
1916+
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1917+
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1918+
Err(e) => {
1919+
log::warn!("Failed to parse user agent header: {e}, falling back to default");
1920+
headers.insert(
1921+
reqwest::header::USER_AGENT,
1922+
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1923+
)
1924+
}
1925+
};
1926+
1927+
// build auth
1928+
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1929+
headers.insert(
1930+
"DD-API-KEY",
1931+
HeaderValue::from_str(local_key.key.as_str())
1932+
.expect("failed to parse DD-API-KEY header"),
1933+
);
1934+
};
1935+
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1936+
headers.insert(
1937+
"DD-APPLICATION-KEY",
1938+
HeaderValue::from_str(local_key.key.as_str())
1939+
.expect("failed to parse DD-APPLICATION-KEY header"),
1940+
);
1941+
};
1942+
1943+
local_req_builder = local_req_builder.headers(headers);
1944+
let local_req = local_req_builder.build()?;
1945+
log::debug!("request content: {:?}", local_req.body());
1946+
let local_resp = local_client.execute(local_req).await?;
1947+
1948+
let local_status = local_resp.status();
1949+
let local_content = local_resp.text().await?;
1950+
log::debug!("response content: {}", local_content);
1951+
1952+
if !local_status.is_client_error() && !local_status.is_server_error() {
1953+
match serde_json::from_str::<crate::datadogV2::model::TeamSyncResponse>(&local_content)
1954+
{
1955+
Ok(e) => {
1956+
return Ok(datadog::ResponseContent {
1957+
status: local_status,
1958+
content: local_content,
1959+
entity: Some(e),
1960+
})
1961+
}
1962+
Err(e) => return Err(datadog::Error::Serde(e)),
1963+
};
1964+
} else {
1965+
let local_entity: Option<GetTeamSyncError> = serde_json::from_str(&local_content).ok();
1966+
let local_error = datadog::ResponseContent {
1967+
status: local_status,
1968+
content: local_content,
1969+
entity: local_entity,
1970+
};
1971+
Err(datadog::Error::ResponseError(local_error))
1972+
}
1973+
}
1974+
18511975
/// Get a list of memberships for a user
18521976
pub async fn get_user_memberships(
18531977
&self,
@@ -2426,7 +2550,7 @@ impl TeamsAPI {
24262550
/// [A GitHub organization must be connected to your Datadog account](<https://docs.datadoghq.com/integrations/github/>),
24272551
/// and the GitHub App integrated with Datadog must have the `Members Read` permission. Matching is performed by comparing the Datadog team handle to the GitHub team slug
24282552
/// using a normalized exact match; case is ignored and spaces are removed. No modifications are made
2429-
/// to teams in GitHub. This will not create new Teams in Datadog.
2553+
/// to teams in GitHub. This only creates new teams in Datadog when type is set to `provision`.
24302554
pub async fn sync_teams(
24312555
&self,
24322556
body: crate::datadogV2::model::TeamSyncRequest,
@@ -2447,7 +2571,7 @@ impl TeamsAPI {
24472571
/// [A GitHub organization must be connected to your Datadog account](<https://docs.datadoghq.com/integrations/github/>),
24482572
/// and the GitHub App integrated with Datadog must have the `Members Read` permission. Matching is performed by comparing the Datadog team handle to the GitHub team slug
24492573
/// using a normalized exact match; case is ignored and spaces are removed. No modifications are made
2450-
/// to teams in GitHub. This will not create new Teams in Datadog.
2574+
/// to teams in GitHub. This only creates new teams in Datadog when type is set to `provision`.
24512575
pub async fn sync_teams_with_http_info(
24522576
&self,
24532577
body: crate::datadogV2::model::TeamSyncRequest,

src/datadogV2/model/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6630,18 +6630,22 @@ pub mod model_team_connection_create_request;
66306630
pub use self::model_team_connection_create_request::TeamConnectionCreateRequest;
66316631
pub mod model_team_connection_create_data;
66326632
pub use self::model_team_connection_create_data::TeamConnectionCreateData;
6633-
pub mod model_team_sync_request;
6634-
pub use self::model_team_sync_request::TeamSyncRequest;
6633+
pub mod model_team_sync_attributes_source;
6634+
pub use self::model_team_sync_attributes_source::TeamSyncAttributesSource;
6635+
pub mod model_team_sync_response;
6636+
pub use self::model_team_sync_response::TeamSyncResponse;
66356637
pub mod model_team_sync_data;
66366638
pub use self::model_team_sync_data::TeamSyncData;
66376639
pub mod model_team_sync_attributes;
66386640
pub use self::model_team_sync_attributes::TeamSyncAttributes;
6639-
pub mod model_team_sync_attributes_source;
6640-
pub use self::model_team_sync_attributes_source::TeamSyncAttributesSource;
6641+
pub mod model_team_sync_attributes_frequency;
6642+
pub use self::model_team_sync_attributes_frequency::TeamSyncAttributesFrequency;
66416643
pub mod model_team_sync_attributes_type;
66426644
pub use self::model_team_sync_attributes_type::TeamSyncAttributesType;
66436645
pub mod model_team_sync_bulk_type;
66446646
pub use self::model_team_sync_bulk_type::TeamSyncBulkType;
6647+
pub mod model_team_sync_request;
6648+
pub use self::model_team_sync_request::TeamSyncRequest;
66456649
pub mod model_add_member_team_request;
66466650
pub use self::model_add_member_team_request::AddMemberTeamRequest;
66476651
pub mod model_member_team;

0 commit comments

Comments
 (0)