-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enabling authentication for metric api scaler (#1137)
Signed-off-by: aman-bansal <[email protected]>
- Loading branch information
1 parent
9433bc1
commit b2abfaf
Showing
4 changed files
with
258 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package util | ||
|
||
import ( | ||
"crypto/tls" | ||
"crypto/x509" | ||
"fmt" | ||
) | ||
|
||
// NewTLSConfig returns a *tls.Config using the given ceClient cert, ceClient key, | ||
// and CA certificate. If none are appropriate, a nil *tls.Config is returned. | ||
func NewTLSConfig(clientCert, clientKey, caCert string) (*tls.Config, error) { | ||
valid := false | ||
|
||
config := &tls.Config{} | ||
|
||
if clientCert != "" && clientKey != "" { | ||
cert, err := tls.X509KeyPair([]byte(clientCert), []byte(clientKey)) | ||
if err != nil { | ||
return nil, fmt.Errorf("error parse X509KeyPair: %s", err) | ||
} | ||
config.Certificates = []tls.Certificate{cert} | ||
valid = true | ||
} | ||
|
||
if caCert != "" { | ||
caCertPool := x509.NewCertPool() | ||
caCertPool.AppendCertsFromPEM([]byte(caCert)) | ||
config.RootCAs = caCertPool | ||
config.InsecureSkipVerify = true | ||
valid = true | ||
} | ||
|
||
if !valid { | ||
config = nil | ||
} | ||
|
||
return config, nil | ||
} |