From 7bfaae19266eee33871fac99ec99638ab3b0f750 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Thu, 14 Nov 2024 07:52:13 -0500 Subject: [PATCH] [Fleet] Revert enrollment api key list removal (#200087) --- oas_docs/bundle.json | 46 ++++++++++++++++++- oas_docs/bundle.serverless.json | 46 ++++++++++++++++++- oas_docs/output/kibana.serverless.yaml | 39 ++++++++++++++++ oas_docs/output/kibana.yaml | 39 ++++++++++++++++ .../types/rest_spec/enrollment_api_key.ts | 5 +- .../routes/enrollment_api_key/handler.ts | 1 + .../server/routes/enrollment_api_key/index.ts | 5 +- .../apis/enrollment_api_keys/crud.ts | 2 + 8 files changed, 179 insertions(+), 4 deletions(-) diff --git a/oas_docs/bundle.json b/oas_docs/bundle.json index aa53ce68e54fd..0fde92c1fa3f9 100644 --- a/oas_docs/bundle.json +++ b/oas_docs/bundle.json @@ -16951,6 +16951,49 @@ }, "type": "array" }, + "list": { + "deprecated": true, + "items": { + "additionalProperties": false, + "properties": { + "active": { + "description": "When false, the enrollment API key is revoked and cannot be used for enrolling Elastic Agents.", + "type": "boolean" + }, + "api_key": { + "description": "The enrollment API key (token) used for enrolling Elastic Agents.", + "type": "string" + }, + "api_key_id": { + "description": "The ID of the API key in the Security API.", + "type": "string" + }, + "created_at": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "description": "The name of the enrollment API key.", + "type": "string" + }, + "policy_id": { + "description": "The ID of the agent policy the Elastic Agent will be enrolled in.", + "type": "string" + } + }, + "required": [ + "id", + "api_key_id", + "api_key", + "active", + "created_at" + ], + "type": "object" + }, + "type": "array" + }, "page": { "type": "number" }, @@ -16965,7 +17008,8 @@ "items", "total", "page", - "perPage" + "perPage", + "list" ], "type": "object" } diff --git a/oas_docs/bundle.serverless.json b/oas_docs/bundle.serverless.json index 1267027a3687a..229bda84b8629 100644 --- a/oas_docs/bundle.serverless.json +++ b/oas_docs/bundle.serverless.json @@ -16951,6 +16951,49 @@ }, "type": "array" }, + "list": { + "deprecated": true, + "items": { + "additionalProperties": false, + "properties": { + "active": { + "description": "When false, the enrollment API key is revoked and cannot be used for enrolling Elastic Agents.", + "type": "boolean" + }, + "api_key": { + "description": "The enrollment API key (token) used for enrolling Elastic Agents.", + "type": "string" + }, + "api_key_id": { + "description": "The ID of the API key in the Security API.", + "type": "string" + }, + "created_at": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "description": "The name of the enrollment API key.", + "type": "string" + }, + "policy_id": { + "description": "The ID of the agent policy the Elastic Agent will be enrolled in.", + "type": "string" + } + }, + "required": [ + "id", + "api_key_id", + "api_key", + "active", + "created_at" + ], + "type": "object" + }, + "type": "array" + }, "page": { "type": "number" }, @@ -16965,7 +17008,8 @@ "items", "total", "page", - "perPage" + "perPage", + "list" ], "type": "object" } diff --git a/oas_docs/output/kibana.serverless.yaml b/oas_docs/output/kibana.serverless.yaml index 10dbdbe44e26a..32d38c3569148 100644 --- a/oas_docs/output/kibana.serverless.yaml +++ b/oas_docs/output/kibana.serverless.yaml @@ -16686,6 +16686,44 @@ paths: - active - created_at type: array + list: + deprecated: true + items: + additionalProperties: false + type: object + properties: + active: + description: >- + When false, the enrollment API key is revoked and + cannot be used for enrolling Elastic Agents. + type: boolean + api_key: + description: >- + The enrollment API key (token) used for enrolling + Elastic Agents. + type: string + api_key_id: + description: The ID of the API key in the Security API. + type: string + created_at: + type: string + id: + type: string + name: + description: The name of the enrollment API key. + type: string + policy_id: + description: >- + The ID of the agent policy the Elastic Agent will be + enrolled in. + type: string + required: + - id + - api_key_id + - api_key + - active + - created_at + type: array page: type: number perPage: @@ -16697,6 +16735,7 @@ paths: - total - page - perPage + - list '400': content: application/json; Elastic-Api-Version=2023-10-31: diff --git a/oas_docs/output/kibana.yaml b/oas_docs/output/kibana.yaml index f84c98205effe..8a3d4d3634b8d 100644 --- a/oas_docs/output/kibana.yaml +++ b/oas_docs/output/kibana.yaml @@ -19470,6 +19470,44 @@ paths: - active - created_at type: array + list: + deprecated: true + items: + additionalProperties: false + type: object + properties: + active: + description: >- + When false, the enrollment API key is revoked and + cannot be used for enrolling Elastic Agents. + type: boolean + api_key: + description: >- + The enrollment API key (token) used for enrolling + Elastic Agents. + type: string + api_key_id: + description: The ID of the API key in the Security API. + type: string + created_at: + type: string + id: + type: string + name: + description: The name of the enrollment API key. + type: string + policy_id: + description: >- + The ID of the agent policy the Elastic Agent will be + enrolled in. + type: string + required: + - id + - api_key_id + - api_key + - active + - created_at + type: array page: type: number perPage: @@ -19481,6 +19519,7 @@ paths: - total - page - perPage + - list '400': content: application/json; Elastic-Api-Version=2023-10-31: diff --git a/x-pack/plugins/fleet/common/types/rest_spec/enrollment_api_key.ts b/x-pack/plugins/fleet/common/types/rest_spec/enrollment_api_key.ts index e1509d551bdef..7fa724e5079c8 100644 --- a/x-pack/plugins/fleet/common/types/rest_spec/enrollment_api_key.ts +++ b/x-pack/plugins/fleet/common/types/rest_spec/enrollment_api_key.ts @@ -13,7 +13,10 @@ export interface GetEnrollmentAPIKeysRequest { query: ListWithKuery; } -export type GetEnrollmentAPIKeysResponse = ListResult; +export type GetEnrollmentAPIKeysResponse = ListResult & { + // deprecated in 8.x + list?: EnrollmentAPIKey[]; +}; export interface GetOneEnrollmentAPIKeyRequest { params: { diff --git a/x-pack/plugins/fleet/server/routes/enrollment_api_key/handler.ts b/x-pack/plugins/fleet/server/routes/enrollment_api_key/handler.ts index cfce60b0f18f5..a38f5bdadc617 100644 --- a/x-pack/plugins/fleet/server/routes/enrollment_api_key/handler.ts +++ b/x-pack/plugins/fleet/server/routes/enrollment_api_key/handler.ts @@ -43,6 +43,7 @@ export const getEnrollmentApiKeysHandler: RequestHandler< spaceId: useSpaceAwareness ? getCurrentNamespace(soClient) : undefined, }); const body: GetEnrollmentAPIKeysResponse = { + list: items, // deprecated items, total, page, diff --git a/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts b/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts index 58538ba18f359..e593bac3180fe 100644 --- a/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts +++ b/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts @@ -111,7 +111,10 @@ export const registerRoutes = (router: FleetAuthzRouter) => { request: GetEnrollmentAPIKeysRequestSchema, response: { 200: { - body: () => ListResponseSchema(EnrollmentAPIKeySchema), + body: () => + ListResponseSchema(EnrollmentAPIKeySchema).extends({ + list: schema.arrayOf(EnrollmentAPIKeySchema, { meta: { deprecated: true } }), + }), }, 400: { body: genericErrorResponse, diff --git a/x-pack/test/fleet_api_integration/apis/enrollment_api_keys/crud.ts b/x-pack/test/fleet_api_integration/apis/enrollment_api_keys/crud.ts index 24d1520d8d6f8..686532f8eae50 100644 --- a/x-pack/test/fleet_api_integration/apis/enrollment_api_keys/crud.ts +++ b/x-pack/test/fleet_api_integration/apis/enrollment_api_keys/crud.ts @@ -43,6 +43,8 @@ export default function (providerContext: FtrProviderContext) { expect(apiResponse.total).to.be(2); expect(apiResponse.items[0]).to.have.keys('id', 'api_key_id', 'name'); + // Deprecated property list + expect(apiResponse.list[0]).to.have.keys('id', 'api_key_id', 'name'); expect(apiResponse).to.have.keys('items'); });