forked from runatlantis/atlantis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
valid.go
90 lines (78 loc) · 1.76 KB
/
valid.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
79
80
81
82
83
84
85
86
87
88
89
90
// Package valid contains the structs representing the atlantis.yaml config
// after it's been parsed and validated.
package valid
import "github.com/hashicorp/go-version"
// Config is the atlantis.yaml config after it's been parsed and validated.
type Config struct {
// Version is the version of the atlantis YAML file. Will always be equal
// to 2.
Version int
Projects []Project
Workflows map[string]Workflow
}
func (c Config) GetPlanStage(workflowName string) *Stage {
for name, flow := range c.Workflows {
if name == workflowName {
return flow.Plan
}
}
return nil
}
func (c Config) GetApplyStage(workflowName string) *Stage {
for name, flow := range c.Workflows {
if name == workflowName {
return flow.Apply
}
}
return nil
}
func (c Config) FindProjectsByDirWorkspace(dir string, workspace string) []Project {
var ps []Project
for _, p := range c.Projects {
if p.Dir == dir && p.Workspace == workspace {
ps = append(ps, p)
}
}
return ps
}
func (c Config) FindProjectByName(name string) *Project {
for _, p := range c.Projects {
if p.Name != nil && *p.Name == name {
return &p
}
}
return nil
}
type Project struct {
Dir string
Workspace string
Name *string
Workflow *string
TerraformVersion *version.Version
Autoplan Autoplan
ApplyRequirements []string
}
// GetName returns the name of the project or an empty string if there is no
// project name.
func (p Project) GetName() string {
if p.Name != nil {
return *p.Name
}
return ""
}
type Autoplan struct {
WhenModified []string
Enabled bool
}
type Stage struct {
Steps []Step
}
type Step struct {
StepName string
ExtraArgs []string
RunCommand []string
}
type Workflow struct {
Apply *Stage
Plan *Stage
}