-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow_update.go
More file actions
48 lines (41 loc) · 1.41 KB
/
workflow_update.go
File metadata and controls
48 lines (41 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package unstructured
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
)
// UpdateWorkflowRequest represents the request to update a workflow.
type UpdateWorkflowRequest struct {
ID string `json:"-"`
Name *string `json:"name,omitempty"`
SourceID *string `json:"source_id,omitempty"`
DestinationID *string `json:"destination_id,omitempty"`
WorkflowType *WorkflowType `json:"workflow_type,omitempty"`
WorkflowNodes []WorkflowNode `json:"workflow_nodes,omitempty"`
Schedule *string `json:"schedule,omitempty"`
ReprocessAll *bool `json:"reprocess_all,omitempty"`
}
// UpdateWorkflow updates the configuration of an existing workflow.
// It returns the updated workflow.
func (c *Client) UpdateWorkflow(ctx context.Context, in UpdateWorkflowRequest) (*Workflow, error) {
body, err := json.Marshal(in)
if err != nil {
return nil, fmt.Errorf("failed to marshal workflow update request: %w", err)
}
req, err := http.NewRequestWithContext(ctx,
http.MethodPut,
c.endpoint.JoinPath("workflows", in.ID).String(),
bytes.NewReader(body),
)
if err != nil {
return nil, fmt.Errorf("failed to create HTTP request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
var workflow Workflow
if err := c.do(req, &workflow); err != nil {
return nil, fmt.Errorf("failed to update workflow: %w", err)
}
return &workflow, nil
}