-
Notifications
You must be signed in to change notification settings - Fork 18
/
persistentworker.go
65 lines (48 loc) · 1.71 KB
/
persistentworker.go
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
package instance
import (
"github.com/cirruslabs/cirrus-ci-agent/api"
"github.com/cirruslabs/cirrus-cli/pkg/parser/instance/isolation"
"github.com/cirruslabs/cirrus-cli/pkg/parser/nameable"
"github.com/cirruslabs/cirrus-cli/pkg/parser/node"
"github.com/cirruslabs/cirrus-cli/pkg/parser/parseable"
"github.com/cirruslabs/cirrus-cli/pkg/parser/schema"
jsschema "github.com/lestrrat-go/jsschema"
)
type PersistentWorker struct {
proto api.PersistentWorkerInstance
parseable.DefaultParser
}
func NewPersistentWorker(mergedEnv map[string]string) *PersistentWorker {
pworker := &PersistentWorker{}
labelsSchema := schema.String("Labels for selection.")
pworker.OptionalField(nameable.NewSimpleNameable("labels"), labelsSchema, func(node *node.Node) error {
labels, err := node.GetStringMapping()
if err != nil {
return err
}
pworker.proto.Labels = labels
return nil
})
isolationSchema := isolation.NewIsolation(mergedEnv).Schema()
pworker.OptionalField(nameable.NewSimpleNameable("isolation"), isolationSchema, func(node *node.Node) error {
isolation := isolation.NewIsolation(mergedEnv)
if err := isolation.Parse(node); err != nil {
return err
}
pworker.proto.Isolation = isolation.Proto()
return nil
})
return pworker
}
func (pworker *PersistentWorker) Parse(node *node.Node) (*api.PersistentWorkerInstance, error) {
if err := pworker.DefaultParser.Parse(node); err != nil {
return nil, err
}
return &pworker.proto, nil
}
func (pworker *PersistentWorker) Schema() *jsschema.Schema {
modifiedSchema := pworker.DefaultParser.Schema()
modifiedSchema.Type = jsschema.PrimitiveTypes{jsschema.ObjectType}
modifiedSchema.Description = "Persistent Worker definition."
return modifiedSchema
}