mirror of
https://github.com/external-secrets/external-secrets.git
synced 2024-12-14 11:57:59 +00:00
fix: improve SecretExists in Bitwarden provider (#4058)
* Make findSecretByRef not return an error when it cant find a matching secret. Added error checks for missing secret in SecretExists and DeleteSecret. Signed-off-by: Anders Olsson <anders.olsson@digitalist.se> * Added check for missing secret in `GetSecret` Signed-off-by: Anders Olsson <anders.olsson@digitalist.se> --------- Signed-off-by: Anders Olsson <anders.olsson@digitalist.se> Co-authored-by: Anders Olsson <anders.olsson@digitalist.se>
This commit is contained in:
parent
db64df2f0c
commit
5088026566
2 changed files with 15 additions and 7 deletions
|
@ -141,6 +141,10 @@ func (p *Provider) GetSecret(ctx context.Context, ref esv1beta1.ExternalSecretDa
|
|||
return nil, fmt.Errorf("error getting secret: %w", err)
|
||||
}
|
||||
|
||||
if secret == nil {
|
||||
return nil, fmt.Errorf("no secret found for project id %s and name %s", spec.Provider.BitwardenSecretsManager.ProjectID, ref.Key)
|
||||
}
|
||||
|
||||
// we found our secret, return the value for it
|
||||
return []byte(secret.Value), nil
|
||||
}
|
||||
|
@ -160,6 +164,10 @@ func (p *Provider) DeleteSecret(ctx context.Context, ref esv1beta1.PushSecretRem
|
|||
return fmt.Errorf("error getting secret: %w", err)
|
||||
}
|
||||
|
||||
if secret == nil {
|
||||
return fmt.Errorf("no secret found for project id %s and name %s", spec.Provider.BitwardenSecretsManager.ProjectID, ref.GetRemoteKey())
|
||||
}
|
||||
|
||||
return p.deleteSecret(ctx, secret.ID)
|
||||
}
|
||||
|
||||
|
@ -197,10 +205,15 @@ func (p *Provider) SecretExists(ctx context.Context, ref esv1beta1.PushSecretRem
|
|||
return false, errors.New("store does not have a provider")
|
||||
}
|
||||
|
||||
if _, err := p.findSecretByRef(ctx, ref.GetRemoteKey(), spec.Provider.BitwardenSecretsManager.ProjectID); err != nil {
|
||||
secret, err := p.findSecretByRef(ctx, ref.GetRemoteKey(), spec.Provider.BitwardenSecretsManager.ProjectID)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("error getting secret: %w", err)
|
||||
}
|
||||
|
||||
if secret == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
@ -302,9 +315,5 @@ func (p *Provider) findSecretByRef(ctx context.Context, key, projectID string) (
|
|||
}
|
||||
}
|
||||
|
||||
if remoteSecret == nil {
|
||||
return nil, fmt.Errorf("no secret found for project id %s and name %s", projectID, key)
|
||||
}
|
||||
|
||||
return remoteSecret, nil
|
||||
}
|
||||
|
|
|
@ -766,7 +766,6 @@ func TestProviderSecretExists(t *testing.T) {
|
|||
},
|
||||
},
|
||||
want: false,
|
||||
wantErr: true, // secret not found
|
||||
},
|
||||
{
|
||||
name: "invalid name format should error",
|
||||
|
|
Loading…
Reference in a new issue