forked from PagerDuty/go-pagerduty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_dependency.go
134 lines (110 loc) · 5.32 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package pagerduty
import (
"context"
"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.
//
// Deprecated: Use ListBusinessServiceDependenciesWithContext instead.
func (c *Client) ListBusinessServiceDependencies(businessServiceID string) (*ListServiceDependencies, *http.Response, error) {
return c.listBusinessServiceDependenciesWithContext(context.Background(), businessServiceID)
}
// ListBusinessServiceDependenciesWithContext lists dependencies of a business service.
func (c *Client) ListBusinessServiceDependenciesWithContext(ctx context.Context, businessServiceID string) (*ListServiceDependencies, error) {
lsd, _, err := c.listBusinessServiceDependenciesWithContext(ctx, businessServiceID)
return lsd, err
}
func (c *Client) listBusinessServiceDependenciesWithContext(ctx context.Context, businessServiceID string) (*ListServiceDependencies, *http.Response, error) {
resp, err := c.get(ctx, "/service_dependencies/business_services/"+businessServiceID)
if err != nil {
return nil, nil, err
}
var result ListServiceDependencies
if err = c.decodeJSON(resp, &result); err != nil {
return nil, resp, err
}
return &result, resp, nil
}
// ListTechnicalServiceDependencies lists dependencies of a technical service.
//
// Deprecated: Use ListTechnicalServiceDependenciesWithContext instead.
func (c *Client) ListTechnicalServiceDependencies(serviceID string) (*ListServiceDependencies, *http.Response, error) {
return c.listTechnicalServiceDependenciesWithContext(context.Background(), serviceID)
}
// ListTechnicalServiceDependenciesWithContext lists dependencies of a technical service.
func (c *Client) ListTechnicalServiceDependenciesWithContext(ctx context.Context, serviceID string) (*ListServiceDependencies, error) {
lsd, _, err := c.listTechnicalServiceDependenciesWithContext(ctx, serviceID)
return lsd, err
}
func (c *Client) listTechnicalServiceDependenciesWithContext(ctx context.Context, serviceID string) (*ListServiceDependencies, *http.Response, error) {
resp, err := c.get(ctx, "/service_dependencies/technical_services/"+serviceID)
if err != nil {
return nil, nil, err
}
var result ListServiceDependencies
if err = c.decodeJSON(resp, &result); err != nil {
return nil, resp, err
}
return &result, resp, nil
}
// AssociateServiceDependencies Create new dependencies between two services.
//
// Deprecated: Use AssociateServiceDependenciesWithContext instead.
func (c *Client) AssociateServiceDependencies(dependencies *ListServiceDependencies) (*ListServiceDependencies, *http.Response, error) {
return c.associateServiceDependenciesWithContext(context.Background(), dependencies)
}
// AssociateServiceDependenciesWithContext Create new dependencies between two services.
func (c *Client) AssociateServiceDependenciesWithContext(ctx context.Context, dependencies *ListServiceDependencies) (*ListServiceDependencies, error) {
lsd, _, err := c.associateServiceDependenciesWithContext(ctx, dependencies)
return lsd, err
}
func (c *Client) associateServiceDependenciesWithContext(ctx context.Context, dependencies *ListServiceDependencies) (*ListServiceDependencies, *http.Response, error) {
resp, err := c.post(ctx, "/service_dependencies/associate", dependencies, nil)
if err != nil {
return nil, nil, err
}
var result ListServiceDependencies
if err = c.decodeJSON(resp, &result); err != nil {
return nil, resp, err
}
return &result, resp, nil
}
// DisassociateServiceDependencies Disassociate dependencies between two services.
//
// Deprecated: Use DisassociateServiceDependenciesWithContext instead.
func (c *Client) DisassociateServiceDependencies(dependencies *ListServiceDependencies) (*ListServiceDependencies, *http.Response, error) {
return c.disassociateServiceDependenciesWithContext(context.Background(), dependencies)
}
// DisassociateServiceDependenciesWithContext Disassociate dependencies between two services.
func (c *Client) DisassociateServiceDependenciesWithContext(ctx context.Context, dependencies *ListServiceDependencies) (*ListServiceDependencies, error) {
lsd, _, err := c.disassociateServiceDependenciesWithContext(ctx, dependencies)
return lsd, err
}
// DisassociateServiceDependencies Disassociate dependencies between two services.
func (c *Client) disassociateServiceDependenciesWithContext(ctx context.Context, dependencies *ListServiceDependencies) (*ListServiceDependencies, *http.Response, error) {
resp, err := c.post(ctx, "/service_dependencies/disassociate", dependencies, nil)
if err != nil {
return nil, nil, err
}
var result ListServiceDependencies
if err = c.decodeJSON(resp, &result); err != nil {
return nil, resp, err
}
return &result, resp, nil
}