Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,14 @@ components:
required: false
schema:
type: boolean
SlackUserUuidQueryParameter:
description: The UUID of the Datadog user to list Slack bindings for.
in: query
name: user_uuid
required: true
schema:
format: uuid
type: string
SloID:
description: The ID of the SLO.
in: path
Expand Down Expand Up @@ -88673,6 +88681,37 @@ components:
required:
- slackTrigger
type: object
SlackUserBindingData:
description: Slack team ID data from a response.
properties:
id:
description: The Slack team ID.
example: "T01234567"
type: string
type:
$ref: "#/components/schemas/SlackUserBindingType"
type: object
SlackUserBindingType:
default: team_id
description: Slack user binding resource type.
enum:
- team_id
example: team_id
type: string
x-enum-varnames:
- TEAM_ID
SlackUserBindingsResponse:
description: Response with a list of Slack user bindings.
properties:
data:
description: An array of Slack user bindings.
example: [{"id": "T01234567", "type": "team_id"}, {"id": "T09876543", "type": "team_id"}]
items:
$ref: "#/components/schemas/SlackUserBindingData"
type: array
required:
- data
type: object
SloDataSource:
default: slo
description: A data source for SLO queries.
Expand Down Expand Up @@ -135946,6 +135985,36 @@ paths:
summary: List ServiceNow users
tags:
- ServiceNow Integration
/api/v2/integration/slack/user-bindings:
get:
description: List all Slack user bindings for a given Datadog user from the Datadog Slack integration.
operationId: ListSlackUserBindings
parameters:
- $ref: "#/components/parameters/SlackUserUuidQueryParameter"
responses:
"200":
content:
application/json:
examples:
default:
value:
data:
- id: T01234567
type: team_id
- id: T09876543
type: team_id
schema:
$ref: "#/components/schemas/SlackUserBindingsResponse"
description: OK
"400":
$ref: "#/components/responses/BadRequestResponse"
"403":
$ref: "#/components/responses/ForbiddenResponse"
"429":
$ref: "#/components/responses/TooManyRequestsResponse"
summary: List Slack user bindings
tags:
- Slack Integration
/api/v2/integration/statuspage/account:
delete:
description: Delete the Statuspage account configured for your organization.
Expand Down Expand Up @@ -185814,6 +185883,13 @@ tags:
name: Service Level Objectives
- description: Manage your ServiceNow Integration. ServiceNow is a cloud-based platform that helps organizations manage digital workflows for enterprise operations.
name: ServiceNow Integration
- description: |-
Configure your [Datadog Slack integration](https://docs.datadoghq.com/integrations/slack/)
directly through the Datadog API.
externalDocs:
description: For more information about the Datadog Slack integration, see the integration page.
url: https://docs.datadoghq.com/integrations/slack/
name: Slack Integration
- description: |-
API to create, update, retrieve, and delete Software Catalog entities.
externalDocs:
Expand Down
20 changes: 20 additions & 0 deletions examples/v2_slack-integration_ListSlackUserBindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// List Slack user bindings returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_slack_integration::SlackIntegrationAPI;
use uuid::Uuid;

#[tokio::main]
async fn main() {
let configuration = datadog::Configuration::new();
let api = SlackIntegrationAPI::with_config(configuration);
let resp = api
.list_slack_user_bindings(
Uuid::parse_str("00000000-0000-0000-0000-000000000000").expect("invalid UUID"),
)
.await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
203 changes: 203 additions & 0 deletions src/datadogV2/api/api_slack_integration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.
use crate::datadog;
use reqwest::header::{HeaderMap, HeaderValue};
use serde::{Deserialize, Serialize};

/// ListSlackUserBindingsError is a struct for typed errors of method [`SlackIntegrationAPI::list_slack_user_bindings`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListSlackUserBindingsError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}

/// Configure your [Datadog Slack integration](<https://docs.datadoghq.com/integrations/slack/>)
/// directly through the Datadog API.
#[derive(Debug, Clone)]
pub struct SlackIntegrationAPI {
config: datadog::Configuration,
client: reqwest_middleware::ClientWithMiddleware,
}

impl Default for SlackIntegrationAPI {
fn default() -> Self {
Self::with_config(datadog::Configuration::default())
}
}

impl SlackIntegrationAPI {
pub fn new() -> Self {
Self::default()
}
pub fn with_config(config: datadog::Configuration) -> Self {
let reqwest_client_builder = {
let builder = reqwest::Client::builder();
#[cfg(not(target_arch = "wasm32"))]
let builder = if let Some(proxy_url) = &config.proxy_url {
builder.proxy(reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL"))
} else {
builder
};
builder
};

let middleware_client_builder = {
let builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
#[cfg(feature = "retry")]
let builder = if config.enable_retry {
struct RetryableStatus;
impl reqwest_retry::RetryableStrategy for RetryableStatus {
fn handle(
&self,
res: &Result<reqwest::Response, reqwest_middleware::Error>,
) -> Option<reqwest_retry::Retryable> {
match res {
Ok(success) => reqwest_retry::default_on_request_success(success),
Err(_) => None,
}
}
}
let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
.build_with_max_retries(config.max_retries);

let retry_middleware =
reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
backoff_policy,
RetryableStatus,
);

builder.with(retry_middleware)
} else {
builder
};
builder
};

let client = middleware_client_builder.build();

Self { config, client }
}

pub fn with_client_and_config(
config: datadog::Configuration,
client: reqwest_middleware::ClientWithMiddleware,
) -> Self {
Self { config, client }
}

/// List all Slack user bindings for a given Datadog user from the Datadog Slack integration.
pub async fn list_slack_user_bindings(
&self,
user_uuid: uuid::Uuid,
) -> Result<
crate::datadogV2::model::SlackUserBindingsResponse,
datadog::Error<ListSlackUserBindingsError>,
> {
match self
.list_slack_user_bindings_with_http_info(user_uuid)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}

/// List all Slack user bindings for a given Datadog user from the Datadog Slack integration.
pub async fn list_slack_user_bindings_with_http_info(
&self,
user_uuid: uuid::Uuid,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SlackUserBindingsResponse>,
datadog::Error<ListSlackUserBindingsError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.list_slack_user_bindings";

let local_client = &self.client;

let local_uri_str = format!(
"{}/api/v2/integration/slack/user-bindings",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());

local_req_builder = local_req_builder.query(&[("user_uuid", &user_uuid.to_string())]);

// build headers
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));

// build user agent
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};

// build auth
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};

local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;

let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);

if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV2::model::SlackUserBindingsResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<ListSlackUserBindingsError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
}
1 change: 1 addition & 0 deletions src/datadogV2/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub mod api_service_accounts;
pub mod api_service_definition;
pub mod api_service_level_objectives;
pub mod api_service_now_integration;
pub mod api_slack_integration;
pub mod api_software_catalog;
pub mod api_spa;
pub mod api_spans;
Expand Down
1 change: 1 addition & 0 deletions src/datadogV2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pub use self::api::api_service_accounts;
pub use self::api::api_service_definition;
pub use self::api::api_service_level_objectives;
pub use self::api::api_service_now_integration;
pub use self::api::api_slack_integration;
pub use self::api::api_software_catalog;
pub use self::api::api_spa;
pub use self::api::api_spans;
Expand Down
6 changes: 6 additions & 0 deletions src/datadogV2/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5144,6 +5144,12 @@ pub mod model_service_now_user_attributes;
pub use self::model_service_now_user_attributes::ServiceNowUserAttributes;
pub mod model_service_now_user_type;
pub use self::model_service_now_user_type::ServiceNowUserType;
pub mod model_slack_user_bindings_response;
pub use self::model_slack_user_bindings_response::SlackUserBindingsResponse;
pub mod model_slack_user_binding_data;
pub use self::model_slack_user_binding_data::SlackUserBindingData;
pub mod model_slack_user_binding_type;
pub use self::model_slack_user_binding_type::SlackUserBindingType;
pub mod model_statuspage_account_response;
pub use self::model_statuspage_account_response::StatuspageAccountResponse;
pub mod model_statuspage_account_response_data;
Expand Down
Loading
Loading