Skip to content

Commit

Permalink
use @kbn/config-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaElastic committed Sep 10, 2024
1 parent ef6b657 commit 3a4da83
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
28 changes: 28 additions & 0 deletions x-pack/plugins/fleet/server/routes/schema/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { schema } from '@kbn/config-schema';

export const genericErrorResponse = () =>
schema.object(
{
statusCode: schema.number(),
error: schema.string(),
message: schema.string(),
},
{
meta: { description: 'Generic Error' },
}
);

export const internalErrorResponse = () =>
schema.object(
{
message: schema.string(),
},
{ meta: { description: 'Internal Server Error' } }
);
36 changes: 35 additions & 1 deletion x-pack/plugins/fleet/server/routes/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { schema } from '@kbn/config-schema';

import type { FleetAuthzRouter } from '../../services/security';

Expand All @@ -12,6 +13,8 @@ import { API_VERSIONS } from '../../../common/constants';

import type { FleetConfigType } from '../../../common/types';

import { genericErrorResponse, internalErrorResponse } from '../schema/errors';

import { getFleetStatusHandler, fleetSetupHandler } from './handlers';

export const registerFleetSetupRoute = (router: FleetAuthzRouter) => {
Expand All @@ -26,7 +29,38 @@ export const registerFleetSetupRoute = (router: FleetAuthzRouter) => {
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: false,
validate: {
// operationId: 'setup',
request: {},
response: {
200: {
body: () =>
schema.object(
{
isInitialized: schema.boolean(),
nonFatalErrors: schema.arrayOf(
schema.object({
name: schema.string(),
message: schema.string(),
})
),
},
{
meta: {
description:
"A summary of the result of Fleet's `setup` lifecycle. If `isInitialized` is true, Fleet is ready to accept agent enrollment. `nonFatalErrors` may include useful insight into non-blocking issues with Fleet setup.",
},
}
),
},
400: {
body: genericErrorResponse,
},
500: {
body: internalErrorResponse,
},
},
},
},
fleetSetupHandler
);
Expand Down

0 comments on commit 3a4da83

Please sign in to comment.