-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwork_command.go
More file actions
79 lines (76 loc) · 2.37 KB
/
Copy pathwork_command.go
File metadata and controls
79 lines (76 loc) · 2.37 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/operatorstack/boatstack/boatstack/internal/softwaredelivery/surfaces"
)
func runFlowWork(arguments []string) error {
if len(arguments) == 0 {
return fmt.Errorf("usage: boatstack flow work <show|input-required|answer|complete|block> [flags]")
}
action := arguments[0]
operations := map[string]surfaces.Operation{
"show": surfaces.OperationWorkShow, "input-required": surfaces.OperationWorkInputRequired,
"answer": surfaces.OperationWorkAnswer, "complete": surfaces.OperationWorkComplete, "block": surfaces.OperationWorkBlock,
}
operation, ok := operations[action]
if !ok {
return fmt.Errorf("unknown foreground work action %q", action)
}
options, err := parseOptions("flow work "+action, arguments[1:], "", nil)
if err != nil {
return err
}
if options.programID == "" || options.entryID == "" || options.runID == "" || options.workID == "" {
return fmt.Errorf("flow work %s requires --flow, --entry, --run-id, and --work-id", action)
}
requestedFormat := options.format
bound, err := bindFlowEntry(context.Background(), options)
if err != nil {
if suspended, ok := flowCommitRequiredResponse(err, operation); ok {
return renderResponse(suspended, requestedFormat)
}
return err
}
request, err := buildRequest(operation, bound)
if err != nil {
return err
}
if options.workQuestionSchemaPath != "" {
request.WorkQuestionSchema, err = os.ReadFile(options.workQuestionSchemaPath)
if err != nil {
return err
}
}
if options.workAnswerPath != "" {
request.WorkAnswer, err = os.ReadFile(options.workAnswerPath)
if err != nil {
return err
}
if !json.Valid(request.WorkAnswer) {
return fmt.Errorf("foreground work answer file is not JSON")
}
}
lease, err := acquireFlowExecutionLease(request)
if err != nil {
return err
}
defer lease.Release()
if err := verifyTrustedRequestControlBundle(context.Background(), request); err != nil {
if suspended, ok := flowCommitRequiredResponse(err, operation); ok {
return renderResponse(suspended, options.format)
}
return err
}
kernel, err := standardKernel(context.Background(), request)
if err != nil {
return err
}
response, handleErr := handleWithHumanIdentity(context.Background(), kernel, request)
if renderErr := renderResponse(response, options.format); renderErr != nil {
return renderErr
}
return handleErr
}