Skip to content

Commit

Permalink
fixing schema validation
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaElastic committed Oct 30, 2023
1 parent 813846d commit fcaa3e8
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions x-pack/plugins/fleet/server/routes/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type { RequestHandler } from '@kbn/core/server';
import type { RequestHandler, RouteValidationResultFactory } from '@kbn/core/server';
import type { TypeOf } from '@kbn/config-schema';

import type { FleetAuthzRouter } from '../../services/security';
Expand All @@ -16,8 +16,8 @@ import { API_VERSIONS, INTERNAL_API_ACCESS } from '../../../common/constants';
import { appContextService } from '../../services';
import type { CheckPermissionsResponse, GenerateServiceTokenResponse } from '../../../common/types';
import { defaultFleetErrorHandler, GenerateServiceTokenError } from '../../errors';
import type { FleetRequestHandler } from '../../types';
import { CheckPermissionsRequestSchema, GenerateServiceTokenRequestSchema } from '../../types';
import type { FleetRequestHandler, GenerateServiceTokenRequestSchema } from '../../types';
import { CheckPermissionsRequestSchema } from '../../types';

export const getCheckPermissionsHandler: FleetRequestHandler<
unknown,
Expand Down Expand Up @@ -96,6 +96,15 @@ export const generateServiceTokenHandler: RequestHandler<
}
};

const serviceTokenBodyValidation = (data: any, validationResult: RouteValidationResultFactory) => {
const { ok } = validationResult;
if (!data) {
return ok({ remote: false });
}
const { remote } = data;
return ok({ remote });
};

export const registerRoutes = (router: FleetAuthzRouter) => {
router.versioned
.get({
Expand All @@ -120,7 +129,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => {
{
version: API_VERSIONS.public.v1,
validate: {
request: GenerateServiceTokenRequestSchema,
request: { body: serviceTokenBodyValidation },
},
},
generateServiceTokenHandler
Expand Down

0 comments on commit fcaa3e8

Please sign in to comment.