This repository has been archived by the owner on Oct 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
deployments.go
60 lines (48 loc) · 1.46 KB
/
deployments.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
package api
import (
"fmt"
"net/url"
)
// ListDeployments returns deployments by newrelic applicationID.
func (c *Client) ListDeployments(id int) ([]Deployment, error) {
deployments := []Deployment{}
reqURL, err := url.Parse(fmt.Sprintf("/applications/%v/deployments.json", id))
if err != nil {
return nil, err
}
nextPath := reqURL.String()
for nextPath != "" {
resp := struct {
Deployments []Deployment `json:"deployments,omitempty"`
}{}
nextPath, err = c.Do("GET", nextPath, nil, &resp)
if err != nil {
return nil, err
}
deployments = append(deployments, resp.Deployments...)
}
return deployments, nil
}
// CreateDeployment creates a deployment for an application.
func (c *Client) CreateDeployment(applicationID int, deployment Deployment) (*Deployment, error) {
req := struct {
Deployment Deployment `json:"deployment"`
}{
Deployment: deployment,
}
resp := struct {
Deployment Deployment `json:"deployment,omitempty"`
}{}
u := &url.URL{Path: fmt.Sprintf("/applications/%v/deployments.json", applicationID)}
_, err := c.Do("POST", u.String(), req, &resp)
if err != nil {
return nil, err
}
return &resp.Deployment, nil
}
// DeleteDeployment deletes an application deployment from an application.
func (c *Client) DeleteDeployment(applicationID, deploymentID int) error {
u := &url.URL{Path: fmt.Sprintf("/applications/%v/deployments/%v.json", applicationID, deploymentID)}
_, err := c.Do("DELETE", u.String(), nil, nil)
return err
}