From a4dd586a81847f267aa75689f32b61dc712c6b60 Mon Sep 17 00:00:00 2001 From: Mariano Cano Date: Fri, 11 Mar 2022 15:13:39 -0800 Subject: [PATCH] Add method to get the CA url from the client. --- ca/client.go | 5 +++++ ca/client_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/ca/client.go b/ca/client.go index 56f17748..40618330 100644 --- a/ca/client.go +++ b/ca/client.go @@ -563,6 +563,11 @@ func (c *Client) retryOnError(r *http.Response) bool { return false } +// GetCaURL returns the configura CA url. +func (c *Client) GetCaURL() string { + return c.endpoint.String() +} + // GetRootCAs returns the RootCAs certificate pool from the configured // transport. func (c *Client) GetRootCAs() *x509.CertPool { diff --git a/ca/client_test.go b/ca/client_test.go index e253dab5..6e352291 100644 --- a/ca/client_test.go +++ b/ca/client_test.go @@ -1128,3 +1128,28 @@ func TestClient_SSHBastion(t *testing.T) { }) } } + +func TestClient_GetCaURL(t *testing.T) { + tests := []struct { + name string + caURL string + want string + }{ + {"ok", "https://ca.com", "https://ca.com"}, + {"ok no schema", "ca.com", "https://ca.com"}, + {"ok with port", "https://ca.com:9000", "https://ca.com:9000"}, + {"ok with version", "https://ca.com/1.0", "https://ca.com/1.0"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c, err := NewClient(tt.caURL) + if err != nil { + t.Errorf("NewClient() error = %v", err) + return + } + if got := c.GetCaURL(); got != tt.want { + t.Errorf("Client.GetCaURL() = %v, want %v", got, tt.want) + } + }) + } +}