diff --git a/integration/vault-plugin-secrets-ksm/ksm/path.go b/integration/vault-plugin-secrets-ksm/ksm/path.go index ebf60e07..2319326f 100644 --- a/integration/vault-plugin-secrets-ksm/ksm/path.go +++ b/integration/vault-plugin-secrets-ksm/ksm/path.go @@ -16,6 +16,18 @@ var ( errUnknownFields = errors.New("unknown fields") ) +// withExistenceCheckValidator wraps an ExistenceFunc and +// validates the user-supplied fields match the schema. +func withExistenceCheckValidator(f framework.ExistenceFunc) framework.ExistenceFunc { + return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (bool, error) { + if err := validateFields(req, d); err != nil { + return false, logical.CodedError(400, err.Error()) + } + + return f(ctx, req, d) + } +} + // withFieldValidator wraps an OperationFunc and // validates the user-supplied fields match the schema. func withFieldValidator(f framework.OperationFunc) framework.OperationFunc { diff --git a/integration/vault-plugin-secrets-ksm/ksm/path_config.go b/integration/vault-plugin-secrets-ksm/ksm/path_config.go index b4611a90..7df1f19e 100644 --- a/integration/vault-plugin-secrets-ksm/ksm/path_config.go +++ b/integration/vault-plugin-secrets-ksm/ksm/path_config.go @@ -60,6 +60,7 @@ func (b *backend) pathConfig() *framework.Path { Callback: withFieldValidator(b.pathConfigDelete), }, }, + ExistenceCheck: withExistenceCheckValidator(b.pathConfigExistenceCheck), HelpSynopsis: pathConfigHelpSyn, HelpDescription: pathConfigHelpDesc, } @@ -123,3 +124,12 @@ func (b *backend) pathConfigDelete(ctx context.Context, req *logical.Request, _ return nil, nil } + +func (b *backend) pathConfigExistenceCheck(ctx context.Context, req *logical.Request, _ *framework.FieldData) (bool, error) { + out, err := req.Storage.Get(ctx, req.Path) + if err != nil { + return false, fmt.Errorf("existence check failed: %w", err) + } + + return out != nil, nil +}