-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathapplication-variant.go
84 lines (76 loc) · 2.53 KB
/
application-variant.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
package cloud66
import (
"fmt"
"time"
)
// ApplicationVariant indicates a rails/rack application deployment variant
type ApplicationVariant struct {
UID string `json:"uid"`
Type string `json:"type"`
SubType string `json:"sub_type"`
GitRepo string `json:"git_repo"`
GitRef string `json:"git_ref"`
GitHash string `json:"git_hash"`
Tag string `json:"tag"`
Percentage int `json:"percentage"`
UpdatedAt time.Time `json:"updated_at_iso"`
CreatedAt time.Time `json:"created_at_iso"`
}
func (a *ApplicationVariant) TypeString() string {
if a.SubType == "" {
return a.Type
}
return fmt.Sprintf("%s/%s", a.Type, a.SubType)
}
func (a *ApplicationVariant) PercentageString() string {
return fmt.Sprintf("%v%%", a.Percentage)
}
// GetApplicationVariants returns list of application variants
func (c *Client) GetApplicationVariants(stackUid string) ([]ApplicationVariant, error) {
var variants []ApplicationVariant
req, err := c.NewRequest("GET", "/stacks/"+stackUid+"/application_variants.json", nil, nil)
if err != nil {
return nil, err
}
err = c.DoReq(req, &variants, nil)
if err != nil {
return nil, err
}
return variants, nil
}
// CommitRolloutVariant locks in the selected rollout variant
func (c *Client) CommitRolloutVariant(stackUid string, rolloutVariant ApplicationVariant) error {
requestBody := struct {
Operation string `json:"operation"`
}{
Operation: "commit",
}
req, err := c.NewRequest("PATCH", "/stacks/"+stackUid+"/application_variants/"+rolloutVariant.UID+".json", requestBody, nil)
if err != nil {
return err
}
return c.DoReq(req, nil, nil)
}
// UpdateCanaryRolloutPercentage updates the canary variant percentage
func (c *Client) UpdateCanaryRolloutPercentage(stackUid string, canaryVariant ApplicationVariant, canaryPercentage int) error {
requestBody := struct {
Operation string `json:"operation"`
CanaryPercentage int `json:"canary_percentage"`
}{
Operation: "commit",
CanaryPercentage: canaryPercentage,
}
req, err := c.NewRequest("PATCH", "/stacks/"+stackUid+"/application_variants/"+canaryVariant.UID+".json", requestBody, nil)
if err != nil {
return err
}
return c.DoReq(req, nil, nil)
}
// DeletePreviewVariant removes the preview variant
func (c *Client) DeletePreviewVariant(stackUid string, previewVariant ApplicationVariant) error {
req, err := c.NewRequest("DELETE", "/stacks/"+stackUid+"/application_variants/"+previewVariant.UID+".json", nil, nil)
if err != nil {
return err
}
return c.DoReq(req, nil, nil)
}