-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
50 lines (46 loc) · 1.29 KB
/
config.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
package main
import (
"encoding/json"
"io/ioutil"
"github.com/brigadecore/brigade-foundations/file"
"github.com/brigadecore/brigade-foundations/os"
"github.com/brigadecore/brigade/sdk/v3"
"github.com/brigadecore/brigade/sdk/v3/restmachinery"
"github.com/pkg/errors"
)
// apiClientConfig populates the Brigade SDK's APIClientOptions from
// environment variables.
func apiClientConfig() (string, string, restmachinery.APIClientOptions, error) {
opts := restmachinery.APIClientOptions{}
address, err := os.GetRequiredEnvVar("API_ADDRESS")
if err != nil {
return address, "", opts, err
}
token, err := os.GetRequiredEnvVar("API_TOKEN")
if err != nil {
return address, token, opts, err
}
opts.AllowInsecureConnections, err =
os.GetBoolFromEnvVar("API_IGNORE_CERT_WARNINGS", false)
return address, token, opts, err
}
func event() (sdk.Event, error) {
event := sdk.Event{}
eventPath, err := os.GetRequiredEnvVar("EVENT_PATH")
if err != nil {
return event, err
}
var exists bool
if exists, err = file.Exists(eventPath); err != nil {
return event, err
}
if !exists {
return event, errors.Errorf("file %s does not exist", eventPath)
}
eventBytes, err := ioutil.ReadFile(eventPath)
if err != nil {
return event, err
}
err = json.Unmarshal(eventBytes, &event)
return event, err
}