-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathevent_bridge_integration.go
157 lines (127 loc) · 4.32 KB
/
event_bridge_integration.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package scalr
import (
"context"
"errors"
"fmt"
"net/url"
)
// Compile-time proof of interface implementation.
var _ EventBridgeIntegrations = (*eventBridgeIntegrations)(nil)
type EventBridgeIntegrations interface {
List(ctx context.Context, options EventBridgeIntegrationListOptions) (*EventBridgeIntegrationList, error)
Create(ctx context.Context, options EventBridgeIntegrationCreateOptions) (*EventBridgeIntegration, error)
Read(ctx context.Context, id string) (*EventBridgeIntegration, error)
Update(ctx context.Context, id string, options EventBridgeIntegrationUpdateOptions) (*EventBridgeIntegration, error)
Delete(ctx context.Context, id string) error
}
// eventBridgeIntegrations implements EventBridgeIntegrations.
type eventBridgeIntegrations struct {
client *Client
}
type EventBridgeIntegrationList struct {
*Pagination
Items []*EventBridgeIntegration
}
// EventBridgeIntegration represents a Scalr IACP eventBridge integration.
type EventBridgeIntegration struct {
ID string `jsonapi:"primary,aws-event-bridge-integrations"`
Name string `jsonapi:"attr,name"`
Status IntegrationStatus `jsonapi:"attr,status"`
EventSource string `jsonapi:"attr,event-source"`
EventSourceARN string `jsonapi:"attr,event-source-arn"`
AWSAccountId string `jsonapi:"attr,aws-account-id"`
Region string `jsonapi:"attr,region"`
// Relations
Account *Account `jsonapi:"relation,account"`
}
type EventBridgeIntegrationListOptions struct {
ListOptions
Name *string `url:"filter[name],omitempty"`
}
type EventBridgeIntegrationCreateOptions struct {
ID string `jsonapi:"primary,aws-event-bridge-integrations"`
Name *string `jsonapi:"attr,name"`
AWSAccountId *string `jsonapi:"attr,aws-account-id"`
Region *string `jsonapi:"attr,region"`
}
type EventBridgeIntegrationUpdateOptions struct {
ID string `jsonapi:"primary,aws-event-bridge-integrations"`
Status IntegrationStatus `jsonapi:"attr,status"`
}
func (s *eventBridgeIntegrations) List(
ctx context.Context, options EventBridgeIntegrationListOptions,
) (*EventBridgeIntegrationList, error) {
req, err := s.client.newRequest("GET", "integrations/aws-event-bridge", &options)
if err != nil {
return nil, err
}
eil := &EventBridgeIntegrationList{}
err = s.client.do(ctx, req, eil)
if err != nil {
return nil, err
}
return eil, nil
}
func (s *eventBridgeIntegrations) Create(
ctx context.Context, options EventBridgeIntegrationCreateOptions,
) (*EventBridgeIntegration, error) {
// Make sure we don't send a user provided ID.
options.ID = ""
req, err := s.client.newRequest("POST", "integrations/aws-event-bridge", &options)
if err != nil {
return nil, err
}
ei := &EventBridgeIntegration{}
err = s.client.do(ctx, req, ei)
if err != nil {
return nil, err
}
return ei, nil
}
func (s *eventBridgeIntegrations) Read(ctx context.Context, id string) (*EventBridgeIntegration, error) {
if !validStringID(&id) {
return nil, errors.New("invalid value for EventBridge integration ID")
}
u := fmt.Sprintf("integrations/aws-event-bridge/%s", url.QueryEscape(id))
req, err := s.client.newRequest("GET", u, nil)
if err != nil {
return nil, err
}
ei := &EventBridgeIntegration{}
err = s.client.do(ctx, req, ei)
if err != nil {
return nil, err
}
return ei, nil
}
func (s *eventBridgeIntegrations) Update(
ctx context.Context, id string, options EventBridgeIntegrationUpdateOptions,
) (*EventBridgeIntegration, error) {
if !validStringID(&id) {
return nil, errors.New("invalid value for EventBridge integration ID")
}
// Make sure we don't send a user provided ID.
options.ID = ""
u := fmt.Sprintf("integrations/aws-event-bridge/%s", url.QueryEscape(id))
req, err := s.client.newRequest("PATCH", u, &options)
if err != nil {
return nil, err
}
ei := &EventBridgeIntegration{}
err = s.client.do(ctx, req, ei)
if err != nil {
return nil, err
}
return ei, nil
}
func (s *eventBridgeIntegrations) Delete(ctx context.Context, id string) error {
if !validStringID(&id) {
return errors.New("invalid value for EventBridge integration ID")
}
u := fmt.Sprintf("integrations/aws-event-bridge/%s", url.QueryEscape(id))
req, err := s.client.newRequest("DELETE", u, nil)
if err != nil {
return err
}
return s.client.do(ctx, req, nil)
}