@@ -79,7 +79,7 @@ func (r *DvlsSecretReconciler) Reconcile(ctx context.Context, req ctrl.Request)
7979 return ctrl.Result {}, fmt .Errorf ("failed to get DvlsSecret object, %w" , err )
8080 }
8181
82- if dvlsSecret . Status . Conditions == nil || len (dvlsSecret .Status .Conditions ) == 0 || dvlsSecret .Status .EntryModifiedDate .IsZero () {
82+ if len (dvlsSecret .Status .Conditions ) == 0 || dvlsSecret .Status .EntryModifiedDate .IsZero () {
8383 meta .SetStatusCondition (& dvlsSecret .Status .Conditions , v1.Condition {Type : statusAvailableDvlsSecret , Status : v1 .ConditionUnknown , Reason : "Reconciling" })
8484 dvlsSecret .Status .EntryModifiedDate = v1 .Date (0001 , time .January , 1 , 1 , 1 , 1 , 1 , time .UTC )
8585 if err := r .Status ().Update (ctx , dvlsSecret ); err != nil {
@@ -102,15 +102,6 @@ func (r *DvlsSecretReconciler) Reconcile(ctx context.Context, req ctrl.Request)
102102 return ctrl.Result {}, nil
103103 }
104104
105- if entry .Type != string (dvls .ServerConnectionCredential ) || entry .SubType != string (dvls .ServerConnectionSubTypeDefault ) {
106- log .Error (err , "entry type not supported, only username/password entries are supported" , "entryId" , dvlsSecret .Spec .EntryID , "entryType" , entry .Type , "entrySubType" , entry .SubType )
107- meta .SetStatusCondition (& dvlsSecret .Status .Conditions , v1.Condition {Type : statusDegradedDvlsSecret , Status : v1 .ConditionTrue , Reason : "Reconciling" , Message : "Entry type not supported, only username/password entries are supported" })
108- if err := r .Status ().Update (ctx , dvlsSecret ); err != nil {
109- log .Error (err , "Failed to update DvlsSecret status" )
110- }
111- return ctrl.Result {}, nil
112- }
113-
114105 kSecret := & corev1.Secret {}
115106 err = r .Get (ctx , req .NamespacedName , kSecret )
116107 if err != nil && ! apierrors .IsNotFound (err ) {
@@ -130,19 +121,9 @@ func (r *DvlsSecretReconciler) Reconcile(ctx context.Context, req ctrl.Request)
130121 }, nil
131122 }
132123
133- defaultData , ok := entry .GetCredentialDefaultData ()
134- if ! ok {
135- return ctrl.Result {}, fmt .Errorf (
136- "failed to extract credential data for entry ID %s: unsupported or unexpected entry type (type: %s, subtype: %s)" ,
137- dvlsSecret .Spec .EntryID , entry .Type , entry .SubType )
138- }
139-
140- secretMap := make (map [string ]string )
141- secretMap ["entry-id" ] = entry .Id
142- secretMap ["entry-name" ] = entry .Name
143- secretMap ["username" ] = defaultData .Username
144- if defaultData .Password != "" {
145- secretMap ["password" ] = defaultData .Password
124+ secretMap , err := setSecretMap (entry )
125+ if err != nil {
126+ return ctrl.Result {}, fmt .Errorf ("failed to set secret map, %w" , err )
146127 }
147128
148129 if kSecretNotFound {
@@ -210,3 +191,87 @@ func (r *DvlsSecretReconciler) SetupWithManager(mgr ctrl.Manager) error {
210191 Owns (& corev1.Secret {}).
211192 Complete (r )
212193}
194+
195+ func setSecretMap (entry dvls.Entry ) (map [string ]string , error ) {
196+ secretMap := make (map [string ]string )
197+ secretMap ["entry-id" ] = entry .Id
198+ secretMap ["entry-name" ] = entry .Name
199+
200+ switch entry .SubType {
201+ case dvls .EntryCredentialSubTypeDefault :
202+ if data , ok := entry .GetCredentialDefaultData (); ok {
203+ if data .Username != "" {
204+ secretMap ["username" ] = data .Username
205+ }
206+ if data .Password != "" {
207+ secretMap ["password" ] = data .Password
208+ }
209+ if data .Domain != "" {
210+ secretMap ["domain" ] = data .Domain
211+ }
212+ }
213+
214+ case dvls .EntryCredentialSubTypeAccessCode :
215+ if data , ok := entry .GetCredentialAccessCodeData (); ok {
216+ if data .Password != "" {
217+ secretMap ["password" ] = data .Password
218+ }
219+ }
220+
221+ case dvls .EntryCredentialSubTypeApiKey :
222+ if data , ok := entry .GetCredentialApiKeyData (); ok {
223+ if data .ApiId != "" {
224+ secretMap ["api-id" ] = data .ApiId
225+ }
226+ if data .ApiKey != "" {
227+ secretMap ["api-key" ] = data .ApiKey
228+ }
229+ if data .TenantId != "" {
230+ secretMap ["tenant-id" ] = data .TenantId
231+ }
232+ }
233+
234+ case dvls .EntryCredentialSubTypeAzureServicePrincipal :
235+ if data , ok := entry .GetCredentialAzureServicePrincipalData (); ok {
236+ if data .ClientId != "" {
237+ secretMap ["client-id" ] = data .ClientId
238+ }
239+ if data .ClientSecret != "" {
240+ secretMap ["client-secret" ] = data .ClientSecret
241+ }
242+ if data .TenantId != "" {
243+ secretMap ["tenant-id" ] = data .TenantId
244+ }
245+ }
246+
247+ case dvls .EntryCredentialSubTypeConnectionString :
248+ if data , ok := entry .GetCredentialConnectionStringData (); ok {
249+ if data .ConnectionString != "" {
250+ secretMap ["connection-string" ] = data .ConnectionString
251+ }
252+ }
253+
254+ case dvls .EntryCredentialSubTypePrivateKey :
255+ if data , ok := entry .GetCredentialPrivateKeyData (); ok {
256+ if data .Username != "" {
257+ secretMap ["username" ] = data .Username
258+ }
259+ if data .Password != "" {
260+ secretMap ["password" ] = data .Password
261+ }
262+ if data .PrivateKey != "" {
263+ secretMap ["private-key" ] = data .PrivateKey
264+ }
265+ if data .PublicKey != "" {
266+ secretMap ["public-key" ] = data .PublicKey
267+ }
268+ if data .Passphrase != "" {
269+ secretMap ["passphrase" ] = data .Passphrase
270+ }
271+ }
272+ default :
273+ return nil , fmt .Errorf ("unsupported credential subtype: %s" , entry .SubType )
274+ }
275+
276+ return secretMap , nil
277+ }
0 commit comments