-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinfracost_integration.go
165 lines (133 loc) · 4.46 KB
/
infracost_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
158
159
160
161
162
163
164
165
package scalr
import (
"context"
"errors"
"fmt"
"net/url"
)
// Compile-time proof of interface implementation.
var _ InfracostIntegrations = (*infracostIntegrations)(nil)
type InfracostIntegrations interface {
List(ctx context.Context, options InfracostIntegrationListOptions) (*InfracostIntegrationList, error)
Create(ctx context.Context, options InfracostIntegrationCreateOptions) (*InfracostIntegration, error)
Read(ctx context.Context, id string) (*InfracostIntegration, error)
Update(ctx context.Context, id string, options InfracostIntegrationUpdateOptions) (*InfracostIntegration, error)
Delete(ctx context.Context, id string) error
}
// infracostIntegrations implements InfracostIntegrations.
type infracostIntegrations struct {
client *Client
}
type InfracostIntegrationList struct {
*Pagination
Items []*InfracostIntegration
}
// InfracostIntegration represents a Scalr IACP Infracost integration.
type InfracostIntegration struct {
ID string `jsonapi:"primary,infracost-integration"`
Name string `jsonapi:"attr,name"`
Status IntegrationStatus `jsonapi:"attr,status"`
ApiKey string `jsonapi:"attr,api-key"`
IsShared bool `jsonapi:"attr,is-shared,omitempty"`
ErrMessage string `jsonapi:"attr,err-message,omitempty"`
// Relations
Environments []*Environment `jsonapi:"relation,environments"`
}
type InfracostIntegrationListOptions struct {
ListOptions
InfracostIntegration *string `url:"filter[infracost-integration],omitempty"`
Name *string `url:"filter[name],omitempty"`
}
type InfracostIntegrationCreateOptions struct {
ID string `jsonapi:"primary,infracost-integration"`
Name *string `jsonapi:"attr,name"`
ApiKey *string `jsonapi:"attr,api-key"`
IsShared *bool `jsonapi:"attr,is-shared,omitempty"`
// Relations
Environments []*Environment `jsonapi:"relation,environments"`
}
type InfracostIntegrationUpdateOptions struct {
ID string `jsonapi:"primary,infracost-integration"`
Name *string `jsonapi:"attr,name,omitempty"`
ApiKey *string `jsonapi:"attr,api-key,omitempty"`
IsShared *bool `jsonapi:"attr,is-shared,omitempty"`
// Relations
Environments []*Environment `jsonapi:"relation,environments"`
}
func (s *infracostIntegrations) List(
ctx context.Context, options InfracostIntegrationListOptions,
) (*InfracostIntegrationList, error) {
req, err := s.client.newRequest("GET", "integrations/infracost", &options)
if err != nil {
return nil, err
}
iil := &InfracostIntegrationList{}
err = s.client.do(ctx, req, iil)
if err != nil {
return nil, err
}
return iil, nil
}
func (s *infracostIntegrations) Create(
ctx context.Context, options InfracostIntegrationCreateOptions,
) (*InfracostIntegration, error) {
// Make sure we don't send a user provided ID.
options.ID = ""
req, err := s.client.newRequest("POST", "integrations/infracost", &options)
if err != nil {
return nil, err
}
ii := &InfracostIntegration{}
err = s.client.do(ctx, req, ii)
if err != nil {
return nil, err
}
return ii, nil
}
func (s *infracostIntegrations) Read(ctx context.Context, id string) (*InfracostIntegration, error) {
if !validStringID(&id) {
return nil, errors.New("invalid value for Infracost integration ID")
}
u := fmt.Sprintf("integrations/infracost/%s", url.QueryEscape(id))
req, err := s.client.newRequest("GET", u, nil)
if err != nil {
return nil, err
}
ii := &InfracostIntegration{}
err = s.client.do(ctx, req, ii)
if err != nil {
return nil, err
}
return ii, nil
}
func (s *infracostIntegrations) Update(
ctx context.Context, id string, options InfracostIntegrationUpdateOptions,
) (*InfracostIntegration, error) {
if !validStringID(&id) {
return nil, errors.New("invalid value for Infracost integration ID")
}
// Make sure we don't send a user provided ID.
options.ID = ""
u := fmt.Sprintf("integrations/infracost/%s", url.QueryEscape(id))
req, err := s.client.newRequest("PATCH", u, &options)
if err != nil {
return nil, err
}
ii := &InfracostIntegration{}
err = s.client.do(ctx, req, ii)
if err != nil {
return nil, err
}
return ii, nil
}
func (s *infracostIntegrations) Delete(ctx context.Context, id string) error {
if !validStringID(&id) {
return errors.New("invalid value for Infracost integration ID")
}
u := fmt.Sprintf("integrations/infracost/%s", url.QueryEscape(id))
req, err := s.client.newRequest("DELETE", u, nil)
if err != nil {
return err
}
return s.client.do(ctx, req, nil)
}