diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index fd30acae5..74d20bb65 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -21314,6 +21314,125 @@ components: - IDENTITY - GZIP - DEFLATE + ControlNotificationEventSetting: + description: The notification settings for a single event type on a control. + properties: + enabled: + description: Whether notifications are enabled for this event type. + example: true + type: boolean + event_type: + description: The event type the notification settings apply to, such as `new_detection`. + example: "new_detection" + type: string + targets: + $ref: "#/components/schemas/ControlNotificationTargetArray" + required: + - event_type + - enabled + - targets + type: object + ControlNotificationEventSettingsArray: + description: The notification settings for each supported event type on the control. + items: + $ref: "#/components/schemas/ControlNotificationEventSetting" + type: array + ControlNotificationSettingsAttributes: + description: The attributes of a governance control's notification settings. + properties: + event_settings: + $ref: "#/components/schemas/ControlNotificationEventSettingsArray" + required: + - event_settings + type: object + ControlNotificationSettingsData: + description: A control notification settings resource. + properties: + attributes: + $ref: "#/components/schemas/ControlNotificationSettingsAttributes" + id: + description: The detection type the notification settings apply to. + example: "unused_api_keys" + type: string + type: + $ref: "#/components/schemas/ControlNotificationSettingsResourceType" + required: + - id + - type + - attributes + type: object + ControlNotificationSettingsResourceType: + description: Control notification settings resource type. + enum: + - control_notification_settings + example: "control_notification_settings" + type: string + x-enum-varnames: + - CONTROL_NOTIFICATION_SETTINGS + ControlNotificationSettingsResponse: + description: The notification settings for a governance control. + properties: + data: + $ref: "#/components/schemas/ControlNotificationSettingsData" + required: + - data + type: object + ControlNotificationSettingsUpdateAttributes: + description: The attributes of a governance control's notification settings that can be updated. + properties: + event_settings: + $ref: "#/components/schemas/ControlNotificationEventSettingsArray" + type: object + ControlNotificationSettingsUpdateData: + description: The data of a control notification settings update request. + properties: + attributes: + $ref: "#/components/schemas/ControlNotificationSettingsUpdateAttributes" + type: + $ref: "#/components/schemas/ControlNotificationSettingsResourceType" + required: + - type + type: object + ControlNotificationSettingsUpdateRequest: + description: A request to update the notification settings for a governance control. + properties: + data: + $ref: "#/components/schemas/ControlNotificationSettingsUpdateData" + required: + - data + type: object + ControlNotificationTarget: + description: A destination that receives notifications for an event type. + properties: + handle: + description: The destination handle, such as an email address, Slack channel, or user handle. + example: "#governance-alerts" + type: string + type: + $ref: "#/components/schemas/ControlNotificationTargetType" + required: + - type + - handle + type: object + ControlNotificationTargetArray: + description: The destinations that receive notifications for an event type. + items: + $ref: "#/components/schemas/ControlNotificationTarget" + type: array + ControlNotificationTargetType: + description: The type of notification destination. + enum: + - email + - slack + - at_mention + - case + example: "slack" + type: string + x-enum-varnames: + - EMAIL + - SLACK + - AT_MENTION + - CASE ConvertJobResultsToSignalsAttributes: description: Attributes for converting historical job results to signals. properties: @@ -41859,6 +41978,58 @@ components: - impact_hint - status type: object + GovernanceConfigAttributes: + description: The attributes of a Governance Console configuration. + properties: + assignment_notifications_enabled: + description: Whether notifications are sent to users when detections are assigned to them. + example: true + type: boolean + enabled: + description: Whether the Governance Console is enabled for the organization. + example: true + type: boolean + usage_attribution_configured: + description: Whether usage attribution is configured for the organization. + example: true + type: boolean + required: + - enabled + - assignment_notifications_enabled + - usage_attribution_configured + type: object + GovernanceConfigData: + description: A Governance Console configuration resource. + properties: + attributes: + $ref: "#/components/schemas/GovernanceConfigAttributes" + id: + description: The unique identifier of the organization the Governance Console configuration applies to. + example: "11111111-2222-3333-4444-555555555555" + type: string + type: + $ref: "#/components/schemas/GovernanceConsoleConfigResourceType" + required: + - id + - type + - attributes + type: object + GovernanceConfigResponse: + description: The Governance Console configuration for an organization. + properties: + data: + $ref: "#/components/schemas/GovernanceConfigData" + required: + - data + type: object + GovernanceConsoleConfigResourceType: + description: Governance console config resource type. + enum: + - governance_console_config + example: "governance_console_config" + type: string + x-enum-varnames: + - GOVERNANCE_CONSOLE_CONFIG GovernanceControlAttributes: description: The attributes of a governance control. properties: @@ -42032,6 +42203,211 @@ components: - type - attributes type: object + GovernanceControlDetectionAssignmentSource: + description: How the detection's current assignment was determined. Possible values are `auto_resolved`, `manual`, `reassigned`, and `cleared`. + enum: + - auto_resolved + - manual + - reassigned + - cleared + example: "manual" + type: string + x-enum-varnames: + - AUTO_RESOLVED + - MANUAL + - REASSIGNED + - CLEARED + GovernanceControlDetectionAttributes: + description: The attributes of a governance control detection. + properties: + assigned_team: + description: The identifier of the team the detection is assigned to, if any. + example: "platform-security" + type: string + assigned_to: + description: The identifier of the user the detection is assigned to, if any. + example: "11111111-2222-3333-4444-555555555555" + type: string + assignment_source: + $ref: "#/components/schemas/GovernanceControlDetectionAssignmentSource" + control_id: + description: The unique identifier of the control that produced this detection. + example: "0d4e6f8a-1b2c-3d4e-5f6a-7b8c9d0e1f2a" + type: string + created_at: + description: The date and time when the detection was created. + example: "2024-03-01T12:00:00Z" + format: date-time + type: string + detection_type: + description: The type of detection, which determines what condition was detected. + example: "unused_api_keys" + type: string + display_name: + description: The human-readable name of the detected resource. + example: "CI Deploy Key" + type: string + exception_at: + description: The date and time when the detection was marked as an exception, if applicable. + example: "2024-03-05T09:00:00Z" + format: date-time + type: string + exception_by: + description: The identifier of the user who marked the detection as an exception, if applicable. + example: "11111111-2222-3333-4444-555555555555" + type: string + metadata: + description: Free-form metadata associated with the detection. + example: + region: "us-east-1" + mitigate_after: + description: The date and time after which the detection is scheduled to be mitigated, if applicable. + example: "2024-03-15T00:00:00Z" + format: date-time + type: string + mitigated_at: + description: The date and time when the detection was mitigated, if applicable. + example: "2024-03-10T15:30:00Z" + format: date-time + type: string + priority: + description: The priority of the detection, if set. + example: 1 + format: int64 + type: integer + resource_id: + description: The identifier of the resource the detection applies to. + example: "api-key-12345" + type: string + resource_url: + description: A link to the detected resource in Datadog. + example: "/organization-settings/api-keys/api-key-12345" + type: string + state: + $ref: "#/components/schemas/GovernanceControlDetectionState" + required: + - state + - control_id + - resource_id + - resource_url + - detection_type + - display_name + - created_at + - assignment_source + - priority + type: object + GovernanceControlDetectionData: + description: A governance control detection resource. + properties: + attributes: + $ref: "#/components/schemas/GovernanceControlDetectionAttributes" + id: + description: The unique identifier of the detection. + example: "3f9b2c1a-8d4e-4a6b-9c2f-1e7d5a0b3c4d" + type: string + type: + $ref: "#/components/schemas/GovernanceControlDetectionResourceType" + required: + - id + - type + - attributes + type: object + GovernanceControlDetectionResourceType: + description: Governance control detection resource type. + enum: + - governance_control_detection + example: "governance_control_detection" + type: string + x-enum-varnames: + - GOVERNANCE_CONTROL_DETECTION + GovernanceControlDetectionResponse: + description: A single governance control detection. + properties: + data: + $ref: "#/components/schemas/GovernanceControlDetectionData" + required: + - data + type: object + GovernanceControlDetectionState: + description: The current state of the detection. Possible values are `active`, `exception`, `mitigated`, `inactive`, `obsolete`, `resolved_externally`, and `mitigation_in_progress`. + enum: + - active + - exception + - mitigated + - inactive + - obsolete + - resolved_externally + - mitigation_in_progress + example: "active" + type: string + x-enum-varnames: + - ACTIVE + - EXCEPTION + - MITIGATED + - INACTIVE + - OBSOLETE + - RESOLVED_EXTERNALLY + - MITIGATION_IN_PROGRESS + GovernanceControlDetectionUpdateAttributes: + description: The attributes of a governance control detection that can be updated. Only the attributes present in the request are modified. + properties: + assigned_team: + description: The handle of the team the detection is assigned to. Set to an empty string to clear the assignment. + example: "platform-security" + type: string + assigned_to: + description: The UUID of the user the detection is assigned to. Set to an empty string to clear the assignment. + example: "11111111-2222-3333-4444-555555555555" + type: string + mitigate_after: + description: The timestamp after which the detection becomes eligible for mitigation. Used to defer mitigation to a later time. + example: "2024-03-15T00:00:00Z" + format: date-time + type: string + state: + $ref: "#/components/schemas/GovernanceControlDetectionUpdateState" + type: object + GovernanceControlDetectionUpdateData: + description: The data of a governance control detection update request. + properties: + attributes: + $ref: "#/components/schemas/GovernanceControlDetectionUpdateAttributes" + type: + $ref: "#/components/schemas/GovernanceControlDetectionResourceType" + required: + - type + type: object + GovernanceControlDetectionUpdateRequest: + description: A request to update a governance control detection. + properties: + data: + $ref: "#/components/schemas/GovernanceControlDetectionUpdateData" + required: + - data + type: object + GovernanceControlDetectionUpdateState: + description: The new state to set for the detection. Set to `exception` to acknowledge the detection and exclude it from active counts, or `active` to reopen it. + enum: + - exception + - active + example: "exception" + type: string + x-enum-varnames: + - EXCEPTION + - ACTIVE + GovernanceControlDetectionsDataArray: + description: An array of governance control detection resources. + items: + $ref: "#/components/schemas/GovernanceControlDetectionData" + type: array + GovernanceControlDetectionsResponse: + description: A list of governance control detections. + properties: + data: + $ref: "#/components/schemas/GovernanceControlDetectionsDataArray" + required: + - data + type: object GovernanceControlMitigationDefinition: description: The definition of a mitigation available for a control. properties: @@ -42497,7 +42873,7 @@ components: example: "line" type: string comparison_shift: - description: The window used for the previous value comparison, for example `week` or `month`. + description: The window used for the previous value comparison; for example, `week` or `month`. example: "month" type: string default_value: @@ -42556,6 +42932,360 @@ components: required: - data type: object + GovernanceLimitAttributes: + description: The attributes of a governance limit. + properties: + description: + description: A description of what the limit measures. + example: "The number of log events indexed in the last 30 days." + type: string + display_name: + description: The human-readable name of the limit. + example: "Indexed Logs" + type: string + limit_type: + description: The type of limit, such as a rate limit or a usage limit. + example: "usage" + type: string + product: + description: The Datadog product the limit belongs to. + example: "logs" + type: string + query: + $ref: "#/components/schemas/GovernanceLimitQuery" + query_config: + $ref: "#/components/schemas/GovernanceLimitQueryConfig" + time_range: + description: The time range over which usage against the limit is measured. + example: "month" + type: string + times_hit_limit: + description: The number of times usage has reached the limit within the measured time range. + example: 2 + format: double + type: number + unit_name: + description: The unit in which the limit and its usage are measured. + example: "events" + type: string + usage_status: + description: The current usage status of the limit relative to its threshold. + example: "approaching" + type: string + required: + - display_name + - description + - product + - limit_type + - unit_name + - time_range + - query + - times_hit_limit + - usage_status + - query_config + type: object + GovernanceLimitData: + description: A governance limit resource. + properties: + attributes: + $ref: "#/components/schemas/GovernanceLimitAttributes" + id: + description: The unique identifier of the limit. + example: "logs_indexed_events" + type: string + type: + $ref: "#/components/schemas/GovernanceLimitResourceType" + required: + - id + - type + - attributes + type: object + GovernanceLimitQuery: + description: A metric query used to compute usage against a limit. + properties: + query: + description: The metric query expression used to compute the limit value. + example: "sum:datadog.estimated_usage.logs.ingested_events{*}" + type: string + reducer: + description: How the query results are aggregated into a single value (for example, sum, max, or avg). + example: "sum" + type: string + source: + description: The data source used to evaluate the metric query (for example, the metrics or events backend). + example: "metrics" + type: string + required: + - source + - query + - reducer + type: object + GovernanceLimitQueryConfig: + description: The query execution context used to visualize a limit and its usage. + properties: + chart_type: + description: The chart type used to visualize the limit and its usage. + example: "line" + type: string + comparison_shift: + description: The time shift applied to compare current usage against a prior period. + example: "month" + type: string + default_value: + description: The default value used for the limit when no explicit value is configured. + example: 0 + format: int64 + type: integer + directionality: + description: The direction in which usage approaches the limit, indicating whether higher or lower values are closer to the limit. + example: "increase_better" + type: string + effective_time_window_days: + description: The number of days of data the limit query evaluates over. + example: 30 + format: int64 + type: integer + type: object + GovernanceLimitResourceType: + description: Limit resource type. + enum: + - limit + example: "limit" + type: string + x-enum-varnames: + - LIMIT + GovernanceLimitsDataArray: + description: An array of governance limit resources. + items: + $ref: "#/components/schemas/GovernanceLimitData" + type: array + GovernanceLimitsResponse: + description: A list of governance limits. + properties: + data: + $ref: "#/components/schemas/GovernanceLimitsDataArray" + required: + - data + type: object + GovernanceMitigationRequest: + description: A request to mitigate a set of governance detections. + properties: + data: + $ref: "#/components/schemas/GovernanceMitigationRequestData" + required: + - data + type: object + GovernanceMitigationRequestAttributes: + description: The attributes of a governance mitigation request. + properties: + detection_ids: + description: The identifiers of the detections to mitigate in this request. + example: + - "3f9b2c1a-8d4e-4a6b-9c2f-1e7d5a0b3c4d" + items: + description: The identifier of a detection to mitigate in this request. + type: string + type: array + detection_type: + description: The detection type whose detections should be mitigated. + example: "unused_api_keys" + type: string + mitigation_parameters: + $ref: "#/components/schemas/GovernanceControlParametersMap" + nullable: true + mitigation_type: + description: The mitigation to apply to the selected detections. Defaults to the control's configured mitigation when omitted. + example: "revoke_api_key" + type: string + type: object + GovernanceMitigationRequestData: + description: The data of a governance mitigation request. + properties: + attributes: + $ref: "#/components/schemas/GovernanceMitigationRequestAttributes" + type: + $ref: "#/components/schemas/GovernanceControlDetectionResourceType" + required: + - type + type: object + GovernanceNotificationSettingsAttributes: + description: The attributes of the organization-wide governance notification settings. + properties: + assignment_notifications_enabled: + description: Whether notifications are sent to users when detections are assigned to them. + example: true + type: boolean + required: + - assignment_notifications_enabled + type: object + GovernanceNotificationSettingsData: + description: A governance notification settings resource. + properties: + attributes: + $ref: "#/components/schemas/GovernanceNotificationSettingsAttributes" + id: + description: The unique identifier of the organization the notification settings apply to. + example: "11111111-2222-3333-4444-555555555555" + type: string + type: + $ref: "#/components/schemas/GovernanceNotificationSettingsResourceType" + required: + - id + - type + - attributes + type: object + GovernanceNotificationSettingsResourceType: + description: Governance notification settings resource type. + enum: + - governance_notification_settings + example: "governance_notification_settings" + type: string + x-enum-varnames: + - GOVERNANCE_NOTIFICATION_SETTINGS + GovernanceNotificationSettingsResponse: + description: The organization-wide governance notification settings. + properties: + data: + $ref: "#/components/schemas/GovernanceNotificationSettingsData" + required: + - data + type: object + GovernanceNotificationSettingsUpdateAttributes: + description: The attributes of the governance notification settings that can be updated. Only the attributes present in the request are modified. + properties: + assignment_notifications_enabled: + description: Whether notifications are sent to users when detections are assigned to them. + example: true + type: boolean + type: object + GovernanceNotificationSettingsUpdateData: + description: The data of a governance notification settings update request. + properties: + attributes: + $ref: "#/components/schemas/GovernanceNotificationSettingsUpdateAttributes" + type: + $ref: "#/components/schemas/GovernanceNotificationSettingsResourceType" + required: + - type + type: object + GovernanceNotificationSettingsUpdateRequest: + description: A request to update the organization-wide governance notification settings. + properties: + data: + $ref: "#/components/schemas/GovernanceNotificationSettingsUpdateData" + required: + - data + type: object + GovernanceResourceLimitAttributes: + description: The attributes of a governance resource limit. + properties: + current_limit: + description: The current limit configured for the resource. + example: 10000 + format: double + type: number + current_value: + description: The current value of the resource. + example: 8200 + format: double + type: number + deep_link: + description: A link to the Datadog page where the resource and its limit can be managed. + example: "/metric/summary" + type: string + default_current_value: + description: The default current value used when the resource value cannot be computed from the query. + example: 0 + format: double + type: number + default_limit_value: + description: The default limit value used when the limit cannot be computed from the query. + example: 0 + format: double + type: number + description: + description: A description of what the resource limit measures. + example: "The number of custom metrics in use against your contracted limit." + type: string + display_name: + description: The human-readable name of the resource limit. + example: "Custom Metrics" + type: string + limit_query: + $ref: "#/components/schemas/GovernanceLimitQuery" + product: + description: The Datadog product the resource limit belongs to. + example: "metrics" + type: string + query: + $ref: "#/components/schemas/GovernanceLimitQuery" + query_config: + $ref: "#/components/schemas/GovernanceLimitQueryConfig" + time_range: + description: The time range over which the resource value is measured. + example: "month" + type: string + unit_name: + description: The unit in which the resource value and limit are measured. + example: "metrics" + type: string + usage_status: + description: The current usage status of the resource relative to its limit. + example: "approaching" + type: string + required: + - display_name + - description + - product + - unit_name + - time_range + - current_value + - current_limit + - default_current_value + - default_limit_value + - deep_link + - query + - limit_query + - query_config + - usage_status + type: object + GovernanceResourceLimitData: + description: A governance resource limit resource. + properties: + attributes: + $ref: "#/components/schemas/GovernanceResourceLimitAttributes" + id: + description: The unique identifier of the resource limit. + example: "custom_metrics" + type: string + type: + $ref: "#/components/schemas/GovernanceResourceLimitResourceType" + required: + - id + - type + - attributes + type: object + GovernanceResourceLimitResourceType: + description: Resource limit resource type. + enum: + - resource-limit + example: "resource-limit" + type: string + x-enum-varnames: + - RESOURCE_LIMIT + GovernanceResourceLimitsDataArray: + description: An array of governance resource limit resources. + items: + $ref: "#/components/schemas/GovernanceResourceLimitData" + type: array + GovernanceResourceLimitsResponse: + description: A list of governance resource limits. + properties: + data: + $ref: "#/components/schemas/GovernanceResourceLimitsDataArray" + required: + - data + type: object GreyNoiseAPIKey: description: The definition of the `GreyNoiseAPIKey` object. properties: @@ -135447,6 +136177,60 @@ paths: operator: OR permissions: - user_access_read + /api/v2/governance/config: + get: + description: |- + Retrieve the Governance Console configuration for the organization, including whether the + Console is enabled, whether assignment notifications are enabled, and whether usage + attribution is configured. + operationId: GetGovernanceConfig + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + assignment_notifications_enabled: true + enabled: true + usage_attribution_configured: true + id: "11111111-2222-3333-4444-555555555555" + type: "governance_console_config" + schema: + $ref: "#/components/schemas/GovernanceConfigResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: [] + summary: Get the governance console configuration + tags: + - Governance Settings + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). /api/v2/governance/control: get: description: |- @@ -135549,9 +136333,17 @@ paths: description: Forbidden "429": $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: [] summary: List governance controls tags: - Governance Controls + "x-permission": + operator: AND + permissions: + - governance_console_read x-unstable: |- **Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). @@ -135648,9 +136440,17 @@ paths: description: Not Found "429": $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: [] summary: Get a governance control tags: - Governance Controls + "x-permission": + operator: AND + permissions: + - governance_console_read x-unstable: |- **Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). @@ -135754,9 +136554,481 @@ paths: description: Not Found "429": $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: [] summary: Update a governance control tags: - Governance Controls + "x-permission": + operator: AND + permissions: + - governance_console_read + - governance_console_write + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). + /api/v2/governance/control/{detection_type}/detections: + get: + description: |- + Retrieve the detections produced by the governance control with the given detection type. + Results can be filtered by state and free-text query, sorted, and paginated. + operationId: ListGovernanceControlDetections + parameters: + - description: The detection type that identifies the control; for example, `unused_api_keys`. + example: "unused_api_keys" + in: path + name: detection_type + required: true + schema: + type: string + - description: Restrict the results to detections in the given state. + example: "active" + in: query + name: filter[state] + required: false + schema: + type: string + - description: Restrict the results to detections matching the given free-text query. + example: "production" + in: query + name: filter[query] + required: false + schema: + type: string + - description: The attribute to sort detections by. Prefix with `-` for descending order. + example: "-created_at" + in: query + name: sort + required: false + schema: + type: string + - description: "The zero-based index of the page to return; the first page is 0." + example: 0 + in: query + name: page[number] + required: false + schema: + default: 0 + format: int64 + type: integer + - description: The number of detections to return per page. + example: 50 + in: query + name: page[size] + required: false + schema: + format: int64 + type: integer + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + - attributes: + assigned_team: "platform-security" + assigned_to: "11111111-2222-3333-4444-555555555555" + assignment_source: "manual" + control_id: "0d4e6f8a-1b2c-3d4e-5f6a-7b8c9d0e1f2a" + created_at: "2024-03-01T12:00:00Z" + detection_type: "unused_api_keys" + display_name: "CI Deploy Key" + metadata: + region: "us-east-1" + priority: 1 + resource_id: "api-key-12345" + resource_url: "/organization-settings/api-keys/api-key-12345" + state: "active" + id: "3f9b2c1a-8d4e-4a6b-9c2f-1e7d5a0b3c4d" + type: "governance_control_detection" + schema: + $ref: "#/components/schemas/GovernanceControlDetectionsResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - governance_console_read + summary: List governance control detections + tags: + - Governance Controls + "x-permission": + operator: AND + permissions: + - governance_console_read + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). + /api/v2/governance/control/{detection_type}/detections/{detection_id}: + get: + description: Retrieve a single detection produced by the governance control with the given detection type. + operationId: GetGovernanceControlDetection + parameters: + - description: The detection type that identifies the control; for example, `unused_api_keys`. + example: "unused_api_keys" + in: path + name: detection_type + required: true + schema: + type: string + - description: The unique identifier of the detection. + example: "3f9b2c1a-8d4e-4a6b-9c2f-1e7d5a0b3c4d" + in: path + name: detection_id + required: true + schema: + type: string + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + assigned_team: "platform-security" + assigned_to: "11111111-2222-3333-4444-555555555555" + assignment_source: "manual" + control_id: "0d4e6f8a-1b2c-3d4e-5f6a-7b8c9d0e1f2a" + created_at: "2024-03-01T12:00:00Z" + detection_type: "unused_api_keys" + display_name: "CI Deploy Key" + metadata: + region: "us-east-1" + priority: 1 + resource_id: "api-key-12345" + resource_url: "/organization-settings/api-keys/api-key-12345" + state: "active" + id: "3f9b2c1a-8d4e-4a6b-9c2f-1e7d5a0b3c4d" + type: "governance_control_detection" + schema: + $ref: "#/components/schemas/GovernanceControlDetectionResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "404": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Not Found + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - governance_console_read + summary: Get a governance control detection + tags: + - Governance Controls + "x-permission": + operator: AND + permissions: + - governance_console_read + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). + patch: + description: |- + Update a detection produced by the governance control with the given detection type. Only the + attributes present in the request are modified, allowing a detection to be acknowledged as an + exception, reopened, reassigned, or deferred for mitigation. + operationId: UpdateGovernanceControlDetection + parameters: + - description: The detection type that identifies the control; for example, `unused_api_keys`. + example: "unused_api_keys" + in: path + name: detection_type + required: true + schema: + type: string + - description: The unique identifier of the detection. + example: "3f9b2c1a-8d4e-4a6b-9c2f-1e7d5a0b3c4d" + in: path + name: detection_id + required: true + schema: + type: string + requestBody: + content: + application/json: + examples: + default: + value: + data: + attributes: + assigned_to: "11111111-2222-3333-4444-555555555555" + state: "exception" + type: "governance_control_detection" + schema: + $ref: "#/components/schemas/GovernanceControlDetectionUpdateRequest" + required: true + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + assigned_team: "platform-security" + assigned_to: "11111111-2222-3333-4444-555555555555" + assignment_source: "manual" + control_id: "0d4e6f8a-1b2c-3d4e-5f6a-7b8c9d0e1f2a" + created_at: "2024-03-01T12:00:00Z" + detection_type: "unused_api_keys" + display_name: "CI Deploy Key" + metadata: + region: "us-east-1" + priority: 1 + resource_id: "api-key-12345" + resource_url: "/organization-settings/api-keys/api-key-12345" + state: "active" + id: "3f9b2c1a-8d4e-4a6b-9c2f-1e7d5a0b3c4d" + type: "governance_control_detection" + schema: + $ref: "#/components/schemas/GovernanceControlDetectionResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "404": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Not Found + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - governance_console_read + summary: Update a governance control detection + tags: + - Governance Controls + "x-permission": + operator: AND + permissions: + - governance_console_read + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). + /api/v2/governance/control/{detection_type}/notification_settings: + get: + description: |- + Retrieve the notification settings for the governance control with the given detection type, + including, for each supported event type, whether notifications are enabled and which + destinations receive them. + operationId: GetGovernanceControlNotificationSettings + parameters: + - description: The detection type that identifies the control; for example, `unused_api_keys`. + example: "unused_api_keys" + in: path + name: detection_type + required: true + schema: + type: string + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + event_settings: + - enabled: true + event_type: "new_detection" + targets: + - handle: "#governance-alerts" + type: "slack" + id: "unused_api_keys" + type: "control_notification_settings" + schema: + $ref: "#/components/schemas/ControlNotificationSettingsResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - governance_console_read + summary: Get governance control notification settings + tags: + - Governance Controls + "x-permission": + operator: AND + permissions: + - governance_console_read + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). + put: + description: |- + Replace the notification settings for the governance control with the given detection type, + setting, for each supported event type, whether notifications are enabled and which + destinations receive them. + operationId: UpdateGovernanceControlNotificationSettings + parameters: + - description: The detection type that identifies the control; for example, `unused_api_keys`. + example: "unused_api_keys" + in: path + name: detection_type + required: true + schema: + type: string + requestBody: + content: + application/json: + examples: + default: + value: + data: + attributes: + event_settings: + - enabled: true + event_type: "new_detection" + targets: + - handle: "#governance-alerts" + type: "slack" + type: "control_notification_settings" + schema: + $ref: "#/components/schemas/ControlNotificationSettingsUpdateRequest" + required: true + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + event_settings: + - enabled: true + event_type: "new_detection" + targets: + - handle: "#governance-alerts" + type: "slack" + id: "unused_api_keys" + type: "control_notification_settings" + schema: + $ref: "#/components/schemas/ControlNotificationSettingsResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - governance_console_read + - governance_console_write + summary: Update governance control notification settings + tags: + - Governance Controls + "x-permission": + operator: AND + permissions: + - governance_console_read + - governance_console_write x-unstable: |- **Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). @@ -135883,9 +137155,365 @@ paths: description: Forbidden "429": $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - audit_logs_read + - events_read + - metrics_read summary: List governance insights tags: - Governance Insights + "x-permission": + operator: OR + permissions: + - metrics_read + - events_read + - audit_logs_read + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). + /api/v2/governance/limits: + get: + description: |- + Retrieve the list of usage limits tracked for the organization in the Governance Console. + Each limit reports the query used to compute current usage, the unit and time range it is + measured over, and its current usage status. + operationId: ListGovernanceLimits + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + - attributes: + description: "The number of log events indexed in the last 30 days." + display_name: "Indexed Logs" + limit_type: "usage" + product: "logs" + query: + query: "sum:datadog.estimated_usage.logs.ingested_events{*}" + reducer: "sum" + source: "metrics" + query_config: + chart_type: "line" + comparison_shift: "month" + default_value: 0 + directionality: "increase_better" + effective_time_window_days: 30 + time_range: "month" + times_hit_limit: 2 + unit_name: "events" + usage_status: "approaching" + id: "logs_indexed_events" + type: "limit" + schema: + $ref: "#/components/schemas/GovernanceLimitsResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - governance_console_read + summary: List governance limits + tags: + - Governance Settings + "x-permission": + operator: AND + permissions: + - governance_console_read + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). + /api/v2/governance/mitigate: + post: + description: |- + Apply a mitigation to a set of governance detections of a given detection type. When the + mitigation type is omitted, the control's configured mitigation is used. The request is + accepted for asynchronous processing. + operationId: CreateGovernanceMitigation + requestBody: + content: + application/json: + examples: + default: + value: + data: + attributes: + detection_ids: + - "3f9b2c1a-8d4e-4a6b-9c2f-1e7d5a0b3c4d" + detection_type: "unused_api_keys" + mitigation_parameters: {} + mitigation_type: "revoke_api_key" + type: "governance_control_detection" + schema: + $ref: "#/components/schemas/GovernanceMitigationRequest" + required: true + responses: + "202": + description: Accepted + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - governance_console_read + summary: Mitigate governance detections + tags: + - Governance Controls + "x-permission": + operator: AND + permissions: + - governance_console_read + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). + /api/v2/governance/notification_settings: + get: + description: |- + Retrieve the organization-wide governance notification settings, including whether users are + notified when detections are assigned to them. + operationId: GetGovernanceNotificationSettings + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + assignment_notifications_enabled: true + id: "11111111-2222-3333-4444-555555555555" + type: "governance_notification_settings" + schema: + $ref: "#/components/schemas/GovernanceNotificationSettingsResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - governance_console_read + summary: Get governance notification settings + tags: + - Governance Settings + "x-permission": + operator: AND + permissions: + - governance_console_read + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). + patch: + description: |- + Update the organization-wide governance notification settings. Only the attributes present in + the request are modified. + operationId: UpdateGovernanceNotificationSettings + requestBody: + content: + application/json: + examples: + default: + value: + data: + attributes: + assignment_notifications_enabled: true + type: "governance_notification_settings" + schema: + $ref: "#/components/schemas/GovernanceNotificationSettingsUpdateRequest" + required: true + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + assignment_notifications_enabled: true + id: "11111111-2222-3333-4444-555555555555" + type: "governance_notification_settings" + schema: + $ref: "#/components/schemas/GovernanceNotificationSettingsResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - governance_console_read + - governance_console_write + summary: Update governance notification settings + tags: + - Governance Settings + "x-permission": + operator: AND + permissions: + - governance_console_read + - governance_console_write + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). + /api/v2/governance/resource-limits: + get: + description: |- + Retrieve the list of resource limits tracked for the organization in the Governance Console. + Each resource limit reports its current value and configured limit, the queries used to + compute them, and its current usage status. + operationId: ListGovernanceResourceLimits + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + - attributes: + current_limit: 10000 + current_value: 8200 + deep_link: "/metric/summary" + default_current_value: 0 + default_limit_value: 0 + description: "The number of custom metrics in use against your contracted limit." + display_name: "Custom Metrics" + limit_query: + query: "sum:datadog.contract.metrics.custom{*}" + reducer: "max" + source: "metrics" + product: "metrics" + query: + query: "sum:datadog.estimated_usage.metrics.custom{*}" + reducer: "sum" + source: "metrics" + query_config: + chart_type: "line" + comparison_shift: "month" + default_value: 0 + directionality: "decrease_better" + effective_time_window_days: 30 + time_range: "month" + unit_name: "metrics" + usage_status: "approaching" + id: "custom_metrics" + type: "resource-limit" + schema: + $ref: "#/components/schemas/GovernanceResourceLimitsResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Unauthorized + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - governance_console_read + summary: List governance resource limits + tags: + - Governance Settings + "x-permission": + operator: AND + permissions: + - governance_console_read x-unstable: |- **Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). @@ -189943,9 +191571,17 @@ paths: description: Forbidden "429": $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] summary: List tag policies tags: - Tag Policies + "x-permission": + operator: OR + permissions: + - telemetry_rules_read + - metrics_read x-unstable: |- **Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). @@ -190034,9 +191670,16 @@ paths: description: Conflict "429": $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] summary: Create a tag policy tags: - Tag Policies + "x-permission": + operator: AND + permissions: + - telemetry_rules_create x-unstable: |- **Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). @@ -190091,9 +191734,16 @@ paths: description: Not Found "429": $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] summary: Delete a tag policy tags: - Tag Policies + "x-permission": + operator: AND + permissions: + - telemetry_rules_create x-unstable: |- **Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). @@ -190203,9 +191853,17 @@ paths: description: Not Found "429": $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] summary: Get a tag policy tags: - Tag Policies + "x-permission": + operator: OR + permissions: + - telemetry_rules_read + - metrics_read x-unstable: |- **Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). @@ -190294,9 +191952,16 @@ paths: description: Not Found "429": $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] summary: Update a tag policy tags: - Tag Policies + "x-permission": + operator: AND + permissions: + - telemetry_rules_create x-unstable: |- **Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). @@ -190376,9 +192041,17 @@ paths: description: Not Found "429": $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] summary: Get a tag policy compliance score tags: - Tag Policies + "x-permission": + operator: OR + permissions: + - telemetry_rules_read + - metrics_read x-unstable: |- **Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/). @@ -196173,6 +197846,11 @@ tags: optionally, a previous value for comparison) along with the query used to compute it, so that the Console can render trends and highlight areas that need attention. name: Governance Insights + - description: |- + Governance Settings cover organization-wide Governance Console configuration, usage limits and + resource limits, and notification preferences that determine when and how the Console alerts + users about governance activity. + name: Governance Settings - description: |- Configure High Availability Multi-Region (HAMR) connections between Datadog organizations. HAMR provides disaster recovery capabilities by maintaining synchronized data between primary diff --git a/examples/v2_governance-controls_CreateGovernanceMitigation.rs b/examples/v2_governance-controls_CreateGovernanceMitigation.rs new file mode 100644 index 000000000..78bf6c62b --- /dev/null +++ b/examples/v2_governance-controls_CreateGovernanceMitigation.rs @@ -0,0 +1,31 @@ +// Mitigate governance detections returns "Accepted" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_governance_controls::GovernanceControlsAPI; +use datadog_api_client::datadogV2::model::GovernanceControlDetectionResourceType; +use datadog_api_client::datadogV2::model::GovernanceMitigationRequest; +use datadog_api_client::datadogV2::model::GovernanceMitigationRequestAttributes; +use datadog_api_client::datadogV2::model::GovernanceMitigationRequestData; + +#[tokio::main] +async fn main() { + let body = GovernanceMitigationRequest::new( + GovernanceMitigationRequestData::new( + GovernanceControlDetectionResourceType::GOVERNANCE_CONTROL_DETECTION, + ) + .attributes( + GovernanceMitigationRequestAttributes::new() + .detection_ids(vec!["3f9b2c1a-8d4e-4a6b-9c2f-1e7d5a0b3c4d".to_string()]) + .detection_type("unused_api_keys".to_string()) + .mitigation_type("revoke_api_key".to_string()), + ), + ); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.CreateGovernanceMitigation", true); + let api = GovernanceControlsAPI::with_config(configuration); + let resp = api.create_governance_mitigation(body).await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_governance-controls_GetGovernanceControlDetection.rs b/examples/v2_governance-controls_GetGovernanceControlDetection.rs new file mode 100644 index 000000000..5395f6922 --- /dev/null +++ b/examples/v2_governance-controls_GetGovernanceControlDetection.rs @@ -0,0 +1,18 @@ +// Get a governance control detection returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_governance_controls::GovernanceControlsAPI; + +#[tokio::main] +async fn main() { + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.GetGovernanceControlDetection", true); + let api = GovernanceControlsAPI::with_config(configuration); + let resp = api + .get_governance_control_detection("detection_type".to_string(), "detection_id".to_string()) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_governance-controls_GetGovernanceControlNotificationSettings.rs b/examples/v2_governance-controls_GetGovernanceControlNotificationSettings.rs new file mode 100644 index 000000000..fac28f6ea --- /dev/null +++ b/examples/v2_governance-controls_GetGovernanceControlNotificationSettings.rs @@ -0,0 +1,19 @@ +// Get governance control notification settings returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_governance_controls::GovernanceControlsAPI; + +#[tokio::main] +async fn main() { + let mut configuration = datadog::Configuration::new(); + configuration + .set_unstable_operation_enabled("v2.GetGovernanceControlNotificationSettings", true); + let api = GovernanceControlsAPI::with_config(configuration); + let resp = api + .get_governance_control_notification_settings("detection_type".to_string()) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_governance-controls_ListGovernanceControlDetections.rs b/examples/v2_governance-controls_ListGovernanceControlDetections.rs new file mode 100644 index 000000000..fe4b2d96b --- /dev/null +++ b/examples/v2_governance-controls_ListGovernanceControlDetections.rs @@ -0,0 +1,22 @@ +// List governance control detections returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_governance_controls::GovernanceControlsAPI; +use datadog_api_client::datadogV2::api_governance_controls::ListGovernanceControlDetectionsOptionalParams; + +#[tokio::main] +async fn main() { + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.ListGovernanceControlDetections", true); + let api = GovernanceControlsAPI::with_config(configuration); + let resp = api + .list_governance_control_detections( + "detection_type".to_string(), + ListGovernanceControlDetectionsOptionalParams::default(), + ) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_governance-controls_UpdateGovernanceControlDetection.rs b/examples/v2_governance-controls_UpdateGovernanceControlDetection.rs new file mode 100644 index 000000000..0febdc39b --- /dev/null +++ b/examples/v2_governance-controls_UpdateGovernanceControlDetection.rs @@ -0,0 +1,44 @@ +// Update a governance control detection returns "OK" response +use chrono::{DateTime, Utc}; +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_governance_controls::GovernanceControlsAPI; +use datadog_api_client::datadogV2::model::GovernanceControlDetectionResourceType; +use datadog_api_client::datadogV2::model::GovernanceControlDetectionUpdateAttributes; +use datadog_api_client::datadogV2::model::GovernanceControlDetectionUpdateData; +use datadog_api_client::datadogV2::model::GovernanceControlDetectionUpdateRequest; +use datadog_api_client::datadogV2::model::GovernanceControlDetectionUpdateState; + +#[tokio::main] +async fn main() { + let body = GovernanceControlDetectionUpdateRequest::new( + GovernanceControlDetectionUpdateData::new( + GovernanceControlDetectionResourceType::GOVERNANCE_CONTROL_DETECTION, + ) + .attributes( + GovernanceControlDetectionUpdateAttributes::new() + .assigned_team("platform-security".to_string()) + .assigned_to("11111111-2222-3333-4444-555555555555".to_string()) + .mitigate_after( + DateTime::parse_from_rfc3339("2024-03-15T00:00:00+00:00") + .expect("Failed to parse datetime") + .with_timezone(&Utc), + ) + .state(GovernanceControlDetectionUpdateState::EXCEPTION), + ), + ); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.UpdateGovernanceControlDetection", true); + let api = GovernanceControlsAPI::with_config(configuration); + let resp = api + .update_governance_control_detection( + "detection_type".to_string(), + "detection_id".to_string(), + body, + ) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_governance-controls_UpdateGovernanceControlNotificationSettings.rs b/examples/v2_governance-controls_UpdateGovernanceControlNotificationSettings.rs new file mode 100644 index 000000000..dcb9a472a --- /dev/null +++ b/examples/v2_governance-controls_UpdateGovernanceControlNotificationSettings.rs @@ -0,0 +1,43 @@ +// Update governance control notification settings returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_governance_controls::GovernanceControlsAPI; +use datadog_api_client::datadogV2::model::ControlNotificationEventSetting; +use datadog_api_client::datadogV2::model::ControlNotificationSettingsResourceType; +use datadog_api_client::datadogV2::model::ControlNotificationSettingsUpdateAttributes; +use datadog_api_client::datadogV2::model::ControlNotificationSettingsUpdateData; +use datadog_api_client::datadogV2::model::ControlNotificationSettingsUpdateRequest; +use datadog_api_client::datadogV2::model::ControlNotificationTarget; +use datadog_api_client::datadogV2::model::ControlNotificationTargetType; + +#[tokio::main] +async fn main() { + let body = ControlNotificationSettingsUpdateRequest::new( + ControlNotificationSettingsUpdateData::new( + ControlNotificationSettingsResourceType::CONTROL_NOTIFICATION_SETTINGS, + ) + .attributes( + ControlNotificationSettingsUpdateAttributes::new().event_settings(vec![ + ControlNotificationEventSetting::new( + true, + "new_detection".to_string(), + vec![ControlNotificationTarget::new( + "#governance-alerts".to_string(), + ControlNotificationTargetType::SLACK, + )], + ), + ]), + ), + ); + let mut configuration = datadog::Configuration::new(); + configuration + .set_unstable_operation_enabled("v2.UpdateGovernanceControlNotificationSettings", true); + let api = GovernanceControlsAPI::with_config(configuration); + let resp = api + .update_governance_control_notification_settings("detection_type".to_string(), body) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_governance-settings_GetGovernanceConfig.rs b/examples/v2_governance-settings_GetGovernanceConfig.rs new file mode 100644 index 000000000..64f1d3b32 --- /dev/null +++ b/examples/v2_governance-settings_GetGovernanceConfig.rs @@ -0,0 +1,16 @@ +// Get the governance console configuration returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_governance_settings::GovernanceSettingsAPI; + +#[tokio::main] +async fn main() { + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.GetGovernanceConfig", true); + let api = GovernanceSettingsAPI::with_config(configuration); + let resp = api.get_governance_config().await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_governance-settings_GetGovernanceNotificationSettings.rs b/examples/v2_governance-settings_GetGovernanceNotificationSettings.rs new file mode 100644 index 000000000..dda118d1e --- /dev/null +++ b/examples/v2_governance-settings_GetGovernanceNotificationSettings.rs @@ -0,0 +1,16 @@ +// Get governance notification settings returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_governance_settings::GovernanceSettingsAPI; + +#[tokio::main] +async fn main() { + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.GetGovernanceNotificationSettings", true); + let api = GovernanceSettingsAPI::with_config(configuration); + let resp = api.get_governance_notification_settings().await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_governance-settings_ListGovernanceLimits.rs b/examples/v2_governance-settings_ListGovernanceLimits.rs new file mode 100644 index 000000000..d39a0f4ed --- /dev/null +++ b/examples/v2_governance-settings_ListGovernanceLimits.rs @@ -0,0 +1,16 @@ +// List governance limits returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_governance_settings::GovernanceSettingsAPI; + +#[tokio::main] +async fn main() { + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.ListGovernanceLimits", true); + let api = GovernanceSettingsAPI::with_config(configuration); + let resp = api.list_governance_limits().await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_governance-settings_ListGovernanceResourceLimits.rs b/examples/v2_governance-settings_ListGovernanceResourceLimits.rs new file mode 100644 index 000000000..042bc3538 --- /dev/null +++ b/examples/v2_governance-settings_ListGovernanceResourceLimits.rs @@ -0,0 +1,16 @@ +// List governance resource limits returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_governance_settings::GovernanceSettingsAPI; + +#[tokio::main] +async fn main() { + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.ListGovernanceResourceLimits", true); + let api = GovernanceSettingsAPI::with_config(configuration); + let resp = api.list_governance_resource_limits().await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_governance-settings_UpdateGovernanceNotificationSettings.rs b/examples/v2_governance-settings_UpdateGovernanceNotificationSettings.rs new file mode 100644 index 000000000..a92c1eded --- /dev/null +++ b/examples/v2_governance-settings_UpdateGovernanceNotificationSettings.rs @@ -0,0 +1,29 @@ +// Update governance notification settings returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_governance_settings::GovernanceSettingsAPI; +use datadog_api_client::datadogV2::model::GovernanceNotificationSettingsResourceType; +use datadog_api_client::datadogV2::model::GovernanceNotificationSettingsUpdateAttributes; +use datadog_api_client::datadogV2::model::GovernanceNotificationSettingsUpdateData; +use datadog_api_client::datadogV2::model::GovernanceNotificationSettingsUpdateRequest; + +#[tokio::main] +async fn main() { + let body = GovernanceNotificationSettingsUpdateRequest::new( + GovernanceNotificationSettingsUpdateData::new( + GovernanceNotificationSettingsResourceType::GOVERNANCE_NOTIFICATION_SETTINGS, + ) + .attributes( + GovernanceNotificationSettingsUpdateAttributes::new() + .assignment_notifications_enabled(true), + ), + ); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.UpdateGovernanceNotificationSettings", true); + let api = GovernanceSettingsAPI::with_config(configuration); + let resp = api.update_governance_notification_settings(body).await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/src/datadog/configuration.rs b/src/datadog/configuration.rs index 21155919a..5025512df 100644 --- a/src/datadog/configuration.rs +++ b/src/datadog/configuration.rs @@ -571,9 +571,29 @@ impl Default for Configuration { ("v2.upsert_and_publish_form_version".to_owned(), false), ("v2.upsert_form_version".to_owned(), false), ("v2.update_org_saml_configurations".to_owned(), false), + ("v2.get_governance_config".to_owned(), false), + ("v2.get_governance_notification_settings".to_owned(), false), + ("v2.list_governance_limits".to_owned(), false), + ("v2.list_governance_resource_limits".to_owned(), false), + ( + "v2.update_governance_notification_settings".to_owned(), + false, + ), + ("v2.create_governance_mitigation".to_owned(), false), ("v2.get_governance_control".to_owned(), false), + ("v2.get_governance_control_detection".to_owned(), false), + ( + "v2.get_governance_control_notification_settings".to_owned(), + false, + ), + ("v2.list_governance_control_detections".to_owned(), false), ("v2.list_governance_controls".to_owned(), false), ("v2.update_governance_control".to_owned(), false), + ("v2.update_governance_control_detection".to_owned(), false), + ( + "v2.update_governance_control_notification_settings".to_owned(), + false, + ), ("v2.list_governance_insights".to_owned(), false), ("v2.create_hamr_org_connection".to_owned(), false), ("v2.get_hamr_org_connection".to_owned(), false), diff --git a/src/datadogV2/api/api_governance_controls.rs b/src/datadogV2/api/api_governance_controls.rs index 1d24426f6..387a213a3 100644 --- a/src/datadogV2/api/api_governance_controls.rs +++ b/src/datadogV2/api/api_governance_controls.rs @@ -11,6 +11,59 @@ use reqwest::header::{HeaderMap, HeaderValue}; use serde::{Deserialize, Serialize}; use std::io::Write; +/// ListGovernanceControlDetectionsOptionalParams is a struct for passing parameters to the method [`GovernanceControlsAPI::list_governance_control_detections`] +#[non_exhaustive] +#[derive(Clone, Default, Debug)] +pub struct ListGovernanceControlDetectionsOptionalParams { + /// Restrict the results to detections in the given state. + pub filter_state: Option, + /// Restrict the results to detections matching the given free-text query. + pub filter_query: Option, + /// The attribute to sort detections by. Prefix with `-` for descending order. + pub sort: Option, + /// The zero-based index of the page to return; the first page is 0. + pub page_number: Option, + /// The number of detections to return per page. + pub page_size: Option, +} + +impl ListGovernanceControlDetectionsOptionalParams { + /// Restrict the results to detections in the given state. + pub fn filter_state(mut self, value: String) -> Self { + self.filter_state = Some(value); + self + } + /// Restrict the results to detections matching the given free-text query. + pub fn filter_query(mut self, value: String) -> Self { + self.filter_query = Some(value); + self + } + /// The attribute to sort detections by. Prefix with `-` for descending order. + pub fn sort(mut self, value: String) -> Self { + self.sort = Some(value); + self + } + /// The zero-based index of the page to return; the first page is 0. + pub fn page_number(mut self, value: i64) -> Self { + self.page_number = Some(value); + self + } + /// The number of detections to return per page. + pub fn page_size(mut self, value: i64) -> Self { + self.page_size = Some(value); + self + } +} + +/// CreateGovernanceMitigationError is a struct for typed errors of method [`GovernanceControlsAPI::create_governance_mitigation`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum CreateGovernanceMitigationError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + /// GetGovernanceControlError is a struct for typed errors of method [`GovernanceControlsAPI::get_governance_control`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -20,6 +73,33 @@ pub enum GetGovernanceControlError { UnknownValue(serde_json::Value), } +/// GetGovernanceControlDetectionError is a struct for typed errors of method [`GovernanceControlsAPI::get_governance_control_detection`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetGovernanceControlDetectionError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// GetGovernanceControlNotificationSettingsError is a struct for typed errors of method [`GovernanceControlsAPI::get_governance_control_notification_settings`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetGovernanceControlNotificationSettingsError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// ListGovernanceControlDetectionsError is a struct for typed errors of method [`GovernanceControlsAPI::list_governance_control_detections`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ListGovernanceControlDetectionsError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + /// ListGovernanceControlsError is a struct for typed errors of method [`GovernanceControlsAPI::list_governance_controls`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -38,6 +118,24 @@ pub enum UpdateGovernanceControlError { UnknownValue(serde_json::Value), } +/// UpdateGovernanceControlDetectionError is a struct for typed errors of method [`GovernanceControlsAPI::update_governance_control_detection`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum UpdateGovernanceControlDetectionError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// UpdateGovernanceControlNotificationSettingsError is a struct for typed errors of method [`GovernanceControlsAPI::update_governance_control_notification_settings`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum UpdateGovernanceControlNotificationSettingsError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + /// Governance Controls pair a detection definition with an organization's detection, notification, /// and mitigation configuration within the Governance Console. Each control reports how a class of /// governance issue (such as unused API keys or unqueried metrics) is detected and remediated, along @@ -115,6 +213,152 @@ impl GovernanceControlsAPI { Self { config, client } } + /// Apply a mitigation to a set of governance detections of a given detection type. When the + /// mitigation type is omitted, the control's configured mitigation is used. The request is + /// accepted for asynchronous processing. + pub async fn create_governance_mitigation( + &self, + body: crate::datadogV2::model::GovernanceMitigationRequest, + ) -> Result<(), datadog::Error> { + match self.create_governance_mitigation_with_http_info(body).await { + Ok(_) => Ok(()), + Err(err) => Err(err), + } + } + + /// Apply a mitigation to a set of governance detections of a given detection type. When the + /// mitigation type is omitted, the control's configured mitigation is used. The request is + /// accepted for asynchronous processing. + pub async fn create_governance_mitigation_with_http_info( + &self, + body: crate::datadogV2::model::GovernanceMitigationRequest, + ) -> Result, datadog::Error> { + let local_configuration = &self.config; + let operation_id = "v2.create_governance_mitigation"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.create_governance_mitigation' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/governance/mitigate", + local_configuration.get_operation_host(operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::POST, 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("*/*")); + + // 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)), + } + } + #[cfg(feature = "zstd")] + "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() { + Ok(datadog::ResponseContent { + status: local_status, + content: local_content, + entity: None, + }) + } else { + let local_entity: Option = + 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)) + } + } + /// Retrieve a single governance control by its detection type, including the organization's current /// detection, notification, and mitigation configuration and detection counts. pub async fn get_governance_control( @@ -237,16 +481,19 @@ impl GovernanceControlsAPI { } } - /// Retrieve the list of governance controls configured for the organization. Each control pairs a - /// detection definition with the organization's current detection, notification, and mitigation - /// configuration, along with counts of active and mitigated detections. - pub async fn list_governance_controls( + /// Retrieve a single detection produced by the governance control with the given detection type. + pub async fn get_governance_control_detection( &self, + detection_type: String, + detection_id: String, ) -> Result< - crate::datadogV2::model::GovernanceControlsResponse, - datadog::Error, + crate::datadogV2::model::GovernanceControlDetectionResponse, + datadog::Error, > { - match self.list_governance_controls_with_http_info().await { + match self + .get_governance_control_detection_with_http_info(detection_type, detection_id) + .await + { Ok(response_content) => { if let Some(e) = response_content.entity { Ok(e) @@ -260,22 +507,22 @@ impl GovernanceControlsAPI { } } - /// Retrieve the list of governance controls configured for the organization. Each control pairs a - /// detection definition with the organization's current detection, notification, and mitigation - /// configuration, along with counts of active and mitigated detections. - pub async fn list_governance_controls_with_http_info( + /// Retrieve a single detection produced by the governance control with the given detection type. + pub async fn get_governance_control_detection_with_http_info( &self, + detection_type: String, + detection_id: String, ) -> Result< - datadog::ResponseContent, - datadog::Error, + datadog::ResponseContent, + datadog::Error, > { let local_configuration = &self.config; - let operation_id = "v2.list_governance_controls"; + let operation_id = "v2.get_governance_control_detection"; if local_configuration.is_unstable_operation_enabled(operation_id) { warn!("Using unstable operation {operation_id}"); } else { let local_error = datadog::UnstableOperationDisabledError { - msg: "Operation 'v2.list_governance_controls' is not enabled".to_string(), + msg: "Operation 'v2.get_governance_control_detection' is not enabled".to_string(), }; return Err(datadog::Error::UnstableOperationDisabledError(local_error)); } @@ -283,8 +530,10 @@ impl GovernanceControlsAPI { let local_client = &self.client; let local_uri_str = format!( - "{}/api/v2/governance/control", - local_configuration.get_operation_host(operation_id) + "{}/api/v2/governance/control/{detection_type}/detections/{detection_id}", + local_configuration.get_operation_host(operation_id), + detection_type = datadog::urlencode(detection_type), + detection_id = datadog::urlencode(detection_id) ); let mut local_req_builder = local_client.request(reqwest::Method::GET, local_uri_str.as_str()); @@ -331,7 +580,7 @@ impl GovernanceControlsAPI { log::debug!("response content: {}", local_content); if !local_status.is_client_error() && !local_status.is_server_error() { - match serde_json::from_str::( + match serde_json::from_str::( &local_content, ) { Ok(e) => { @@ -344,7 +593,7 @@ impl GovernanceControlsAPI { Err(e) => return Err(datadog::Error::Serde(e)), }; } else { - let local_entity: Option = + let local_entity: Option = serde_json::from_str(&local_content).ok(); let local_error = datadog::ResponseContent { status: local_status, @@ -355,19 +604,18 @@ impl GovernanceControlsAPI { } } - /// Update the detection, notification, and mitigation configuration of a governance control. Only - /// the attributes present in the request are modified. Changing the mitigation type or its - /// parameters may require additional permissions. - pub async fn update_governance_control( + /// Retrieve the notification settings for the governance control with the given detection type, + /// including, for each supported event type, whether notifications are enabled and which + /// destinations receive them. + pub async fn get_governance_control_notification_settings( &self, detection_type: String, - body: crate::datadogV2::model::GovernanceControlUpdateRequest, ) -> Result< - crate::datadogV2::model::GovernanceControlResponse, - datadog::Error, + crate::datadogV2::model::ControlNotificationSettingsResponse, + datadog::Error, > { match self - .update_governance_control_with_http_info(detection_type, body) + .get_governance_control_notification_settings_with_http_info(detection_type) .await { Ok(response_content) => { @@ -383,24 +631,24 @@ impl GovernanceControlsAPI { } } - /// Update the detection, notification, and mitigation configuration of a governance control. Only - /// the attributes present in the request are modified. Changing the mitigation type or its - /// parameters may require additional permissions. - pub async fn update_governance_control_with_http_info( + /// Retrieve the notification settings for the governance control with the given detection type, + /// including, for each supported event type, whether notifications are enabled and which + /// destinations receive them. + pub async fn get_governance_control_notification_settings_with_http_info( &self, detection_type: String, - body: crate::datadogV2::model::GovernanceControlUpdateRequest, ) -> Result< - datadog::ResponseContent, - datadog::Error, + datadog::ResponseContent, + datadog::Error, > { let local_configuration = &self.config; - let operation_id = "v2.update_governance_control"; + let operation_id = "v2.get_governance_control_notification_settings"; 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_governance_control' is not enabled".to_string(), + msg: "Operation 'v2.get_governance_control_notification_settings' is not enabled" + .to_string(), }; return Err(datadog::Error::UnstableOperationDisabledError(local_error)); } @@ -408,16 +656,15 @@ impl GovernanceControlsAPI { let local_client = &self.client; let local_uri_str = format!( - "{}/api/v2/governance/control/{detection_type}", + "{}/api/v2/governance/control/{detection_type}/notification_settings", local_configuration.get_operation_host(operation_id), detection_type = datadog::urlencode(detection_type) ); let mut local_req_builder = - local_client.request(reqwest::Method::PATCH, local_uri_str.as_str()); + local_client.request(reqwest::Method::GET, 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 @@ -448,42 +695,616 @@ impl GovernanceControlsAPI { ); }; - // 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)), - } - } - #[cfg(feature = "zstd")] - "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.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::( + &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 = + 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)) + } + } + + /// Retrieve the detections produced by the governance control with the given detection type. + /// Results can be filtered by state and free-text query, sorted, and paginated. + pub async fn list_governance_control_detections( + &self, + detection_type: String, + params: ListGovernanceControlDetectionsOptionalParams, + ) -> Result< + crate::datadogV2::model::GovernanceControlDetectionsResponse, + datadog::Error, + > { + match self + .list_governance_control_detections_with_http_info(detection_type, params) + .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), + } + } + + /// Retrieve the detections produced by the governance control with the given detection type. + /// Results can be filtered by state and free-text query, sorted, and paginated. + pub async fn list_governance_control_detections_with_http_info( + &self, + detection_type: String, + params: ListGovernanceControlDetectionsOptionalParams, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.list_governance_control_detections"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.list_governance_control_detections' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + // unbox and build optional parameters + let filter_state = params.filter_state; + let filter_query = params.filter_query; + let sort = params.sort; + let page_number = params.page_number; + let page_size = params.page_size; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/governance/control/{detection_type}/detections", + local_configuration.get_operation_host(operation_id), + detection_type = datadog::urlencode(detection_type) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + if let Some(ref local_query_param) = filter_state { + local_req_builder = + local_req_builder.query(&[("filter[state]", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = filter_query { + local_req_builder = + local_req_builder.query(&[("filter[query]", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = sort { + local_req_builder = + local_req_builder.query(&[("sort", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = page_number { + local_req_builder = + local_req_builder.query(&[("page[number]", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = page_size { + local_req_builder = + local_req_builder.query(&[("page[size]", &local_query_param.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::( + &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 = + 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)) + } + } + + /// Retrieve the list of governance controls configured for the organization. Each control pairs a + /// detection definition with the organization's current detection, notification, and mitigation + /// configuration, along with counts of active and mitigated detections. + pub async fn list_governance_controls( + &self, + ) -> Result< + crate::datadogV2::model::GovernanceControlsResponse, + datadog::Error, + > { + match self.list_governance_controls_with_http_info().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), + } + } + + /// Retrieve the list of governance controls configured for the organization. Each control pairs a + /// detection definition with the organization's current detection, notification, and mitigation + /// configuration, along with counts of active and mitigated detections. + pub async fn list_governance_controls_with_http_info( + &self, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.list_governance_controls"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.list_governance_controls' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/governance/control", + local_configuration.get_operation_host(operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + // 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::( + &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 = + 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)) + } + } + + /// Update the detection, notification, and mitigation configuration of a governance control. Only + /// the attributes present in the request are modified. Changing the mitigation type or its + /// parameters may require additional permissions. + pub async fn update_governance_control( + &self, + detection_type: String, + body: crate::datadogV2::model::GovernanceControlUpdateRequest, + ) -> Result< + crate::datadogV2::model::GovernanceControlResponse, + datadog::Error, + > { + match self + .update_governance_control_with_http_info(detection_type, 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), + } + } + + /// Update the detection, notification, and mitigation configuration of a governance control. Only + /// the attributes present in the request are modified. Changing the mitigation type or its + /// parameters may require additional permissions. + pub async fn update_governance_control_with_http_info( + &self, + detection_type: String, + body: crate::datadogV2::model::GovernanceControlUpdateRequest, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.update_governance_control"; + 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_governance_control' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/governance/control/{detection_type}", + local_configuration.get_operation_host(operation_id), + detection_type = datadog::urlencode(detection_type) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::PATCH, 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)), + } + } + #[cfg(feature = "zstd")] + "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::( + &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 = + 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)) + } + } + + /// Update a detection produced by the governance control with the given detection type. Only the + /// attributes present in the request are modified, allowing a detection to be acknowledged as an + /// exception, reopened, reassigned, or deferred for mitigation. + pub async fn update_governance_control_detection( + &self, + detection_type: String, + detection_id: String, + body: crate::datadogV2::model::GovernanceControlDetectionUpdateRequest, + ) -> Result< + crate::datadogV2::model::GovernanceControlDetectionResponse, + datadog::Error, + > { + match self + .update_governance_control_detection_with_http_info(detection_type, detection_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), + } + } + + /// Update a detection produced by the governance control with the given detection type. Only the + /// attributes present in the request are modified, allowing a detection to be acknowledged as an + /// exception, reopened, reassigned, or deferred for mitigation. + pub async fn update_governance_control_detection_with_http_info( + &self, + detection_type: String, + detection_id: String, + body: crate::datadogV2::model::GovernanceControlDetectionUpdateRequest, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.update_governance_control_detection"; + 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_governance_control_detection' is not enabled" + .to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/governance/control/{detection_type}/detections/{detection_id}", + local_configuration.get_operation_host(operation_id), + detection_type = datadog::urlencode(detection_type), + detection_id = datadog::urlencode(detection_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::PATCH, 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)), + } + } + #[cfg(feature = "zstd")] + "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()); @@ -504,7 +1325,7 @@ impl GovernanceControlsAPI { log::debug!("response content: {}", local_content); if !local_status.is_client_error() && !local_status.is_server_error() { - match serde_json::from_str::( + match serde_json::from_str::( &local_content, ) { Ok(e) => { @@ -517,7 +1338,182 @@ impl GovernanceControlsAPI { Err(e) => return Err(datadog::Error::Serde(e)), }; } else { - let local_entity: Option = + let local_entity: Option = + 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)) + } + } + + /// Replace the notification settings for the governance control with the given detection type, + /// setting, for each supported event type, whether notifications are enabled and which + /// destinations receive them. + pub async fn update_governance_control_notification_settings( + &self, + detection_type: String, + body: crate::datadogV2::model::ControlNotificationSettingsUpdateRequest, + ) -> Result< + crate::datadogV2::model::ControlNotificationSettingsResponse, + datadog::Error, + > { + match self + .update_governance_control_notification_settings_with_http_info(detection_type, 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), + } + } + + /// Replace the notification settings for the governance control with the given detection type, + /// setting, for each supported event type, whether notifications are enabled and which + /// destinations receive them. + pub async fn update_governance_control_notification_settings_with_http_info( + &self, + detection_type: String, + body: crate::datadogV2::model::ControlNotificationSettingsUpdateRequest, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.update_governance_control_notification_settings"; + 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_governance_control_notification_settings' is not enabled" + .to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/governance/control/{detection_type}/notification_settings", + local_configuration.get_operation_host(operation_id), + detection_type = datadog::urlencode(detection_type) + ); + 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)), + } + } + #[cfg(feature = "zstd")] + "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::( + &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 = serde_json::from_str(&local_content).ok(); let local_error = datadog::ResponseContent { status: local_status, diff --git a/src/datadogV2/api/api_governance_settings.rs b/src/datadogV2/api/api_governance_settings.rs new file mode 100644 index 000000000..3e31326c2 --- /dev/null +++ b/src/datadogV2/api/api_governance_settings.rs @@ -0,0 +1,779 @@ +// 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 flate2::{ + write::{GzEncoder, ZlibEncoder}, + Compression, +}; +use log::warn; +use reqwest::header::{HeaderMap, HeaderValue}; +use serde::{Deserialize, Serialize}; +use std::io::Write; + +/// GetGovernanceConfigError is a struct for typed errors of method [`GovernanceSettingsAPI::get_governance_config`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetGovernanceConfigError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// GetGovernanceNotificationSettingsError is a struct for typed errors of method [`GovernanceSettingsAPI::get_governance_notification_settings`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetGovernanceNotificationSettingsError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// ListGovernanceLimitsError is a struct for typed errors of method [`GovernanceSettingsAPI::list_governance_limits`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ListGovernanceLimitsError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// ListGovernanceResourceLimitsError is a struct for typed errors of method [`GovernanceSettingsAPI::list_governance_resource_limits`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ListGovernanceResourceLimitsError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// UpdateGovernanceNotificationSettingsError is a struct for typed errors of method [`GovernanceSettingsAPI::update_governance_notification_settings`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum UpdateGovernanceNotificationSettingsError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// Governance Settings cover organization-wide Governance Console configuration, usage limits and +/// resource limits, and notification preferences that determine when and how the Console alerts +/// users about governance activity. +#[derive(Debug, Clone)] +pub struct GovernanceSettingsAPI { + config: datadog::Configuration, + client: reqwest_middleware::ClientWithMiddleware, +} + +impl Default for GovernanceSettingsAPI { + fn default() -> Self { + Self::with_config(datadog::Configuration::default()) + } +} + +impl GovernanceSettingsAPI { + 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, + ) -> Option { + 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 } + } + + /// Retrieve the Governance Console configuration for the organization, including whether the + /// Console is enabled, whether assignment notifications are enabled, and whether usage + /// attribution is configured. + pub async fn get_governance_config( + &self, + ) -> Result< + crate::datadogV2::model::GovernanceConfigResponse, + datadog::Error, + > { + match self.get_governance_config_with_http_info().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), + } + } + + /// Retrieve the Governance Console configuration for the organization, including whether the + /// Console is enabled, whether assignment notifications are enabled, and whether usage + /// attribution is configured. + pub async fn get_governance_config_with_http_info( + &self, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.get_governance_config"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.get_governance_config' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/governance/config", + local_configuration.get_operation_host(operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + // 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::( + &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 = + 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)) + } + } + + /// Retrieve the organization-wide governance notification settings, including whether users are + /// notified when detections are assigned to them. + pub async fn get_governance_notification_settings( + &self, + ) -> Result< + crate::datadogV2::model::GovernanceNotificationSettingsResponse, + datadog::Error, + > { + match self + .get_governance_notification_settings_with_http_info() + .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), + } + } + + /// Retrieve the organization-wide governance notification settings, including whether users are + /// notified when detections are assigned to them. + pub async fn get_governance_notification_settings_with_http_info( + &self, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.get_governance_notification_settings"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.get_governance_notification_settings' is not enabled" + .to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/governance/notification_settings", + local_configuration.get_operation_host(operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + // 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::GovernanceNotificationSettingsResponse, + >(&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 = + 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)) + } + } + + /// Retrieve the list of usage limits tracked for the organization in the Governance Console. + /// Each limit reports the query used to compute current usage, the unit and time range it is + /// measured over, and its current usage status. + pub async fn list_governance_limits( + &self, + ) -> Result< + crate::datadogV2::model::GovernanceLimitsResponse, + datadog::Error, + > { + match self.list_governance_limits_with_http_info().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), + } + } + + /// Retrieve the list of usage limits tracked for the organization in the Governance Console. + /// Each limit reports the query used to compute current usage, the unit and time range it is + /// measured over, and its current usage status. + pub async fn list_governance_limits_with_http_info( + &self, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.list_governance_limits"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.list_governance_limits' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/governance/limits", + local_configuration.get_operation_host(operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + // 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::( + &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 = + 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)) + } + } + + /// Retrieve the list of resource limits tracked for the organization in the Governance Console. + /// Each resource limit reports its current value and configured limit, the queries used to + /// compute them, and its current usage status. + pub async fn list_governance_resource_limits( + &self, + ) -> Result< + crate::datadogV2::model::GovernanceResourceLimitsResponse, + datadog::Error, + > { + match self.list_governance_resource_limits_with_http_info().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), + } + } + + /// Retrieve the list of resource limits tracked for the organization in the Governance Console. + /// Each resource limit reports its current value and configured limit, the queries used to + /// compute them, and its current usage status. + pub async fn list_governance_resource_limits_with_http_info( + &self, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.list_governance_resource_limits"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.list_governance_resource_limits' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/governance/resource-limits", + local_configuration.get_operation_host(operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + // 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::( + &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 = + 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)) + } + } + + /// Update the organization-wide governance notification settings. Only the attributes present in + /// the request are modified. + pub async fn update_governance_notification_settings( + &self, + body: crate::datadogV2::model::GovernanceNotificationSettingsUpdateRequest, + ) -> Result< + crate::datadogV2::model::GovernanceNotificationSettingsResponse, + datadog::Error, + > { + match self + .update_governance_notification_settings_with_http_info(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), + } + } + + /// Update the organization-wide governance notification settings. Only the attributes present in + /// the request are modified. + pub async fn update_governance_notification_settings_with_http_info( + &self, + body: crate::datadogV2::model::GovernanceNotificationSettingsUpdateRequest, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.update_governance_notification_settings"; + 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_governance_notification_settings' is not enabled" + .to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/governance/notification_settings", + local_configuration.get_operation_host(operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::PATCH, 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)), + } + } + #[cfg(feature = "zstd")] + "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::GovernanceNotificationSettingsResponse, + >(&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 = + 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)) + } + } +} diff --git a/src/datadogV2/api/mod.rs b/src/datadogV2/api/mod.rs index 8ddf05a20..b6aba8b82 100644 --- a/src/datadogV2/api/mod.rs +++ b/src/datadogV2/api/mod.rs @@ -61,6 +61,7 @@ pub mod api_gcp_integration; pub mod api_google_chat_integration; pub mod api_governance_controls; pub mod api_governance_insights; +pub mod api_governance_settings; pub mod api_high_availability_multi_region; pub mod api_incidents; pub mod api_integrations; diff --git a/src/datadogV2/mod.rs b/src/datadogV2/mod.rs index 6dc5a58fa..e514ba86a 100644 --- a/src/datadogV2/mod.rs +++ b/src/datadogV2/mod.rs @@ -62,6 +62,7 @@ pub use self::api::api_gcp_integration; pub use self::api::api_google_chat_integration; pub use self::api::api_governance_controls; pub use self::api::api_governance_insights; +pub use self::api::api_governance_settings; pub use self::api::api_high_availability_multi_region; pub use self::api::api_incidents; pub use self::api::api_integrations; diff --git a/src/datadogV2/model/mod.rs b/src/datadogV2/model/mod.rs index 31806e554..38a08c994 100644 --- a/src/datadogV2/model/mod.rs +++ b/src/datadogV2/model/mod.rs @@ -4220,6 +4220,14 @@ pub mod model_global_orgs_meta_page; pub use self::model_global_orgs_meta_page::GlobalOrgsMetaPage; pub mod model_global_orgs_meta_page_type; pub use self::model_global_orgs_meta_page_type::GlobalOrgsMetaPageType; +pub mod model_governance_config_response; +pub use self::model_governance_config_response::GovernanceConfigResponse; +pub mod model_governance_config_data; +pub use self::model_governance_config_data::GovernanceConfigData; +pub mod model_governance_config_attributes; +pub use self::model_governance_config_attributes::GovernanceConfigAttributes; +pub mod model_governance_console_config_resource_type; +pub use self::model_governance_console_config_resource_type::GovernanceConsoleConfigResourceType; pub mod model_governance_controls_response; pub use self::model_governance_controls_response::GovernanceControlsResponse; pub mod model_governance_control_data; @@ -4242,6 +4250,48 @@ pub mod model_governance_control_update_data; pub use self::model_governance_control_update_data::GovernanceControlUpdateData; pub mod model_governance_control_update_attributes; pub use self::model_governance_control_update_attributes::GovernanceControlUpdateAttributes; +pub mod model_governance_control_detections_response; +pub use self::model_governance_control_detections_response::GovernanceControlDetectionsResponse; +pub mod model_governance_control_detection_data; +pub use self::model_governance_control_detection_data::GovernanceControlDetectionData; +pub mod model_governance_control_detection_attributes; +pub use self::model_governance_control_detection_attributes::GovernanceControlDetectionAttributes; +pub mod model_governance_control_detection_assignment_source; +pub use self::model_governance_control_detection_assignment_source::GovernanceControlDetectionAssignmentSource; +pub mod model_governance_control_detection_state; +pub use self::model_governance_control_detection_state::GovernanceControlDetectionState; +pub mod model_governance_control_detection_resource_type; +pub use self::model_governance_control_detection_resource_type::GovernanceControlDetectionResourceType; +pub mod model_governance_control_detection_response; +pub use self::model_governance_control_detection_response::GovernanceControlDetectionResponse; +pub mod model_governance_control_detection_update_request; +pub use self::model_governance_control_detection_update_request::GovernanceControlDetectionUpdateRequest; +pub mod model_governance_control_detection_update_data; +pub use self::model_governance_control_detection_update_data::GovernanceControlDetectionUpdateData; +pub mod model_governance_control_detection_update_attributes; +pub use self::model_governance_control_detection_update_attributes::GovernanceControlDetectionUpdateAttributes; +pub mod model_governance_control_detection_update_state; +pub use self::model_governance_control_detection_update_state::GovernanceControlDetectionUpdateState; +pub mod model_control_notification_settings_response; +pub use self::model_control_notification_settings_response::ControlNotificationSettingsResponse; +pub mod model_control_notification_settings_data; +pub use self::model_control_notification_settings_data::ControlNotificationSettingsData; +pub mod model_control_notification_settings_attributes; +pub use self::model_control_notification_settings_attributes::ControlNotificationSettingsAttributes; +pub mod model_control_notification_event_setting; +pub use self::model_control_notification_event_setting::ControlNotificationEventSetting; +pub mod model_control_notification_target; +pub use self::model_control_notification_target::ControlNotificationTarget; +pub mod model_control_notification_target_type; +pub use self::model_control_notification_target_type::ControlNotificationTargetType; +pub mod model_control_notification_settings_resource_type; +pub use self::model_control_notification_settings_resource_type::ControlNotificationSettingsResourceType; +pub mod model_control_notification_settings_update_request; +pub use self::model_control_notification_settings_update_request::ControlNotificationSettingsUpdateRequest; +pub mod model_control_notification_settings_update_data; +pub use self::model_control_notification_settings_update_data::ControlNotificationSettingsUpdateData; +pub mod model_control_notification_settings_update_attributes; +pub use self::model_control_notification_settings_update_attributes::ControlNotificationSettingsUpdateAttributes; pub mod model_governance_insights_response; pub use self::model_governance_insights_response::GovernanceInsightsResponse; pub mod model_governance_insight_data; @@ -4268,6 +4318,46 @@ pub mod model_governance_insight_usage_query; pub use self::model_governance_insight_usage_query::GovernanceInsightUsageQuery; pub mod model_governance_insight_resource_type; pub use self::model_governance_insight_resource_type::GovernanceInsightResourceType; +pub mod model_governance_limits_response; +pub use self::model_governance_limits_response::GovernanceLimitsResponse; +pub mod model_governance_limit_data; +pub use self::model_governance_limit_data::GovernanceLimitData; +pub mod model_governance_limit_attributes; +pub use self::model_governance_limit_attributes::GovernanceLimitAttributes; +pub mod model_governance_limit_query; +pub use self::model_governance_limit_query::GovernanceLimitQuery; +pub mod model_governance_limit_query_config; +pub use self::model_governance_limit_query_config::GovernanceLimitQueryConfig; +pub mod model_governance_limit_resource_type; +pub use self::model_governance_limit_resource_type::GovernanceLimitResourceType; +pub mod model_governance_mitigation_request; +pub use self::model_governance_mitigation_request::GovernanceMitigationRequest; +pub mod model_governance_mitigation_request_data; +pub use self::model_governance_mitigation_request_data::GovernanceMitigationRequestData; +pub mod model_governance_mitigation_request_attributes; +pub use self::model_governance_mitigation_request_attributes::GovernanceMitigationRequestAttributes; +pub mod model_governance_notification_settings_response; +pub use self::model_governance_notification_settings_response::GovernanceNotificationSettingsResponse; +pub mod model_governance_notification_settings_data; +pub use self::model_governance_notification_settings_data::GovernanceNotificationSettingsData; +pub mod model_governance_notification_settings_attributes; +pub use self::model_governance_notification_settings_attributes::GovernanceNotificationSettingsAttributes; +pub mod model_governance_notification_settings_resource_type; +pub use self::model_governance_notification_settings_resource_type::GovernanceNotificationSettingsResourceType; +pub mod model_governance_notification_settings_update_request; +pub use self::model_governance_notification_settings_update_request::GovernanceNotificationSettingsUpdateRequest; +pub mod model_governance_notification_settings_update_data; +pub use self::model_governance_notification_settings_update_data::GovernanceNotificationSettingsUpdateData; +pub mod model_governance_notification_settings_update_attributes; +pub use self::model_governance_notification_settings_update_attributes::GovernanceNotificationSettingsUpdateAttributes; +pub mod model_governance_resource_limits_response; +pub use self::model_governance_resource_limits_response::GovernanceResourceLimitsResponse; +pub mod model_governance_resource_limit_data; +pub use self::model_governance_resource_limit_data::GovernanceResourceLimitData; +pub mod model_governance_resource_limit_attributes; +pub use self::model_governance_resource_limit_attributes::GovernanceResourceLimitAttributes; +pub mod model_governance_resource_limit_resource_type; +pub use self::model_governance_resource_limit_resource_type::GovernanceResourceLimitResourceType; pub mod model_hamr_org_connection_response; pub use self::model_hamr_org_connection_response::HamrOrgConnectionResponse; pub mod model_hamr_org_connection_data_response; diff --git a/src/datadogV2/model/model_control_notification_event_setting.rs b/src/datadogV2/model/model_control_notification_event_setting.rs new file mode 100644 index 000000000..938a67657 --- /dev/null +++ b/src/datadogV2/model/model_control_notification_event_setting.rs @@ -0,0 +1,117 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The notification settings for a single event type on a control. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ControlNotificationEventSetting { + /// Whether notifications are enabled for this event type. + #[serde(rename = "enabled")] + pub enabled: bool, + /// The event type the notification settings apply to, such as `new_detection`. + #[serde(rename = "event_type")] + pub event_type: String, + /// The destinations that receive notifications for an event type. + #[serde(rename = "targets")] + pub targets: Vec, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ControlNotificationEventSetting { + pub fn new( + enabled: bool, + event_type: String, + targets: Vec, + ) -> ControlNotificationEventSetting { + ControlNotificationEventSetting { + enabled, + event_type, + targets, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for ControlNotificationEventSetting { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ControlNotificationEventSettingVisitor; + impl<'a> Visitor<'a> for ControlNotificationEventSettingVisitor { + type Value = ControlNotificationEventSetting; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut enabled: Option = None; + let mut event_type: Option = None; + let mut targets: Option> = + None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "enabled" => { + enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "event_type" => { + event_type = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "targets" => { + targets = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let enabled = enabled.ok_or_else(|| M::Error::missing_field("enabled"))?; + let event_type = event_type.ok_or_else(|| M::Error::missing_field("event_type"))?; + let targets = targets.ok_or_else(|| M::Error::missing_field("targets"))?; + + let content = ControlNotificationEventSetting { + enabled, + event_type, + targets, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ControlNotificationEventSettingVisitor) + } +} diff --git a/src/datadogV2/model/model_control_notification_settings_attributes.rs b/src/datadogV2/model/model_control_notification_settings_attributes.rs new file mode 100644 index 000000000..28df6ead2 --- /dev/null +++ b/src/datadogV2/model/model_control_notification_settings_attributes.rs @@ -0,0 +1,98 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The attributes of a governance control's notification settings. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ControlNotificationSettingsAttributes { + /// The notification settings for each supported event type on the control. + #[serde(rename = "event_settings")] + pub event_settings: Vec, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ControlNotificationSettingsAttributes { + pub fn new( + event_settings: Vec, + ) -> ControlNotificationSettingsAttributes { + ControlNotificationSettingsAttributes { + event_settings, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for ControlNotificationSettingsAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ControlNotificationSettingsAttributesVisitor; + impl<'a> Visitor<'a> for ControlNotificationSettingsAttributesVisitor { + type Value = ControlNotificationSettingsAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut event_settings: Option< + Vec, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "event_settings" => { + event_settings = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let event_settings = + event_settings.ok_or_else(|| M::Error::missing_field("event_settings"))?; + + let content = ControlNotificationSettingsAttributes { + event_settings, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ControlNotificationSettingsAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_control_notification_settings_data.rs b/src/datadogV2/model/model_control_notification_settings_data.rs new file mode 100644 index 000000000..5d3e93ed5 --- /dev/null +++ b/src/datadogV2/model/model_control_notification_settings_data.rs @@ -0,0 +1,128 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A control notification settings resource. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ControlNotificationSettingsData { + /// The attributes of a governance control's notification settings. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::ControlNotificationSettingsAttributes, + /// The detection type the notification settings apply to. + #[serde(rename = "id")] + pub id: String, + /// Control notification settings resource type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::ControlNotificationSettingsResourceType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ControlNotificationSettingsData { + pub fn new( + attributes: crate::datadogV2::model::ControlNotificationSettingsAttributes, + id: String, + type_: crate::datadogV2::model::ControlNotificationSettingsResourceType, + ) -> ControlNotificationSettingsData { + ControlNotificationSettingsData { + attributes, + id, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for ControlNotificationSettingsData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ControlNotificationSettingsDataVisitor; + impl<'a> Visitor<'a> for ControlNotificationSettingsDataVisitor { + type Value = ControlNotificationSettingsData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option< + crate::datadogV2::model::ControlNotificationSettingsAttributes, + > = None; + let mut id: Option = None; + let mut type_: Option< + crate::datadogV2::model::ControlNotificationSettingsResourceType, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::ControlNotificationSettingsResourceType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?; + let id = id.ok_or_else(|| M::Error::missing_field("id"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = ControlNotificationSettingsData { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ControlNotificationSettingsDataVisitor) + } +} diff --git a/src/datadogV2/model/model_control_notification_settings_resource_type.rs b/src/datadogV2/model/model_control_notification_settings_resource_type.rs new file mode 100644 index 000000000..f13ac7bb6 --- /dev/null +++ b/src/datadogV2/model/model_control_notification_settings_resource_type.rs @@ -0,0 +1,48 @@ +// 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 serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum ControlNotificationSettingsResourceType { + CONTROL_NOTIFICATION_SETTINGS, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for ControlNotificationSettingsResourceType { + fn to_string(&self) -> String { + match self { + Self::CONTROL_NOTIFICATION_SETTINGS => String::from("control_notification_settings"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for ControlNotificationSettingsResourceType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for ControlNotificationSettingsResourceType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "control_notification_settings" => Self::CONTROL_NOTIFICATION_SETTINGS, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_control_notification_settings_response.rs b/src/datadogV2/model/model_control_notification_settings_response.rs new file mode 100644 index 000000000..ebd8e9307 --- /dev/null +++ b/src/datadogV2/model/model_control_notification_settings_response.rs @@ -0,0 +1,95 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The notification settings for a governance control. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ControlNotificationSettingsResponse { + /// A control notification settings resource. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::ControlNotificationSettingsData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ControlNotificationSettingsResponse { + pub fn new( + data: crate::datadogV2::model::ControlNotificationSettingsData, + ) -> ControlNotificationSettingsResponse { + ControlNotificationSettingsResponse { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for ControlNotificationSettingsResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ControlNotificationSettingsResponseVisitor; + impl<'a> Visitor<'a> for ControlNotificationSettingsResponseVisitor { + type Value = ControlNotificationSettingsResponse; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option = + None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = ControlNotificationSettingsResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ControlNotificationSettingsResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_control_notification_settings_update_attributes.rs b/src/datadogV2/model/model_control_notification_settings_update_attributes.rs new file mode 100644 index 000000000..b46896507 --- /dev/null +++ b/src/datadogV2/model/model_control_notification_settings_update_attributes.rs @@ -0,0 +1,111 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The attributes of a governance control's notification settings that can be updated. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ControlNotificationSettingsUpdateAttributes { + /// The notification settings for each supported event type on the control. + #[serde(rename = "event_settings")] + pub event_settings: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ControlNotificationSettingsUpdateAttributes { + pub fn new() -> ControlNotificationSettingsUpdateAttributes { + ControlNotificationSettingsUpdateAttributes { + event_settings: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn event_settings( + mut self, + value: Vec, + ) -> Self { + self.event_settings = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for ControlNotificationSettingsUpdateAttributes { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for ControlNotificationSettingsUpdateAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ControlNotificationSettingsUpdateAttributesVisitor; + impl<'a> Visitor<'a> for ControlNotificationSettingsUpdateAttributesVisitor { + type Value = ControlNotificationSettingsUpdateAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut event_settings: Option< + Vec, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "event_settings" => { + if v.is_null() { + continue; + } + event_settings = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = ControlNotificationSettingsUpdateAttributes { + event_settings, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ControlNotificationSettingsUpdateAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_control_notification_settings_update_data.rs b/src/datadogV2/model/model_control_notification_settings_update_data.rs new file mode 100644 index 000000000..2d689eb98 --- /dev/null +++ b/src/datadogV2/model/model_control_notification_settings_update_data.rs @@ -0,0 +1,126 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The data of a control notification settings update request. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ControlNotificationSettingsUpdateData { + /// The attributes of a governance control's notification settings that can be updated. + #[serde(rename = "attributes")] + pub attributes: Option, + /// Control notification settings resource type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::ControlNotificationSettingsResourceType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ControlNotificationSettingsUpdateData { + pub fn new( + type_: crate::datadogV2::model::ControlNotificationSettingsResourceType, + ) -> ControlNotificationSettingsUpdateData { + ControlNotificationSettingsUpdateData { + attributes: None, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes( + mut self, + value: crate::datadogV2::model::ControlNotificationSettingsUpdateAttributes, + ) -> Self { + self.attributes = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for ControlNotificationSettingsUpdateData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ControlNotificationSettingsUpdateDataVisitor; + impl<'a> Visitor<'a> for ControlNotificationSettingsUpdateDataVisitor { + type Value = ControlNotificationSettingsUpdateData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option< + crate::datadogV2::model::ControlNotificationSettingsUpdateAttributes, + > = None; + let mut type_: Option< + crate::datadogV2::model::ControlNotificationSettingsResourceType, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + if v.is_null() { + continue; + } + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::ControlNotificationSettingsResourceType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = ControlNotificationSettingsUpdateData { + attributes, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ControlNotificationSettingsUpdateDataVisitor) + } +} diff --git a/src/datadogV2/model/model_control_notification_settings_update_request.rs b/src/datadogV2/model/model_control_notification_settings_update_request.rs new file mode 100644 index 000000000..64e5d17c6 --- /dev/null +++ b/src/datadogV2/model/model_control_notification_settings_update_request.rs @@ -0,0 +1,96 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A request to update the notification settings for a governance control. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ControlNotificationSettingsUpdateRequest { + /// The data of a control notification settings update request. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::ControlNotificationSettingsUpdateData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ControlNotificationSettingsUpdateRequest { + pub fn new( + data: crate::datadogV2::model::ControlNotificationSettingsUpdateData, + ) -> ControlNotificationSettingsUpdateRequest { + ControlNotificationSettingsUpdateRequest { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for ControlNotificationSettingsUpdateRequest { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ControlNotificationSettingsUpdateRequestVisitor; + impl<'a> Visitor<'a> for ControlNotificationSettingsUpdateRequestVisitor { + type Value = ControlNotificationSettingsUpdateRequest; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option< + crate::datadogV2::model::ControlNotificationSettingsUpdateData, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = ControlNotificationSettingsUpdateRequest { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ControlNotificationSettingsUpdateRequestVisitor) + } +} diff --git a/src/datadogV2/model/model_control_notification_target.rs b/src/datadogV2/model/model_control_notification_target.rs new file mode 100644 index 000000000..3e7b5acff --- /dev/null +++ b/src/datadogV2/model/model_control_notification_target.rs @@ -0,0 +1,114 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A destination that receives notifications for an event type. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ControlNotificationTarget { + /// The destination handle, such as an email address, Slack channel, or user handle. + #[serde(rename = "handle")] + pub handle: String, + /// The type of notification destination. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::ControlNotificationTargetType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ControlNotificationTarget { + pub fn new( + handle: String, + type_: crate::datadogV2::model::ControlNotificationTargetType, + ) -> ControlNotificationTarget { + ControlNotificationTarget { + handle, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for ControlNotificationTarget { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ControlNotificationTargetVisitor; + impl<'a> Visitor<'a> for ControlNotificationTargetVisitor { + type Value = ControlNotificationTarget; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut handle: Option = None; + let mut type_: Option = + None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "handle" => { + handle = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::ControlNotificationTargetType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let handle = handle.ok_or_else(|| M::Error::missing_field("handle"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = ControlNotificationTarget { + handle, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ControlNotificationTargetVisitor) + } +} diff --git a/src/datadogV2/model/model_control_notification_target_type.rs b/src/datadogV2/model/model_control_notification_target_type.rs new file mode 100644 index 000000000..8aa7d5fb0 --- /dev/null +++ b/src/datadogV2/model/model_control_notification_target_type.rs @@ -0,0 +1,57 @@ +// 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 serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum ControlNotificationTargetType { + EMAIL, + SLACK, + AT_MENTION, + CASE, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for ControlNotificationTargetType { + fn to_string(&self) -> String { + match self { + Self::EMAIL => String::from("email"), + Self::SLACK => String::from("slack"), + Self::AT_MENTION => String::from("at_mention"), + Self::CASE => String::from("case"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for ControlNotificationTargetType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for ControlNotificationTargetType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "email" => Self::EMAIL, + "slack" => Self::SLACK, + "at_mention" => Self::AT_MENTION, + "case" => Self::CASE, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_governance_config_attributes.rs b/src/datadogV2/model/model_governance_config_attributes.rs new file mode 100644 index 000000000..45928ff8c --- /dev/null +++ b/src/datadogV2/model/model_governance_config_attributes.rs @@ -0,0 +1,120 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The attributes of a Governance Console configuration. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceConfigAttributes { + /// Whether notifications are sent to users when detections are assigned to them. + #[serde(rename = "assignment_notifications_enabled")] + pub assignment_notifications_enabled: bool, + /// Whether the Governance Console is enabled for the organization. + #[serde(rename = "enabled")] + pub enabled: bool, + /// Whether usage attribution is configured for the organization. + #[serde(rename = "usage_attribution_configured")] + pub usage_attribution_configured: bool, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceConfigAttributes { + pub fn new( + assignment_notifications_enabled: bool, + enabled: bool, + usage_attribution_configured: bool, + ) -> GovernanceConfigAttributes { + GovernanceConfigAttributes { + assignment_notifications_enabled, + enabled, + usage_attribution_configured, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceConfigAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceConfigAttributesVisitor; + impl<'a> Visitor<'a> for GovernanceConfigAttributesVisitor { + type Value = GovernanceConfigAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut assignment_notifications_enabled: Option = None; + let mut enabled: Option = None; + let mut usage_attribution_configured: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "assignment_notifications_enabled" => { + assignment_notifications_enabled = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "enabled" => { + enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "usage_attribution_configured" => { + usage_attribution_configured = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let assignment_notifications_enabled = assignment_notifications_enabled + .ok_or_else(|| M::Error::missing_field("assignment_notifications_enabled"))?; + let enabled = enabled.ok_or_else(|| M::Error::missing_field("enabled"))?; + let usage_attribution_configured = usage_attribution_configured + .ok_or_else(|| M::Error::missing_field("usage_attribution_configured"))?; + + let content = GovernanceConfigAttributes { + assignment_notifications_enabled, + enabled, + usage_attribution_configured, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceConfigAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_config_data.rs b/src/datadogV2/model/model_governance_config_data.rs new file mode 100644 index 000000000..6665b9318 --- /dev/null +++ b/src/datadogV2/model/model_governance_config_data.rs @@ -0,0 +1,127 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A Governance Console configuration resource. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceConfigData { + /// The attributes of a Governance Console configuration. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::GovernanceConfigAttributes, + /// The unique identifier of the organization the Governance Console configuration applies to. + #[serde(rename = "id")] + pub id: String, + /// Governance console config resource type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::GovernanceConsoleConfigResourceType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceConfigData { + pub fn new( + attributes: crate::datadogV2::model::GovernanceConfigAttributes, + id: String, + type_: crate::datadogV2::model::GovernanceConsoleConfigResourceType, + ) -> GovernanceConfigData { + GovernanceConfigData { + attributes, + id, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceConfigData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceConfigDataVisitor; + impl<'a> Visitor<'a> for GovernanceConfigDataVisitor { + type Value = GovernanceConfigData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option = + None; + let mut id: Option = None; + let mut type_: Option< + crate::datadogV2::model::GovernanceConsoleConfigResourceType, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::GovernanceConsoleConfigResourceType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?; + let id = id.ok_or_else(|| M::Error::missing_field("id"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = GovernanceConfigData { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceConfigDataVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_config_response.rs b/src/datadogV2/model/model_governance_config_response.rs new file mode 100644 index 000000000..55629664f --- /dev/null +++ b/src/datadogV2/model/model_governance_config_response.rs @@ -0,0 +1,92 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The Governance Console configuration for an organization. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceConfigResponse { + /// A Governance Console configuration resource. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::GovernanceConfigData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceConfigResponse { + pub fn new(data: crate::datadogV2::model::GovernanceConfigData) -> GovernanceConfigResponse { + GovernanceConfigResponse { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceConfigResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceConfigResponseVisitor; + impl<'a> Visitor<'a> for GovernanceConfigResponseVisitor { + type Value = GovernanceConfigResponse; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = GovernanceConfigResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceConfigResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_console_config_resource_type.rs b/src/datadogV2/model/model_governance_console_config_resource_type.rs new file mode 100644 index 000000000..2729074d8 --- /dev/null +++ b/src/datadogV2/model/model_governance_console_config_resource_type.rs @@ -0,0 +1,48 @@ +// 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 serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum GovernanceConsoleConfigResourceType { + GOVERNANCE_CONSOLE_CONFIG, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for GovernanceConsoleConfigResourceType { + fn to_string(&self) -> String { + match self { + Self::GOVERNANCE_CONSOLE_CONFIG => String::from("governance_console_config"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for GovernanceConsoleConfigResourceType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for GovernanceConsoleConfigResourceType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "governance_console_config" => Self::GOVERNANCE_CONSOLE_CONFIG, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_governance_control_detection_assignment_source.rs b/src/datadogV2/model/model_governance_control_detection_assignment_source.rs new file mode 100644 index 000000000..bfb139a7c --- /dev/null +++ b/src/datadogV2/model/model_governance_control_detection_assignment_source.rs @@ -0,0 +1,57 @@ +// 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 serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum GovernanceControlDetectionAssignmentSource { + AUTO_RESOLVED, + MANUAL, + REASSIGNED, + CLEARED, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for GovernanceControlDetectionAssignmentSource { + fn to_string(&self) -> String { + match self { + Self::AUTO_RESOLVED => String::from("auto_resolved"), + Self::MANUAL => String::from("manual"), + Self::REASSIGNED => String::from("reassigned"), + Self::CLEARED => String::from("cleared"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for GovernanceControlDetectionAssignmentSource { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for GovernanceControlDetectionAssignmentSource { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "auto_resolved" => Self::AUTO_RESOLVED, + "manual" => Self::MANUAL, + "reassigned" => Self::REASSIGNED, + "cleared" => Self::CLEARED, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_governance_control_detection_attributes.rs b/src/datadogV2/model/model_governance_control_detection_attributes.rs new file mode 100644 index 000000000..6b789cf45 --- /dev/null +++ b/src/datadogV2/model/model_governance_control_detection_attributes.rs @@ -0,0 +1,336 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The attributes of a governance control detection. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceControlDetectionAttributes { + /// The identifier of the team the detection is assigned to, if any. + #[serde(rename = "assigned_team")] + pub assigned_team: Option, + /// The identifier of the user the detection is assigned to, if any. + #[serde(rename = "assigned_to")] + pub assigned_to: Option, + /// How the detection's current assignment was determined. Possible values are `auto_resolved`, `manual`, `reassigned`, and `cleared`. + #[serde(rename = "assignment_source")] + pub assignment_source: crate::datadogV2::model::GovernanceControlDetectionAssignmentSource, + /// The unique identifier of the control that produced this detection. + #[serde(rename = "control_id")] + pub control_id: String, + /// The date and time when the detection was created. + #[serde(rename = "created_at")] + pub created_at: chrono::DateTime, + /// The type of detection, which determines what condition was detected. + #[serde(rename = "detection_type")] + pub detection_type: String, + /// The human-readable name of the detected resource. + #[serde(rename = "display_name")] + pub display_name: String, + /// The date and time when the detection was marked as an exception, if applicable. + #[serde(rename = "exception_at")] + pub exception_at: Option>, + /// The identifier of the user who marked the detection as an exception, if applicable. + #[serde(rename = "exception_by")] + pub exception_by: Option, + /// Free-form metadata associated with the detection. + #[serde(rename = "metadata")] + pub metadata: Option, + /// The date and time after which the detection is scheduled to be mitigated, if applicable. + #[serde(rename = "mitigate_after")] + pub mitigate_after: Option>, + /// The date and time when the detection was mitigated, if applicable. + #[serde(rename = "mitigated_at")] + pub mitigated_at: Option>, + /// The priority of the detection, if set. + #[serde(rename = "priority")] + pub priority: i64, + /// The identifier of the resource the detection applies to. + #[serde(rename = "resource_id")] + pub resource_id: String, + /// A link to the detected resource in Datadog. + #[serde(rename = "resource_url")] + pub resource_url: String, + /// The current state of the detection. Possible values are `active`, `exception`, `mitigated`, `inactive`, `obsolete`, `resolved_externally`, and `mitigation_in_progress`. + #[serde(rename = "state")] + pub state: crate::datadogV2::model::GovernanceControlDetectionState, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceControlDetectionAttributes { + pub fn new( + assignment_source: crate::datadogV2::model::GovernanceControlDetectionAssignmentSource, + control_id: String, + created_at: chrono::DateTime, + detection_type: String, + display_name: String, + priority: i64, + resource_id: String, + resource_url: String, + state: crate::datadogV2::model::GovernanceControlDetectionState, + ) -> GovernanceControlDetectionAttributes { + GovernanceControlDetectionAttributes { + assigned_team: None, + assigned_to: None, + assignment_source, + control_id, + created_at, + detection_type, + display_name, + exception_at: None, + exception_by: None, + metadata: None, + mitigate_after: None, + mitigated_at: None, + priority, + resource_id, + resource_url, + state, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn assigned_team(mut self, value: String) -> Self { + self.assigned_team = Some(value); + self + } + + pub fn assigned_to(mut self, value: String) -> Self { + self.assigned_to = Some(value); + self + } + + pub fn exception_at(mut self, value: chrono::DateTime) -> Self { + self.exception_at = Some(value); + self + } + + pub fn exception_by(mut self, value: String) -> Self { + self.exception_by = Some(value); + self + } + + pub fn metadata(mut self, value: serde_json::Value) -> Self { + self.metadata = Some(value); + self + } + + pub fn mitigate_after(mut self, value: chrono::DateTime) -> Self { + self.mitigate_after = Some(value); + self + } + + pub fn mitigated_at(mut self, value: chrono::DateTime) -> Self { + self.mitigated_at = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceControlDetectionAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceControlDetectionAttributesVisitor; + impl<'a> Visitor<'a> for GovernanceControlDetectionAttributesVisitor { + type Value = GovernanceControlDetectionAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut assigned_team: Option = None; + let mut assigned_to: Option = None; + let mut assignment_source: Option< + crate::datadogV2::model::GovernanceControlDetectionAssignmentSource, + > = None; + let mut control_id: Option = None; + let mut created_at: Option> = None; + let mut detection_type: Option = None; + let mut display_name: Option = None; + let mut exception_at: Option> = None; + let mut exception_by: Option = None; + let mut metadata: Option = None; + let mut mitigate_after: Option> = None; + let mut mitigated_at: Option> = None; + let mut priority: Option = None; + let mut resource_id: Option = None; + let mut resource_url: Option = None; + let mut state: Option = + None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "assigned_team" => { + if v.is_null() { + continue; + } + assigned_team = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "assigned_to" => { + if v.is_null() { + continue; + } + assigned_to = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "assignment_source" => { + assignment_source = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _assignment_source) = assignment_source { + match _assignment_source { + crate::datadogV2::model::GovernanceControlDetectionAssignmentSource::UnparsedObject(_assignment_source) => { + _unparsed = true; + }, + _ => {} + } + } + } + "control_id" => { + control_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "created_at" => { + created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "detection_type" => { + detection_type = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "display_name" => { + display_name = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "exception_at" => { + if v.is_null() { + continue; + } + exception_at = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "exception_by" => { + if v.is_null() { + continue; + } + exception_by = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "metadata" => { + if v.is_null() { + continue; + } + metadata = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "mitigate_after" => { + if v.is_null() { + continue; + } + mitigate_after = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "mitigated_at" => { + if v.is_null() { + continue; + } + mitigated_at = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "priority" => { + priority = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "resource_id" => { + resource_id = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "resource_url" => { + resource_url = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "state" => { + state = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _state) = state { + match _state { + crate::datadogV2::model::GovernanceControlDetectionState::UnparsedObject(_state) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let assignment_source = assignment_source + .ok_or_else(|| M::Error::missing_field("assignment_source"))?; + let control_id = control_id.ok_or_else(|| M::Error::missing_field("control_id"))?; + let created_at = created_at.ok_or_else(|| M::Error::missing_field("created_at"))?; + let detection_type = + detection_type.ok_or_else(|| M::Error::missing_field("detection_type"))?; + let display_name = + display_name.ok_or_else(|| M::Error::missing_field("display_name"))?; + let priority = priority.ok_or_else(|| M::Error::missing_field("priority"))?; + let resource_id = + resource_id.ok_or_else(|| M::Error::missing_field("resource_id"))?; + let resource_url = + resource_url.ok_or_else(|| M::Error::missing_field("resource_url"))?; + let state = state.ok_or_else(|| M::Error::missing_field("state"))?; + + let content = GovernanceControlDetectionAttributes { + assigned_team, + assigned_to, + assignment_source, + control_id, + created_at, + detection_type, + display_name, + exception_at, + exception_by, + metadata, + mitigate_after, + mitigated_at, + priority, + resource_id, + resource_url, + state, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceControlDetectionAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_control_detection_data.rs b/src/datadogV2/model/model_governance_control_detection_data.rs new file mode 100644 index 000000000..96a589b95 --- /dev/null +++ b/src/datadogV2/model/model_governance_control_detection_data.rs @@ -0,0 +1,128 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A governance control detection resource. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceControlDetectionData { + /// The attributes of a governance control detection. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::GovernanceControlDetectionAttributes, + /// The unique identifier of the detection. + #[serde(rename = "id")] + pub id: String, + /// Governance control detection resource type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::GovernanceControlDetectionResourceType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceControlDetectionData { + pub fn new( + attributes: crate::datadogV2::model::GovernanceControlDetectionAttributes, + id: String, + type_: crate::datadogV2::model::GovernanceControlDetectionResourceType, + ) -> GovernanceControlDetectionData { + GovernanceControlDetectionData { + attributes, + id, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceControlDetectionData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceControlDetectionDataVisitor; + impl<'a> Visitor<'a> for GovernanceControlDetectionDataVisitor { + type Value = GovernanceControlDetectionData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option< + crate::datadogV2::model::GovernanceControlDetectionAttributes, + > = None; + let mut id: Option = None; + let mut type_: Option< + crate::datadogV2::model::GovernanceControlDetectionResourceType, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::GovernanceControlDetectionResourceType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?; + let id = id.ok_or_else(|| M::Error::missing_field("id"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = GovernanceControlDetectionData { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceControlDetectionDataVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_control_detection_resource_type.rs b/src/datadogV2/model/model_governance_control_detection_resource_type.rs new file mode 100644 index 000000000..10f79d2f9 --- /dev/null +++ b/src/datadogV2/model/model_governance_control_detection_resource_type.rs @@ -0,0 +1,48 @@ +// 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 serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum GovernanceControlDetectionResourceType { + GOVERNANCE_CONTROL_DETECTION, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for GovernanceControlDetectionResourceType { + fn to_string(&self) -> String { + match self { + Self::GOVERNANCE_CONTROL_DETECTION => String::from("governance_control_detection"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for GovernanceControlDetectionResourceType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for GovernanceControlDetectionResourceType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "governance_control_detection" => Self::GOVERNANCE_CONTROL_DETECTION, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_governance_control_detection_response.rs b/src/datadogV2/model/model_governance_control_detection_response.rs new file mode 100644 index 000000000..c8ec2809b --- /dev/null +++ b/src/datadogV2/model/model_governance_control_detection_response.rs @@ -0,0 +1,95 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A single governance control detection. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceControlDetectionResponse { + /// A governance control detection resource. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::GovernanceControlDetectionData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceControlDetectionResponse { + pub fn new( + data: crate::datadogV2::model::GovernanceControlDetectionData, + ) -> GovernanceControlDetectionResponse { + GovernanceControlDetectionResponse { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceControlDetectionResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceControlDetectionResponseVisitor; + impl<'a> Visitor<'a> for GovernanceControlDetectionResponseVisitor { + type Value = GovernanceControlDetectionResponse; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option = + None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = GovernanceControlDetectionResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceControlDetectionResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_control_detection_state.rs b/src/datadogV2/model/model_governance_control_detection_state.rs new file mode 100644 index 000000000..53ffe6abf --- /dev/null +++ b/src/datadogV2/model/model_governance_control_detection_state.rs @@ -0,0 +1,66 @@ +// 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 serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum GovernanceControlDetectionState { + ACTIVE, + EXCEPTION, + MITIGATED, + INACTIVE, + OBSOLETE, + RESOLVED_EXTERNALLY, + MITIGATION_IN_PROGRESS, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for GovernanceControlDetectionState { + fn to_string(&self) -> String { + match self { + Self::ACTIVE => String::from("active"), + Self::EXCEPTION => String::from("exception"), + Self::MITIGATED => String::from("mitigated"), + Self::INACTIVE => String::from("inactive"), + Self::OBSOLETE => String::from("obsolete"), + Self::RESOLVED_EXTERNALLY => String::from("resolved_externally"), + Self::MITIGATION_IN_PROGRESS => String::from("mitigation_in_progress"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for GovernanceControlDetectionState { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for GovernanceControlDetectionState { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "active" => Self::ACTIVE, + "exception" => Self::EXCEPTION, + "mitigated" => Self::MITIGATED, + "inactive" => Self::INACTIVE, + "obsolete" => Self::OBSOLETE, + "resolved_externally" => Self::RESOLVED_EXTERNALLY, + "mitigation_in_progress" => Self::MITIGATION_IN_PROGRESS, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_governance_control_detection_update_attributes.rs b/src/datadogV2/model/model_governance_control_detection_update_attributes.rs new file mode 100644 index 000000000..a207643af --- /dev/null +++ b/src/datadogV2/model/model_governance_control_detection_update_attributes.rs @@ -0,0 +1,172 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The attributes of a governance control detection that can be updated. Only the attributes present in the request are modified. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceControlDetectionUpdateAttributes { + /// The handle of the team the detection is assigned to. Set to an empty string to clear the assignment. + #[serde(rename = "assigned_team")] + pub assigned_team: Option, + /// The UUID of the user the detection is assigned to. Set to an empty string to clear the assignment. + #[serde(rename = "assigned_to")] + pub assigned_to: Option, + /// The timestamp after which the detection becomes eligible for mitigation. Used to defer mitigation to a later time. + #[serde(rename = "mitigate_after")] + pub mitigate_after: Option>, + /// The new state to set for the detection. Set to `exception` to acknowledge the detection and exclude it from active counts, or `active` to reopen it. + #[serde(rename = "state")] + pub state: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceControlDetectionUpdateAttributes { + pub fn new() -> GovernanceControlDetectionUpdateAttributes { + GovernanceControlDetectionUpdateAttributes { + assigned_team: None, + assigned_to: None, + mitigate_after: None, + state: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn assigned_team(mut self, value: String) -> Self { + self.assigned_team = Some(value); + self + } + + pub fn assigned_to(mut self, value: String) -> Self { + self.assigned_to = Some(value); + self + } + + pub fn mitigate_after(mut self, value: chrono::DateTime) -> Self { + self.mitigate_after = Some(value); + self + } + + pub fn state( + mut self, + value: crate::datadogV2::model::GovernanceControlDetectionUpdateState, + ) -> Self { + self.state = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for GovernanceControlDetectionUpdateAttributes { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for GovernanceControlDetectionUpdateAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceControlDetectionUpdateAttributesVisitor; + impl<'a> Visitor<'a> for GovernanceControlDetectionUpdateAttributesVisitor { + type Value = GovernanceControlDetectionUpdateAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut assigned_team: Option = None; + let mut assigned_to: Option = None; + let mut mitigate_after: Option> = None; + let mut state: Option< + crate::datadogV2::model::GovernanceControlDetectionUpdateState, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "assigned_team" => { + if v.is_null() { + continue; + } + assigned_team = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "assigned_to" => { + if v.is_null() { + continue; + } + assigned_to = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "mitigate_after" => { + if v.is_null() { + continue; + } + mitigate_after = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "state" => { + if v.is_null() { + continue; + } + state = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _state) = state { + match _state { + crate::datadogV2::model::GovernanceControlDetectionUpdateState::UnparsedObject(_state) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = GovernanceControlDetectionUpdateAttributes { + assigned_team, + assigned_to, + mitigate_after, + state, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceControlDetectionUpdateAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_control_detection_update_data.rs b/src/datadogV2/model/model_governance_control_detection_update_data.rs new file mode 100644 index 000000000..5d67b920e --- /dev/null +++ b/src/datadogV2/model/model_governance_control_detection_update_data.rs @@ -0,0 +1,126 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The data of a governance control detection update request. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceControlDetectionUpdateData { + /// The attributes of a governance control detection that can be updated. Only the attributes present in the request are modified. + #[serde(rename = "attributes")] + pub attributes: Option, + /// Governance control detection resource type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::GovernanceControlDetectionResourceType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceControlDetectionUpdateData { + pub fn new( + type_: crate::datadogV2::model::GovernanceControlDetectionResourceType, + ) -> GovernanceControlDetectionUpdateData { + GovernanceControlDetectionUpdateData { + attributes: None, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes( + mut self, + value: crate::datadogV2::model::GovernanceControlDetectionUpdateAttributes, + ) -> Self { + self.attributes = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceControlDetectionUpdateData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceControlDetectionUpdateDataVisitor; + impl<'a> Visitor<'a> for GovernanceControlDetectionUpdateDataVisitor { + type Value = GovernanceControlDetectionUpdateData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option< + crate::datadogV2::model::GovernanceControlDetectionUpdateAttributes, + > = None; + let mut type_: Option< + crate::datadogV2::model::GovernanceControlDetectionResourceType, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + if v.is_null() { + continue; + } + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::GovernanceControlDetectionResourceType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = GovernanceControlDetectionUpdateData { + attributes, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceControlDetectionUpdateDataVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_control_detection_update_request.rs b/src/datadogV2/model/model_governance_control_detection_update_request.rs new file mode 100644 index 000000000..3a194cf94 --- /dev/null +++ b/src/datadogV2/model/model_governance_control_detection_update_request.rs @@ -0,0 +1,96 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A request to update a governance control detection. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceControlDetectionUpdateRequest { + /// The data of a governance control detection update request. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::GovernanceControlDetectionUpdateData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceControlDetectionUpdateRequest { + pub fn new( + data: crate::datadogV2::model::GovernanceControlDetectionUpdateData, + ) -> GovernanceControlDetectionUpdateRequest { + GovernanceControlDetectionUpdateRequest { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceControlDetectionUpdateRequest { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceControlDetectionUpdateRequestVisitor; + impl<'a> Visitor<'a> for GovernanceControlDetectionUpdateRequestVisitor { + type Value = GovernanceControlDetectionUpdateRequest; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option< + crate::datadogV2::model::GovernanceControlDetectionUpdateData, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = GovernanceControlDetectionUpdateRequest { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceControlDetectionUpdateRequestVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_control_detection_update_state.rs b/src/datadogV2/model/model_governance_control_detection_update_state.rs new file mode 100644 index 000000000..567d8e5f1 --- /dev/null +++ b/src/datadogV2/model/model_governance_control_detection_update_state.rs @@ -0,0 +1,51 @@ +// 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 serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum GovernanceControlDetectionUpdateState { + EXCEPTION, + ACTIVE, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for GovernanceControlDetectionUpdateState { + fn to_string(&self) -> String { + match self { + Self::EXCEPTION => String::from("exception"), + Self::ACTIVE => String::from("active"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for GovernanceControlDetectionUpdateState { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for GovernanceControlDetectionUpdateState { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "exception" => Self::EXCEPTION, + "active" => Self::ACTIVE, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_governance_control_detections_response.rs b/src/datadogV2/model/model_governance_control_detections_response.rs new file mode 100644 index 000000000..b0a398081 --- /dev/null +++ b/src/datadogV2/model/model_governance_control_detections_response.rs @@ -0,0 +1,95 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A list of governance control detections. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceControlDetectionsResponse { + /// An array of governance control detection resources. + #[serde(rename = "data")] + pub data: Vec, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceControlDetectionsResponse { + pub fn new( + data: Vec, + ) -> GovernanceControlDetectionsResponse { + GovernanceControlDetectionsResponse { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceControlDetectionsResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceControlDetectionsResponseVisitor; + impl<'a> Visitor<'a> for GovernanceControlDetectionsResponseVisitor { + type Value = GovernanceControlDetectionsResponse; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option> = + None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = GovernanceControlDetectionsResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceControlDetectionsResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_insight_query_config.rs b/src/datadogV2/model/model_governance_insight_query_config.rs index 1336c804b..faeecb734 100644 --- a/src/datadogV2/model/model_governance_insight_query_config.rs +++ b/src/datadogV2/model/model_governance_insight_query_config.rs @@ -14,7 +14,7 @@ pub struct GovernanceInsightQueryConfig { /// The chart type the frontend should use to render the insight. #[serde(rename = "chart_type")] pub chart_type: Option, - /// The window used for the previous value comparison, for example `week` or `month`. + /// The window used for the previous value comparison; for example, `week` or `month`. #[serde(rename = "comparison_shift")] pub comparison_shift: String, /// The default value to display when no data is available. diff --git a/src/datadogV2/model/model_governance_limit_attributes.rs b/src/datadogV2/model/model_governance_limit_attributes.rs new file mode 100644 index 000000000..3583ea79d --- /dev/null +++ b/src/datadogV2/model/model_governance_limit_attributes.rs @@ -0,0 +1,204 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The attributes of a governance limit. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceLimitAttributes { + /// A description of what the limit measures. + #[serde(rename = "description")] + pub description: String, + /// The human-readable name of the limit. + #[serde(rename = "display_name")] + pub display_name: String, + /// The type of limit, such as a rate limit or a usage limit. + #[serde(rename = "limit_type")] + pub limit_type: String, + /// The Datadog product the limit belongs to. + #[serde(rename = "product")] + pub product: String, + /// A metric query used to compute usage against a limit. + #[serde(rename = "query")] + pub query: crate::datadogV2::model::GovernanceLimitQuery, + /// The query execution context used to visualize a limit and its usage. + #[serde(rename = "query_config")] + pub query_config: crate::datadogV2::model::GovernanceLimitQueryConfig, + /// The time range over which usage against the limit is measured. + #[serde(rename = "time_range")] + pub time_range: String, + /// The number of times usage has reached the limit within the measured time range. + #[serde(rename = "times_hit_limit")] + pub times_hit_limit: f64, + /// The unit in which the limit and its usage are measured. + #[serde(rename = "unit_name")] + pub unit_name: String, + /// The current usage status of the limit relative to its threshold. + #[serde(rename = "usage_status")] + pub usage_status: String, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceLimitAttributes { + pub fn new( + description: String, + display_name: String, + limit_type: String, + product: String, + query: crate::datadogV2::model::GovernanceLimitQuery, + query_config: crate::datadogV2::model::GovernanceLimitQueryConfig, + time_range: String, + times_hit_limit: f64, + unit_name: String, + usage_status: String, + ) -> GovernanceLimitAttributes { + GovernanceLimitAttributes { + description, + display_name, + limit_type, + product, + query, + query_config, + time_range, + times_hit_limit, + unit_name, + usage_status, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceLimitAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceLimitAttributesVisitor; + impl<'a> Visitor<'a> for GovernanceLimitAttributesVisitor { + type Value = GovernanceLimitAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut description: Option = None; + let mut display_name: Option = None; + let mut limit_type: Option = None; + let mut product: Option = None; + let mut query: Option = None; + let mut query_config: Option = + None; + let mut time_range: Option = None; + let mut times_hit_limit: Option = None; + let mut unit_name: Option = None; + let mut usage_status: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "description" => { + description = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "display_name" => { + display_name = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "limit_type" => { + limit_type = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "product" => { + product = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "query" => { + query = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "query_config" => { + query_config = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "time_range" => { + time_range = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "times_hit_limit" => { + times_hit_limit = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "unit_name" => { + unit_name = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "usage_status" => { + usage_status = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let description = + description.ok_or_else(|| M::Error::missing_field("description"))?; + let display_name = + display_name.ok_or_else(|| M::Error::missing_field("display_name"))?; + let limit_type = limit_type.ok_or_else(|| M::Error::missing_field("limit_type"))?; + let product = product.ok_or_else(|| M::Error::missing_field("product"))?; + let query = query.ok_or_else(|| M::Error::missing_field("query"))?; + let query_config = + query_config.ok_or_else(|| M::Error::missing_field("query_config"))?; + let time_range = time_range.ok_or_else(|| M::Error::missing_field("time_range"))?; + let times_hit_limit = + times_hit_limit.ok_or_else(|| M::Error::missing_field("times_hit_limit"))?; + let unit_name = unit_name.ok_or_else(|| M::Error::missing_field("unit_name"))?; + let usage_status = + usage_status.ok_or_else(|| M::Error::missing_field("usage_status"))?; + + let content = GovernanceLimitAttributes { + description, + display_name, + limit_type, + product, + query, + query_config, + time_range, + times_hit_limit, + unit_name, + usage_status, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceLimitAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_limit_data.rs b/src/datadogV2/model/model_governance_limit_data.rs new file mode 100644 index 000000000..7f573b4e7 --- /dev/null +++ b/src/datadogV2/model/model_governance_limit_data.rs @@ -0,0 +1,125 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A governance limit resource. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceLimitData { + /// The attributes of a governance limit. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::GovernanceLimitAttributes, + /// The unique identifier of the limit. + #[serde(rename = "id")] + pub id: String, + /// Limit resource type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::GovernanceLimitResourceType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceLimitData { + pub fn new( + attributes: crate::datadogV2::model::GovernanceLimitAttributes, + id: String, + type_: crate::datadogV2::model::GovernanceLimitResourceType, + ) -> GovernanceLimitData { + GovernanceLimitData { + attributes, + id, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceLimitData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceLimitDataVisitor; + impl<'a> Visitor<'a> for GovernanceLimitDataVisitor { + type Value = GovernanceLimitData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option = + None; + let mut id: Option = None; + let mut type_: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::GovernanceLimitResourceType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?; + let id = id.ok_or_else(|| M::Error::missing_field("id"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = GovernanceLimitData { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceLimitDataVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_limit_query.rs b/src/datadogV2/model/model_governance_limit_query.rs new file mode 100644 index 000000000..15f90cffb --- /dev/null +++ b/src/datadogV2/model/model_governance_limit_query.rs @@ -0,0 +1,112 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A metric query used to compute usage against a limit. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceLimitQuery { + /// The metric query expression used to compute the limit value. + #[serde(rename = "query")] + pub query: String, + /// How the query results are aggregated into a single value (for example, sum, max, or avg). + #[serde(rename = "reducer")] + pub reducer: String, + /// The data source used to evaluate the metric query (for example, the metrics or events backend). + #[serde(rename = "source")] + pub source: String, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceLimitQuery { + pub fn new(query: String, reducer: String, source: String) -> GovernanceLimitQuery { + GovernanceLimitQuery { + query, + reducer, + source, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceLimitQuery { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceLimitQueryVisitor; + impl<'a> Visitor<'a> for GovernanceLimitQueryVisitor { + type Value = GovernanceLimitQuery; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut query: Option = None; + let mut reducer: Option = None; + let mut source: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "query" => { + query = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "reducer" => { + reducer = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "source" => { + source = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let query = query.ok_or_else(|| M::Error::missing_field("query"))?; + let reducer = reducer.ok_or_else(|| M::Error::missing_field("reducer"))?; + let source = source.ok_or_else(|| M::Error::missing_field("source"))?; + + let content = GovernanceLimitQuery { + query, + reducer, + source, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceLimitQueryVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_limit_query_config.rs b/src/datadogV2/model/model_governance_limit_query_config.rs new file mode 100644 index 000000000..ece27fa09 --- /dev/null +++ b/src/datadogV2/model/model_governance_limit_query_config.rs @@ -0,0 +1,177 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The query execution context used to visualize a limit and its usage. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceLimitQueryConfig { + /// The chart type used to visualize the limit and its usage. + #[serde(rename = "chart_type")] + pub chart_type: Option, + /// The time shift applied to compare current usage against a prior period. + #[serde(rename = "comparison_shift")] + pub comparison_shift: Option, + /// The default value used for the limit when no explicit value is configured. + #[serde(rename = "default_value")] + pub default_value: Option, + /// The direction in which usage approaches the limit, indicating whether higher or lower values are closer to the limit. + #[serde(rename = "directionality")] + pub directionality: Option, + /// The number of days of data the limit query evaluates over. + #[serde(rename = "effective_time_window_days")] + pub effective_time_window_days: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceLimitQueryConfig { + pub fn new() -> GovernanceLimitQueryConfig { + GovernanceLimitQueryConfig { + chart_type: None, + comparison_shift: None, + default_value: None, + directionality: None, + effective_time_window_days: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn chart_type(mut self, value: String) -> Self { + self.chart_type = Some(value); + self + } + + pub fn comparison_shift(mut self, value: String) -> Self { + self.comparison_shift = Some(value); + self + } + + pub fn default_value(mut self, value: i64) -> Self { + self.default_value = Some(value); + self + } + + pub fn directionality(mut self, value: String) -> Self { + self.directionality = Some(value); + self + } + + pub fn effective_time_window_days(mut self, value: i64) -> Self { + self.effective_time_window_days = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for GovernanceLimitQueryConfig { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for GovernanceLimitQueryConfig { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceLimitQueryConfigVisitor; + impl<'a> Visitor<'a> for GovernanceLimitQueryConfigVisitor { + type Value = GovernanceLimitQueryConfig; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut chart_type: Option = None; + let mut comparison_shift: Option = None; + let mut default_value: Option = None; + let mut directionality: Option = None; + let mut effective_time_window_days: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "chart_type" => { + if v.is_null() { + continue; + } + chart_type = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "comparison_shift" => { + if v.is_null() { + continue; + } + comparison_shift = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "default_value" => { + if v.is_null() { + continue; + } + default_value = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "directionality" => { + if v.is_null() { + continue; + } + directionality = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "effective_time_window_days" => { + if v.is_null() { + continue; + } + effective_time_window_days = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = GovernanceLimitQueryConfig { + chart_type, + comparison_shift, + default_value, + directionality, + effective_time_window_days, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceLimitQueryConfigVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_limit_resource_type.rs b/src/datadogV2/model/model_governance_limit_resource_type.rs new file mode 100644 index 000000000..103354b3e --- /dev/null +++ b/src/datadogV2/model/model_governance_limit_resource_type.rs @@ -0,0 +1,48 @@ +// 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 serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum GovernanceLimitResourceType { + LIMIT, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for GovernanceLimitResourceType { + fn to_string(&self) -> String { + match self { + Self::LIMIT => String::from("limit"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for GovernanceLimitResourceType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for GovernanceLimitResourceType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "limit" => Self::LIMIT, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_governance_limits_response.rs b/src/datadogV2/model/model_governance_limits_response.rs new file mode 100644 index 000000000..2a4e17993 --- /dev/null +++ b/src/datadogV2/model/model_governance_limits_response.rs @@ -0,0 +1,94 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A list of governance limits. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceLimitsResponse { + /// An array of governance limit resources. + #[serde(rename = "data")] + pub data: Vec, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceLimitsResponse { + pub fn new( + data: Vec, + ) -> GovernanceLimitsResponse { + GovernanceLimitsResponse { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceLimitsResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceLimitsResponseVisitor; + impl<'a> Visitor<'a> for GovernanceLimitsResponseVisitor { + type Value = GovernanceLimitsResponse; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option> = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = GovernanceLimitsResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceLimitsResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_mitigation_request.rs b/src/datadogV2/model/model_governance_mitigation_request.rs new file mode 100644 index 000000000..88eff5074 --- /dev/null +++ b/src/datadogV2/model/model_governance_mitigation_request.rs @@ -0,0 +1,95 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A request to mitigate a set of governance detections. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceMitigationRequest { + /// The data of a governance mitigation request. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::GovernanceMitigationRequestData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceMitigationRequest { + pub fn new( + data: crate::datadogV2::model::GovernanceMitigationRequestData, + ) -> GovernanceMitigationRequest { + GovernanceMitigationRequest { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceMitigationRequest { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceMitigationRequestVisitor; + impl<'a> Visitor<'a> for GovernanceMitigationRequestVisitor { + type Value = GovernanceMitigationRequest; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option = + None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = GovernanceMitigationRequest { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceMitigationRequestVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_mitigation_request_attributes.rs b/src/datadogV2/model/model_governance_mitigation_request_attributes.rs new file mode 100644 index 000000000..47b3fdefa --- /dev/null +++ b/src/datadogV2/model/model_governance_mitigation_request_attributes.rs @@ -0,0 +1,165 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The attributes of a governance mitigation request. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceMitigationRequestAttributes { + /// The identifiers of the detections to mitigate in this request. + #[serde(rename = "detection_ids")] + pub detection_ids: Option>, + /// The detection type whose detections should be mitigated. + #[serde(rename = "detection_type")] + pub detection_type: Option, + /// A free-form map of parameter names to their configured values. + #[serde(rename = "mitigation_parameters")] + pub mitigation_parameters: Option>, + /// The mitigation to apply to the selected detections. Defaults to the control's configured mitigation when omitted. + #[serde(rename = "mitigation_type")] + pub mitigation_type: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceMitigationRequestAttributes { + pub fn new() -> GovernanceMitigationRequestAttributes { + GovernanceMitigationRequestAttributes { + detection_ids: None, + detection_type: None, + mitigation_parameters: None, + mitigation_type: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn detection_ids(mut self, value: Vec) -> Self { + self.detection_ids = Some(value); + self + } + + pub fn detection_type(mut self, value: String) -> Self { + self.detection_type = Some(value); + self + } + + pub fn mitigation_parameters( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.mitigation_parameters = Some(value); + self + } + + pub fn mitigation_type(mut self, value: String) -> Self { + self.mitigation_type = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for GovernanceMitigationRequestAttributes { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for GovernanceMitigationRequestAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceMitigationRequestAttributesVisitor; + impl<'a> Visitor<'a> for GovernanceMitigationRequestAttributesVisitor { + type Value = GovernanceMitigationRequestAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut detection_ids: Option> = None; + let mut detection_type: Option = None; + let mut mitigation_parameters: Option< + std::collections::BTreeMap, + > = None; + let mut mitigation_type: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "detection_ids" => { + if v.is_null() { + continue; + } + detection_ids = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "detection_type" => { + if v.is_null() { + continue; + } + detection_type = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "mitigation_parameters" => { + if v.is_null() { + continue; + } + mitigation_parameters = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "mitigation_type" => { + if v.is_null() { + continue; + } + mitigation_type = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = GovernanceMitigationRequestAttributes { + detection_ids, + detection_type, + mitigation_parameters, + mitigation_type, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceMitigationRequestAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_mitigation_request_data.rs b/src/datadogV2/model/model_governance_mitigation_request_data.rs new file mode 100644 index 000000000..f0256433c --- /dev/null +++ b/src/datadogV2/model/model_governance_mitigation_request_data.rs @@ -0,0 +1,126 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The data of a governance mitigation request. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceMitigationRequestData { + /// The attributes of a governance mitigation request. + #[serde(rename = "attributes")] + pub attributes: Option, + /// Governance control detection resource type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::GovernanceControlDetectionResourceType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceMitigationRequestData { + pub fn new( + type_: crate::datadogV2::model::GovernanceControlDetectionResourceType, + ) -> GovernanceMitigationRequestData { + GovernanceMitigationRequestData { + attributes: None, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes( + mut self, + value: crate::datadogV2::model::GovernanceMitigationRequestAttributes, + ) -> Self { + self.attributes = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceMitigationRequestData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceMitigationRequestDataVisitor; + impl<'a> Visitor<'a> for GovernanceMitigationRequestDataVisitor { + type Value = GovernanceMitigationRequestData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option< + crate::datadogV2::model::GovernanceMitigationRequestAttributes, + > = None; + let mut type_: Option< + crate::datadogV2::model::GovernanceControlDetectionResourceType, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + if v.is_null() { + continue; + } + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::GovernanceControlDetectionResourceType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = GovernanceMitigationRequestData { + attributes, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceMitigationRequestDataVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_notification_settings_attributes.rs b/src/datadogV2/model/model_governance_notification_settings_attributes.rs new file mode 100644 index 000000000..44eb19d5a --- /dev/null +++ b/src/datadogV2/model/model_governance_notification_settings_attributes.rs @@ -0,0 +1,94 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The attributes of the organization-wide governance notification settings. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceNotificationSettingsAttributes { + /// Whether notifications are sent to users when detections are assigned to them. + #[serde(rename = "assignment_notifications_enabled")] + pub assignment_notifications_enabled: bool, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceNotificationSettingsAttributes { + pub fn new(assignment_notifications_enabled: bool) -> GovernanceNotificationSettingsAttributes { + GovernanceNotificationSettingsAttributes { + assignment_notifications_enabled, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceNotificationSettingsAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceNotificationSettingsAttributesVisitor; + impl<'a> Visitor<'a> for GovernanceNotificationSettingsAttributesVisitor { + type Value = GovernanceNotificationSettingsAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut assignment_notifications_enabled: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "assignment_notifications_enabled" => { + assignment_notifications_enabled = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let assignment_notifications_enabled = assignment_notifications_enabled + .ok_or_else(|| M::Error::missing_field("assignment_notifications_enabled"))?; + + let content = GovernanceNotificationSettingsAttributes { + assignment_notifications_enabled, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceNotificationSettingsAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_notification_settings_data.rs b/src/datadogV2/model/model_governance_notification_settings_data.rs new file mode 100644 index 000000000..8b9e3c2c7 --- /dev/null +++ b/src/datadogV2/model/model_governance_notification_settings_data.rs @@ -0,0 +1,128 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A governance notification settings resource. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceNotificationSettingsData { + /// The attributes of the organization-wide governance notification settings. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::GovernanceNotificationSettingsAttributes, + /// The unique identifier of the organization the notification settings apply to. + #[serde(rename = "id")] + pub id: String, + /// Governance notification settings resource type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::GovernanceNotificationSettingsResourceType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceNotificationSettingsData { + pub fn new( + attributes: crate::datadogV2::model::GovernanceNotificationSettingsAttributes, + id: String, + type_: crate::datadogV2::model::GovernanceNotificationSettingsResourceType, + ) -> GovernanceNotificationSettingsData { + GovernanceNotificationSettingsData { + attributes, + id, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceNotificationSettingsData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceNotificationSettingsDataVisitor; + impl<'a> Visitor<'a> for GovernanceNotificationSettingsDataVisitor { + type Value = GovernanceNotificationSettingsData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option< + crate::datadogV2::model::GovernanceNotificationSettingsAttributes, + > = None; + let mut id: Option = None; + let mut type_: Option< + crate::datadogV2::model::GovernanceNotificationSettingsResourceType, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::GovernanceNotificationSettingsResourceType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?; + let id = id.ok_or_else(|| M::Error::missing_field("id"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = GovernanceNotificationSettingsData { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceNotificationSettingsDataVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_notification_settings_resource_type.rs b/src/datadogV2/model/model_governance_notification_settings_resource_type.rs new file mode 100644 index 000000000..75094738a --- /dev/null +++ b/src/datadogV2/model/model_governance_notification_settings_resource_type.rs @@ -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 2019-Present Datadog, Inc. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum GovernanceNotificationSettingsResourceType { + GOVERNANCE_NOTIFICATION_SETTINGS, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for GovernanceNotificationSettingsResourceType { + fn to_string(&self) -> String { + match self { + Self::GOVERNANCE_NOTIFICATION_SETTINGS => { + String::from("governance_notification_settings") + } + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for GovernanceNotificationSettingsResourceType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for GovernanceNotificationSettingsResourceType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "governance_notification_settings" => Self::GOVERNANCE_NOTIFICATION_SETTINGS, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_governance_notification_settings_response.rs b/src/datadogV2/model/model_governance_notification_settings_response.rs new file mode 100644 index 000000000..5a13b7a7d --- /dev/null +++ b/src/datadogV2/model/model_governance_notification_settings_response.rs @@ -0,0 +1,95 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The organization-wide governance notification settings. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceNotificationSettingsResponse { + /// A governance notification settings resource. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::GovernanceNotificationSettingsData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceNotificationSettingsResponse { + pub fn new( + data: crate::datadogV2::model::GovernanceNotificationSettingsData, + ) -> GovernanceNotificationSettingsResponse { + GovernanceNotificationSettingsResponse { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceNotificationSettingsResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceNotificationSettingsResponseVisitor; + impl<'a> Visitor<'a> for GovernanceNotificationSettingsResponseVisitor { + type Value = GovernanceNotificationSettingsResponse; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option = + None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = GovernanceNotificationSettingsResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceNotificationSettingsResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_notification_settings_update_attributes.rs b/src/datadogV2/model/model_governance_notification_settings_update_attributes.rs new file mode 100644 index 000000000..e2277dd62 --- /dev/null +++ b/src/datadogV2/model/model_governance_notification_settings_update_attributes.rs @@ -0,0 +1,106 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The attributes of the governance notification settings that can be updated. Only the attributes present in the request are modified. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceNotificationSettingsUpdateAttributes { + /// Whether notifications are sent to users when detections are assigned to them. + #[serde(rename = "assignment_notifications_enabled")] + pub assignment_notifications_enabled: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceNotificationSettingsUpdateAttributes { + pub fn new() -> GovernanceNotificationSettingsUpdateAttributes { + GovernanceNotificationSettingsUpdateAttributes { + assignment_notifications_enabled: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn assignment_notifications_enabled(mut self, value: bool) -> Self { + self.assignment_notifications_enabled = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for GovernanceNotificationSettingsUpdateAttributes { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for GovernanceNotificationSettingsUpdateAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceNotificationSettingsUpdateAttributesVisitor; + impl<'a> Visitor<'a> for GovernanceNotificationSettingsUpdateAttributesVisitor { + type Value = GovernanceNotificationSettingsUpdateAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut assignment_notifications_enabled: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "assignment_notifications_enabled" => { + if v.is_null() { + continue; + } + assignment_notifications_enabled = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = GovernanceNotificationSettingsUpdateAttributes { + assignment_notifications_enabled, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceNotificationSettingsUpdateAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_notification_settings_update_data.rs b/src/datadogV2/model/model_governance_notification_settings_update_data.rs new file mode 100644 index 000000000..de09a613b --- /dev/null +++ b/src/datadogV2/model/model_governance_notification_settings_update_data.rs @@ -0,0 +1,126 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The data of a governance notification settings update request. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceNotificationSettingsUpdateData { + /// The attributes of the governance notification settings that can be updated. Only the attributes present in the request are modified. + #[serde(rename = "attributes")] + pub attributes: Option, + /// Governance notification settings resource type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::GovernanceNotificationSettingsResourceType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceNotificationSettingsUpdateData { + pub fn new( + type_: crate::datadogV2::model::GovernanceNotificationSettingsResourceType, + ) -> GovernanceNotificationSettingsUpdateData { + GovernanceNotificationSettingsUpdateData { + attributes: None, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes( + mut self, + value: crate::datadogV2::model::GovernanceNotificationSettingsUpdateAttributes, + ) -> Self { + self.attributes = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceNotificationSettingsUpdateData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceNotificationSettingsUpdateDataVisitor; + impl<'a> Visitor<'a> for GovernanceNotificationSettingsUpdateDataVisitor { + type Value = GovernanceNotificationSettingsUpdateData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option< + crate::datadogV2::model::GovernanceNotificationSettingsUpdateAttributes, + > = None; + let mut type_: Option< + crate::datadogV2::model::GovernanceNotificationSettingsResourceType, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + if v.is_null() { + continue; + } + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::GovernanceNotificationSettingsResourceType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = GovernanceNotificationSettingsUpdateData { + attributes, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceNotificationSettingsUpdateDataVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_notification_settings_update_request.rs b/src/datadogV2/model/model_governance_notification_settings_update_request.rs new file mode 100644 index 000000000..e8240def3 --- /dev/null +++ b/src/datadogV2/model/model_governance_notification_settings_update_request.rs @@ -0,0 +1,96 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A request to update the organization-wide governance notification settings. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceNotificationSettingsUpdateRequest { + /// The data of a governance notification settings update request. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::GovernanceNotificationSettingsUpdateData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceNotificationSettingsUpdateRequest { + pub fn new( + data: crate::datadogV2::model::GovernanceNotificationSettingsUpdateData, + ) -> GovernanceNotificationSettingsUpdateRequest { + GovernanceNotificationSettingsUpdateRequest { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceNotificationSettingsUpdateRequest { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceNotificationSettingsUpdateRequestVisitor; + impl<'a> Visitor<'a> for GovernanceNotificationSettingsUpdateRequestVisitor { + type Value = GovernanceNotificationSettingsUpdateRequest; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option< + crate::datadogV2::model::GovernanceNotificationSettingsUpdateData, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = GovernanceNotificationSettingsUpdateRequest { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceNotificationSettingsUpdateRequestVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_resource_limit_attributes.rs b/src/datadogV2/model/model_governance_resource_limit_attributes.rs new file mode 100644 index 000000000..be0fae2a5 --- /dev/null +++ b/src/datadogV2/model/model_governance_resource_limit_attributes.rs @@ -0,0 +1,256 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The attributes of a governance resource limit. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceResourceLimitAttributes { + /// The current limit configured for the resource. + #[serde(rename = "current_limit")] + pub current_limit: f64, + /// The current value of the resource. + #[serde(rename = "current_value")] + pub current_value: f64, + /// A link to the Datadog page where the resource and its limit can be managed. + #[serde(rename = "deep_link")] + pub deep_link: String, + /// The default current value used when the resource value cannot be computed from the query. + #[serde(rename = "default_current_value")] + pub default_current_value: f64, + /// The default limit value used when the limit cannot be computed from the query. + #[serde(rename = "default_limit_value")] + pub default_limit_value: f64, + /// A description of what the resource limit measures. + #[serde(rename = "description")] + pub description: String, + /// The human-readable name of the resource limit. + #[serde(rename = "display_name")] + pub display_name: String, + /// A metric query used to compute usage against a limit. + #[serde(rename = "limit_query")] + pub limit_query: crate::datadogV2::model::GovernanceLimitQuery, + /// The Datadog product the resource limit belongs to. + #[serde(rename = "product")] + pub product: String, + /// A metric query used to compute usage against a limit. + #[serde(rename = "query")] + pub query: crate::datadogV2::model::GovernanceLimitQuery, + /// The query execution context used to visualize a limit and its usage. + #[serde(rename = "query_config")] + pub query_config: crate::datadogV2::model::GovernanceLimitQueryConfig, + /// The time range over which the resource value is measured. + #[serde(rename = "time_range")] + pub time_range: String, + /// The unit in which the resource value and limit are measured. + #[serde(rename = "unit_name")] + pub unit_name: String, + /// The current usage status of the resource relative to its limit. + #[serde(rename = "usage_status")] + pub usage_status: String, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceResourceLimitAttributes { + pub fn new( + current_limit: f64, + current_value: f64, + deep_link: String, + default_current_value: f64, + default_limit_value: f64, + description: String, + display_name: String, + limit_query: crate::datadogV2::model::GovernanceLimitQuery, + product: String, + query: crate::datadogV2::model::GovernanceLimitQuery, + query_config: crate::datadogV2::model::GovernanceLimitQueryConfig, + time_range: String, + unit_name: String, + usage_status: String, + ) -> GovernanceResourceLimitAttributes { + GovernanceResourceLimitAttributes { + current_limit, + current_value, + deep_link, + default_current_value, + default_limit_value, + description, + display_name, + limit_query, + product, + query, + query_config, + time_range, + unit_name, + usage_status, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceResourceLimitAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceResourceLimitAttributesVisitor; + impl<'a> Visitor<'a> for GovernanceResourceLimitAttributesVisitor { + type Value = GovernanceResourceLimitAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut current_limit: Option = None; + let mut current_value: Option = None; + let mut deep_link: Option = None; + let mut default_current_value: Option = None; + let mut default_limit_value: Option = None; + let mut description: Option = None; + let mut display_name: Option = None; + let mut limit_query: Option = None; + let mut product: Option = None; + let mut query: Option = None; + let mut query_config: Option = + None; + let mut time_range: Option = None; + let mut unit_name: Option = None; + let mut usage_status: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "current_limit" => { + current_limit = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "current_value" => { + current_value = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "deep_link" => { + deep_link = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "default_current_value" => { + default_current_value = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "default_limit_value" => { + default_limit_value = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "description" => { + description = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "display_name" => { + display_name = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "limit_query" => { + limit_query = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "product" => { + product = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "query" => { + query = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "query_config" => { + query_config = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "time_range" => { + time_range = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "unit_name" => { + unit_name = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "usage_status" => { + usage_status = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let current_limit = + current_limit.ok_or_else(|| M::Error::missing_field("current_limit"))?; + let current_value = + current_value.ok_or_else(|| M::Error::missing_field("current_value"))?; + let deep_link = deep_link.ok_or_else(|| M::Error::missing_field("deep_link"))?; + let default_current_value = default_current_value + .ok_or_else(|| M::Error::missing_field("default_current_value"))?; + let default_limit_value = default_limit_value + .ok_or_else(|| M::Error::missing_field("default_limit_value"))?; + let description = + description.ok_or_else(|| M::Error::missing_field("description"))?; + let display_name = + display_name.ok_or_else(|| M::Error::missing_field("display_name"))?; + let limit_query = + limit_query.ok_or_else(|| M::Error::missing_field("limit_query"))?; + let product = product.ok_or_else(|| M::Error::missing_field("product"))?; + let query = query.ok_or_else(|| M::Error::missing_field("query"))?; + let query_config = + query_config.ok_or_else(|| M::Error::missing_field("query_config"))?; + let time_range = time_range.ok_or_else(|| M::Error::missing_field("time_range"))?; + let unit_name = unit_name.ok_or_else(|| M::Error::missing_field("unit_name"))?; + let usage_status = + usage_status.ok_or_else(|| M::Error::missing_field("usage_status"))?; + + let content = GovernanceResourceLimitAttributes { + current_limit, + current_value, + deep_link, + default_current_value, + default_limit_value, + description, + display_name, + limit_query, + product, + query, + query_config, + time_range, + unit_name, + usage_status, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceResourceLimitAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_resource_limit_data.rs b/src/datadogV2/model/model_governance_resource_limit_data.rs new file mode 100644 index 000000000..0d3262c7d --- /dev/null +++ b/src/datadogV2/model/model_governance_resource_limit_data.rs @@ -0,0 +1,128 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A governance resource limit resource. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceResourceLimitData { + /// The attributes of a governance resource limit. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::GovernanceResourceLimitAttributes, + /// The unique identifier of the resource limit. + #[serde(rename = "id")] + pub id: String, + /// Resource limit resource type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::GovernanceResourceLimitResourceType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceResourceLimitData { + pub fn new( + attributes: crate::datadogV2::model::GovernanceResourceLimitAttributes, + id: String, + type_: crate::datadogV2::model::GovernanceResourceLimitResourceType, + ) -> GovernanceResourceLimitData { + GovernanceResourceLimitData { + attributes, + id, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceResourceLimitData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceResourceLimitDataVisitor; + impl<'a> Visitor<'a> for GovernanceResourceLimitDataVisitor { + type Value = GovernanceResourceLimitData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option< + crate::datadogV2::model::GovernanceResourceLimitAttributes, + > = None; + let mut id: Option = None; + let mut type_: Option< + crate::datadogV2::model::GovernanceResourceLimitResourceType, + > = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::GovernanceResourceLimitResourceType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?; + let id = id.ok_or_else(|| M::Error::missing_field("id"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = GovernanceResourceLimitData { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceResourceLimitDataVisitor) + } +} diff --git a/src/datadogV2/model/model_governance_resource_limit_resource_type.rs b/src/datadogV2/model/model_governance_resource_limit_resource_type.rs new file mode 100644 index 000000000..47d094021 --- /dev/null +++ b/src/datadogV2/model/model_governance_resource_limit_resource_type.rs @@ -0,0 +1,48 @@ +// 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 serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum GovernanceResourceLimitResourceType { + RESOURCE_LIMIT, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for GovernanceResourceLimitResourceType { + fn to_string(&self) -> String { + match self { + Self::RESOURCE_LIMIT => String::from("resource-limit"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for GovernanceResourceLimitResourceType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for GovernanceResourceLimitResourceType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "resource-limit" => Self::RESOURCE_LIMIT, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_governance_resource_limits_response.rs b/src/datadogV2/model/model_governance_resource_limits_response.rs new file mode 100644 index 000000000..161ff813f --- /dev/null +++ b/src/datadogV2/model/model_governance_resource_limits_response.rs @@ -0,0 +1,95 @@ +// 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 serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// A list of governance resource limits. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct GovernanceResourceLimitsResponse { + /// An array of governance resource limit resources. + #[serde(rename = "data")] + pub data: Vec, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl GovernanceResourceLimitsResponse { + pub fn new( + data: Vec, + ) -> GovernanceResourceLimitsResponse { + GovernanceResourceLimitsResponse { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for GovernanceResourceLimitsResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct GovernanceResourceLimitsResponseVisitor; + impl<'a> Visitor<'a> for GovernanceResourceLimitsResponseVisitor { + type Value = GovernanceResourceLimitsResponse; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option> = + None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = GovernanceResourceLimitsResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(GovernanceResourceLimitsResponseVisitor) + } +} diff --git a/tests/scenarios/features/v2/governance_controls.feature b/tests/scenarios/features/v2/governance_controls.feature index 1207f5cf5..c16b96508 100644 --- a/tests/scenarios/features/v2/governance_controls.feature +++ b/tests/scenarios/features/v2/governance_controls.feature @@ -11,6 +11,33 @@ Feature: Governance Controls And a valid "appKeyAuth" key in the system And an instance of "GovernanceControls" API + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Get a governance control detection returns "Bad Request" response + Given operation "GetGovernanceControlDetection" enabled + And new "GetGovernanceControlDetection" request + And request contains "detection_type" parameter from "REPLACE.ME" + And request contains "detection_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Get a governance control detection returns "Not Found" response + Given operation "GetGovernanceControlDetection" enabled + And new "GetGovernanceControlDetection" request + And request contains "detection_type" parameter from "REPLACE.ME" + And request contains "detection_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Get a governance control detection returns "OK" response + Given operation "GetGovernanceControlDetection" enabled + And new "GetGovernanceControlDetection" request + And request contains "detection_type" parameter from "REPLACE.ME" + And request contains "detection_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 OK + @generated @skip @team:DataDog/aaa-governance-console Scenario: Get a governance control returns "Bad Request" response Given operation "GetGovernanceControl" enabled @@ -35,6 +62,38 @@ Feature: Governance Controls When the request is sent Then the response status is 200 OK + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Get governance control notification settings returns "Bad Request" response + Given operation "GetGovernanceControlNotificationSettings" enabled + And new "GetGovernanceControlNotificationSettings" request + And request contains "detection_type" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Get governance control notification settings returns "OK" response + Given operation "GetGovernanceControlNotificationSettings" enabled + And new "GetGovernanceControlNotificationSettings" request + And request contains "detection_type" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: List governance control detections returns "Bad Request" response + Given operation "ListGovernanceControlDetections" enabled + And new "ListGovernanceControlDetections" request + And request contains "detection_type" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: List governance control detections returns "OK" response + Given operation "ListGovernanceControlDetections" enabled + And new "ListGovernanceControlDetections" request + And request contains "detection_type" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 OK + @generated @skip @team:DataDog/aaa-governance-console Scenario: List governance controls returns "Bad Request" response Given operation "ListGovernanceControls" enabled @@ -49,6 +108,52 @@ Feature: Governance Controls When the request is sent Then the response status is 200 OK + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Mitigate governance detections returns "Accepted" response + Given operation "CreateGovernanceMitigation" enabled + And new "CreateGovernanceMitigation" request + And body with value {"data": {"attributes": {"detection_ids": ["3f9b2c1a-8d4e-4a6b-9c2f-1e7d5a0b3c4d"], "detection_type": "unused_api_keys", "mitigation_type": "revoke_api_key"}, "type": "governance_control_detection"}} + When the request is sent + Then the response status is 202 Accepted + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Mitigate governance detections returns "Bad Request" response + Given operation "CreateGovernanceMitigation" enabled + And new "CreateGovernanceMitigation" request + And body with value {"data": {"attributes": {"detection_ids": ["3f9b2c1a-8d4e-4a6b-9c2f-1e7d5a0b3c4d"], "detection_type": "unused_api_keys", "mitigation_type": "revoke_api_key"}, "type": "governance_control_detection"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Update a governance control detection returns "Bad Request" response + Given operation "UpdateGovernanceControlDetection" enabled + And new "UpdateGovernanceControlDetection" request + And request contains "detection_type" parameter from "REPLACE.ME" + And request contains "detection_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"assigned_team": "platform-security", "assigned_to": "11111111-2222-3333-4444-555555555555", "mitigate_after": "2024-03-15T00:00:00Z", "state": "exception"}, "type": "governance_control_detection"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Update a governance control detection returns "Not Found" response + Given operation "UpdateGovernanceControlDetection" enabled + And new "UpdateGovernanceControlDetection" request + And request contains "detection_type" parameter from "REPLACE.ME" + And request contains "detection_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"assigned_team": "platform-security", "assigned_to": "11111111-2222-3333-4444-555555555555", "mitigate_after": "2024-03-15T00:00:00Z", "state": "exception"}, "type": "governance_control_detection"}} + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Update a governance control detection returns "OK" response + Given operation "UpdateGovernanceControlDetection" enabled + And new "UpdateGovernanceControlDetection" request + And request contains "detection_type" parameter from "REPLACE.ME" + And request contains "detection_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"assigned_team": "platform-security", "assigned_to": "11111111-2222-3333-4444-555555555555", "mitigate_after": "2024-03-15T00:00:00Z", "state": "exception"}, "type": "governance_control_detection"}} + When the request is sent + Then the response status is 200 OK + @generated @skip @team:DataDog/aaa-governance-console Scenario: Update a governance control returns "Bad Request" response Given operation "UpdateGovernanceControl" enabled @@ -75,3 +180,21 @@ Feature: Governance Controls And body with value {"data": {"attributes": {"detection_frequency": "daily", "mitigation_type": "revoke_api_key", "name": "Unused API Keys", "notification_frequency": "daily", "notification_type": "slack"}, "id": "0d4e6f8a-1b2c-3d4e-5f6a-7b8c9d0e1f2a", "type": "governance_control"}} When the request is sent Then the response status is 200 OK + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Update governance control notification settings returns "Bad Request" response + Given operation "UpdateGovernanceControlNotificationSettings" enabled + And new "UpdateGovernanceControlNotificationSettings" request + And request contains "detection_type" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"event_settings": [{"enabled": true, "event_type": "new_detection", "targets": [{"handle": "#governance-alerts", "type": "slack"}]}]}, "type": "control_notification_settings"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Update governance control notification settings returns "OK" response + Given operation "UpdateGovernanceControlNotificationSettings" enabled + And new "UpdateGovernanceControlNotificationSettings" request + And request contains "detection_type" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"event_settings": [{"enabled": true, "event_type": "new_detection", "targets": [{"handle": "#governance-alerts", "type": "slack"}]}]}, "type": "control_notification_settings"}} + When the request is sent + Then the response status is 200 OK diff --git a/tests/scenarios/features/v2/governance_settings.feature b/tests/scenarios/features/v2/governance_settings.feature new file mode 100644 index 000000000..a44857231 --- /dev/null +++ b/tests/scenarios/features/v2/governance_settings.feature @@ -0,0 +1,83 @@ +@endpoint(governance-settings) @endpoint(governance-settings-v2) +Feature: Governance Settings + Governance Settings cover organization-wide Governance Console + configuration, usage limits and resource limits, and notification + preferences that determine when and how the Console alerts users about + governance activity. + + Background: + Given a valid "apiKeyAuth" key in the system + And a valid "appKeyAuth" key in the system + And an instance of "GovernanceSettings" API + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Get governance notification settings returns "Bad Request" response + Given operation "GetGovernanceNotificationSettings" enabled + And new "GetGovernanceNotificationSettings" request + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Get governance notification settings returns "OK" response + Given operation "GetGovernanceNotificationSettings" enabled + And new "GetGovernanceNotificationSettings" request + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Get the governance console configuration returns "Bad Request" response + Given operation "GetGovernanceConfig" enabled + And new "GetGovernanceConfig" request + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Get the governance console configuration returns "OK" response + Given operation "GetGovernanceConfig" enabled + And new "GetGovernanceConfig" request + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: List governance limits returns "Bad Request" response + Given operation "ListGovernanceLimits" enabled + And new "ListGovernanceLimits" request + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: List governance limits returns "OK" response + Given operation "ListGovernanceLimits" enabled + And new "ListGovernanceLimits" request + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: List governance resource limits returns "Bad Request" response + Given operation "ListGovernanceResourceLimits" enabled + And new "ListGovernanceResourceLimits" request + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: List governance resource limits returns "OK" response + Given operation "ListGovernanceResourceLimits" enabled + And new "ListGovernanceResourceLimits" request + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Update governance notification settings returns "Bad Request" response + Given operation "UpdateGovernanceNotificationSettings" enabled + And new "UpdateGovernanceNotificationSettings" request + And body with value {"data": {"attributes": {"assignment_notifications_enabled": true}, "type": "governance_notification_settings"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/aaa-governance-console + Scenario: Update governance notification settings returns "OK" response + Given operation "UpdateGovernanceNotificationSettings" enabled + And new "UpdateGovernanceNotificationSettings" request + And body with value {"data": {"attributes": {"assignment_notifications_enabled": true}, "type": "governance_notification_settings"}} + When the request is sent + Then the response status is 200 OK diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index c07e3792a..2f2c9c766 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -2792,6 +2792,12 @@ "type": "safe" } }, + "GetGovernanceConfig": { + "tag": "Governance Settings", + "undo": { + "type": "safe" + } + }, "ListGovernanceControls": { "tag": "Governance Controls", "undo": { @@ -2810,12 +2816,72 @@ "type": "idempotent" } }, + "ListGovernanceControlDetections": { + "tag": "Governance Controls", + "undo": { + "type": "safe" + } + }, + "GetGovernanceControlDetection": { + "tag": "Governance Controls", + "undo": { + "type": "safe" + } + }, + "UpdateGovernanceControlDetection": { + "tag": "Governance Controls", + "undo": { + "type": "idempotent" + } + }, + "GetGovernanceControlNotificationSettings": { + "tag": "Governance Controls", + "undo": { + "type": "safe" + } + }, + "UpdateGovernanceControlNotificationSettings": { + "tag": "Governance Controls", + "undo": { + "type": "idempotent" + } + }, "ListGovernanceInsights": { "tag": "Governance Insights", "undo": { "type": "safe" } }, + "ListGovernanceLimits": { + "tag": "Governance Settings", + "undo": { + "type": "safe" + } + }, + "CreateGovernanceMitigation": { + "tag": "Governance Controls", + "undo": { + "type": "unsafe" + } + }, + "GetGovernanceNotificationSettings": { + "tag": "Governance Settings", + "undo": { + "type": "safe" + } + }, + "UpdateGovernanceNotificationSettings": { + "tag": "Governance Settings", + "undo": { + "type": "idempotent" + } + }, + "ListGovernanceResourceLimits": { + "tag": "Governance Settings", + "undo": { + "type": "safe" + } + }, "GetHamrOrgConnection": { "tag": "High Availability MultiRegion", "undo": { diff --git a/tests/scenarios/function_mappings.rs b/tests/scenarios/function_mappings.rs index d7d6a2015..2592e4393 100644 --- a/tests/scenarios/function_mappings.rs +++ b/tests/scenarios/function_mappings.rs @@ -112,6 +112,8 @@ pub struct ApiInstances { pub v2_api_feature_flags: Option, pub v2_api_forms: Option, pub v2_api_organizations: Option, + pub v2_api_governance_settings: + Option, pub v2_api_governance_controls: Option, pub v2_api_governance_insights: @@ -908,6 +910,14 @@ pub fn initialize_api_instance(world: &mut DatadogWorld, api: String) { world.http_client.as_ref().unwrap().clone(), )); } + "GovernanceSettings" => { + world.api_instances.v2_api_governance_settings = Some( + datadogV2::api_governance_settings::GovernanceSettingsAPI::with_client_and_config( + world.config.clone(), + world.http_client.as_ref().unwrap().clone(), + ), + ); + } "GovernanceControls" => { world.api_instances.v2_api_governance_controls = Some( datadogV2::api_governance_controls::GovernanceControlsAPI::with_client_and_config( @@ -4835,6 +4845,26 @@ pub fn collect_function_calls(world: &mut DatadogWorld) { "v2.UpdateSAMLConfiguration".into(), test_v2_update_saml_configuration, ); + world.function_mappings.insert( + "v2.GetGovernanceConfig".into(), + test_v2_get_governance_config, + ); + world.function_mappings.insert( + "v2.ListGovernanceLimits".into(), + test_v2_list_governance_limits, + ); + world.function_mappings.insert( + "v2.GetGovernanceNotificationSettings".into(), + test_v2_get_governance_notification_settings, + ); + world.function_mappings.insert( + "v2.UpdateGovernanceNotificationSettings".into(), + test_v2_update_governance_notification_settings, + ); + world.function_mappings.insert( + "v2.ListGovernanceResourceLimits".into(), + test_v2_list_governance_resource_limits, + ); world.function_mappings.insert( "v2.ListGovernanceControls".into(), test_v2_list_governance_controls, @@ -4847,6 +4877,30 @@ pub fn collect_function_calls(world: &mut DatadogWorld) { "v2.UpdateGovernanceControl".into(), test_v2_update_governance_control, ); + world.function_mappings.insert( + "v2.ListGovernanceControlDetections".into(), + test_v2_list_governance_control_detections, + ); + world.function_mappings.insert( + "v2.GetGovernanceControlDetection".into(), + test_v2_get_governance_control_detection, + ); + world.function_mappings.insert( + "v2.UpdateGovernanceControlDetection".into(), + test_v2_update_governance_control_detection, + ); + world.function_mappings.insert( + "v2.GetGovernanceControlNotificationSettings".into(), + test_v2_get_governance_control_notification_settings, + ); + world.function_mappings.insert( + "v2.UpdateGovernanceControlNotificationSettings".into(), + test_v2_update_governance_control_notification_settings, + ); + world.function_mappings.insert( + "v2.CreateGovernanceMitigation".into(), + test_v2_create_governance_mitigation, + ); world.function_mappings.insert( "v2.ListGovernanceInsights".into(), test_v2_list_governance_insights, @@ -37084,6 +37138,137 @@ fn test_v2_update_saml_configuration( world.response.code = response.status.as_u16(); } +fn test_v2_get_governance_config(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_governance_settings + .as_ref() + .expect("api instance not found"); + let response = match block_on(api.get_governance_config_with_http_info()) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_list_governance_limits(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_governance_settings + .as_ref() + .expect("api instance not found"); + let response = match block_on(api.list_governance_limits_with_http_info()) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_get_governance_notification_settings( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_governance_settings + .as_ref() + .expect("api instance not found"); + let response = match block_on(api.get_governance_notification_settings_with_http_info()) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_update_governance_notification_settings( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_governance_settings + .as_ref() + .expect("api instance not found"); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = match block_on(api.update_governance_notification_settings_with_http_info(body)) + { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_list_governance_resource_limits( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_governance_settings + .as_ref() + .expect("api instance not found"); + let response = match block_on(api.list_governance_resource_limits_with_http_info()) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + fn test_v2_list_governance_controls( world: &mut DatadogWorld, _parameters: &HashMap, @@ -37168,6 +37353,220 @@ fn test_v2_update_governance_control( world.response.code = response.status.as_u16(); } +fn test_v2_list_governance_control_detections( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_governance_controls + .as_ref() + .expect("api instance not found"); + let detection_type = + serde_json::from_value(_parameters.get("detection_type").unwrap().clone()).unwrap(); + let filter_state = _parameters + .get("filter[state]") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let filter_query = _parameters + .get("filter[query]") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let sort = _parameters + .get("sort") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let page_number = _parameters + .get("page[number]") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let page_size = _parameters + .get("page[size]") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let mut params = + datadogV2::api_governance_controls::ListGovernanceControlDetectionsOptionalParams::default( + ); + params.filter_state = filter_state; + params.filter_query = filter_query; + params.sort = sort; + params.page_number = page_number; + params.page_size = page_size; + let response = match block_on( + api.list_governance_control_detections_with_http_info(detection_type, params), + ) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_get_governance_control_detection( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_governance_controls + .as_ref() + .expect("api instance not found"); + let detection_type = + serde_json::from_value(_parameters.get("detection_type").unwrap().clone()).unwrap(); + let detection_id = + serde_json::from_value(_parameters.get("detection_id").unwrap().clone()).unwrap(); + let response = match block_on( + api.get_governance_control_detection_with_http_info(detection_type, detection_id), + ) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_update_governance_control_detection( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_governance_controls + .as_ref() + .expect("api instance not found"); + let detection_type = + serde_json::from_value(_parameters.get("detection_type").unwrap().clone()).unwrap(); + let detection_id = + serde_json::from_value(_parameters.get("detection_id").unwrap().clone()).unwrap(); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = match block_on(api.update_governance_control_detection_with_http_info( + detection_type, + detection_id, + body, + )) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_get_governance_control_notification_settings( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_governance_controls + .as_ref() + .expect("api instance not found"); + let detection_type = + serde_json::from_value(_parameters.get("detection_type").unwrap().clone()).unwrap(); + let response = match block_on( + api.get_governance_control_notification_settings_with_http_info(detection_type), + ) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_update_governance_control_notification_settings( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_governance_controls + .as_ref() + .expect("api instance not found"); + let detection_type = + serde_json::from_value(_parameters.get("detection_type").unwrap().clone()).unwrap(); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = match block_on( + api.update_governance_control_notification_settings_with_http_info(detection_type, body), + ) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_create_governance_mitigation( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_governance_controls + .as_ref() + .expect("api instance not found"); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = match block_on(api.create_governance_mitigation_with_http_info(body)) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + fn test_v2_list_governance_insights( world: &mut DatadogWorld, _parameters: &HashMap,