@@ -41,6 +41,16 @@ type Config struct {
41
41
// Password is the Password for the Basic Auth.
42
42
Password null.String `json:"password"`
43
43
44
+ // ClientCertificate is the public key of the SSL certificate.
45
+ // It is expected the path of the certificate on the file system.
46
+ // If it is required a dedicated Certifacate Authority then it should be added
47
+ // to the conventional folders defined by the operating system's registry.
48
+ ClientCertificate null.String `json:"clientCertificate"`
49
+
50
+ // ClientCertificateKey is the private key of the SSL certificate.
51
+ // It is expected the path of the certificate on the file system.
52
+ ClientCertificateKey null.String `json:"clientCertificateKey"`
53
+
44
54
// BearerToken if set is the token used for the `Authorization` header.
45
55
BearerToken null.String `json:"bearerToken"`
46
56
@@ -92,6 +102,14 @@ func (conf Config) RemoteConfig() (*remote.HTTPConfig, error) {
92
102
InsecureSkipVerify : conf .InsecureSkipTLSVerify .Bool , //nolint:gosec
93
103
}
94
104
105
+ if conf .ClientCertificate .Valid && conf .ClientCertificateKey .Valid {
106
+ cert , err := tls .LoadX509KeyPair (conf .ClientCertificate .String , conf .ClientCertificateKey .String )
107
+ if err != nil {
108
+ return nil , fmt .Errorf ("failed to load the TLS certificate: %w" , err )
109
+ }
110
+ hc .TLSConfig .Certificates = []tls.Certificate {cert }
111
+ }
112
+
95
113
if len (conf .Headers ) > 0 {
96
114
hc .Headers = make (http.Header )
97
115
for k , v := range conf .Headers {
@@ -150,6 +168,14 @@ func (conf Config) Apply(applied Config) Config {
150
168
copy (conf .TrendStats , applied .TrendStats )
151
169
}
152
170
171
+ if applied .ClientCertificate .Valid {
172
+ conf .ClientCertificate = applied .ClientCertificate
173
+ }
174
+
175
+ if applied .ClientCertificateKey .Valid {
176
+ conf .ClientCertificateKey = applied .ClientCertificateKey
177
+ }
178
+
153
179
return conf
154
180
}
155
181
@@ -242,6 +268,14 @@ func parseEnvs(env map[string]string) (Config, error) {
242
268
c .Password = null .StringFrom (password )
243
269
}
244
270
271
+ if clientCertificate , certDefined := env ["K6_PROMETHEUS_RW_CLIENT_CERTIFICATE" ]; certDefined {
272
+ c .ClientCertificate = null .StringFrom (clientCertificate )
273
+ }
274
+
275
+ if clientCertificateKey , certDefined := env ["K6_PROMETHEUS_RW_CLIENT_CERTIFICATE_KEY" ]; certDefined {
276
+ c .ClientCertificateKey = null .StringFrom (clientCertificateKey )
277
+ }
278
+
245
279
envHeaders := getEnvMap (env , "K6_PROMETHEUS_RW_HEADERS_" )
246
280
for k , v := range envHeaders {
247
281
c .Headers [k ] = v
@@ -324,6 +358,11 @@ func parseArg(text string) (Config, error) {
324
358
//c.TrendStats = strings.Split(v, ",")
325
359
//}
326
360
361
+ case "clientCertificate" :
362
+ c .ClientCertificate = null .StringFrom (v )
363
+ case "clientCertificateKey" :
364
+ c .ClientCertificateKey = null .StringFrom (v )
365
+
327
366
default :
328
367
if ! strings .HasPrefix (key , "headers." ) {
329
368
return c , fmt .Errorf ("%q is an unknown option's key" , r [0 ])
0 commit comments