Skip to content

Commit 449d881

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add PUT endpoint to scorecards APIs (#219)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 61a8006 commit 449d881

16 files changed

+876
-12
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.6",
7-
"regenerated": "2024-07-30 19:24:54.991074",
8-
"spec_repo_commit": "edbd396a"
7+
"regenerated": "2024-08-01 14:34:21.815588",
8+
"spec_repo_commit": "d28278c6"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2024-07-30 19:24:55.009349",
13-
"spec_repo_commit": "edbd396a"
12+
"regenerated": "2024-08-01 14:34:21.833584",
13+
"spec_repo_commit": "d28278c6"
1414
}
1515
}
1616
}

.generator/schemas/v2/openapi.yaml

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ components:
464464
schema:
465465
type: string
466466
RuleId:
467-
description: The ID of the rule/scorecard.
467+
description: The ID of the rule.
468468
in: path
469469
name: rule_id
470470
required: true
@@ -16546,7 +16546,7 @@ components:
1654616546
properties:
1654716547
id:
1654816548
description: The unique ID for a scorecard.
16549-
example: 00000000-0000-beef-0000-000000000000
16549+
example: q8MQxk8TCqrHnWkp
1655016550
type: string
1655116551
type:
1655216552
$ref: '#/components/schemas/ScorecardType'
@@ -17391,7 +17391,7 @@ components:
1739117391
type: object
1739217392
RuleId:
1739317393
description: The unique ID for a scorecard rule.
17394-
example: 00000000-0000-beef-0000-000000000000
17394+
example: q8MQxk8TCqrHnWkx
1739517395
type: string
1739617396
RuleOutcomeRelationships:
1739717397
description: The JSON:API relationship to a scorecard rule.
@@ -23230,6 +23230,38 @@ components:
2323023230
id:
2323123231
$ref: '#/components/schemas/ApiID'
2323223232
type: object
23233+
UpdateRuleRequest:
23234+
description: Request to update a scorecard rule.
23235+
properties:
23236+
data:
23237+
$ref: '#/components/schemas/UpdateRuleRequestData'
23238+
type: object
23239+
UpdateRuleRequestData:
23240+
description: Data for the request to update a scorecard rule.
23241+
properties:
23242+
attributes:
23243+
$ref: '#/components/schemas/RuleAttributes'
23244+
type:
23245+
$ref: '#/components/schemas/RuleType'
23246+
type: object
23247+
UpdateRuleResponse:
23248+
description: The response from a rule update request.
23249+
properties:
23250+
data:
23251+
$ref: '#/components/schemas/UpdateRuleResponseData'
23252+
type: object
23253+
UpdateRuleResponseData:
23254+
description: The data for a rule update response.
23255+
properties:
23256+
attributes:
23257+
$ref: '#/components/schemas/RuleAttributes'
23258+
id:
23259+
$ref: '#/components/schemas/RuleId'
23260+
relationships:
23261+
$ref: '#/components/schemas/RelationshipToRule'
23262+
type:
23263+
$ref: '#/components/schemas/RuleType'
23264+
type: object
2323323265
UsageApplicationSecurityMonitoringResponse:
2323423266
description: Application Security Monitoring usage response.
2323523267
properties:
@@ -33671,6 +33703,43 @@ paths:
3367133703
x-unstable: '**Note**: This endpoint is in public beta.
3367233704

3367333705
If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).'
33706+
put:
33707+
description: Updates an existing rule.
33708+
operationId: UpdateScorecardRule
33709+
parameters:
33710+
- $ref: '#/components/parameters/RuleId'
33711+
requestBody:
33712+
content:
33713+
application/json:
33714+
schema:
33715+
$ref: '#/components/schemas/UpdateRuleRequest'
33716+
description: Rule attributes.
33717+
required: true
33718+
responses:
33719+
'200':
33720+
content:
33721+
application/json:
33722+
schema:
33723+
$ref: '#/components/schemas/UpdateRuleResponse'
33724+
description: Rule updated successfully
33725+
'400':
33726+
$ref: '#/components/responses/BadRequestResponse'
33727+
'403':
33728+
$ref: '#/components/responses/ForbiddenResponse'
33729+
'429':
33730+
$ref: '#/components/responses/TooManyRequestsResponse'
33731+
security:
33732+
- apiKeyAuth: []
33733+
appKeyAuth: []
33734+
- AuthZ:
33735+
- apm_service_catalog_write
33736+
summary: Update an existing rule
33737+
tags:
33738+
- Service Scorecards
33739+
x-codegen-request-body-name: body
33740+
x-unstable: '**Note**: This endpoint is in public beta.
33741+
33742+
If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).'
3367433743
/api/v2/security/cloud_workload/policy/download:
3367533744
get:
3367633745
description: 'The download endpoint generates a Cloud Workload Security policy
@@ -38387,8 +38456,8 @@ tags:
3838738456

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

3839338462

3839438463
This feature is currently in BETA. If you have any feedback, contact [Datadog

LICENSE-3rdparty.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ windows_x86_64_gnu,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Mic
151151
windows_x86_64_gnullvm,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Microsoft
152152
windows_x86_64_msvc,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Microsoft
153153
winreg,https://github.com/gentoo90/winreg-rs,MIT,Igor Shaula <[email protected]>
154-
zerocopy,https://github.com/google/zerocopy,BSD-2-Clause OR Apache-2.0 OR MIT,Joshua Liebow-Feeser <[email protected]>
154+
zerocopy,https://github.com/google/zerocopy,BSD-2-Clause,Joshua Liebow-Feeser <[email protected]>
155155
zstd,https://github.com/gyscos/zstd-rs,MIT,Alexandre Bury <[email protected]>
156156
zstd-safe,https://github.com/gyscos/zstd-rs,MIT OR Apache-2.0,Alexandre Bury <[email protected]>
157157
zstd-sys,https://github.com/gyscos/zstd-rs,MIT OR Apache-2.0,Alexandre Bury <[email protected]>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Update an existing rule returns "Rule updated successfully" response
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV2::api_service_scorecards::ServiceScorecardsAPI;
4+
use datadog_api_client::datadogV2::model::RuleAttributes;
5+
use datadog_api_client::datadogV2::model::UpdateRuleRequest;
6+
use datadog_api_client::datadogV2::model::UpdateRuleRequestData;
7+
8+
#[tokio::main]
9+
async fn main() {
10+
// there is a valid "create_scorecard_rule" in the system
11+
let create_scorecard_rule_data_attributes_name =
12+
std::env::var("CREATE_SCORECARD_RULE_DATA_ATTRIBUTES_NAME").unwrap();
13+
let create_scorecard_rule_data_attributes_scorecard_name =
14+
std::env::var("CREATE_SCORECARD_RULE_DATA_ATTRIBUTES_SCORECARD_NAME").unwrap();
15+
let create_scorecard_rule_data_id = std::env::var("CREATE_SCORECARD_RULE_DATA_ID").unwrap();
16+
let body = UpdateRuleRequest::new().data(
17+
UpdateRuleRequestData::new().attributes(
18+
RuleAttributes::new()
19+
.description("Updated description via test".to_string())
20+
.enabled(true)
21+
.name(create_scorecard_rule_data_attributes_name.clone())
22+
.scorecard_name(create_scorecard_rule_data_attributes_scorecard_name.clone()),
23+
),
24+
);
25+
let mut configuration = datadog::Configuration::new();
26+
configuration.set_unstable_operation_enabled("v2.UpdateScorecardRule", true);
27+
let api = ServiceScorecardsAPI::with_config(configuration);
28+
let resp = api
29+
.update_scorecard_rule(create_scorecard_rule_data_id.clone(), body)
30+
.await;
31+
if let Ok(value) = resp {
32+
println!("{:#?}", value);
33+
} else {
34+
println!("{:#?}", resp.unwrap_err());
35+
}
36+
}

src/datadog/configuration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ impl Default for Configuration {
166166
("v2.delete_scorecard_rule".to_owned(), false),
167167
("v2.list_scorecard_outcomes".to_owned(), false),
168168
("v2.list_scorecard_rules".to_owned(), false),
169+
("v2.update_scorecard_rule".to_owned(), false),
169170
("v2.create_incident_service".to_owned(), false),
170171
("v2.delete_incident_service".to_owned(), false),
171172
("v2.get_incident_service".to_owned(), false),

src/datadogV2/api/api_service_scorecards.rs

Lines changed: 175 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,15 @@ pub enum ListScorecardRulesError {
211211
UnknownValue(serde_json::Value),
212212
}
213213

214-
/// API to create, update scorecard rules and outcomes. See [Service Scorecards](<https://docs.datadoghq.com/service_catalog/scorecards>) for more information.
214+
/// UpdateScorecardRuleError is a struct for typed errors of method [`ServiceScorecardsAPI::update_scorecard_rule`]
215+
#[derive(Debug, Clone, Serialize, Deserialize)]
216+
#[serde(untagged)]
217+
pub enum UpdateScorecardRuleError {
218+
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
219+
UnknownValue(serde_json::Value),
220+
}
221+
222+
/// API to create and update scorecard rules and outcomes. See [Service Scorecards](<https://docs.datadoghq.com/service_catalog/scorecards>) for more information.
215223
///
216224
/// This feature is currently in BETA. If you have any feedback, contact [Datadog support](<https://docs.datadoghq.com/help/>).
217225
#[derive(Debug, Clone)]
@@ -1108,4 +1116,170 @@ impl ServiceScorecardsAPI {
11081116
Err(datadog::Error::ResponseError(local_error))
11091117
}
11101118
}
1119+
1120+
/// Updates an existing rule.
1121+
pub async fn update_scorecard_rule(
1122+
&self,
1123+
rule_id: String,
1124+
body: crate::datadogV2::model::UpdateRuleRequest,
1125+
) -> Result<crate::datadogV2::model::UpdateRuleResponse, datadog::Error<UpdateScorecardRuleError>>
1126+
{
1127+
match self
1128+
.update_scorecard_rule_with_http_info(rule_id, body)
1129+
.await
1130+
{
1131+
Ok(response_content) => {
1132+
if let Some(e) = response_content.entity {
1133+
Ok(e)
1134+
} else {
1135+
Err(datadog::Error::Serde(serde::de::Error::custom(
1136+
"response content was None",
1137+
)))
1138+
}
1139+
}
1140+
Err(err) => Err(err),
1141+
}
1142+
}
1143+
1144+
/// Updates an existing rule.
1145+
pub async fn update_scorecard_rule_with_http_info(
1146+
&self,
1147+
rule_id: String,
1148+
body: crate::datadogV2::model::UpdateRuleRequest,
1149+
) -> Result<
1150+
datadog::ResponseContent<crate::datadogV2::model::UpdateRuleResponse>,
1151+
datadog::Error<UpdateScorecardRuleError>,
1152+
> {
1153+
let local_configuration = &self.config;
1154+
let operation_id = "v2.update_scorecard_rule";
1155+
if local_configuration.is_unstable_operation_enabled(operation_id) {
1156+
warn!("Using unstable operation {operation_id}");
1157+
} else {
1158+
let local_error = datadog::UnstableOperationDisabledError {
1159+
msg: "Operation 'v2.update_scorecard_rule' is not enabled".to_string(),
1160+
};
1161+
return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1162+
}
1163+
1164+
let local_client = &self.client;
1165+
1166+
let local_uri_str = format!(
1167+
"{}/api/v2/scorecard/rules/{rule_id}",
1168+
local_configuration.get_operation_host(operation_id),
1169+
rule_id = datadog::urlencode(rule_id)
1170+
);
1171+
let mut local_req_builder =
1172+
local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
1173+
1174+
// build headers
1175+
let mut headers = HeaderMap::new();
1176+
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1177+
headers.insert("Accept", HeaderValue::from_static("application/json"));
1178+
1179+
// build user agent
1180+
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1181+
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1182+
Err(e) => {
1183+
log::warn!("Failed to parse user agent header: {e}, falling back to default");
1184+
headers.insert(
1185+
reqwest::header::USER_AGENT,
1186+
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1187+
)
1188+
}
1189+
};
1190+
1191+
// build auth
1192+
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1193+
headers.insert(
1194+
"DD-API-KEY",
1195+
HeaderValue::from_str(local_key.key.as_str())
1196+
.expect("failed to parse DD-API-KEY header"),
1197+
);
1198+
};
1199+
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1200+
headers.insert(
1201+
"DD-APPLICATION-KEY",
1202+
HeaderValue::from_str(local_key.key.as_str())
1203+
.expect("failed to parse DD-APPLICATION-KEY header"),
1204+
);
1205+
};
1206+
1207+
// build body parameters
1208+
let output = Vec::new();
1209+
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1210+
if body.serialize(&mut ser).is_ok() {
1211+
if let Some(content_encoding) = headers.get("Content-Encoding") {
1212+
match content_encoding.to_str().unwrap_or_default() {
1213+
"gzip" => {
1214+
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1215+
let _ = enc.write_all(ser.into_inner().as_slice());
1216+
match enc.finish() {
1217+
Ok(buf) => {
1218+
local_req_builder = local_req_builder.body(buf);
1219+
}
1220+
Err(e) => return Err(datadog::Error::Io(e)),
1221+
}
1222+
}
1223+
"deflate" => {
1224+
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1225+
let _ = enc.write_all(ser.into_inner().as_slice());
1226+
match enc.finish() {
1227+
Ok(buf) => {
1228+
local_req_builder = local_req_builder.body(buf);
1229+
}
1230+
Err(e) => return Err(datadog::Error::Io(e)),
1231+
}
1232+
}
1233+
"zstd1" => {
1234+
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1235+
let _ = enc.write_all(ser.into_inner().as_slice());
1236+
match enc.finish() {
1237+
Ok(buf) => {
1238+
local_req_builder = local_req_builder.body(buf);
1239+
}
1240+
Err(e) => return Err(datadog::Error::Io(e)),
1241+
}
1242+
}
1243+
_ => {
1244+
local_req_builder = local_req_builder.body(ser.into_inner());
1245+
}
1246+
}
1247+
} else {
1248+
local_req_builder = local_req_builder.body(ser.into_inner());
1249+
}
1250+
}
1251+
1252+
local_req_builder = local_req_builder.headers(headers);
1253+
let local_req = local_req_builder.build()?;
1254+
log::debug!("request content: {:?}", local_req.body());
1255+
let local_resp = local_client.execute(local_req).await?;
1256+
1257+
let local_status = local_resp.status();
1258+
let local_content = local_resp.text().await?;
1259+
log::debug!("response content: {}", local_content);
1260+
1261+
if !local_status.is_client_error() && !local_status.is_server_error() {
1262+
match serde_json::from_str::<crate::datadogV2::model::UpdateRuleResponse>(
1263+
&local_content,
1264+
) {
1265+
Ok(e) => {
1266+
return Ok(datadog::ResponseContent {
1267+
status: local_status,
1268+
content: local_content,
1269+
entity: Some(e),
1270+
})
1271+
}
1272+
Err(e) => return Err(datadog::Error::Serde(e)),
1273+
};
1274+
} else {
1275+
let local_entity: Option<UpdateScorecardRuleError> =
1276+
serde_json::from_str(&local_content).ok();
1277+
let local_error = datadog::ResponseContent {
1278+
status: local_status,
1279+
content: local_content,
1280+
entity: local_entity,
1281+
};
1282+
Err(datadog::Error::ResponseError(local_error))
1283+
}
1284+
}
11111285
}

src/datadogV2/model/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,6 +2190,14 @@ pub mod model_create_rule_response;
21902190
pub use self::model_create_rule_response::CreateRuleResponse;
21912191
pub mod model_create_rule_response_data;
21922192
pub use self::model_create_rule_response_data::CreateRuleResponseData;
2193+
pub mod model_update_rule_request;
2194+
pub use self::model_update_rule_request::UpdateRuleRequest;
2195+
pub mod model_update_rule_request_data;
2196+
pub use self::model_update_rule_request_data::UpdateRuleRequestData;
2197+
pub mod model_update_rule_response;
2198+
pub use self::model_update_rule_response::UpdateRuleResponse;
2199+
pub mod model_update_rule_response_data;
2200+
pub use self::model_update_rule_response_data::UpdateRuleResponseData;
21932201
pub mod model_security_filters_response;
21942202
pub use self::model_security_filters_response::SecurityFiltersResponse;
21952203
pub mod model_security_filter;

0 commit comments

Comments
 (0)