2021-03-16 18:31:04 +00:00
|
|
|
package tls
|
|
|
|
|
|
|
|
import (
|
2023-02-01 06:38:04 +00:00
|
|
|
"fmt"
|
|
|
|
|
2022-05-17 14:14:31 +00:00
|
|
|
corev1 "k8s.io/api/core/v1"
|
2022-12-07 06:08:37 +00:00
|
|
|
corev1listers "k8s.io/client-go/listers/core/v1"
|
2021-03-16 18:31:04 +00:00
|
|
|
)
|
|
|
|
|
2023-08-25 11:24:52 +00:00
|
|
|
var errorsNotFound = "root CA certificate not found"
|
2021-05-05 05:10:01 +00:00
|
|
|
|
2021-03-16 18:31:04 +00:00
|
|
|
// ReadRootCASecret returns the RootCA from the pre-defined secret
|
2023-08-25 11:24:52 +00:00
|
|
|
func ReadRootCASecret(name, namespace string, client corev1listers.SecretNamespaceLister) ([]byte, error) {
|
|
|
|
stlsca, err := client.Get(name)
|
2021-03-16 18:31:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-05-11 07:11:50 +00:00
|
|
|
// try "tls.crt"
|
2022-05-17 14:14:31 +00:00
|
|
|
result := stlsca.Data[corev1.TLSCertKey]
|
2022-05-11 07:11:50 +00:00
|
|
|
// if not there, try old "rootCA.crt"
|
|
|
|
if len(result) == 0 {
|
2022-10-13 09:46:05 +00:00
|
|
|
result = stlsca.Data[rootCAKey]
|
2022-05-11 07:11:50 +00:00
|
|
|
}
|
2021-03-16 18:31:04 +00:00
|
|
|
if len(result) == 0 {
|
2023-08-25 11:24:52 +00:00
|
|
|
return nil, fmt.Errorf("%s in secret %s/%s", errorsNotFound, namespace, stlsca.Name)
|
2021-03-16 18:31:04 +00:00
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|