Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API Deprecations] Skip HTTP resources #207725

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import {
export const getIsAccessApiDeprecation = ({
isInternalApiRequest,
isPublicAccess,
isHttpResource,
}: PostValidationMetadata): boolean => {
const isNotPublicAccess = !isPublicAccess;
const isNotInternalRequest = !isInternalApiRequest;
const isNotHttpResource = !isHttpResource;

return !!(isNotPublicAccess && isNotInternalRequest);
return isNotPublicAccess && isNotInternalRequest && isNotHttpResource;
};

export const buildApiAccessDeprecationDetails = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('handle', () => {
deprecated: undefined,
isInternalApiRequest: false,
isPublicAccess: false,
isHttpResource: false,
});
expect(router.emitPostValidate).toHaveBeenNthCalledWith(2, expect.any(Object), {
deprecated: {
Expand All @@ -75,6 +76,7 @@ describe('handle', () => {
},
isInternalApiRequest: false,
isPublicAccess: false,
isHttpResource: false,
});
});

Expand Down Expand Up @@ -109,6 +111,7 @@ describe('handle', () => {
},
isInternalApiRequest: false,
isPublicAccess: false,
isHttpResource: false,
});
});
});
Expand Down Expand Up @@ -168,6 +171,7 @@ describe('validateHapiRequest', () => {
deprecated: undefined,
isInternalApiRequest: false,
isPublicAccess: true,
isHttpResource: false,
});
}
{
Expand All @@ -182,6 +186,7 @@ describe('validateHapiRequest', () => {
deprecated: undefined,
isInternalApiRequest: false,
isPublicAccess: true,
isHttpResource: false,
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
type SafeRouteMethod,
type RouteConfig,
getRequestValidation,
type PostValidationMetadata,
} from '@kbn/core-http-server';
import type {
RouteSecurityGetter,
Expand Down Expand Up @@ -205,10 +206,14 @@ function routeSchemasFromRouteConfig<P, Q, B>(
}
}

function getPostValidateEventMetadata(request: AnyKibanaRequest, routeInfo: RouteInfo) {
function getPostValidateEventMetadata(
request: AnyKibanaRequest,
routeInfo: RouteInfo
): PostValidationMetadata {
return {
deprecated: routeInfo.deprecated,
isInternalApiRequest: request.isInternalApiRequest,
isPublicAccess: isPublicAccessApiRoute(routeInfo),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isPublicAccess: isPublicAccessApiRoute(routeInfo),
isPublicAccess: routeInfo.access === 'public'

On alternative to the proposed changes is to preserve the previous behaviour instead of the using/fixing isPublicAccessApiRoute here.

isHttpResource: !!routeInfo.httpResource,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export class Router<Context extends RequestHandlerContextBase = RequestHandlerCo
postValidateConext: PostValidationMetadata = {
isInternalApiRequest: true,
isPublicAccess: false,
isHttpResource: false,
}
) => {
const postValidate: RouterEvents = 'onPostValidate';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ describe('Versioned route', () => {
},
isInternalApiRequest: false,
isPublicAccess: false,
isHttpResource: false,
}
);
expect(router.emitPostValidate).toHaveBeenNthCalledWith(
Expand All @@ -756,6 +757,7 @@ describe('Versioned route', () => {
},
isInternalApiRequest: false,
isPublicAccess: false,
isHttpResource: false,
}
);
});
Expand Down Expand Up @@ -789,6 +791,7 @@ describe('Versioned route', () => {
},
isInternalApiRequest: false,
isPublicAccess: false,
isHttpResource: false,
}
);
});
Expand Down
1 change: 1 addition & 0 deletions src/core/packages/http/server/src/router/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,4 +532,5 @@ export interface PostValidationMetadata {
deprecated?: RouteDeprecationInfo;
isInternalApiRequest: boolean;
isPublicAccess: boolean;
isHttpResource: boolean;
}