-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.go
75 lines (62 loc) · 1.75 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
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
package main
import (
"fmt"
"os"
"strings"
)
type configType struct {
otelEndpoint string
otelHeaders map[string]string
serviceName string
runID string
repository string
owner string
repo string
githubToken string
}
func getConfig() (configType, error) {
endpoint := os.Getenv("OTEL_EXPORTER_ENDPOINT")
if len(endpoint) == 0 {
return configType{}, fmt.Errorf("missing env: OTEL_EXPORTER_ENDPOINT")
}
headers := os.Getenv("OTEL_EXPORTER_HEADERS")
if len(headers) == 0 {
return configType{}, fmt.Errorf("missing env: OTEL_EXPORTER_HEADERS")
}
serviceName := os.Getenv("OTEL_SERVICE_NAME")
if len(serviceName) == 0 {
return configType{}, fmt.Errorf("missing env: OTEL_SERVICE_NAME")
}
repository := os.Getenv("GITHUB_REPOSITORY")
if len(repository) == 0 {
return configType{}, fmt.Errorf("missing env: GITHUB_REPOSITORY")
}
runID := os.Getenv("GITHUB_RUN_ID")
if len(runID) == 0 {
return configType{}, fmt.Errorf("missing env: GITHUB_RUN_ID")
}
githubToken := os.Getenv("GITHUB_TOKEN")
repoDetails := strings.Split(repository, "/")
if len(repoDetails) != 2 {
return configType{}, fmt.Errorf("invalid env: GITHUB_REPOSITORY")
}
headersMap := map[string]string{}
headersSplit := strings.Split(headers, ",")
for i := 0; i < len(headersSplit); i++ {
splitHeaders := strings.Split(headersSplit[i], ":")
if len(splitHeaders) != 2 {
return configType{}, fmt.Errorf("invalid env: OTEL_EXPORTER_HEADERS")
}
headersMap[splitHeaders[0]] = splitHeaders[1]
}
return configType{
otelEndpoint: endpoint,
otelHeaders: headersMap,
serviceName: serviceName,
runID: runID,
repository: repository,
owner: repoDetails[0],
repo: repoDetails[1],
githubToken: githubToken,
}, nil
}