@@ -2,6 +2,7 @@ package v1beta1
22
33import (
44 "fmt"
5+ "strings"
56
67 corev1 "k8s.io/api/core/v1"
78 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -15,10 +16,10 @@ type VMUserSpec struct {
1516 // Name of the VMUser object.
1617 // +optional
1718 Name * string `json:"name,omitempty"`
18- // UserName basic auth user name for accessing protected endpoint,
19+ // Username basic auth user name for accessing protected endpoint,
1920 // will be replaced with metadata.name of VMUser if omitted.
2021 // +optional
21- UserName * string `json:"username,omitempty"`
22+ Username * string `json:"username,omitempty"`
2223 // Password basic auth password for accessing protected endpoint.
2324 // +optional
2425 Password * string `json:"password,omitempty"`
@@ -119,6 +120,7 @@ func (cr *CRDRef) AddRefToObj(obj client.Object) client.Object {
119120 return obj
120121}
121122
123+ // AsKey returns unique key for object
122124func (cr * CRDRef ) AsKey () string {
123125 return fmt .Sprintf ("%s/%s/%s" , cr .Kind , cr .Namespace , cr .Name )
124126}
@@ -232,11 +234,37 @@ func (cr *VMUser) GetStatusMetadata() *StatusMetadata {
232234 return & cr .Status .StatusMetadata
233235}
234236
237+ func (cr * VMUser ) AsKey (hide bool ) string {
238+ var id string
239+ if cr .Spec .Username != nil {
240+ v := * cr .Spec .Username
241+ if hide {
242+ v = strings .Repeat ("*" , 5 )
243+ }
244+ id = "basicAuth:" + v
245+ }
246+ if cr .Spec .Password != nil {
247+ v := * cr .Spec .Password
248+ if hide {
249+ v = strings .Repeat ("*" , 5 )
250+ }
251+ return id + ":" + v
252+ }
253+ if cr .Spec .BearerToken != nil {
254+ v := * cr .Spec .BearerToken
255+ if hide {
256+ v = strings .Repeat ("*" , 5 )
257+ }
258+ return "bearerToken:" + v
259+ }
260+ return id
261+ }
262+
235263func (cr * VMUser ) Validate () error {
236264 if MustSkipCRValidation (cr ) {
237265 return nil
238266 }
239- if cr .Spec .UserName != nil && cr .Spec .BearerToken != nil {
267+ if cr .Spec .Username != nil && cr .Spec .BearerToken != nil {
240268 return fmt .Errorf ("one of spec.username and spec.bearerToken must be defined for user, got both" )
241269 }
242270 if cr .Spec .PasswordRef != nil && cr .Spec .Password != nil {
0 commit comments