@@ -97,8 +97,14 @@ func (uc *IntegrationUseCase) AddDependencyTrack(ctx context.Context, orgID, hos
9797 return nil , NewErrInvalidUUID (err )
9898 }
9999
100+ // Validate Credentials before saving them
101+ creds := & credentials.APICreds {Host : host , Key : apiKey }
102+ if err := creds .Validate (); err != nil {
103+ return nil , newErrValidation (err )
104+ }
105+
100106 // Create the secret in the external secrets manager
101- secretID , err := uc .credsRW .SaveAPICreds (ctx , orgID , & credentials. APICreds { Host : host , Key : apiKey } )
107+ secretID , err := uc .credsRW .SaveCredentials (ctx , orgID , creds )
102108 if err != nil {
103109 return nil , fmt .Errorf ("storing the credentials: %w" , err )
104110 }
@@ -160,7 +166,7 @@ func (uc *IntegrationUseCase) Delete(ctx context.Context, orgID, integrationID s
160166
161167 if integration .SecretName != "" {
162168 uc .logger .Infow ("msg" , "deleting integration external secrets" , "ID" , integrationID , "secretName" , integration .SecretName )
163- if err := uc .credsRW .DeleteCreds (ctx , integration .SecretName ); err != nil {
169+ if err := uc .credsRW .DeleteCredentials (ctx , integration .SecretName ); err != nil {
164170 return fmt .Errorf ("deleting the credentials: %w" , err )
165171 }
166172 }
@@ -274,10 +280,14 @@ func validateAttachment(ctx context.Context, integration *Integration, credsR cr
274280
275281 // Check with the actual remote data that an upload would be possible
276282 creds := & credentials.APICreds {}
277- if err := credsR .ReadAPICreds (ctx , integration .SecretName , creds ); err != nil {
283+ if err := credsR .ReadCredentials (ctx , integration .SecretName , creds ); err != nil {
278284 return err
279285 }
280286
287+ if err := creds .Validate (); err != nil {
288+ return newErrValidation (err )
289+ }
290+
281291 // Instantiate an actual uploader to see if it would work with the current configuration
282292 d , err := dependencytrack .NewSBOMUploader (c .DependencyTrack .GetDomain (), creds .Key ,
283293 nil , ac .GetDependencyTrack ().GetProjectId (), ac .GetDependencyTrack ().GetProjectName ())
0 commit comments