Skip to content

Commit

Permalink
Add the TLS struct support for service operators
Browse files Browse the repository at this point in the history
Initial commit

Signed-off-by: Veronika Fisarova <vfisarov@vfisarov-thinkpadt14sgen2i.remote.csb>
Signed-off-by: Veronika Fisarova <vfisarov@redhat.com>
  • Loading branch information
Veronika Fisarova authored and Deydra71 committed Sep 11, 2023
1 parent 6c3c0ce commit 2797a84
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
44 changes: 44 additions & 0 deletions modules/common/test/helpers/tls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2023 Red Hat
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package helpers

import (
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
"github.com/openstack-k8s-operators/lib-common/modules/certmanager"
)

// NewTLS - function to initialize and return a TLS struct.
func NewTLS(secretName string, caSecretName []string, disableNonTLSListeners bool) *TLS {
return &TLS{
SecretName: secretName,
CaSecretName: caSecretName,
DisableNonTLSListeners: disableNonTLSListeners,
}
}

// GetCASecretNameFromIssuer retrieves the CASecretName from an issuer object.
func GetCASecretNameFromIssuer(issuer *certmanager.Issuer) []string {
if issuer.CAIssuer != nil {
return []string{issuer.CAIssuer.SecretName}
}
return []string{}
}

// GetSecretNameFromCertificate retrieves the SecretName from a certificate object.
func GetSecretNameFromCertificate(certificate *certmanager.Certificate) string {
if certificate.Certificate != nil {
return certificate.Certificate.Spec.SecretName
}
return ""
}
39 changes: 39 additions & 0 deletions modules/common/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ limitations under the License.
*/
package tls

<<<<<<< HEAD
// TLSSpec allows the configuration of the TLS used by the service
type TLSSpec struct {
=======
package tls

import (
"github.com/openstack-k8s-operators/lib-common/modules/certmanager"
)

// TLS allows the configuration of the TLS used by the service
type TLS struct {
>>>>>>> e52563d (Add the TLS struct support for service operators)
// +kubebuilder:validation:Optional
// Name of a Secret in the same Namespace as the service object, containing the server's private key & server's public certificate
// The Secret must store these as tls.key and tls.crt, respectively.
Expand All @@ -31,3 +42,31 @@ type TLSSpec struct {
// When set to true, the service disables non-TLS endpoints, only clients supporting TLS are able to connect
DisableNonTLSListeners bool `json:"disableNonTLSListeners,omitempty"`
}
<<<<<<< HEAD
=======

// NewTLS - function to initialize and return a TLS struct.
func NewTLS(secretName string, caSecretName []string, disableNonTLSListeners bool) *TLS {
return &TLS{
SecretName: secretName,
CaSecretName: caSecretName,
DisableNonTLSListeners: disableNonTLSListeners,
}
}

// GetCASecretNameFromIssuer retrieves the CASecretName from an issuer object.
func GetCASecretNameFromIssuer(issuer *certmanager.Issuer) []string {
if issuer.CAIssuer != nil {
return []string{issuer.CAIssuer.SecretName}
}
return []string{}
}

// GetSecretNameFromCertificate retrieves the SecretName from a certificate object.
func GetSecretNameFromCertificate(certificate *certmanager.Certificate) string {
if certificate.Certificate != nil {
return certificate.Certificate.Spec.SecretName
}
return ""
}
>>>>>>> e52563d (Add the TLS struct support for service operators)

0 comments on commit 2797a84

Please sign in to comment.