diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 9bceb715496a..746ddbe0fcb3 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -16644,6 +16644,14 @@ components: required: - id type: object + DeploymentGateRulesResponse: + description: Response for a deployment gate rules. + properties: + data: + items: + $ref: '#/components/schemas/DeploymentRuleResponseData' + type: array + type: object DeploymentMetadata: description: Metadata object containing the publication creation information. properties: @@ -64391,6 +64399,50 @@ paths: If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' /api/v2/deployment_gates/{gate_id}/rules: + get: + description: Endpoint to get rules for a deployment gate. + operationId: GetDeploymentGateRules + parameters: + - description: The ID of the deployment gate. + in: path + name: gate_id + required: true + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/DeploymentGateRulesResponse' + description: OK + '400': + $ref: '#/components/responses/HTTPCDGatesBadRequestResponse' + '401': + $ref: '#/components/responses/UnauthorizedResponse' + '403': + $ref: '#/components/responses/ForbiddenResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + '500': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPCIAppErrors' + description: Internal Server Error + security: + - apiKeyAuth: [] + appKeyAuth: [] + summary: Get rules for a deployment gate + tags: + - Deployment Gates + x-permission: + operator: OR + permissions: + - deployment_gates_read + x-unstable: '**Note**: This endpoint is in preview and may be subject to change. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' post: description: Endpoint to create a deployment rule. A gate for the rule must already exist. diff --git a/examples/v2/deployment-gates/GetDeploymentGateRules.ts b/examples/v2/deployment-gates/GetDeploymentGateRules.ts new file mode 100644 index 000000000000..54a7897b862e --- /dev/null +++ b/examples/v2/deployment-gates/GetDeploymentGateRules.ts @@ -0,0 +1,25 @@ +/** + * Get rules for a deployment gate returns "OK" response + */ + +import { client, v2 } from "@datadog/datadog-api-client"; + +const configuration = client.createConfiguration(); +configuration.unstableOperations["v2.getDeploymentGateRules"] = true; +const apiInstance = new v2.DeploymentGatesApi(configuration); + +// there is a valid "deployment_gate" in the system +const DEPLOYMENT_GATE_DATA_ID = process.env.DEPLOYMENT_GATE_DATA_ID as string; + +const params: v2.DeploymentGatesApiGetDeploymentGateRulesRequest = { + gateId: DEPLOYMENT_GATE_DATA_ID, +}; + +apiInstance + .getDeploymentGateRules(params) + .then((data: v2.DeploymentGateRulesResponse) => { + console.log( + "API called successfully. Returned data: " + JSON.stringify(data) + ); + }) + .catch((error: any) => console.error(error)); diff --git a/features/support/scenarios_model_mapping.ts b/features/support/scenarios_model_mapping.ts index 7bfe6adf50be..a73703759533 100644 --- a/features/support/scenarios_model_mapping.ts +++ b/features/support/scenarios_model_mapping.ts @@ -5320,6 +5320,13 @@ export const ScenariosModelMappings: {[key: string]: {[key: string]: any}} = { }, "operationResponseType": "DeploymentGateResponse", }, + "v2.GetDeploymentGateRules": { + "gateId": { + "type": "string", + "format": "", + }, + "operationResponseType": "DeploymentGateRulesResponse", + }, "v2.CreateDeploymentRule": { "gateId": { "type": "string", diff --git a/features/v2/deployment_gates.feature b/features/v2/deployment_gates.feature index e4023c5650b1..cb0c5a1262d6 100644 --- a/features/v2/deployment_gates.feature +++ b/features/v2/deployment_gates.feature @@ -207,6 +207,23 @@ Feature: Deployment Gates When the request is sent Then the response status is 200 OK + @generated @skip @team:DataDog/ci-app-backend + Scenario: Get rules for a deployment gate returns "Bad request." response + Given operation "GetDeploymentGateRules" enabled + And new "GetDeploymentGateRules" request + And request contains "gate_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad request. + + @team:DataDog/ci-app-backend + Scenario: Get rules for a deployment gate returns "OK" response + Given there is a valid "deployment_gate" in the system + And operation "GetDeploymentGateRules" enabled + And new "GetDeploymentGateRules" request + And request contains "gate_id" parameter from "deployment_gate.data.id" + When the request is sent + Then the response status is 200 OK + @team:DataDog/ci-app-backend Scenario: Update deployment gate returns "Bad Request" response Given operation "UpdateDeploymentGate" enabled diff --git a/features/v2/undo.json b/features/v2/undo.json index 3799e64e630d..619834eec839 100644 --- a/features/v2/undo.json +++ b/features/v2/undo.json @@ -1323,6 +1323,12 @@ "type": "unsafe" } }, + "GetDeploymentGateRules": { + "tag": "Deployment Gates", + "undo": { + "type": "safe" + } + }, "CreateDeploymentRule": { "tag": "Deployment Gates", "undo": { diff --git a/packages/datadog-api-client-common/configuration.ts b/packages/datadog-api-client-common/configuration.ts index 89150931a146..5627e1d4764c 100644 --- a/packages/datadog-api-client-common/configuration.ts +++ b/packages/datadog-api-client-common/configuration.ts @@ -273,6 +273,7 @@ export function createConfiguration( "v2.deleteDeploymentGate": false, "v2.deleteDeploymentRule": false, "v2.getDeploymentGate": false, + "v2.getDeploymentGateRules": false, "v2.getDeploymentRule": false, "v2.updateDeploymentGate": false, "v2.updateDeploymentRule": false, diff --git a/packages/datadog-api-client-v2/apis/DeploymentGatesApi.ts b/packages/datadog-api-client-v2/apis/DeploymentGatesApi.ts index a248d90a62f9..c15441dbb7e0 100644 --- a/packages/datadog-api-client-v2/apis/DeploymentGatesApi.ts +++ b/packages/datadog-api-client-v2/apis/DeploymentGatesApi.ts @@ -20,6 +20,7 @@ import { APIErrorResponse } from "../models/APIErrorResponse"; import { CreateDeploymentGateParams } from "../models/CreateDeploymentGateParams"; import { CreateDeploymentRuleParams } from "../models/CreateDeploymentRuleParams"; import { DeploymentGateResponse } from "../models/DeploymentGateResponse"; +import { DeploymentGateRulesResponse } from "../models/DeploymentGateRulesResponse"; import { DeploymentRuleResponse } from "../models/DeploymentRuleResponse"; import { HTTPCDGatesBadRequestResponse } from "../models/HTTPCDGatesBadRequestResponse"; import { HTTPCDGatesNotFoundResponse } from "../models/HTTPCDGatesNotFoundResponse"; @@ -249,6 +250,46 @@ export class DeploymentGatesApiRequestFactory extends BaseAPIRequestFactory { return requestContext; } + public async getDeploymentGateRules( + gateId: string, + _options?: Configuration + ): Promise { + const _config = _options || this.configuration; + + logger.warn("Using unstable operation 'getDeploymentGateRules'"); + if (!_config.unstableOperations["v2.getDeploymentGateRules"]) { + throw new Error( + "Unstable operation 'getDeploymentGateRules' is disabled" + ); + } + + // verify required parameter 'gateId' is not null or undefined + if (gateId === null || gateId === undefined) { + throw new RequiredError("gateId", "getDeploymentGateRules"); + } + + // Path Params + const localVarPath = "/api/v2/deployment_gates/{gate_id}/rules".replace( + "{gate_id}", + encodeURIComponent(String(gateId)) + ); + + // Make Request Context + const requestContext = _config + .getServer("v2.DeploymentGatesApi.getDeploymentGateRules") + .makeRequestContext(localVarPath, HttpMethod.GET); + requestContext.setHeaderParam("Accept", "application/json"); + requestContext.setHttpConfig(_config.httpConfig); + + // Apply auth methods + applySecurityAuthentication(_config, requestContext, [ + "apiKeyAuth", + "appKeyAuth", + ]); + + return requestContext; + } + public async getDeploymentRule( gateId: string, id: string, @@ -981,6 +1022,111 @@ export class DeploymentGatesApiResponseProcessor { ); } + /** + * Unwraps the actual response sent by the server from the response context and deserializes the response content + * to the expected objects + * + * @params response Response returned by the server for a request to getDeploymentGateRules + * @throws ApiException if the response code was not in [200, 299] + */ + public async getDeploymentGateRules( + response: ResponseContext + ): Promise { + const contentType = ObjectSerializer.normalizeMediaType( + response.headers["content-type"] + ); + if (response.httpStatusCode === 200) { + const body: DeploymentGateRulesResponse = ObjectSerializer.deserialize( + ObjectSerializer.parse(await response.body.text(), contentType), + "DeploymentGateRulesResponse" + ) as DeploymentGateRulesResponse; + return body; + } + if (response.httpStatusCode === 400) { + const bodyText = ObjectSerializer.parse( + await response.body.text(), + contentType + ); + let body: HTTPCDGatesBadRequestResponse; + try { + body = ObjectSerializer.deserialize( + bodyText, + "HTTPCDGatesBadRequestResponse" + ) as HTTPCDGatesBadRequestResponse; + } catch (error) { + logger.debug(`Got error deserializing error: ${error}`); + throw new ApiException( + response.httpStatusCode, + bodyText + ); + } + throw new ApiException( + response.httpStatusCode, + body + ); + } + if ( + response.httpStatusCode === 401 || + response.httpStatusCode === 403 || + response.httpStatusCode === 429 + ) { + const bodyText = ObjectSerializer.parse( + await response.body.text(), + contentType + ); + let body: APIErrorResponse; + try { + body = ObjectSerializer.deserialize( + bodyText, + "APIErrorResponse" + ) as APIErrorResponse; + } catch (error) { + logger.debug(`Got error deserializing error: ${error}`); + throw new ApiException( + response.httpStatusCode, + bodyText + ); + } + throw new ApiException(response.httpStatusCode, body); + } + if (response.httpStatusCode === 500) { + const bodyText = ObjectSerializer.parse( + await response.body.text(), + contentType + ); + let body: HTTPCIAppErrors; + try { + body = ObjectSerializer.deserialize( + bodyText, + "HTTPCIAppErrors" + ) as HTTPCIAppErrors; + } catch (error) { + logger.debug(`Got error deserializing error: ${error}`); + throw new ApiException( + response.httpStatusCode, + bodyText + ); + } + throw new ApiException(response.httpStatusCode, body); + } + + // Work around for missing responses in specification, e.g. for petstore.yaml + if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { + const body: DeploymentGateRulesResponse = ObjectSerializer.deserialize( + ObjectSerializer.parse(await response.body.text(), contentType), + "DeploymentGateRulesResponse", + "" + ) as DeploymentGateRulesResponse; + return body; + } + + const body = (await response.body.text()) || ""; + throw new ApiException( + response.httpStatusCode, + 'Unknown API Status Code!\nBody: "' + body + '"' + ); + } + /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects @@ -1414,6 +1560,14 @@ export interface DeploymentGatesApiGetDeploymentGateRequest { id: string; } +export interface DeploymentGatesApiGetDeploymentGateRulesRequest { + /** + * The ID of the deployment gate. + * @type string + */ + gateId: string; +} + export interface DeploymentGatesApiGetDeploymentRuleRequest { /** * The ID of the deployment gate. @@ -1580,6 +1734,27 @@ export class DeploymentGatesApi { }); } + /** + * Endpoint to get rules for a deployment gate. + * @param param The request object + */ + public getDeploymentGateRules( + param: DeploymentGatesApiGetDeploymentGateRulesRequest, + options?: Configuration + ): Promise { + const requestContextPromise = this.requestFactory.getDeploymentGateRules( + param.gateId, + options + ); + return requestContextPromise.then((requestContext) => { + return this.configuration.httpApi + .send(requestContext) + .then((responseContext) => { + return this.responseProcessor.getDeploymentGateRules(responseContext); + }); + }); + } + /** * Endpoint to get a deployment rule. * @param param The request object diff --git a/packages/datadog-api-client-v2/index.ts b/packages/datadog-api-client-v2/index.ts index 00bee8317f47..121f9c9ce933 100644 --- a/packages/datadog-api-client-v2/index.ts +++ b/packages/datadog-api-client-v2/index.ts @@ -300,6 +300,7 @@ export { DeploymentGatesApiDeleteDeploymentGateRequest, DeploymentGatesApiDeleteDeploymentRuleRequest, DeploymentGatesApiGetDeploymentGateRequest, + DeploymentGatesApiGetDeploymentGateRulesRequest, DeploymentGatesApiGetDeploymentRuleRequest, DeploymentGatesApiUpdateDeploymentGateRequest, DeploymentGatesApiUpdateDeploymentRuleRequest, @@ -1875,6 +1876,7 @@ export { DeploymentGateResponseData } from "./models/DeploymentGateResponseData" export { DeploymentGateResponseDataAttributes } from "./models/DeploymentGateResponseDataAttributes"; export { DeploymentGateResponseDataAttributesCreatedBy } from "./models/DeploymentGateResponseDataAttributesCreatedBy"; export { DeploymentGateResponseDataAttributesUpdatedBy } from "./models/DeploymentGateResponseDataAttributesUpdatedBy"; +export { DeploymentGateRulesResponse } from "./models/DeploymentGateRulesResponse"; export { DeploymentMetadata } from "./models/DeploymentMetadata"; export { DeploymentRelationship } from "./models/DeploymentRelationship"; export { DeploymentRelationshipData } from "./models/DeploymentRelationshipData"; diff --git a/packages/datadog-api-client-v2/models/DeploymentGateRulesResponse.ts b/packages/datadog-api-client-v2/models/DeploymentGateRulesResponse.ts new file mode 100644 index 000000000000..08914d036998 --- /dev/null +++ b/packages/datadog-api-client-v2/models/DeploymentGateRulesResponse.ts @@ -0,0 +1,50 @@ +/** + * 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 2020-Present Datadog, Inc. + */ +import { DeploymentRuleResponseData } from "./DeploymentRuleResponseData"; + +import { AttributeTypeMap } from "../../datadog-api-client-common/util"; + +/** + * Response for a deployment gate rules. + */ +export class DeploymentGateRulesResponse { + "data"?: Array; + + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + "additionalProperties"?: { [key: string]: any }; + + /** + * @ignore + */ + "_unparsed"?: boolean; + + /** + * @ignore + */ + static readonly attributeTypeMap: AttributeTypeMap = { + data: { + baseName: "data", + type: "Array", + }, + additionalProperties: { + baseName: "additionalProperties", + type: "{ [key: string]: any; }", + }, + }; + + /** + * @ignore + */ + static getAttributeTypeMap(): AttributeTypeMap { + return DeploymentGateRulesResponse.attributeTypeMap; + } + + public constructor() {} +} diff --git a/packages/datadog-api-client-v2/models/ObjectSerializer.ts b/packages/datadog-api-client-v2/models/ObjectSerializer.ts index df5aaf40e489..23dbd1a64e84 100644 --- a/packages/datadog-api-client-v2/models/ObjectSerializer.ts +++ b/packages/datadog-api-client-v2/models/ObjectSerializer.ts @@ -730,6 +730,7 @@ import { DeploymentGateResponseData } from "./DeploymentGateResponseData"; import { DeploymentGateResponseDataAttributes } from "./DeploymentGateResponseDataAttributes"; import { DeploymentGateResponseDataAttributesCreatedBy } from "./DeploymentGateResponseDataAttributesCreatedBy"; import { DeploymentGateResponseDataAttributesUpdatedBy } from "./DeploymentGateResponseDataAttributesUpdatedBy"; +import { DeploymentGateRulesResponse } from "./DeploymentGateRulesResponse"; import { DeploymentMetadata } from "./DeploymentMetadata"; import { DeploymentRelationship } from "./DeploymentRelationship"; import { DeploymentRelationshipData } from "./DeploymentRelationshipData"; @@ -5172,6 +5173,7 @@ const typeMap: { [index: string]: any } = { DeploymentGateResponseDataAttributesCreatedBy, DeploymentGateResponseDataAttributesUpdatedBy: DeploymentGateResponseDataAttributesUpdatedBy, + DeploymentGateRulesResponse: DeploymentGateRulesResponse, DeploymentMetadata: DeploymentMetadata, DeploymentRelationship: DeploymentRelationship, DeploymentRelationshipData: DeploymentRelationshipData,