-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.go
More file actions
76 lines (68 loc) · 1.95 KB
/
Copy pathrequest.go
File metadata and controls
76 lines (68 loc) · 1.95 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
package taskrun
import (
"context"
"io"
"github.com/gookit/taskrun/internal/data"
)
// Request describes one isolated run. Inputs are copied when the run starts;
// the caller must not mutate them concurrently during Run.
type Request struct {
Task string
Args []string
Vars map[string]any
Env map[string]string
HostData map[string]any
Dir string
DryRun bool
IO IO
}
// IO controls process streams and bounded capture. A nil Stdin means EOF and a
// nil Stdout or Stderr means the data is discarded. CaptureLimit is a per
// stream byte bound: 0 streams without collecting, negative values are
// rejected.
type IO struct {
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
CaptureLimit int64
}
// HostCall is the isolated input to a Handler. Handlers must respect ctx
// cooperatively: a Go goroutine cannot be stopped by force.
type HostCall struct {
Name string
Args []any
Vars map[string]any
Env map[string]string
Dir string
}
// validate rejects a request that cannot be executed safely.
func (r Request) validate() error {
if r.Task == "" {
return &RunError{Kind: ErrKindInvalidRequest, Err: errf("Task is required")}
}
if r.IO.CaptureLimit < 0 {
return &RunError{Kind: ErrKindInvalidRequest, Err: errf("IO.CaptureLimit must not be negative")}
}
if err := validateData(r.Vars, "Request.Vars"); err != nil {
return err
}
if err := validateData(r.HostData, "Request.HostData"); err != nil {
return err
}
for key := range r.Env {
if key == "" {
return &RunError{Kind: ErrKindInvalidRequest, Err: errf("Request.Env contains an empty key")}
}
}
return nil
}
// newRequest copies caller data so a run never observes later mutations.
func newRequest(req Request) Request {
out := req
out.Args = append([]string(nil), req.Args...)
out.Vars = data.CloneMap(req.Vars)
out.Env = data.CloneStringMap(req.Env)
out.HostData = data.CloneMap(req.HostData)
return out
}
var _ = context.Canceled