forked from PagerDuty/go-pagerduty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_dependency.go
68 lines (60 loc) · 2.55 KB
/
service_dependency.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
package pagerduty
import (
"net/http"
)
// ServiceDependency represents a relationship between a business and technical service
type ServiceDependency struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
SupportingService *ServiceObj `json:"supporting_service,omitempty"`
DependentService *ServiceObj `json:"dependent_service,omitempty"`
}
// ServiceObj represents a service object in service relationship
type ServiceObj struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
}
// ListServiceDependencies represents a list of dependencies for a service
type ListServiceDependencies struct {
Relationships []*ServiceDependency `json:"relationships,omitempty"`
}
// ListBusinessServiceDependencies lists dependencies of a business service.
func (c *Client) ListBusinessServiceDependencies(businessServiceID string) (*ListServiceDependencies, *http.Response, error) {
resp, err := c.get("/service_dependencies/business_services/" + businessServiceID)
if err != nil {
return nil, nil, err
}
var result ListServiceDependencies
return &result, resp, c.decodeJSON(resp, &result)
}
// ListTechnicalServiceDependencies lists dependencies of a technical service.
func (c *Client) ListTechnicalServiceDependencies(serviceID string) (*ListServiceDependencies, *http.Response, error) {
resp, err := c.get("/service_dependencies/technical_services/" + serviceID)
if err != nil {
return nil, nil, err
}
var result ListServiceDependencies
return &result, resp, c.decodeJSON(resp, &result)
}
// AssociateServiceDependencies Create new dependencies between two services.
func (c *Client) AssociateServiceDependencies(dependencies *ListServiceDependencies) (*ListServiceDependencies, *http.Response, error) {
data := make(map[string]*ListServiceDependencies)
data["relationships"] = dependencies
resp, err := c.post("/service_dependencies/associate", data, nil)
if err != nil {
return nil, nil, err
}
var result ListServiceDependencies
return &result, resp, c.decodeJSON(resp, &result)
}
// DisassociateServiceDependencies Disassociate dependencies between two services.
func (c *Client) DisassociateServiceDependencies(dependencies *ListServiceDependencies) (*ListServiceDependencies, *http.Response, error) {
data := make(map[string]*ListServiceDependencies)
data["relationships"] = dependencies
resp, err := c.post("/service_dependencies/disassociate", data, nil)
if err != nil {
return nil, nil, err
}
var result ListServiceDependencies
return &result, resp, c.decodeJSON(resp, &result)
}