forked from PagerDuty/go-pagerduty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_dependency.go
112 lines (92 loc) · 4.07 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
package pagerduty
import (
"context"
)
// 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, 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) {
resp, err := c.get(ctx, "/service_dependencies/business_services/"+businessServiceID)
if err != nil {
return nil, err
}
var result ListServiceDependencies
if err = c.decodeJSON(resp, &result); err != nil {
return nil, err
}
return &result, nil
}
// ListTechnicalServiceDependencies lists dependencies of a technical service.
//
// Deprecated: Use ListTechnicalServiceDependenciesWithContext instead.
func (c *Client) ListTechnicalServiceDependencies(serviceID string) (*ListServiceDependencies, 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) {
resp, err := c.get(ctx, "/service_dependencies/technical_services/"+serviceID)
if err != nil {
return nil, err
}
var result ListServiceDependencies
if err = c.decodeJSON(resp, &result); err != nil {
return nil, err
}
return &result, nil
}
// AssociateServiceDependencies Create new dependencies between two services.
//
// Deprecated: Use AssociateServiceDependenciesWithContext instead.
func (c *Client) AssociateServiceDependencies(dependencies *ListServiceDependencies) (*ListServiceDependencies, 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) {
resp, err := c.post(ctx, "/service_dependencies/associate", dependencies, nil)
if err != nil {
return nil, err
}
var result ListServiceDependencies
if err = c.decodeJSON(resp, &result); err != nil {
return nil, err
}
return &result, nil
}
// DisassociateServiceDependencies Disassociate dependencies between two services.
//
// Deprecated: Use DisassociateServiceDependenciesWithContext instead.
func (c *Client) DisassociateServiceDependencies(dependencies *ListServiceDependencies) (*ListServiceDependencies, error) {
return c.DisassociateServiceDependenciesWithContext(context.Background(), dependencies)
}
// DisassociateServiceDependenciesWithContext Disassociate dependencies between two services.
func (c *Client) DisassociateServiceDependenciesWithContext(ctx context.Context, dependencies *ListServiceDependencies) (*ListServiceDependencies, error) {
resp, err := c.post(ctx, "/service_dependencies/disassociate", dependencies, nil)
if err != nil {
return nil, err
}
var result ListServiceDependencies
if err = c.decodeJSON(resp, &result); err != nil {
return nil, err
}
return &result, nil
}