From 1f223eb69ce173278fd107adfe03ec7065e84375 Mon Sep 17 00:00:00 2001 From: Zach Leslie Date: Thu, 23 May 2024 23:14:14 +0000 Subject: [PATCH] Fix TLS struct keys and adjust field tags to match field names (#27) * Update TLS configuration to control json field names * Update docker examples after TLS updates * Include additional struct field * Clean up struct keys * Update examples/param/param.js * Update examples/template/template.js * Describe TLS config in README --------- Co-authored-by: A. Stoewer --- README.md | 21 +++++++++++++++++---- examples/param/param.js | 6 ++++-- examples/template/template.js | 4 +++- tracing.go | 26 ++++++++++++++++++-------- 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ef27f17..2082c67 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,25 @@ The configuration is an object with the following schema: endpoint: string, // The exporter protocol used for sending the traces: tracing.EXPORTER_OTLP or tracing.EXPORTER_JAEGER exporter: string, - // Whether insecure connections are allowed (optional, default: false) - insecure: bool, - // Credentials used for authentication + // Credentials used for authentication (optional) authentication: { user: string, password: string }, - // Additional headers sent by the client + // Additional headers sent by the client (optional) headers: { string : string } + // TLS configuration + tls: { + // Whether insecure connections are allowed (optional, default: false) + insecure: boolean, + // Enable TLS but skip verification (optional, default: false) + insecure_skip_verify: boolean, + // The server name requested by the client (optional) + server_name: string, + // The path to the CA certificate file (optional) + ca_file: string, + // The path to the certificate file (optional) + cert_file: string, + // The path to the key file (optional) + key_file: string, + }, } ``` diff --git a/examples/param/param.js b/examples/param/param.js index fb64ee9..0ba6abc 100644 --- a/examples/param/param.js +++ b/examples/param/param.js @@ -11,7 +11,9 @@ const endpoint = __ENV.ENDPOINT || "otel-collector:4317" const client = new tracing.Client({ endpoint, exporter: tracing.EXPORTER_OTLP, - insecure: true, + tls: { + insecure: true, + } }); export default function () { @@ -45,4 +47,4 @@ export default function () { export function teardown() { client.shutdown(); -} \ No newline at end of file +} diff --git a/examples/template/template.js b/examples/template/template.js index c36855f..1f6d17f 100644 --- a/examples/template/template.js +++ b/examples/template/template.js @@ -12,7 +12,9 @@ const orgid = __ENV.TEMPO_X_SCOPE_ORGID || "k6-test" const client = new tracing.Client({ endpoint, exporter: tracing.EXPORTER_OTLP, - insecure: true, + tls: { + insecure: true, + }, headers: { "X-Scope-Orgid": orgid } diff --git a/tracing.go b/tracing.go index 9d085e0..8092b7e 100644 --- a/tracing.go +++ b/tracing.go @@ -143,15 +143,24 @@ func (ct *TracingModule) newTemplatedGenerator(g goja.ConstructorCall, rt *goja. return rt.ToValue(generator).ToObject(rt) } +type TLSClientConfig struct { + Insecure bool `js:"insecure"` + InsecureSkipVerify bool `js:"insecure_skip_verify"` + ServerName string `js:"server_name"` + CAFile string `js:"ca_file"` + CertFile string `js:"cert_file"` + KeyFile string `js:"key_file"` +} + type ClientConfig struct { - Exporter exporterType `json:"type"` - Endpoint string `json:"url"` - TLS configtls.TLSClientSetting `json:"tls"` + Exporter exporterType `js:"exporter"` + Endpoint string `js:"endpoint"` + TLS TLSClientConfig `js:"tls"` Authentication struct { - User string `json:"user"` - Password string `json:"password"` + User string `js:"user"` + Password string `js:"password"` } - Headers map[string]configopaque.String `json:"headers"` + Headers map[string]configopaque.String `js:"headers"` } type Client struct { @@ -170,8 +179,9 @@ func NewClient(cfg *ClientConfig, vu modules.VU) (*Client, error) { ) tlsConfig := configtls.TLSClientSetting{ - Insecure: cfg.TLS.Insecure, - ServerName: cfg.TLS.ServerName, + Insecure: cfg.TLS.Insecure, + InsecureSkipVerify: cfg.TLS.InsecureSkipVerify, + ServerName: cfg.TLS.ServerName, TLSSetting: configtls.TLSSetting{ CAFile: cfg.TLS.CAFile, CertFile: cfg.TLS.CertFile,