generated from brevdev/seed
-
Notifications
You must be signed in to change notification settings - Fork 9
/
autostop.go
65 lines (55 loc) · 1.41 KB
/
autostop.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
package store
import (
breverrors "github.com/brevdev/brev-cli/pkg/errors"
)
const pathDownloadURL = "api/autostop/cli-download-url"
func (n NoAuthHTTPStore) DownloadURL() (string, error) {
res, err := n.noAuthHTTPClient.restyClient.R().
Get(pathDownloadURL)
if err != nil {
return "", breverrors.WrapAndTrace(err)
}
if res.IsError() {
return "", NewHTTPResponseError(res)
}
return res.String(), nil
}
const pathRegisterNotificationEmail = "api/autostop/register"
func (n NoAuthHTTPStore) RegisterNotificationEmail(email string) error {
res, err := n.noAuthHTTPClient.restyClient.R().
SetHeader("Content-Type", "application/json").
SetBody(map[string]any{
"email": email,
}).
Post(pathRegisterNotificationEmail)
if err != nil {
return breverrors.WrapAndTrace(err)
}
if res.IsError() {
return NewHTTPResponseError(res)
}
return nil
}
const pathRecordAutoStop = "api/autostop/record"
type RecordAutopstopBody struct {
Email string
InstanceType string
Region string
Name string
EnvID string
}
func (n NoAuthHTTPStore) RecordAutoStop(
recordAutopstopBody RecordAutopstopBody,
) error {
res, err := n.noAuthHTTPClient.restyClient.R().
SetHeader("Content-Type", "application/json").
SetBody(recordAutopstopBody).
Post(pathRecordAutoStop)
if err != nil {
return breverrors.WrapAndTrace(err)
}
if res.IsError() {
return NewHTTPResponseError(res)
}
return nil
}