Skip to content

Commit

Permalink
Add new method to access a client config's TLSConfig. (#20265)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncabatoff authored Apr 19, 2023
1 parent caf8323 commit 5ce3054
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ type Config struct {
// commands such as 'vault operator raft snapshot' as this redirects to the
// primary node.
DisableRedirects bool
clientTLSConfig *tls.Config
}

// TLSConfig contains the parameters needed to configure TLS on the HTTP client
Expand Down Expand Up @@ -337,10 +338,17 @@ func (c *Config) configureTLS(t *TLSConfig) error {
if t.TLSServerName != "" {
clientTLSConfig.ServerName = t.TLSServerName
}
c.clientTLSConfig = clientTLSConfig

return nil
}

func (c *Config) TLSConfig() *tls.Config {
c.modifyLock.RLock()
defer c.modifyLock.RUnlock()
return c.clientTLSConfig.Clone()
}

// ConfigureTLS takes a set of TLS configurations and applies those to the
// HTTP client.
func (c *Config) ConfigureTLS(t *TLSConfig) error {
Expand Down Expand Up @@ -665,6 +673,7 @@ func (c *Client) CloneConfig() *Config {
newConfig.CloneHeaders = c.config.CloneHeaders
newConfig.CloneToken = c.config.CloneToken
newConfig.ReadYourWrites = c.config.ReadYourWrites
newConfig.clientTLSConfig = c.config.clientTLSConfig

// we specifically want a _copy_ of the client here, not a pointer to the original one
newClient := *c.config.HttpClient
Expand Down
3 changes: 3 additions & 0 deletions changelog/20265.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
* api: Add Config.TLSConfig method to fetch the TLS configuration from a client config.
```

0 comments on commit 5ce3054

Please sign in to comment.