-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreleases.go
More file actions
97 lines (78 loc) · 2.58 KB
/
releases.go
File metadata and controls
97 lines (78 loc) · 2.58 KB
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
// Package releases provides methods for managing app releases.
package releases
import (
"encoding/json"
"fmt"
drycc "github.com/drycc/controller-sdk-go"
"github.com/drycc/controller-sdk-go/api"
)
// List lists an app's releases.
func List(c *drycc.Client, appID, ptypes string, results int) ([]api.Release, int, error) {
u := fmt.Sprintf("/v2/apps/%s/releases/", appID)
if ptypes != "" {
u += fmt.Sprintf("?ptypes=%s", ptypes)
}
body, count, reqErr := c.LimitedRequest(u, results)
if reqErr != nil && !drycc.IsErrAPIMismatch(reqErr) {
return []api.Release{}, -1, reqErr
}
var releases []api.Release
if err := json.Unmarshal([]byte(body), &releases); err != nil {
return []api.Release{}, -1, err
}
return releases, count, reqErr
}
// Get retrieves a release of an app.
func Get(c *drycc.Client, appID string, version int) (api.Release, error) {
u := fmt.Sprintf("/v2/apps/%s/releases/v%d/", appID, version)
res, reqErr := c.Request("GET", u, nil)
if reqErr != nil && !drycc.IsErrAPIMismatch(reqErr) {
return api.Release{}, reqErr
}
defer res.Body.Close()
release := api.Release{}
if err := json.NewDecoder(res.Body).Decode(&release); err != nil {
return api.Release{}, err
}
return release, nil
}
// Deploy deploy an app's processes. To deploy all app processes, pass empty strings for
// procType and name. To deploy an specific process, pass an procType by leave name empty.
// To deploy a specific instance, pass a procType and a name.
func Deploy(c *drycc.Client, appID string, targets map[string]any) error {
u := fmt.Sprintf("/v2/apps/%s/releases/deploy/", appID)
body, err := json.Marshal(targets)
if err != nil {
return err
}
res, err := c.Request("POST", u, body)
if err != nil && !drycc.IsErrAPIMismatch(err) {
return err
}
defer res.Body.Close()
return err
}
// Rollback rolls back an app to a previous release. If version is -1, this rolls back to
// the previous release. Otherwise, roll back to the specified version.
func Rollback(c *drycc.Client, appID string, ptypes string, version int) (int, error) {
u := fmt.Sprintf("/v2/apps/%s/releases/rollback/", appID)
req := api.ReleaseRollback{Ptypes: ptypes, Version: version}
var err error
var reqBody []byte
if version != -1 {
reqBody, err = json.Marshal(req)
if err != nil {
return -1, err
}
}
res, reqErr := c.Request("POST", u, reqBody)
if reqErr != nil && !drycc.IsErrAPIMismatch(reqErr) {
return -1, reqErr
}
defer res.Body.Close()
response := api.ReleaseRollback{}
if err = json.NewDecoder(res.Body).Decode(&response); err != nil {
return -1, err
}
return response.Version, reqErr
}