@@ -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"`
@@ -232,11 +233,37 @@ func (cr *VMUser) GetStatusMetadata() *StatusMetadata {
232233 return & cr .Status .StatusMetadata
233234}
234235
236+ func (cr * VMUser ) AsKey (hide bool ) string {
237+ var id string
238+ if cr .Spec .Username != nil {
239+ v := * cr .Spec .Username
240+ if hide {
241+ v = strings .Repeat ("*" , 5 )
242+ }
243+ id = "basicAuth:" + v
244+ }
245+ if cr .Spec .Password != nil {
246+ v := * cr .Spec .Password
247+ if hide {
248+ v = strings .Repeat ("*" , 5 )
249+ }
250+ return id + ":" + v
251+ }
252+ if cr .Spec .BearerToken != nil {
253+ v := * cr .Spec .BearerToken
254+ if hide {
255+ v = strings .Repeat ("*" , 5 )
256+ }
257+ return "bearerToken:" + v
258+ }
259+ return id
260+ }
261+
235262func (cr * VMUser ) Validate () error {
236263 if MustSkipCRValidation (cr ) {
237264 return nil
238265 }
239- if cr .Spec .UserName != nil && cr .Spec .BearerToken != nil {
266+ if cr .Spec .Username != nil && cr .Spec .BearerToken != nil {
240267 return fmt .Errorf ("one of spec.username and spec.bearerToken must be defined for user, got both" )
241268 }
242269 if cr .Spec .PasswordRef != nil && cr .Spec .Password != nil {
0 commit comments