/
pipeline_stage.go
156 lines (145 loc) · 5.46 KB
/
pipeline_stage.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package provider
import (
"errors"
"github.com/get-bridge/terraform-provider-spinnaker/client"
"github.com/hashicorp/terraform/helper/schema"
)
type stage interface {
fromClientStage(client.Stage) (stage, error)
toClientStage(config *client.Config, refID string) (client.Stage, error)
SetResourceData(*schema.ResourceData) error
}
type baseStage struct {
Name string `mapstructure:"name"`
RequisiteStageRefIds []string `mapstructure:"requisite_stage_ref_ids"`
ExpectedArtifacts *[]*manifestExpectedArtifact `mapstructure:"expected_artifact"`
Notifications *[]map[string]interface{} `mapstructure:"notification"`
StageEnabled *[]*stageEnabled `mapstructure:"stage_enabled"`
CompleteOtherBranchesThenFail bool `mapstructure:"complete_other_branches_then_fail"`
ContinuePipeline bool `mapstructure:"continue_pipeline"`
FailOnFailedExpressions bool `mapstructure:"fail_on_failed_expressions"`
FailPipeline bool `mapstructure:"fail_pipeline"`
OverrideTimeout bool `mapstructure:"override_timeout"`
StageTimeoutMS int `mapstructure:"stage_timeout_ms"`
RestrictExecutionDuringTimeWindow bool `mapstructure:"restrict_execution_during_time_window"`
RestrictedExecutionWindow *[]*stageExecutionWindow `mapstructure:"restricted_execution_window"`
RequiredArtifactIds *[]string `mapstructure:"required_artifact_ids"`
}
func newBaseStage() *baseStage {
return &baseStage{
FailPipeline: true,
}
}
func (s *baseStage) baseToClientStage(cs *client.BaseStage, refID string, notificationFactory func() notification) error {
if refID == "" {
return errors.New("Ref Id cannot be empty")
}
notifications, err := toClientNotifications(notificationFactory, s.Notifications)
if err != nil {
return err
}
cs.Name = s.Name
cs.RefID = refID
cs.RequisiteStageRefIds = s.RequisiteStageRefIds
art, err := toClientExpectedArtifacts(s.ExpectedArtifacts)
if err != nil {
return err
}
cs.ExpectedArtifacts = art
cs.Notifications = notifications
cs.SendNotifications = notifications != nil && len(*notifications) > 0
cs.StageEnabled = toClientStageEnabled(s.StageEnabled)
cs.CompleteOtherBranchesThenFail = s.CompleteOtherBranchesThenFail
cs.ContinuePipeline = s.ContinuePipeline
cs.FailOnFailedExpressions = s.FailOnFailedExpressions
cs.FailPipeline = s.FailPipeline
cs.OverrideTimeout = s.OverrideTimeout
cs.StageTimeoutMS = s.StageTimeoutMS
cs.RestrictExecutionDuringTimeWindow = s.RestrictExecutionDuringTimeWindow
cs.RestrictedExecutionWindow = toClientExecutionWindow(s.RestrictedExecutionWindow)
cs.RequiredArtifactIds = s.RequiredArtifactIds
return nil
}
func newDefaultNotificationInterface() notification {
return newDefaultNotification()
}
func (s *baseStage) baseFromClientStage(clientStage *client.BaseStage, notificationFactory func() notification) error {
s.Name = clientStage.Name
s.RequisiteStageRefIds = clientStage.RequisiteStageRefIds
notifications, err := fromClientNotifications(notificationFactory, clientStage.Notifications)
if err != nil {
return err
}
s.ExpectedArtifacts = fromClientExpectedArtifacts(clientStage.ExpectedArtifacts)
s.Notifications = notifications
s.StageEnabled = fromClientStageEnabled(clientStage.StageEnabled)
s.CompleteOtherBranchesThenFail = clientStage.CompleteOtherBranchesThenFail
s.ContinuePipeline = clientStage.ContinuePipeline
s.FailOnFailedExpressions = clientStage.FailOnFailedExpressions
s.FailPipeline = clientStage.FailPipeline
s.OverrideTimeout = clientStage.OverrideTimeout
s.StageTimeoutMS = clientStage.StageTimeoutMS
s.RestrictExecutionDuringTimeWindow = clientStage.RestrictExecutionDuringTimeWindow
s.RestrictedExecutionWindow = fromClientExecutionWindow(clientStage.RestrictedExecutionWindow)
s.RequiredArtifactIds = clientStage.RequiredArtifactIds
return nil
}
func (s *baseStage) baseSetResourceData(d *schema.ResourceData) error {
err := d.Set("name", s.Name)
if err != nil {
return err
}
err = d.Set("expected_artifact", s.ExpectedArtifacts)
if err != nil {
return err
}
err = d.Set("notification", s.Notifications)
if err != nil {
return err
}
err = d.Set("notification", s.Notifications)
if err != nil {
return err
}
err = d.Set("stage_enabled", s.StageEnabled)
if err != nil {
return err
}
err = d.Set("complete_other_branches_then_fail", s.CompleteOtherBranchesThenFail)
if err != nil {
return err
}
err = d.Set("continue_pipeline", s.ContinuePipeline)
if err != nil {
return err
}
err = d.Set("fail_on_failed_expressions", s.FailOnFailedExpressions)
if err != nil {
return err
}
err = d.Set("fail_pipeline", s.FailPipeline)
if err != nil {
return err
}
err = d.Set("override_timeout", s.OverrideTimeout)
if err != nil {
return err
}
err = d.Set("stage_timeout_ms", s.StageTimeoutMS)
if err != nil {
return err
}
err = d.Set("restrict_execution_during_time_window", s.RestrictExecutionDuringTimeWindow)
if err != nil {
return err
}
err = d.Set("restricted_execution_window", s.RestrictedExecutionWindow)
if err != nil {
return err
}
err = d.Set("required_artifact_ids", s.RequiredArtifactIds)
if err != nil {
return err
}
return nil
}