Skip to content

Commit d49202c

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add new endpoint for listing rules for a gate (#1041)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 375c663 commit d49202c

14 files changed

+785
-14
lines changed

.generator/schemas/v2/openapi.yaml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17075,6 +17075,12 @@ components:
1707517075
required:
1707617076
- id
1707717077
type: object
17078+
DeploymentGateRulesResponse:
17079+
description: Response for a deployment gate rules.
17080+
properties:
17081+
data:
17082+
$ref: '#/components/schemas/ListDeploymentRuleResponseData'
17083+
type: object
1707817084
DeploymentMetadata:
1707917085
description: Metadata object containing the publication creation information.
1708017086
properties:
@@ -30199,6 +30205,37 @@ components:
3019930205
type: string
3020030206
x-enum-varnames:
3020130207
- LIST_CONNECTIONS_RESPONSE
30208+
ListDeploymentRuleResponseData:
30209+
description: Data for a list of deployment rules.
30210+
properties:
30211+
attributes:
30212+
$ref: '#/components/schemas/ListDeploymentRulesResponseDataAttributes'
30213+
id:
30214+
description: Unique identifier of the deployment rule.
30215+
example: 1111-2222-3333-4444-555566667777
30216+
type: string
30217+
type:
30218+
$ref: '#/components/schemas/ListDeploymentRulesDataType'
30219+
required:
30220+
- type
30221+
- attributes
30222+
- id
30223+
type: object
30224+
ListDeploymentRulesDataType:
30225+
description: List deployment rule resource type.
30226+
enum:
30227+
- list_deployment_rules
30228+
example: list_deployment_rules
30229+
type: string
30230+
x-enum-varnames:
30231+
- LIST_DEPLOYMENT_RULES
30232+
ListDeploymentRulesResponseDataAttributes:
30233+
properties:
30234+
rules:
30235+
items:
30236+
$ref: '#/components/schemas/DeploymentRuleResponseDataAttributes'
30237+
type: array
30238+
type: object
3020230239
ListDevicesResponse:
3020330240
description: List devices response.
3020430241
properties:
@@ -66236,6 +66273,50 @@ paths:
6623666273

6623766274
If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).'
6623866275
/api/v2/deployment_gates/{gate_id}/rules:
66276+
get:
66277+
description: Endpoint to get rules for a deployment gate.
66278+
operationId: GetDeploymentGateRules
66279+
parameters:
66280+
- description: The ID of the deployment gate.
66281+
in: path
66282+
name: gate_id
66283+
required: true
66284+
schema:
66285+
type: string
66286+
responses:
66287+
'200':
66288+
content:
66289+
application/json:
66290+
schema:
66291+
$ref: '#/components/schemas/DeploymentGateRulesResponse'
66292+
description: OK
66293+
'400':
66294+
$ref: '#/components/responses/HTTPCDGatesBadRequestResponse'
66295+
'401':
66296+
$ref: '#/components/responses/UnauthorizedResponse'
66297+
'403':
66298+
$ref: '#/components/responses/ForbiddenResponse'
66299+
'429':
66300+
$ref: '#/components/responses/TooManyRequestsResponse'
66301+
'500':
66302+
content:
66303+
application/json:
66304+
schema:
66305+
$ref: '#/components/schemas/HTTPCIAppErrors'
66306+
description: Internal Server Error
66307+
security:
66308+
- apiKeyAuth: []
66309+
appKeyAuth: []
66310+
summary: Get rules for a deployment gate
66311+
tags:
66312+
- Deployment Gates
66313+
x-permission:
66314+
operator: OR
66315+
permissions:
66316+
- deployment_gates_read
66317+
x-unstable: '**Note**: This endpoint is in preview and may be subject to change.
66318+
66319+
If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).'
6623966320
post:
6624066321
description: Endpoint to create a deployment rule. A gate for the rule must
6624166322
already exist.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Get rules for a deployment gate returns "OK" response
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV2::api_deployment_gates::DeploymentGatesAPI;
4+
5+
#[tokio::main]
6+
async fn main() {
7+
// there is a valid "deployment_gate" in the system
8+
let deployment_gate_data_id = std::env::var("DEPLOYMENT_GATE_DATA_ID").unwrap();
9+
let mut configuration = datadog::Configuration::new();
10+
configuration.set_unstable_operation_enabled("v2.GetDeploymentGateRules", true);
11+
let api = DeploymentGatesAPI::with_config(configuration);
12+
let resp = api
13+
.get_deployment_gate_rules(deployment_gate_data_id.clone())
14+
.await;
15+
if let Ok(value) = resp {
16+
println!("{:#?}", value);
17+
} else {
18+
println!("{:#?}", resp.unwrap_err());
19+
}
20+
}

src/datadog/configuration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ impl Default for Configuration {
183183
("v2.delete_deployment_gate".to_owned(), false),
184184
("v2.delete_deployment_rule".to_owned(), false),
185185
("v2.get_deployment_gate".to_owned(), false),
186+
("v2.get_deployment_gate_rules".to_owned(), false),
186187
("v2.get_deployment_rule".to_owned(), false),
187188
("v2.update_deployment_gate".to_owned(), false),
188189
("v2.update_deployment_rule".to_owned(), false),

src/datadogV2/api/api_deployment_gates.rs

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ pub enum GetDeploymentGateError {
6464
UnknownValue(serde_json::Value),
6565
}
6666

67+
/// GetDeploymentGateRulesError is a struct for typed errors of method [`DeploymentGatesAPI::get_deployment_gate_rules`]
68+
#[derive(Debug, Clone, Serialize, Deserialize)]
69+
#[serde(untagged)]
70+
pub enum GetDeploymentGateRulesError {
71+
HTTPCDGatesBadRequestResponse(crate::datadogV2::model::HTTPCDGatesBadRequestResponse),
72+
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
73+
HTTPCIAppErrors(crate::datadogV2::model::HTTPCIAppErrors),
74+
UnknownValue(serde_json::Value),
75+
}
76+
6777
/// GetDeploymentRuleError is a struct for typed errors of method [`DeploymentGatesAPI::get_deployment_rule`]
6878
#[derive(Debug, Clone, Serialize, Deserialize)]
6979
#[serde(untagged)]
@@ -807,6 +817,123 @@ impl DeploymentGatesAPI {
807817
}
808818
}
809819

820+
/// Endpoint to get rules for a deployment gate.
821+
pub async fn get_deployment_gate_rules(
822+
&self,
823+
gate_id: String,
824+
) -> Result<
825+
crate::datadogV2::model::DeploymentGateRulesResponse,
826+
datadog::Error<GetDeploymentGateRulesError>,
827+
> {
828+
match self.get_deployment_gate_rules_with_http_info(gate_id).await {
829+
Ok(response_content) => {
830+
if let Some(e) = response_content.entity {
831+
Ok(e)
832+
} else {
833+
Err(datadog::Error::Serde(serde::de::Error::custom(
834+
"response content was None",
835+
)))
836+
}
837+
}
838+
Err(err) => Err(err),
839+
}
840+
}
841+
842+
/// Endpoint to get rules for a deployment gate.
843+
pub async fn get_deployment_gate_rules_with_http_info(
844+
&self,
845+
gate_id: String,
846+
) -> Result<
847+
datadog::ResponseContent<crate::datadogV2::model::DeploymentGateRulesResponse>,
848+
datadog::Error<GetDeploymentGateRulesError>,
849+
> {
850+
let local_configuration = &self.config;
851+
let operation_id = "v2.get_deployment_gate_rules";
852+
if local_configuration.is_unstable_operation_enabled(operation_id) {
853+
warn!("Using unstable operation {operation_id}");
854+
} else {
855+
let local_error = datadog::UnstableOperationDisabledError {
856+
msg: "Operation 'v2.get_deployment_gate_rules' is not enabled".to_string(),
857+
};
858+
return Err(datadog::Error::UnstableOperationDisabledError(local_error));
859+
}
860+
861+
let local_client = &self.client;
862+
863+
let local_uri_str = format!(
864+
"{}/api/v2/deployment_gates/{gate_id}/rules",
865+
local_configuration.get_operation_host(operation_id),
866+
gate_id = datadog::urlencode(gate_id)
867+
);
868+
let mut local_req_builder =
869+
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
870+
871+
// build headers
872+
let mut headers = HeaderMap::new();
873+
headers.insert("Accept", HeaderValue::from_static("application/json"));
874+
875+
// build user agent
876+
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
877+
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
878+
Err(e) => {
879+
log::warn!("Failed to parse user agent header: {e}, falling back to default");
880+
headers.insert(
881+
reqwest::header::USER_AGENT,
882+
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
883+
)
884+
}
885+
};
886+
887+
// build auth
888+
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
889+
headers.insert(
890+
"DD-API-KEY",
891+
HeaderValue::from_str(local_key.key.as_str())
892+
.expect("failed to parse DD-API-KEY header"),
893+
);
894+
};
895+
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
896+
headers.insert(
897+
"DD-APPLICATION-KEY",
898+
HeaderValue::from_str(local_key.key.as_str())
899+
.expect("failed to parse DD-APPLICATION-KEY header"),
900+
);
901+
};
902+
903+
local_req_builder = local_req_builder.headers(headers);
904+
let local_req = local_req_builder.build()?;
905+
log::debug!("request content: {:?}", local_req.body());
906+
let local_resp = local_client.execute(local_req).await?;
907+
908+
let local_status = local_resp.status();
909+
let local_content = local_resp.text().await?;
910+
log::debug!("response content: {}", local_content);
911+
912+
if !local_status.is_client_error() && !local_status.is_server_error() {
913+
match serde_json::from_str::<crate::datadogV2::model::DeploymentGateRulesResponse>(
914+
&local_content,
915+
) {
916+
Ok(e) => {
917+
return Ok(datadog::ResponseContent {
918+
status: local_status,
919+
content: local_content,
920+
entity: Some(e),
921+
})
922+
}
923+
Err(e) => return Err(datadog::Error::Serde(e)),
924+
};
925+
} else {
926+
let local_entity: Option<GetDeploymentGateRulesError> =
927+
serde_json::from_str(&local_content).ok();
928+
let local_error = datadog::ResponseContent {
929+
status: local_status,
930+
content: local_content,
931+
entity: local_entity,
932+
};
933+
Err(datadog::Error::ResponseError(local_error))
934+
}
935+
}
936+
810937
/// Endpoint to get a deployment rule.
811938
pub async fn get_deployment_rule(
812939
&self,

src/datadogV2/model/mod.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,32 +2210,40 @@ pub mod model_deployment_gate_response_data_attributes_updated_by;
22102210
pub use self::model_deployment_gate_response_data_attributes_updated_by::DeploymentGateResponseDataAttributesUpdatedBy;
22112211
pub mod model_httpcd_gates_bad_request_response;
22122212
pub use self::model_httpcd_gates_bad_request_response::HTTPCDGatesBadRequestResponse;
2213-
pub mod model_create_deployment_rule_params;
2214-
pub use self::model_create_deployment_rule_params::CreateDeploymentRuleParams;
2215-
pub mod model_create_deployment_rule_params_data;
2216-
pub use self::model_create_deployment_rule_params_data::CreateDeploymentRuleParamsData;
2217-
pub mod model_create_deployment_rule_params_data_attributes;
2218-
pub use self::model_create_deployment_rule_params_data_attributes::CreateDeploymentRuleParamsDataAttributes;
2213+
pub mod model_deployment_gate_rules_response;
2214+
pub use self::model_deployment_gate_rules_response::DeploymentGateRulesResponse;
2215+
pub mod model_list_deployment_rule_response_data;
2216+
pub use self::model_list_deployment_rule_response_data::ListDeploymentRuleResponseData;
2217+
pub mod model_list_deployment_rules_response_data_attributes;
2218+
pub use self::model_list_deployment_rules_response_data_attributes::ListDeploymentRulesResponseDataAttributes;
2219+
pub mod model_deployment_rule_response_data_attributes;
2220+
pub use self::model_deployment_rule_response_data_attributes::DeploymentRuleResponseDataAttributes;
2221+
pub mod model_deployment_rule_response_data_attributes_created_by;
2222+
pub use self::model_deployment_rule_response_data_attributes_created_by::DeploymentRuleResponseDataAttributesCreatedBy;
22192223
pub mod model_deployment_rule_options_faulty_deployment_detection;
22202224
pub use self::model_deployment_rule_options_faulty_deployment_detection::DeploymentRuleOptionsFaultyDeploymentDetection;
22212225
pub mod model_deployment_rule_options_monitor;
22222226
pub use self::model_deployment_rule_options_monitor::DeploymentRuleOptionsMonitor;
22232227
pub mod model_deployment_rules_options;
22242228
pub use self::model_deployment_rules_options::DeploymentRulesOptions;
2229+
pub mod model_deployment_rule_response_data_attributes_type;
2230+
pub use self::model_deployment_rule_response_data_attributes_type::DeploymentRuleResponseDataAttributesType;
2231+
pub mod model_deployment_rule_response_data_attributes_updated_by;
2232+
pub use self::model_deployment_rule_response_data_attributes_updated_by::DeploymentRuleResponseDataAttributesUpdatedBy;
2233+
pub mod model_list_deployment_rules_data_type;
2234+
pub use self::model_list_deployment_rules_data_type::ListDeploymentRulesDataType;
2235+
pub mod model_create_deployment_rule_params;
2236+
pub use self::model_create_deployment_rule_params::CreateDeploymentRuleParams;
2237+
pub mod model_create_deployment_rule_params_data;
2238+
pub use self::model_create_deployment_rule_params_data::CreateDeploymentRuleParamsData;
2239+
pub mod model_create_deployment_rule_params_data_attributes;
2240+
pub use self::model_create_deployment_rule_params_data_attributes::CreateDeploymentRuleParamsDataAttributes;
22252241
pub mod model_deployment_rule_data_type;
22262242
pub use self::model_deployment_rule_data_type::DeploymentRuleDataType;
22272243
pub mod model_deployment_rule_response;
22282244
pub use self::model_deployment_rule_response::DeploymentRuleResponse;
22292245
pub mod model_deployment_rule_response_data;
22302246
pub use self::model_deployment_rule_response_data::DeploymentRuleResponseData;
2231-
pub mod model_deployment_rule_response_data_attributes;
2232-
pub use self::model_deployment_rule_response_data_attributes::DeploymentRuleResponseDataAttributes;
2233-
pub mod model_deployment_rule_response_data_attributes_created_by;
2234-
pub use self::model_deployment_rule_response_data_attributes_created_by::DeploymentRuleResponseDataAttributesCreatedBy;
2235-
pub mod model_deployment_rule_response_data_attributes_type;
2236-
pub use self::model_deployment_rule_response_data_attributes_type::DeploymentRuleResponseDataAttributesType;
2237-
pub mod model_deployment_rule_response_data_attributes_updated_by;
2238-
pub use self::model_deployment_rule_response_data_attributes_updated_by::DeploymentRuleResponseDataAttributesUpdatedBy;
22392247
pub mod model_httpcd_gates_not_found_response;
22402248
pub use self::model_httpcd_gates_not_found_response::HTTPCDGatesNotFoundResponse;
22412249
pub mod model_httpcd_rules_not_found_response;

0 commit comments

Comments
 (0)