Skip to content

Commit

Permalink
fix up linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chelseakomlo committed Nov 12, 2017
1 parent 208b127 commit e8b715f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions command/agent/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ func TestHTTP_VerifyHTTPSClient_AfterConfigReload(t *testing.T) {
// First test with a plaintext request
transport := &http.Transport{}
client := &http.Client{Transport: transport}
req, err := http.NewRequest("GET", reqURL, nil)
_, err := http.NewRequest("GET", reqURL, nil)
assert.Nil(err)

// Next, reload the TLS configuration
Expand Down Expand Up @@ -590,7 +590,7 @@ func TestHTTP_VerifyHTTPSClient_AfterConfigReload(t *testing.T) {

transport = &http.Transport{TLSClientConfig: tlsConf}
client = &http.Client{Transport: transport}
req, err = http.NewRequest("GET", httpsReqURL, nil)
req, err := http.NewRequest("GET", httpsReqURL, nil)
assert.Nil(err)

resp, err := client.Do(req)
Expand Down
25 changes: 21 additions & 4 deletions nomad/structs/config/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,35 @@ func (k *KeyLoader) GetOutgoingCertificate(*tls.ClientHelloInfo) (*tls.Certifica
}

func (t *TLSConfig) GetKeyLoader() *KeyLoader {
t.configLock.Lock()
defer t.configLock.Unlock()

// If the keyloader has not yet been initialized, do it here
if t.KeyLoader == nil {
t.configLock.Lock()
t.KeyLoader = &KeyLoader{}
t.configLock.Unlock()
}
return t.KeyLoader
}

// Copy copies the fields of TLSConfig to another TLSConfig object. Required as
// to not copy mutexes between objects.
func (t *TLSConfig) Copy() *TLSConfig {
new := &TLSConfig{}
new.EnableHTTP = t.EnableHTTP
new.EnableRPC = t.EnableRPC
new.VerifyServerHostname = t.VerifyServerHostname
new.CAFile = t.CAFile
new.CertFile = t.CertFile
new.KeyLoader = t.KeyLoader
new.KeyFile = t.KeyFile
new.RPCUpgradeMode = t.RPCUpgradeMode
new.VerifyHTTPSClient = t.VerifyHTTPSClient
return new
}

// Merge is used to merge two TLS configs together
func (t *TLSConfig) Merge(b *TLSConfig) *TLSConfig {
result := *t
result := t.Copy()

if b.EnableHTTP {
result.EnableHTTP = true
Expand All @@ -113,5 +130,5 @@ func (t *TLSConfig) Merge(b *TLSConfig) *TLSConfig {
if b.VerifyHTTPSClient {
result.VerifyHTTPSClient = true
}
return &result
return result
}

0 comments on commit e8b715f

Please sign in to comment.