generated from brevdev/seed
-
Notifications
You must be signed in to change notification settings - Fork 14
/
setupscripturl.go
64 lines (48 loc) · 1.55 KB
/
setupscripturl.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
package store
import (
"regexp"
breverrors "github.com/brevdev/brev-cli/pkg/errors"
"github.com/go-resty/resty/v2"
)
// type GithubReleaseMetadata struct {
// TagName string `json:"tag_name"`
// IsDraft bool `json:"draft"`
// IsPrerelease bool `json:"prerelease"`
// Name string `json:"name"`
// Body string `json:"body"`
// }
// const (
// cliReleaseURL = "https://api.github.com/repos/brevdev/brev-cli/releases/latest"
// )
func (n NoAuthHTTPStore) GetSetupScriptContentsByURL(url string) (string, error) {
var result string
client := resty.New()
res, err := client.R().SetResult(&result).Get(url)
if err != nil {
return "", breverrors.WrapAndTrace(err)
}
if res.IsError() {
return "", NewHTTPResponseError(res)
}
bodyAsString := string(res.Body())
// This shouldn't be done, but is better than scripts not working because of carriage returns (\r)
re := regexp.MustCompile(`\r?\n`)
bodyAsString = re.ReplaceAllString(bodyAsString, "\n")
return bodyAsString, nil
}
func (s AuthHTTPStore) GetSetupScriptContentsByURL(url string) (string, error) {
var result string
client := resty.New()
res, err := client.R().SetResult(&result).Get(url)
if err != nil {
return "", breverrors.WrapAndTrace(err)
}
if res.IsError() {
return "", NewHTTPResponseError(res)
}
bodyAsString := string(res.Body())
// This shouldn't be done, but is better than scripts not working because of carriage returns (\r)
re := regexp.MustCompile(`\r?\n`)
bodyAsString = re.ReplaceAllString(bodyAsString, "\n")
return bodyAsString, nil
}