diff --git a/docs/api/saved-objects/rotate_encryption_key.asciidoc b/docs/api/saved-objects/rotate_encryption_key.asciidoc index 0a66ed2b4b3610..efc57ddb4308d6 100644 --- a/docs/api/saved-objects/rotate_encryption_key.asciidoc +++ b/docs/api/saved-objects/rotate_encryption_key.asciidoc @@ -25,7 +25,7 @@ Bulk key rotation can consume a considerable amount of resources and hence only `type`:: (Optional, string) Limits encryption key rotation only to the saved objects with the specified type. By default, {kib} tries to rotate the encryption key for all saved object types that may contain encrypted attributes. -`batchSize`:: +`batch_size`:: (Optional, number) Specifies a maximum number of saved objects that {kib} can process in a single batch. Bulk key rotation is an iterative process since {kib} may not be able to fetch and process all required saved objects in one go and splits processing into consequent batches. By default, the batch size is 10000, which is also a maximum allowed value. [[saved-objects-api-rotate-encryption-key-response-body]] @@ -91,7 +91,7 @@ In this example, key rotation is performed for all saved objects with the `alert [source,sh] -------------------------------------------------- -$ curl -X POST /api/encrypted_saved_objects/_rotate_key?type=alert&batchSize=5000 +$ curl -X POST /api/encrypted_saved_objects/_rotate_key?type=alert&batch_size=5000 -------------------------------------------------- // KIBANA diff --git a/x-pack/plugins/encrypted_saved_objects/server/routes/key_rotation.test.ts b/x-pack/plugins/encrypted_saved_objects/server/routes/key_rotation.test.ts index ced4dda48fcd2a..acc2d2247efcb0 100644 --- a/x-pack/plugins/encrypted_saved_objects/server/routes/key_rotation.test.ts +++ b/x-pack/plugins/encrypted_saved_objects/server/routes/key_rotation.test.ts @@ -57,24 +57,24 @@ describe('Key rotation routes', () => { const queryValidator = (routeConfig.validate as any).query as Type; expect( queryValidator.validate({ - batchSize: 100, + batch_size: 100, type: 'some-type', }) ).toEqual({ - batchSize: 100, + batch_size: 100, type: 'some-type', }); - expect(queryValidator.validate({ batchSize: 1 })).toEqual({ batchSize: 1 }); - expect(queryValidator.validate({ batchSize: 10000 })).toEqual({ batchSize: 10000 }); - expect(queryValidator.validate({})).toEqual({ batchSize: 10000 }); + expect(queryValidator.validate({ batch_size: 1 })).toEqual({ batch_size: 1 }); + expect(queryValidator.validate({ batch_size: 10000 })).toEqual({ batch_size: 10000 }); + expect(queryValidator.validate({})).toEqual({ batch_size: 10000 }); - expect(() => queryValidator.validate({ batchSize: 0 })).toThrowErrorMatchingInlineSnapshot( - `"[batchSize]: Value must be equal to or greater than [1]."` + expect(() => queryValidator.validate({ batch_size: 0 })).toThrowErrorMatchingInlineSnapshot( + `"[batch_size]: Value must be equal to or greater than [1]."` ); expect(() => - queryValidator.validate({ batchSize: 10001 }) + queryValidator.validate({ batch_size: 10001 }) ).toThrowErrorMatchingInlineSnapshot( - `"[batchSize]: Value must be equal to or lower than [10000]."` + `"[batch_size]: Value must be equal to or lower than [10000]."` ); expect(() => queryValidator.validate({ type: 100 })).toThrowErrorMatchingInlineSnapshot( @@ -106,7 +106,7 @@ describe('Key rotation routes', () => { const unhandledException = new Error('Something went wrong.'); mockEncryptionKeyRotationService.rotate.mockRejectedValue(unhandledException); - const mockRequest = httpServerMock.createKibanaRequest({ query: { batchSize: 1234 } }); + const mockRequest = httpServerMock.createKibanaRequest({ query: { batch_size: 1234 } }); const response = await routeHandler(mockContext, mockRequest, kibanaResponseFactory); expect(response.status).toBe(500); @@ -117,7 +117,7 @@ describe('Key rotation routes', () => { }); it('returns whatever `rotate` returns.', async () => { - const mockRequest = httpServerMock.createKibanaRequest({ query: { batchSize: 1234 } }); + const mockRequest = httpServerMock.createKibanaRequest({ query: { batch_size: 1234 } }); mockEncryptionKeyRotationService.rotate.mockResolvedValue({ total: 3, successful: 6, @@ -132,7 +132,7 @@ describe('Key rotation routes', () => { }); it('returns 429 if called while rotation is in progress.', async () => { - const mockRequest = httpServerMock.createKibanaRequest({ query: { batchSize: 1234 } }); + const mockRequest = httpServerMock.createKibanaRequest({ query: { batch_size: 1234 } }); mockEncryptionKeyRotationService.rotate.mockResolvedValue({ total: 3, successful: 6, diff --git a/x-pack/plugins/encrypted_saved_objects/server/routes/key_rotation.ts b/x-pack/plugins/encrypted_saved_objects/server/routes/key_rotation.ts index 48b29387106ee3..c74f67220472c0 100644 --- a/x-pack/plugins/encrypted_saved_objects/server/routes/key_rotation.ts +++ b/x-pack/plugins/encrypted_saved_objects/server/routes/key_rotation.ts @@ -28,7 +28,7 @@ export function defineKeyRotationRoutes({ path: '/api/encrypted_saved_objects/_rotate_key', validate: { query: schema.object({ - batchSize: schema.number({ + batch_size: schema.number({ min: 1, max: DEFAULT_MAX_RESULT_WINDOW, defaultValue: DEFAULT_MAX_RESULT_WINDOW, @@ -60,7 +60,7 @@ export function defineKeyRotationRoutes({ try { return response.ok({ body: await encryptionKeyRotationService.rotate(request, { - batchSize: request.query.batchSize, + batchSize: request.query.batch_size, type: request.query.type, }), });