-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d90173
commit 4ae2408
Showing
21 changed files
with
925 additions
and
157 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ vendor | |
|
||
# editor and IDE paraphernalia | ||
.idea | ||
.vscode | ||
*.swp | ||
*.swo | ||
*~ |
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,25 @@ | ||
package v1alpha1 | ||
|
||
func IsClientSecurityEnabled(c *EtcdCluster) bool { | ||
clientSecurityEnabled := false | ||
if c.Spec.Security != nil && c.Spec.Security.TLS.ClientSecret != "" { | ||
clientSecurityEnabled = true | ||
} | ||
return clientSecurityEnabled | ||
} | ||
|
||
func IsServerSecurityEnabled(c *EtcdCluster) bool { | ||
serverSecurityEnabled := false | ||
if c.Spec.Security != nil && c.Spec.Security.TLS.ServerSecret != "" { | ||
serverSecurityEnabled = true | ||
} | ||
return serverSecurityEnabled | ||
} | ||
|
||
func IsServerCADefined(c *EtcdCluster) bool { | ||
serverCADefined := false | ||
if c.Spec.Security != nil && c.Spec.Security.TLS.ServerTrustedCASecret != "" { | ||
serverCADefined = true | ||
} | ||
return serverCADefined | ||
} |
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,109 @@ | ||
package v1alpha1_test | ||
|
||
import ( | ||
"github.com/aenix-io/etcd-operator/api/v1alpha1" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Aux Functions", func() { | ||
|
||
Context("When running IsClientSecurityEnabled function", func() { | ||
It("should return true if ClientSecret is set", func() { | ||
cluster := &v1alpha1.EtcdCluster{ | ||
Spec: v1alpha1.EtcdClusterSpec{ | ||
Security: &v1alpha1.SecuritySpec{ | ||
TLS: v1alpha1.TLSSpec{ | ||
ClientSecret: "some-client-secret", | ||
}, | ||
}, | ||
}, | ||
} | ||
Expect(v1alpha1.IsClientSecurityEnabled(cluster)).To(BeTrue()) | ||
}) | ||
|
||
It("should return false if ClientSecret is not set", func() { | ||
cluster := &v1alpha1.EtcdCluster{ | ||
Spec: v1alpha1.EtcdClusterSpec{ | ||
Security: &v1alpha1.SecuritySpec{ | ||
TLS: v1alpha1.TLSSpec{}, | ||
}, | ||
}, | ||
} | ||
Expect(v1alpha1.IsClientSecurityEnabled(cluster)).To(BeFalse()) | ||
}) | ||
|
||
It("should return false if Security is nil", func() { | ||
cluster := &v1alpha1.EtcdCluster{ | ||
Spec: v1alpha1.EtcdClusterSpec{}, | ||
} | ||
Expect(v1alpha1.IsClientSecurityEnabled(cluster)).To(BeFalse()) | ||
}) | ||
}) | ||
|
||
Context("When running IsServerSecurityEnabled function", func() { | ||
It("should return true if ServerSecret is set", func() { | ||
cluster := &v1alpha1.EtcdCluster{ | ||
Spec: v1alpha1.EtcdClusterSpec{ | ||
Security: &v1alpha1.SecuritySpec{ | ||
TLS: v1alpha1.TLSSpec{ | ||
ServerSecret: "some-server-secret", | ||
}, | ||
}, | ||
}, | ||
} | ||
Expect(v1alpha1.IsServerSecurityEnabled(cluster)).To(BeTrue()) | ||
}) | ||
|
||
It("should return false if ServerSecret is not set", func() { | ||
cluster := &v1alpha1.EtcdCluster{ | ||
Spec: v1alpha1.EtcdClusterSpec{ | ||
Security: &v1alpha1.SecuritySpec{ | ||
TLS: v1alpha1.TLSSpec{}, | ||
}, | ||
}, | ||
} | ||
Expect(v1alpha1.IsServerSecurityEnabled(cluster)).To(BeFalse()) | ||
}) | ||
|
||
It("should return false if Security is nil", func() { | ||
cluster := &v1alpha1.EtcdCluster{ | ||
Spec: v1alpha1.EtcdClusterSpec{}, | ||
} | ||
Expect(v1alpha1.IsServerSecurityEnabled(cluster)).To(BeFalse()) | ||
}) | ||
}) | ||
|
||
Context("When running IsServerCADefined function", func() { | ||
It("should return true if ServerTrustedCASecret is set", func() { | ||
cluster := &v1alpha1.EtcdCluster{ | ||
Spec: v1alpha1.EtcdClusterSpec{ | ||
Security: &v1alpha1.SecuritySpec{ | ||
TLS: v1alpha1.TLSSpec{ | ||
ServerTrustedCASecret: "some-ca-secret", | ||
}, | ||
}, | ||
}, | ||
} | ||
Expect(v1alpha1.IsServerCADefined(cluster)).To(BeTrue()) | ||
}) | ||
|
||
It("should return false if ServerTrustedCASecret is not set", func() { | ||
cluster := &v1alpha1.EtcdCluster{ | ||
Spec: v1alpha1.EtcdClusterSpec{ | ||
Security: &v1alpha1.SecuritySpec{ | ||
TLS: v1alpha1.TLSSpec{}, | ||
}, | ||
}, | ||
} | ||
Expect(v1alpha1.IsServerCADefined(cluster)).To(BeFalse()) | ||
}) | ||
|
||
It("should return false if Security is nil", func() { | ||
cluster := &v1alpha1.EtcdCluster{ | ||
Spec: v1alpha1.EtcdClusterSpec{}, | ||
} | ||
Expect(v1alpha1.IsServerCADefined(cluster)).To(BeFalse()) | ||
}) | ||
}) | ||
}) |
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
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
Oops, something went wrong.