Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for tls client auth in prometheus datasource #267

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions datasource/prometheus/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ func WithCertificate(certificate string) Option {
}
}

// WithTLSClientAuth sets the client tls keypair.
func WithTLSClientAuth(certificate, key string) Option {
return func(datasource *Prometheus) error {
datasource.builder.JSONData.(map[string]interface{})["tlsAuth"] = true
datasource.builder.SecureJSONData.(map[string]interface{})["tlsClientCert"] = certificate
datasource.builder.SecureJSONData.(map[string]interface{})["tlsClientKey"] = key

return nil
}
}

// WithCredentials joins credentials such as cookies or auth headers to cross-site requests.
func WithCredentials() Option {
return func(datasource *Prometheus) error {
Expand Down
9 changes: 9 additions & 0 deletions datasource/prometheus/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ func TestWithCertificate(t *testing.T) {
req.Equal("certificate-content", datasource.builder.SecureJSONData.(map[string]interface{})["tlsCACert"])
}

func TestWithTLSClientAuuth(t *testing.T) {
req := require.New(t)
datasource, err := New("", "", WithTLSClientAuth("cert-content", "key-content"))
req.NoError(err)
req.Equal(true, datasource.builder.JSONData.(map[string]interface{})["tlsAuth"])
req.Equal("cert-content", datasource.builder.SecureJSONData.(map[string]interface{})["tlsClientCert"])
req.Equal("key-content", datasource.builder.SecureJSONData.(map[string]interface{})["tlsClientKey"])
}

func TestWithCredentials(t *testing.T) {
req := require.New(t)

Expand Down
Loading