-
Notifications
You must be signed in to change notification settings - Fork 18
/
isolation.go
78 lines (56 loc) · 2 KB
/
isolation.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
66
67
68
69
70
71
72
73
74
75
76
77
78
package isolation
import (
"github.com/cirruslabs/cirrus-ci-agent/api"
"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/parserkit"
jsschema "github.com/lestrrat-go/jsschema"
)
type Isolation struct {
proto api.Isolation
parseable.DefaultParser
}
func NewIsolation(mergedEnv map[string]string, parserKit *parserkit.ParserKit) *Isolation {
isolation := &Isolation{}
parallelsSchema := NewParallels(mergedEnv).Schema()
isolation.OptionalField(nameable.NewSimpleNameable("parallels"), parallelsSchema, func(node *node.Node) error {
parallels := NewParallels(mergedEnv)
if err := parallels.Parse(node, parserKit); err != nil {
return err
}
isolation.proto.Type = parallels.Proto()
return nil
})
containerSchema := NewContainer(mergedEnv).Schema()
isolation.OptionalField(nameable.NewSimpleNameable("container"), containerSchema, func(node *node.Node) error {
container := NewContainer(mergedEnv)
if err := container.Parse(node, parserKit); err != nil {
return err
}
isolation.proto.Type = container.Proto()
return nil
})
tartSchema := NewTart(mergedEnv).Schema()
isolation.OptionalField(nameable.NewSimpleNameable("tart"), tartSchema, func(node *node.Node) error {
tart := NewTart(mergedEnv)
if err := tart.Parse(node, parserKit); err != nil {
return err
}
isolation.proto.Type = tart.Proto()
return nil
})
return isolation
}
func (isolation *Isolation) Parse(node *node.Node, parserKit *parserkit.ParserKit) error {
return isolation.DefaultParser.Parse(node, parserKit)
}
func (isolation *Isolation) Proto() *api.Isolation {
return &isolation.proto
}
func (isolation *Isolation) Schema() *jsschema.Schema {
modifiedSchema := isolation.DefaultParser.Schema()
modifiedSchema.Type = jsschema.PrimitiveTypes{jsschema.ObjectType}
modifiedSchema.Description = "Persistent Worker isolation."
return modifiedSchema
}