diff --git a/.apigentools-info b/.apigentools-info index b0a71487f90..449f8c311d8 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2024-07-03 18:25:17.326220", - "spec_repo_commit": "ce846cd6" + "regenerated": "2024-07-09 13:59:08.988581", + "spec_repo_commit": "23c35cbe" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2024-07-03 18:25:17.346033", - "spec_repo_commit": "ce846cd6" + "regenerated": "2024-07-09 13:59:09.006686", + "spec_repo_commit": "23c35cbe" } } } \ No newline at end of file diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 5a23c3a6fdd..eb28e3182ce 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -351,6 +351,13 @@ components: required: true schema: type: string + InstanceId: + description: The ID of the workflow instance. + in: path + name: instance_id + required: true + schema: + type: string MetricID: description: The name of the log-based metric. in: path @@ -536,6 +543,13 @@ components: schema: example: 00000000-0000-9999-0000-000000000000 type: string + WorkflowId: + description: The ID of the workflow. + in: path + name: workflow_id + required: true + schema: + type: string requestBodies: {} responses: BadRequestResponse: @@ -23233,6 +23247,40 @@ components: - PAST_SIX_MONTHS - PAST_ONE_YEAR - ALERT + WorkflowInstanceCreateMeta: + description: Additional information for creating a workflow instance + properties: + payload: + additionalProperties: {} + description: The input parameters to the workflow + type: object + type: object + WorkflowInstanceCreateRequest: + description: Request used to create a workflow instance. + properties: + meta: + $ref: '#/components/schemas/WorkflowInstanceCreateMeta' + type: object + WorkflowInstanceCreateResponse: + description: Response returned upon successful workflow instance Creation + properties: + instanceId: + description: The ID of the workflow execution. Can be used to fetch execution + status + type: string + type: object + WorkflowListInstancesResponse: + additionalProperties: {} + description: Response returned when listing workflow instances + type: object + WorklflowCancelInstanceResponse: + additionalProperties: {} + description: Information about the canceled instance + type: object + WorklflowGetInstanceResponse: + additionalProperties: {} + description: State of the given workflow instance + type: object securitySchemes: AuthZ: description: This API uses OAuth 2 with the implicit grant flow. @@ -36928,6 +36976,148 @@ paths: summary: Get user memberships tags: - Teams + /api/v2/workflows/{workflow_id}/instances: + get: + description: List all instances of a given workflow + operationId: ListWorkflowInstances + parameters: + - $ref: '#/components/parameters/WorkflowId' + - $ref: '#/components/parameters/PageSize' + - $ref: '#/components/parameters/PageNumber' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/WorkflowListInstancesResponse' + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Forbidden + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: List workflow instances + tags: + - Workflow Automation + post: + description: Execute the given workflow + operationId: CreateWorkflowInstance + parameters: + - $ref: '#/components/parameters/WorkflowId' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/WorkflowInstanceCreateRequest' + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/WorkflowInstanceCreateResponse' + description: Created + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Forbidden + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Execute a workflow + tags: + - Workflow Automation + x-codegen-request-body-name: body + /api/v2/workflows/{workflow_id}/instances/{instance_id}: + get: + description: Get a specific execution of a given workflow + operationId: GetWorkflowInstance + parameters: + - $ref: '#/components/parameters/WorkflowId' + - $ref: '#/components/parameters/InstanceId' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/WorklflowGetInstanceResponse' + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Forbidden + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Not Found + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Get a workflow instance + tags: + - Workflow Automation + /api/v2/workflows/{workflow_id}/instances/{instance_id}/cancel: + put: + description: Cancels a specific execution of a given workflow + operationId: CancelWorkflowInstance + parameters: + - $ref: '#/components/parameters/WorkflowId' + - $ref: '#/components/parameters/InstanceId' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/WorklflowCancelInstanceResponse' + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Forbidden + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Not Found + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Cancel a workflow instance + tags: + - Workflow Automation security: - apiKeyAuth: [] appKeyAuth: [] @@ -37295,4 +37485,9 @@ tags: externalDocs: url: https://docs.datadoghq.com/account_management/users name: Users +- description: Automate your teams operational processes with Datadog Workflow Automation. + externalDocs: + description: Find out more at + url: https://docs.datadoghq.com/service_management/workflows/ + name: Workflow Automation x-group-parameters: true diff --git a/api/datadogV2/api_workflow_automation.go b/api/datadogV2/api_workflow_automation.go new file mode 100644 index 00000000000..a07a0c649b8 --- /dev/null +++ b/api/datadogV2/api_workflow_automation.go @@ -0,0 +1,351 @@ +// 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. + +package datadogV2 + +import ( + _context "context" + _nethttp "net/http" + _neturl "net/url" + "strings" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WorkflowAutomationApi service type +type WorkflowAutomationApi datadog.Service + +// CancelWorkflowInstance Cancel a workflow instance. +// Cancels a specific execution of a given workflow +func (a *WorkflowAutomationApi) CancelWorkflowInstance(ctx _context.Context, workflowId string, instanceId string) (WorklflowCancelInstanceResponse, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodPut + localVarPostBody interface{} + localVarReturnValue WorklflowCancelInstanceResponse + ) + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.WorkflowAutomationApi.CancelWorkflowInstance") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/workflows/{workflow_id}/instances/{instance_id}/cancel" + localVarPath = strings.Replace(localVarPath, "{"+"workflow_id"+"}", _neturl.PathEscape(datadog.ParameterToString(workflowId, "")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"instance_id"+"}", _neturl.PathEscape(datadog.ParameterToString(instanceId, "")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Accept"] = "application/json" + + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 || localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +// CreateWorkflowInstance Execute a workflow. +// Execute the given workflow +func (a *WorkflowAutomationApi) CreateWorkflowInstance(ctx _context.Context, workflowId string, body WorkflowInstanceCreateRequest) (WorkflowInstanceCreateResponse, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodPost + localVarPostBody interface{} + localVarReturnValue WorkflowInstanceCreateResponse + ) + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.WorkflowAutomationApi.CreateWorkflowInstance") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/workflows/{workflow_id}/instances" + localVarPath = strings.Replace(localVarPath, "{"+"workflow_id"+"}", _neturl.PathEscape(datadog.ParameterToString(workflowId, "")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Content-Type"] = "application/json" + localVarHeaderParams["Accept"] = "application/json" + + // body params + localVarPostBody = &body + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +// GetWorkflowInstance Get a workflow instance. +// Get a specific execution of a given workflow +func (a *WorkflowAutomationApi) GetWorkflowInstance(ctx _context.Context, workflowId string, instanceId string) (WorklflowGetInstanceResponse, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodGet + localVarPostBody interface{} + localVarReturnValue WorklflowGetInstanceResponse + ) + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.WorkflowAutomationApi.GetWorkflowInstance") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/workflows/{workflow_id}/instances/{instance_id}" + localVarPath = strings.Replace(localVarPath, "{"+"workflow_id"+"}", _neturl.PathEscape(datadog.ParameterToString(workflowId, "")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"instance_id"+"}", _neturl.PathEscape(datadog.ParameterToString(instanceId, "")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Accept"] = "application/json" + + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 || localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +// ListWorkflowInstancesOptionalParameters holds optional parameters for ListWorkflowInstances. +type ListWorkflowInstancesOptionalParameters struct { + PageSize *int64 + PageNumber *int64 +} + +// NewListWorkflowInstancesOptionalParameters creates an empty struct for parameters. +func NewListWorkflowInstancesOptionalParameters() *ListWorkflowInstancesOptionalParameters { + this := ListWorkflowInstancesOptionalParameters{} + return &this +} + +// WithPageSize sets the corresponding parameter name and returns the struct. +func (r *ListWorkflowInstancesOptionalParameters) WithPageSize(pageSize int64) *ListWorkflowInstancesOptionalParameters { + r.PageSize = &pageSize + return r +} + +// WithPageNumber sets the corresponding parameter name and returns the struct. +func (r *ListWorkflowInstancesOptionalParameters) WithPageNumber(pageNumber int64) *ListWorkflowInstancesOptionalParameters { + r.PageNumber = &pageNumber + return r +} + +// ListWorkflowInstances List workflow instances. +// List all instances of a given workflow +func (a *WorkflowAutomationApi) ListWorkflowInstances(ctx _context.Context, workflowId string, o ...ListWorkflowInstancesOptionalParameters) (WorkflowListInstancesResponse, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodGet + localVarPostBody interface{} + localVarReturnValue WorkflowListInstancesResponse + optionalParams ListWorkflowInstancesOptionalParameters + ) + + if len(o) > 1 { + return localVarReturnValue, nil, datadog.ReportError("only one argument of type ListWorkflowInstancesOptionalParameters is allowed") + } + if len(o) == 1 { + optionalParams = o[0] + } + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.WorkflowAutomationApi.ListWorkflowInstances") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/workflows/{workflow_id}/instances" + localVarPath = strings.Replace(localVarPath, "{"+"workflow_id"+"}", _neturl.PathEscape(datadog.ParameterToString(workflowId, "")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + if optionalParams.PageSize != nil { + localVarQueryParams.Add("page[size]", datadog.ParameterToString(*optionalParams.PageSize, "")) + } + if optionalParams.PageNumber != nil { + localVarQueryParams.Add("page[number]", datadog.ParameterToString(*optionalParams.PageNumber, "")) + } + localVarHeaderParams["Accept"] = "application/json" + + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +// NewWorkflowAutomationApi Returns NewWorkflowAutomationApi. +func NewWorkflowAutomationApi(client *datadog.APIClient) *WorkflowAutomationApi { + return &WorkflowAutomationApi{ + Client: client, + } +} diff --git a/api/datadogV2/doc.go b/api/datadogV2/doc.go index d98f3333db8..0eca7922f25 100644 --- a/api/datadogV2/doc.go +++ b/api/datadogV2/doc.go @@ -342,4 +342,8 @@ // - [UsersApi.ListUsers] // - [UsersApi.SendInvitations] // - [UsersApi.UpdateUser] +// - [WorkflowAutomationApi.CancelWorkflowInstance] +// - [WorkflowAutomationApi.CreateWorkflowInstance] +// - [WorkflowAutomationApi.GetWorkflowInstance] +// - [WorkflowAutomationApi.ListWorkflowInstances] package datadogV2 diff --git a/api/datadogV2/model_workflow_instance_create_meta.go b/api/datadogV2/model_workflow_instance_create_meta.go new file mode 100644 index 00000000000..681ef704db1 --- /dev/null +++ b/api/datadogV2/model_workflow_instance_create_meta.go @@ -0,0 +1,102 @@ +// 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. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WorkflowInstanceCreateMeta Additional information for creating a workflow instance +type WorkflowInstanceCreateMeta struct { + // The input parameters to the workflow + Payload map[string]interface{} `json:"payload,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} +} + +// NewWorkflowInstanceCreateMeta instantiates a new WorkflowInstanceCreateMeta object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWorkflowInstanceCreateMeta() *WorkflowInstanceCreateMeta { + this := WorkflowInstanceCreateMeta{} + return &this +} + +// NewWorkflowInstanceCreateMetaWithDefaults instantiates a new WorkflowInstanceCreateMeta object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWorkflowInstanceCreateMetaWithDefaults() *WorkflowInstanceCreateMeta { + this := WorkflowInstanceCreateMeta{} + return &this +} + +// GetPayload returns the Payload field value if set, zero value otherwise. +func (o *WorkflowInstanceCreateMeta) GetPayload() map[string]interface{} { + if o == nil || o.Payload == nil { + var ret map[string]interface{} + return ret + } + return o.Payload +} + +// GetPayloadOk returns a tuple with the Payload field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WorkflowInstanceCreateMeta) GetPayloadOk() (*map[string]interface{}, bool) { + if o == nil || o.Payload == nil { + return nil, false + } + return &o.Payload, true +} + +// HasPayload returns a boolean if a field has been set. +func (o *WorkflowInstanceCreateMeta) HasPayload() bool { + return o != nil && o.Payload != nil +} + +// SetPayload gets a reference to the given map[string]interface{} and assigns it to the Payload field. +func (o *WorkflowInstanceCreateMeta) SetPayload(v map[string]interface{}) { + o.Payload = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o WorkflowInstanceCreateMeta) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Payload != nil { + toSerialize["payload"] = o.Payload + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WorkflowInstanceCreateMeta) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Payload map[string]interface{} `json:"payload,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"payload"}) + } else { + return err + } + o.Payload = all.Payload + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV2/model_workflow_instance_create_request.go b/api/datadogV2/model_workflow_instance_create_request.go new file mode 100644 index 00000000000..030cd4adf1c --- /dev/null +++ b/api/datadogV2/model_workflow_instance_create_request.go @@ -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. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WorkflowInstanceCreateRequest Request used to create a workflow instance. +type WorkflowInstanceCreateRequest struct { + // Additional information for creating a workflow instance + Meta *WorkflowInstanceCreateMeta `json:"meta,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} +} + +// NewWorkflowInstanceCreateRequest instantiates a new WorkflowInstanceCreateRequest object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWorkflowInstanceCreateRequest() *WorkflowInstanceCreateRequest { + this := WorkflowInstanceCreateRequest{} + return &this +} + +// NewWorkflowInstanceCreateRequestWithDefaults instantiates a new WorkflowInstanceCreateRequest object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWorkflowInstanceCreateRequestWithDefaults() *WorkflowInstanceCreateRequest { + this := WorkflowInstanceCreateRequest{} + return &this +} + +// GetMeta returns the Meta field value if set, zero value otherwise. +func (o *WorkflowInstanceCreateRequest) GetMeta() WorkflowInstanceCreateMeta { + if o == nil || o.Meta == nil { + var ret WorkflowInstanceCreateMeta + return ret + } + return *o.Meta +} + +// GetMetaOk returns a tuple with the Meta field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WorkflowInstanceCreateRequest) GetMetaOk() (*WorkflowInstanceCreateMeta, bool) { + if o == nil || o.Meta == nil { + return nil, false + } + return o.Meta, true +} + +// HasMeta returns a boolean if a field has been set. +func (o *WorkflowInstanceCreateRequest) HasMeta() bool { + return o != nil && o.Meta != nil +} + +// SetMeta gets a reference to the given WorkflowInstanceCreateMeta and assigns it to the Meta field. +func (o *WorkflowInstanceCreateRequest) SetMeta(v WorkflowInstanceCreateMeta) { + o.Meta = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o WorkflowInstanceCreateRequest) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Meta != nil { + toSerialize["meta"] = o.Meta + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WorkflowInstanceCreateRequest) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Meta *WorkflowInstanceCreateMeta `json:"meta,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"meta"}) + } else { + return err + } + + hasInvalidField := false + if all.Meta != nil && all.Meta.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Meta = all.Meta + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_workflow_instance_create_response.go b/api/datadogV2/model_workflow_instance_create_response.go new file mode 100644 index 00000000000..0e971ea3c65 --- /dev/null +++ b/api/datadogV2/model_workflow_instance_create_response.go @@ -0,0 +1,102 @@ +// 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. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WorkflowInstanceCreateResponse Response returned upon successful workflow instance Creation +type WorkflowInstanceCreateResponse struct { + // The ID of the workflow execution. Can be used to fetch execution status + InstanceId *string `json:"instanceId,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} +} + +// NewWorkflowInstanceCreateResponse instantiates a new WorkflowInstanceCreateResponse object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWorkflowInstanceCreateResponse() *WorkflowInstanceCreateResponse { + this := WorkflowInstanceCreateResponse{} + return &this +} + +// NewWorkflowInstanceCreateResponseWithDefaults instantiates a new WorkflowInstanceCreateResponse object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWorkflowInstanceCreateResponseWithDefaults() *WorkflowInstanceCreateResponse { + this := WorkflowInstanceCreateResponse{} + return &this +} + +// GetInstanceId returns the InstanceId field value if set, zero value otherwise. +func (o *WorkflowInstanceCreateResponse) GetInstanceId() string { + if o == nil || o.InstanceId == nil { + var ret string + return ret + } + return *o.InstanceId +} + +// GetInstanceIdOk returns a tuple with the InstanceId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WorkflowInstanceCreateResponse) GetInstanceIdOk() (*string, bool) { + if o == nil || o.InstanceId == nil { + return nil, false + } + return o.InstanceId, true +} + +// HasInstanceId returns a boolean if a field has been set. +func (o *WorkflowInstanceCreateResponse) HasInstanceId() bool { + return o != nil && o.InstanceId != nil +} + +// SetInstanceId gets a reference to the given string and assigns it to the InstanceId field. +func (o *WorkflowInstanceCreateResponse) SetInstanceId(v string) { + o.InstanceId = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o WorkflowInstanceCreateResponse) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.InstanceId != nil { + toSerialize["instanceId"] = o.InstanceId + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WorkflowInstanceCreateResponse) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + InstanceId *string `json:"instanceId,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"instanceId"}) + } else { + return err + } + o.InstanceId = all.InstanceId + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/examples/v2/workflow-automation/CancelWorkflowInstance.go b/examples/v2/workflow-automation/CancelWorkflowInstance.go new file mode 100644 index 00000000000..7959395a9fe --- /dev/null +++ b/examples/v2/workflow-automation/CancelWorkflowInstance.go @@ -0,0 +1,29 @@ +// Cancel a workflow instance returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" +) + +func main() { + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewWorkflowAutomationApi(apiClient) + resp, r, err := api.CancelWorkflowInstance(ctx, "workflow_id", "instance_id") + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `WorkflowAutomationApi.CancelWorkflowInstance`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `WorkflowAutomationApi.CancelWorkflowInstance`:\n%s\n", responseContent) +} diff --git a/examples/v2/workflow-automation/CreateWorkflowInstance.go b/examples/v2/workflow-automation/CreateWorkflowInstance.go new file mode 100644 index 00000000000..109343f16e5 --- /dev/null +++ b/examples/v2/workflow-automation/CreateWorkflowInstance.go @@ -0,0 +1,32 @@ +// Execute a workflow returns "Created" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" +) + +func main() { + body := datadogV2.WorkflowInstanceCreateRequest{ + Meta: &datadogV2.WorkflowInstanceCreateMeta{}, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewWorkflowAutomationApi(apiClient) + resp, r, err := api.CreateWorkflowInstance(ctx, "workflow_id", body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `WorkflowAutomationApi.CreateWorkflowInstance`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `WorkflowAutomationApi.CreateWorkflowInstance`:\n%s\n", responseContent) +} diff --git a/examples/v2/workflow-automation/GetWorkflowInstance.go b/examples/v2/workflow-automation/GetWorkflowInstance.go new file mode 100644 index 00000000000..6a0e601e67b --- /dev/null +++ b/examples/v2/workflow-automation/GetWorkflowInstance.go @@ -0,0 +1,29 @@ +// Get a workflow instance returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" +) + +func main() { + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewWorkflowAutomationApi(apiClient) + resp, r, err := api.GetWorkflowInstance(ctx, "workflow_id", "instance_id") + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `WorkflowAutomationApi.GetWorkflowInstance`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `WorkflowAutomationApi.GetWorkflowInstance`:\n%s\n", responseContent) +} diff --git a/examples/v2/workflow-automation/ListWorkflowInstances.go b/examples/v2/workflow-automation/ListWorkflowInstances.go new file mode 100644 index 00000000000..25d5261193e --- /dev/null +++ b/examples/v2/workflow-automation/ListWorkflowInstances.go @@ -0,0 +1,29 @@ +// List workflow instances returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" +) + +func main() { + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewWorkflowAutomationApi(apiClient) + resp, r, err := api.ListWorkflowInstances(ctx, "workflow_id", *datadogV2.NewListWorkflowInstancesOptionalParameters()) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `WorkflowAutomationApi.ListWorkflowInstances`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `WorkflowAutomationApi.ListWorkflowInstances`:\n%s\n", responseContent) +} diff --git a/tests/scenarios/api_mappings.go b/tests/scenarios/api_mappings.go index 1ab20dc1789..7014f8c929e 100644 --- a/tests/scenarios/api_mappings.go +++ b/tests/scenarios/api_mappings.go @@ -94,5 +94,6 @@ var apiMappings = map[string]map[string]reflect.Value{ "TeamsApi": reflect.ValueOf(datadogV2.NewTeamsApi), "IncidentTeamsApi": reflect.ValueOf(datadogV2.NewIncidentTeamsApi), "UsersApi": reflect.ValueOf(datadogV2.NewUsersApi), + "WorkflowAutomationApi": reflect.ValueOf(datadogV2.NewWorkflowAutomationApi), }, } \ No newline at end of file diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index 0126ff4b812..025369b0f2f 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -2376,5 +2376,31 @@ "undo": { "type": "safe" } + }, + "ListWorkflowInstances": { + "tag": "Workflow Automation", + "undo": { + "type": "safe" + } + }, + "CreateWorkflowInstance": { + "tag": "Workflow Automation", + "undo": { + "operationId": "TODO", + "parameters": [], + "type": "unsafe" + } + }, + "GetWorkflowInstance": { + "tag": "Workflow Automation", + "undo": { + "type": "safe" + } + }, + "CancelWorkflowInstance": { + "tag": "Workflow Automation", + "undo": { + "type": "safe" + } } } diff --git a/tests/scenarios/features/v2/workflow_automation.feature b/tests/scenarios/features/v2/workflow_automation.feature new file mode 100644 index 00000000000..f8fe951158f --- /dev/null +++ b/tests/scenarios/features/v2/workflow_automation.feature @@ -0,0 +1,87 @@ +@endpoint(workflow-automation) @endpoint(workflow-automation-v2) +Feature: Workflow Automation + Automate your teams operational processes with Datadog Workflow + Automation. + + Background: + Given a valid "apiKeyAuth" key in the system + And a valid "appKeyAuth" key in the system + And an instance of "WorkflowAutomation" API + + @generated @skip @team:DataDog/workflow-automation-dev + Scenario: Cancel a workflow instance returns "Bad Request" response + Given new "CancelWorkflowInstance" request + And request contains "workflow_id" parameter from "REPLACE.ME" + And request contains "instance_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/workflow-automation-dev + Scenario: Cancel a workflow instance returns "Not Found" response + Given new "CancelWorkflowInstance" request + And request contains "workflow_id" parameter from "REPLACE.ME" + And request contains "instance_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/workflow-automation-dev + Scenario: Cancel a workflow instance returns "OK" response + Given new "CancelWorkflowInstance" request + And request contains "workflow_id" parameter from "REPLACE.ME" + And request contains "instance_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/workflow-automation-dev + Scenario: Execute a workflow returns "Bad Request" response + Given new "CreateWorkflowInstance" request + And request contains "workflow_id" parameter from "REPLACE.ME" + And body with value {"meta": {}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/workflow-automation-dev + Scenario: Execute a workflow returns "Created" response + Given new "CreateWorkflowInstance" request + And request contains "workflow_id" parameter from "REPLACE.ME" + And body with value {"meta": {}} + When the request is sent + Then the response status is 200 Created + + @generated @skip @team:DataDog/workflow-automation-dev + Scenario: Get a workflow instance returns "Bad Request" response + Given new "GetWorkflowInstance" request + And request contains "workflow_id" parameter from "REPLACE.ME" + And request contains "instance_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/workflow-automation-dev + Scenario: Get a workflow instance returns "Not Found" response + Given new "GetWorkflowInstance" request + And request contains "workflow_id" parameter from "REPLACE.ME" + And request contains "instance_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/workflow-automation-dev + Scenario: Get a workflow instance returns "OK" response + Given new "GetWorkflowInstance" request + And request contains "workflow_id" parameter from "REPLACE.ME" + And request contains "instance_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/workflow-automation-dev + Scenario: List workflow instances returns "Bad Request" response + Given new "ListWorkflowInstances" request + And request contains "workflow_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/workflow-automation-dev + Scenario: List workflow instances returns "OK" response + Given new "ListWorkflowInstances" request + And request contains "workflow_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 OK