-
Notifications
You must be signed in to change notification settings - Fork 127
/
variables.go
76 lines (68 loc) · 3.32 KB
/
variables.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
package envs
import (
"github.com/pkg/errors"
"github.com/kelseyhightower/envconfig"
"github.com/kubeshop/testkube/pkg/executor/output"
"github.com/kubeshop/testkube/pkg/ui"
)
// Params are the environment variables provided by the Testkube api-server
type Params struct {
Endpoint string // RUNNER_ENDPOINT
AccessKeyID string // RUNNER_ACCESSKEYID
SecretAccessKey string // RUNNER_SECRETACCESSKEY
Region string // RUNNER_REGION
Token string // RUNNER_TOKEN
Bucket string // RUNNER_BUCKET
Ssl bool // RUNNER_SSL
ScrapperEnabled bool // RUNNER_SCRAPPERENABLED
DataDir string // RUNNER_DATADIR
GitUsername string // RUNNER_GITUSERNAME
GitToken string // RUNNER_GITTOKEN
ClusterID string `envconfig:"RUNNER_CLUSTERID"` // RUNNER_CLUSTERID
CDEventsTarget string `envconfig:"RUNNER_CDEVENTS_TARGET"` // RUNNER_CDEVENTS_TARGET
CloudMode bool `envconfig:"RUNNER_CLOUD_MODE"` // RUNNER_CLOUD_MODE
CloudAPIKey string `envconfig:"RUNNER_CLOUD_API_KEY"` // RUNNER_CLOUD_API_KEY
CloudAPITLSInsecure bool `envconfig:"RUNNER_CLOUD_API_TLS_INSECURE"` // RUNNER_CLOUD_API_TLS_INSECURE
CloudAPIURL string `envconfig:"RUNNER_CLOUD_API_URL"` // RUNNER_CLOUD_API_URL
}
// LoadTestkubeVariables loads the parameters provided as environment variables in the Test CRD
func LoadTestkubeVariables() (Params, error) {
var params Params
output.PrintLogf("%s Reading environment variables...", ui.IconWorld)
err := envconfig.Process("runner", ¶ms)
if err != nil {
output.PrintLogf("%s Failed to read environment variables: %s", ui.IconCross, err.Error())
return params, errors.Errorf("failed to read environment variables: %v", err)
}
output.PrintLogf("%s Environment variables read successfully", ui.IconCheckMark)
printParams(params)
return params, nil
}
// printParams shows the read parameters in logs
func printParams(params Params) {
output.PrintLogf("RUNNER_ENDPOINT=\"%s\"", params.Endpoint)
printSensitiveParam("RUNNER_ACCESSKEYID", params.AccessKeyID)
printSensitiveParam("RUNNER_SECRETACCESSKEY", params.SecretAccessKey)
output.PrintLogf("RUNNER_REGION=\"%s\"", params.Region)
printSensitiveParam("RUNNER_TOKEN", params.Token)
output.PrintLogf("RUNNER_BUCKET=\"%s\"", params.Bucket)
output.PrintLogf("RUNNER_SSL=%t", params.Ssl)
output.PrintLogf("RUNNER_SCRAPPERENABLED=\"%t\"", params.ScrapperEnabled)
output.PrintLogf("RUNNER_GITUSERNAME=\"%s\"", params.GitUsername)
printSensitiveParam("RUNNER_GITTOKEN", params.GitToken)
output.PrintLogf("RUNNER_DATADIR=\"%s\"", params.DataDir)
output.PrintLogf("RUNNER_CLUSTERID=\"%s\"", params.ClusterID)
output.PrintLogf("RUNNER_CDEVENTS_TARGET=\"%s\"", params.CDEventsTarget)
output.PrintLogf("RUNNER_CLOUD_MODE=\"%t\"", params.CloudMode)
output.PrintLogf("RUNNER_CLOUD_API_TLS_INSECURE=\"%t\"", params.CloudAPITLSInsecure)
output.PrintLogf("RUNNER_CLOUD_API_URL=\"%s\"", params.CloudAPIURL)
printSensitiveParam("RUNNER_CLOUD_API_KEY", params.CloudAPIKey)
}
// printSensitiveParam shows in logs if a parameter is set or not
func printSensitiveParam(name string, value string) {
if len(value) == 0 {
output.PrintLogf("%s=\"\"", name)
} else {
output.PrintLogf("%s=\"********\"", name)
}
}