Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KSM-504 Added ExistenceCheck with Validator #584

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions integration/vault-plugin-secrets-ksm/ksm/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions integration/vault-plugin-secrets-ksm/ksm/path_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (b *backend) pathConfig() *framework.Path {
Callback: withFieldValidator(b.pathConfigDelete),
},
},
ExistenceCheck: withExistenceCheckValidator(b.pathConfigExistenceCheck),
HelpSynopsis: pathConfigHelpSyn,
HelpDescription: pathConfigHelpDesc,
}
Expand Down Expand Up @@ -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
}
Loading