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

VAULT-12144: add openapi responses for /sys/rotate endpoints #18624

Merged
merged 8 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 3 additions & 0 deletions changelog/18624.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
openapi: add openapi response definitions to /sys/rotate endpoints
```
37 changes: 34 additions & 3 deletions vault/logical_system_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,33 @@ func (b *SystemBackend) sealPaths() []*framework.Path {
Operations: map[logical.Operation]framework.OperationHandler{
logical.ReadOperation: &framework.PathOperation{
Callback: b.handleKeyRotationConfigRead,
Responses: map[int][]framework.Response{
http.StatusOK: {{
Description: "OK",
Fields: map[string]*framework.FieldSchema{
"max_operations": {
Type: framework.TypeInt64,
Required: true,
},
"enabled": {
Type: framework.TypeBool,
Required: true,
},
"interval": {
Type: framework.TypeDurationSecond,
Required: true,
},
},
}},
},
},
logical.UpdateOperation: &framework.PathOperation{
Callback: b.handleKeyRotationConfigUpdate,
Callback: b.handleKeyRotationConfigUpdate,
Responses: map[int][]framework.Response{
http.StatusNoContent: {{
Description: "OK",
}},
},
ForwardPerformanceSecondary: true,
ForwardPerformanceStandby: true,
},
Expand All @@ -789,8 +813,15 @@ func (b *SystemBackend) sealPaths() []*framework.Path {
{
Pattern: "rotate$",

Callbacks: map[logical.Operation]framework.OperationFunc{
logical.UpdateOperation: b.handleRotate,
Operations: map[logical.Operation]framework.OperationHandler{
logical.UpdateOperation: &framework.PathOperation{
Callback: b.handleRotate,
Responses: map[int][]framework.Response{
http.StatusNoContent: {{
Description: "OK",
}},
},
},
},

HelpSynopsis: strings.TrimSpace(sysHelp["rotate"][0]),
Expand Down
20 changes: 20 additions & 0 deletions vault/logical_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2906,12 +2906,20 @@ func TestSystemBackend_keyStatus(t *testing.T) {

func TestSystemBackend_rotateConfig(t *testing.T) {
b := testSystemBackend(t)
paths := b.(*SystemBackend).sealPaths()
req := logical.TestRequest(t, logical.ReadOperation, "rotate/config")
resp, err := b.HandleRequest(namespace.RootContext(nil), req)
if err != nil {
t.Fatalf("err: %v", err)
}

schema.ValidateResponse(
t,
schema.GetResponseSchema(t, b.(*SystemBackend).Route(req.Path), req.Operation),
resp,
true,
)

exp := map[string]interface{}{
"max_operations": absoluteOperationMaximum,
"interval": 0,
Expand All @@ -2930,11 +2938,23 @@ func TestSystemBackend_rotateConfig(t *testing.T) {
if err != nil {
t.Fatalf("err: %v", err)
}
schema.ValidateResponse(
t,
schema.FindResponseSchema(t, paths, 1, req2.Operation),
dhuckins marked this conversation as resolved.
Show resolved Hide resolved
resp,
true,
)

resp, err = b.HandleRequest(namespace.RootContext(nil), req)
if err != nil {
t.Fatalf("err: %v", err)
}
schema.ValidateResponse(
t,
schema.FindResponseSchema(t, paths, 1, req.Operation),
dhuckins marked this conversation as resolved.
Show resolved Hide resolved
resp,
true,
)

exp = map[string]interface{}{
"max_operations": int64(3221225472),
Expand Down