github.com/kubeshop/testkube@v1.17.23/cmd/tcl/testworkflow-toolkit/env/config.go (about) 1 // Copyright 2024 Testkube. 2 // 3 // Licensed as a Testkube Pro file under the Testkube Community 4 // License (the "License"); you may not use this file except in compliance with 5 // the License. You may obtain a copy of the License at 6 // 7 // https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt 8 9 package env 10 11 import ( 12 "github.com/kelseyhightower/envconfig" 13 14 "github.com/kubeshop/testkube/pkg/ui" 15 ) 16 17 var ( 18 UseProxyValue = false 19 ) 20 21 type envObjectStorageConfig struct { 22 Endpoint string `envconfig:"TK_OS_ENDPOINT"` 23 AccessKeyID string `envconfig:"TK_OS_ACCESSKEY"` 24 SecretAccessKey string `envconfig:"TK_OS_SECRETKEY"` 25 Region string `envconfig:"TK_OS_REGION"` 26 Token string `envconfig:"TK_OS_TOKEN"` 27 Bucket string `envconfig:"TK_OS_BUCKET"` 28 Ssl bool `envconfig:"TK_OS_SSL" default:"false"` 29 SkipVerify bool `envconfig:"TK_OS_SSL_SKIP_VERIFY" default:"false"` 30 CertFile string `envconfig:"TK_OS_CERT_FILE"` 31 KeyFile string `envconfig:"TK_OS_KEY_FILE"` 32 CAFile string `envconfig:"TK_OS_CA_FILE"` 33 } 34 35 type envCloudConfig struct { 36 Url string `envconfig:"TK_C_URL"` 37 ApiKey string `envconfig:"TK_C_KEY"` 38 SkipVerify bool `envconfig:"TK_C_SKIP_VERIFY" default:"false"` 39 TlsInsecure bool `envconfig:"TK_C_TLS_INSECURE" default:"false"` 40 } 41 42 type envExecutionConfig struct { 43 WorkflowName string `envconfig:"TK_WF"` 44 Id string `envconfig:"TK_EX"` 45 GlobalTemplate string `envconfig:"TK_TMPL"` 46 } 47 48 type envSystemConfig struct { 49 Debug string `envconfig:"DEBUG"` 50 Ref string `envconfig:"TK_REF"` 51 Namespace string `envconfig:"TK_NS"` 52 Ip string `envconfig:"TK_IP"` 53 } 54 55 type envImagesConfig struct { 56 Init string `envconfig:"TK_IMG_INIT"` 57 Toolkit string `envconfig:"TK_IMG_TOOLKIT"` 58 } 59 60 type envConfig struct { 61 System envSystemConfig 62 ObjectStorage envObjectStorageConfig 63 Cloud envCloudConfig 64 Execution envExecutionConfig 65 Images envImagesConfig 66 } 67 68 var cfg envConfig 69 var cfgLoaded = false 70 71 func Config() *envConfig { 72 if !cfgLoaded { 73 err := envconfig.Process("", &cfg.System) 74 ui.ExitOnError("configuring environment", err) 75 err = envconfig.Process("", &cfg.ObjectStorage) 76 ui.ExitOnError("configuring environment", err) 77 err = envconfig.Process("", &cfg.Cloud) 78 ui.ExitOnError("configuring environment", err) 79 err = envconfig.Process("", &cfg.Execution) 80 ui.ExitOnError("configuring environment", err) 81 err = envconfig.Process("", &cfg.Images) 82 ui.ExitOnError("configuring environment", err) 83 } 84 cfgLoaded = true 85 return &cfg 86 } 87 88 func Debug() bool { 89 return Config().System.Debug == "1" 90 } 91 92 func CloudEnabled() bool { 93 return Config().Cloud.ApiKey != "" 94 } 95 96 func UseProxy() bool { 97 return UseProxyValue 98 } 99 100 func Ref() string { 101 return Config().System.Ref 102 } 103 104 func Namespace() string { 105 return Config().System.Namespace 106 } 107 108 func IP() string { 109 return Config().System.Ip 110 } 111 112 func WorkflowName() string { 113 return Config().Execution.WorkflowName 114 } 115 116 func ExecutionId() string { 117 return Config().Execution.Id 118 }