-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment_config.go
159 lines (128 loc) · 4.41 KB
/
deployment_config.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
157
158
159
package awsspec
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/codedeploy"
)
// DeploymentConfigExists returns true if the specified Deployment Config exist
func (c CodeDeploySpec) DeploymentConfigExists(name string) (res bool, err error) {
_, err = getDeploymentConfig(c.Session, name)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "DeploymentConfigDoesNotExistException" {
return false, nil
}
}
return
}
return true, nil
}
// DeploymentConfigHasComputePlatform returns true if the compute platform for the specified Deployment Config matches the one provided
func (c CodeDeploySpec) DeploymentConfigHasComputePlatform(name, computePlatform string) (res bool, err error) {
cfg, err := getDeploymentConfig(c.Session, name)
if err != nil {
return
}
if aws.StringValue(cfg.DeploymentConfigInfo.ComputePlatform) == computePlatform {
return true, nil
}
return
}
// DeploymentConfigIsCanary returns true if the traffic routing type of the specified Deployment Config is of type "TimeBasedCanary"
func (c CodeDeploySpec) DeploymentConfigIsCanary(name string) (res bool, err error) {
cfg, err := getDeploymentConfig(c.Session, name)
if err != nil {
return
}
if aws.StringValue(cfg.DeploymentConfigInfo.TrafficRoutingConfig.Type) == "TimeBasedCanary" {
return true, nil
}
return
}
// DeploymentConfigIsLinear returns true if the traffic routing type of the specified Deployment Config is of type "TimeBasedLinear"
func (c CodeDeploySpec) DeploymentConfigIsLinear(name string) (res bool, err error) {
cfg, err := getDeploymentConfig(c.Session, name)
if err != nil {
return
}
if aws.StringValue(cfg.DeploymentConfigInfo.TrafficRoutingConfig.Type) == "TimeBasedLinear" {
return true, nil
}
return
}
// DeploymentConfigHasCanaryInterval returns true if the canary interval of the specified Deployment Config matches the one provided
func (c CodeDeploySpec) DeploymentConfigHasCanaryInterval(name string, interval int) (res bool, err error) {
res, err = c.DeploymentConfigIsCanary(name)
if err != nil || !res {
return
}
cfg, err := getDeploymentConfig(c.Session, name)
if err != nil {
return
}
i := cfg.DeploymentConfigInfo.TrafficRoutingConfig.TimeBasedCanary.CanaryInterval
if int(aws.Int64Value(i)) == interval {
return true, nil
}
return false, nil
}
// DeploymentConfigHasCanaryPercentage returns true if the canary percentage of the specified Deployment Config matches the one provided
func (c CodeDeploySpec) DeploymentConfigHasCanaryPercentage(name string, percent int) (res bool, err error) {
res, err = c.DeploymentConfigIsCanary(name)
if err != nil || !res {
return
}
cfg, err := getDeploymentConfig(c.Session, name)
if err != nil {
return
}
i := cfg.DeploymentConfigInfo.TrafficRoutingConfig.TimeBasedCanary.CanaryPercentage
if int(aws.Int64Value(i)) == percent {
return true, nil
}
return false, nil
}
// DeploymentConfigHasLinearInterval returns true if the linear interval of the specified Deployment Config matches the one provided
func (c CodeDeploySpec) DeploymentConfigHasLinearInterval(name string, interval int) (res bool, err error) {
res, err = c.DeploymentConfigIsLinear(name)
if err != nil || !res {
return
}
cfg, err := getDeploymentConfig(c.Session, name)
if err != nil {
return
}
i := cfg.DeploymentConfigInfo.TrafficRoutingConfig.TimeBasedLinear.LinearInterval
if int(aws.Int64Value(i)) == interval {
return true, nil
}
return false, nil
}
// DeploymentConfigHasLinearPercentage returns true if the linear percentage of the specified Deployment Config matches the one provided
func (c CodeDeploySpec) DeploymentConfigHasLinearPercentage(name string, percent int) (res bool, err error) {
res, err = c.DeploymentConfigIsLinear(name)
if err != nil || !res {
return
}
cfg, err := getDeploymentConfig(c.Session, name)
if err != nil {
return
}
i := cfg.DeploymentConfigInfo.TrafficRoutingConfig.TimeBasedLinear.LinearPercentage
if int(aws.Int64Value(i)) == percent {
return true, nil
}
return false, nil
}
func getDeploymentConfig(s *session.Session, name string) (cfg *codedeploy.GetDeploymentConfigOutput, err error) {
svc := getCodeDeployAPI(s)
in := &codedeploy.GetDeploymentConfigInput{
DeploymentConfigName: aws.String(name),
}
cfg, err = svc.GetDeploymentConfig(in)
if err != nil {
return
}
return
}