Skip to content

Commit

Permalink
Add PUT endpoint to scorecards APIs (#219)
Browse files Browse the repository at this point in the history
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
  • Loading branch information
api-clients-generation-pipeline[bot] and ci.datadog-api-spec authored Aug 1, 2024
1 parent 61a8006 commit 449d881
Show file tree
Hide file tree
Showing 16 changed files with 876 additions and 12 deletions.
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2024-07-30 19:24:54.991074",
"spec_repo_commit": "edbd396a"
"regenerated": "2024-08-01 14:34:21.815588",
"spec_repo_commit": "d28278c6"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-07-30 19:24:55.009349",
"spec_repo_commit": "edbd396a"
"regenerated": "2024-08-01 14:34:21.833584",
"spec_repo_commit": "d28278c6"
}
}
}
79 changes: 74 additions & 5 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ components:
schema:
type: string
RuleId:
description: The ID of the rule/scorecard.
description: The ID of the rule.
in: path
name: rule_id
required: true
Expand Down Expand Up @@ -16546,7 +16546,7 @@ components:
properties:
id:
description: The unique ID for a scorecard.
example: 00000000-0000-beef-0000-000000000000
example: q8MQxk8TCqrHnWkp
type: string
type:
$ref: '#/components/schemas/ScorecardType'
Expand Down Expand Up @@ -17391,7 +17391,7 @@ components:
type: object
RuleId:
description: The unique ID for a scorecard rule.
example: 00000000-0000-beef-0000-000000000000
example: q8MQxk8TCqrHnWkx
type: string
RuleOutcomeRelationships:
description: The JSON:API relationship to a scorecard rule.
Expand Down Expand Up @@ -23230,6 +23230,38 @@ components:
id:
$ref: '#/components/schemas/ApiID'
type: object
UpdateRuleRequest:
description: Request to update a scorecard rule.
properties:
data:
$ref: '#/components/schemas/UpdateRuleRequestData'
type: object
UpdateRuleRequestData:
description: Data for the request to update a scorecard rule.
properties:
attributes:
$ref: '#/components/schemas/RuleAttributes'
type:
$ref: '#/components/schemas/RuleType'
type: object
UpdateRuleResponse:
description: The response from a rule update request.
properties:
data:
$ref: '#/components/schemas/UpdateRuleResponseData'
type: object
UpdateRuleResponseData:
description: The data for a rule update response.
properties:
attributes:
$ref: '#/components/schemas/RuleAttributes'
id:
$ref: '#/components/schemas/RuleId'
relationships:
$ref: '#/components/schemas/RelationshipToRule'
type:
$ref: '#/components/schemas/RuleType'
type: object
UsageApplicationSecurityMonitoringResponse:
description: Application Security Monitoring usage response.
properties:
Expand Down Expand Up @@ -33671,6 +33703,43 @@ paths:
x-unstable: '**Note**: This endpoint is in public beta.

If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).'
put:
description: Updates an existing rule.
operationId: UpdateScorecardRule
parameters:
- $ref: '#/components/parameters/RuleId'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UpdateRuleRequest'
description: Rule attributes.
required: true
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/UpdateRuleResponse'
description: Rule updated successfully
'400':
$ref: '#/components/responses/BadRequestResponse'
'403':
$ref: '#/components/responses/ForbiddenResponse'
'429':
$ref: '#/components/responses/TooManyRequestsResponse'
security:
- apiKeyAuth: []
appKeyAuth: []
- AuthZ:
- apm_service_catalog_write
summary: Update an existing rule
tags:
- Service Scorecards
x-codegen-request-body-name: body
x-unstable: '**Note**: This endpoint is in public beta.

If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).'
/api/v2/security/cloud_workload/policy/download:
get:
description: 'The download endpoint generates a Cloud Workload Security policy
Expand Down Expand Up @@ -38387,8 +38456,8 @@ tags:

and improve communication with internal and external users.'
name: Service Level Objectives
- description: 'API to create, update scorecard rules and outcomes. See [Service Scorecards](https://docs.datadoghq.com/service_catalog/scorecards)
for more information.
- description: 'API to create and update scorecard rules and outcomes. See [Service
Scorecards](https://docs.datadoghq.com/service_catalog/scorecards) for more information.


This feature is currently in BETA. If you have any feedback, contact [Datadog
Expand Down
2 changes: 1 addition & 1 deletion LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ windows_x86_64_gnu,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Mic
windows_x86_64_gnullvm,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Microsoft
windows_x86_64_msvc,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Microsoft
winreg,https://github.com/gentoo90/winreg-rs,MIT,Igor Shaula <gentoo90@gmail.com>
zerocopy,https://github.com/google/zerocopy,BSD-2-Clause OR Apache-2.0 OR MIT,Joshua Liebow-Feeser <joshlf@google.com>
zerocopy,https://github.com/google/zerocopy,BSD-2-Clause,Joshua Liebow-Feeser <joshlf@google.com>
zstd,https://github.com/gyscos/zstd-rs,MIT,Alexandre Bury <alexandre.bury@gmail.com>
zstd-safe,https://github.com/gyscos/zstd-rs,MIT OR Apache-2.0,Alexandre Bury <alexandre.bury@gmail.com>
zstd-sys,https://github.com/gyscos/zstd-rs,MIT OR Apache-2.0,Alexandre Bury <alexandre.bury@gmail.com>
36 changes: 36 additions & 0 deletions examples/v2_service-scorecards_UpdateScorecardRule.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Update an existing rule returns "Rule updated successfully" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_service_scorecards::ServiceScorecardsAPI;
use datadog_api_client::datadogV2::model::RuleAttributes;
use datadog_api_client::datadogV2::model::UpdateRuleRequest;
use datadog_api_client::datadogV2::model::UpdateRuleRequestData;

#[tokio::main]
async fn main() {
// there is a valid "create_scorecard_rule" in the system
let create_scorecard_rule_data_attributes_name =
std::env::var("CREATE_SCORECARD_RULE_DATA_ATTRIBUTES_NAME").unwrap();
let create_scorecard_rule_data_attributes_scorecard_name =
std::env::var("CREATE_SCORECARD_RULE_DATA_ATTRIBUTES_SCORECARD_NAME").unwrap();
let create_scorecard_rule_data_id = std::env::var("CREATE_SCORECARD_RULE_DATA_ID").unwrap();
let body = UpdateRuleRequest::new().data(
UpdateRuleRequestData::new().attributes(
RuleAttributes::new()
.description("Updated description via test".to_string())
.enabled(true)
.name(create_scorecard_rule_data_attributes_name.clone())
.scorecard_name(create_scorecard_rule_data_attributes_scorecard_name.clone()),
),
);
let mut configuration = datadog::Configuration::new();
configuration.set_unstable_operation_enabled("v2.UpdateScorecardRule", true);
let api = ServiceScorecardsAPI::with_config(configuration);
let resp = api
.update_scorecard_rule(create_scorecard_rule_data_id.clone(), body)
.await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
1 change: 1 addition & 0 deletions src/datadog/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ impl Default for Configuration {
("v2.delete_scorecard_rule".to_owned(), false),
("v2.list_scorecard_outcomes".to_owned(), false),
("v2.list_scorecard_rules".to_owned(), false),
("v2.update_scorecard_rule".to_owned(), false),
("v2.create_incident_service".to_owned(), false),
("v2.delete_incident_service".to_owned(), false),
("v2.get_incident_service".to_owned(), false),
Expand Down
176 changes: 175 additions & 1 deletion src/datadogV2/api/api_service_scorecards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,15 @@ pub enum ListScorecardRulesError {
UnknownValue(serde_json::Value),
}

/// API to create, update scorecard rules and outcomes. See [Service Scorecards](<https://docs.datadoghq.com/service_catalog/scorecards>) for more information.
/// UpdateScorecardRuleError is a struct for typed errors of method [`ServiceScorecardsAPI::update_scorecard_rule`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateScorecardRuleError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}

/// API to create and update scorecard rules and outcomes. See [Service Scorecards](<https://docs.datadoghq.com/service_catalog/scorecards>) for more information.
///
/// This feature is currently in BETA. If you have any feedback, contact [Datadog support](<https://docs.datadoghq.com/help/>).
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -1108,4 +1116,170 @@ impl ServiceScorecardsAPI {
Err(datadog::Error::ResponseError(local_error))
}
}

/// Updates an existing rule.
pub async fn update_scorecard_rule(
&self,
rule_id: String,
body: crate::datadogV2::model::UpdateRuleRequest,
) -> Result<crate::datadogV2::model::UpdateRuleResponse, datadog::Error<UpdateScorecardRuleError>>
{
match self
.update_scorecard_rule_with_http_info(rule_id, body)
.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),
}
}

/// Updates an existing rule.
pub async fn update_scorecard_rule_with_http_info(
&self,
rule_id: String,
body: crate::datadogV2::model::UpdateRuleRequest,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::UpdateRuleResponse>,
datadog::Error<UpdateScorecardRuleError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.update_scorecard_rule";
if local_configuration.is_unstable_operation_enabled(operation_id) {
warn!("Using unstable operation {operation_id}");
} else {
let local_error = datadog::UnstableOperationDisabledError {
msg: "Operation 'v2.update_scorecard_rule' is not enabled".to_string(),
};
return Err(datadog::Error::UnstableOperationDisabledError(local_error));
}

let local_client = &self.client;

let local_uri_str = format!(
"{}/api/v2/scorecard/rules/{rule_id}",
local_configuration.get_operation_host(operation_id),
rule_id = datadog::urlencode(rule_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::PUT, local_uri_str.as_str());

// build headers
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
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"),
);
};

// build body parameters
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}

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::UpdateRuleResponse>(
&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<UpdateScorecardRuleError> =
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))
}
}
}
8 changes: 8 additions & 0 deletions src/datadogV2/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2190,6 +2190,14 @@ pub mod model_create_rule_response;
pub use self::model_create_rule_response::CreateRuleResponse;
pub mod model_create_rule_response_data;
pub use self::model_create_rule_response_data::CreateRuleResponseData;
pub mod model_update_rule_request;
pub use self::model_update_rule_request::UpdateRuleRequest;
pub mod model_update_rule_request_data;
pub use self::model_update_rule_request_data::UpdateRuleRequestData;
pub mod model_update_rule_response;
pub use self::model_update_rule_response::UpdateRuleResponse;
pub mod model_update_rule_response_data;
pub use self::model_update_rule_response_data::UpdateRuleResponseData;
pub mod model_security_filters_response;
pub use self::model_security_filters_response::SecurityFiltersResponse;
pub mod model_security_filter;
Expand Down
Loading

0 comments on commit 449d881

Please sign in to comment.