From 243c86b2c5a44e5295c3c12bef1dfc524cb010b3 Mon Sep 17 00:00:00 2001 From: Daniel Huckins Date: Tue, 28 Mar 2023 15:40:48 -0400 Subject: [PATCH] VAULT-12144: add openapi responses for /sys/rotate endpoints (#18624) * responses for rotate endpoints Signed-off-by: Daniel Huckins * added changelog * add test for rotate config Signed-off-by: Daniel Huckins * update to use newer function Signed-off-by: Daniel Huckins * use new func Signed-off-by: Daniel Huckins --------- Signed-off-by: Daniel Huckins --- changelog/18624.txt | 3 +++ vault/logical_system_paths.go | 37 ++++++++++++++++++++++++++++++++--- vault/logical_system_test.go | 18 +++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 changelog/18624.txt diff --git a/changelog/18624.txt b/changelog/18624.txt new file mode 100644 index 000000000..91209bb46 --- /dev/null +++ b/changelog/18624.txt @@ -0,0 +1,3 @@ +```release-note:improvement +openapi: add openapi response definitions to /sys/rotate endpoints +``` diff --git a/vault/logical_system_paths.go b/vault/logical_system_paths.go index c0ebe478f..40a8c41d6 100644 --- a/vault/logical_system_paths.go +++ b/vault/logical_system_paths.go @@ -1482,9 +1482,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, }, @@ -1497,8 +1521,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]), diff --git a/vault/logical_system_test.go b/vault/logical_system_test.go index 69dbc9444..3dcb6e5b3 100644 --- a/vault/logical_system_test.go +++ b/vault/logical_system_test.go @@ -3146,6 +3146,13 @@ func TestSystemBackend_rotateConfig(t *testing.T) { 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, @@ -3164,11 +3171,22 @@ func TestSystemBackend_rotateConfig(t *testing.T) { if err != nil { t.Fatalf("err: %v", err) } + schema.ValidateResponse( + t, + schema.GetResponseSchema(t, b.(*SystemBackend).Route(req2.Path), req2.Operation), + resp, + true, + ) 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": int64(3221225472),