forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release_series.go
90 lines (66 loc) · 1.79 KB
/
release_series.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 director
import (
"fmt"
gourl "net/url"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type ReleaseSeriesImpl struct {
client Client
name string
}
func (rs ReleaseSeriesImpl) Name() string { return rs.name }
func (rs ReleaseSeriesImpl) Delete(force bool) error {
err := rs.client.DeleteReleaseOrSeries(rs.name, "", force)
if err != nil {
resps, listErr := rs.client.ReleaseSeries()
if listErr != nil {
return err
}
for _, resp := range resps {
if resp.Name == rs.name {
return err
}
}
}
return nil
}
type ReleaseSeriesResp struct {
Name string
Versions []ReleaseVersionResp `json:"release_versions"`
}
type ReleaseVersionResp struct {
Version string
CurrentlyDeployed bool `json:"currently_deployed"`
CommitHash string `json:"commit_hash"`
UncommittedChanges bool `json:"uncommitted_changes"`
}
func (d DirectorImpl) FindReleaseSeries(slug ReleaseSeriesSlug) (ReleaseSeries, error) {
return ReleaseSeriesImpl{client: d.client, name: slug.Name()}, nil
}
func (c Client) ReleaseSeries() ([]ReleaseSeriesResp, error) {
var resps []ReleaseSeriesResp
err := c.clientRequest.Get("/releases", &resps)
if err != nil {
return resps, bosherr.WrapErrorf(err, "Finding releases")
}
return resps, nil
}
func (c Client) DeleteReleaseOrSeries(name, version string, force bool) error {
if len(name) == 0 {
return bosherr.Error("Expected non-empty release name")
}
// version may be empty
query := gourl.Values{}
if len(version) > 0 {
query.Add("version", version)
}
if force {
query.Add("force", "true")
}
path := fmt.Sprintf("/releases/%s?%s", name, query.Encode())
_, err := c.taskClientRequest.DeleteResult(path)
if err != nil {
return bosherr.WrapErrorf(err, "Deleting release or series '%s[/%s]'", name, version)
}
return nil
}