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

Access the impl in interceptor #1370

Open
wenerme opened this issue Dec 18, 2024 · 0 comments
Open

Access the impl in interceptor #1370

wenerme opened this issue Dec 18, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@wenerme
Copy link

wenerme commented Dec 18, 2024

Is your feature request related to a problem? Please describe.

I want to access the metadata for the impl from interceptor, seems this is impossible.

I want to get the spec.impl, it's even better to allowed access the service impl givend by router.service

export async function invokeUnaryImplementation<
I extends DescMessage,
O extends DescMessage,
>(
spec: MethodImplSpec<I, O> & { kind: "unary" },
context: HandlerContext,
input: MessageShape<I>,
interceptors: Interceptor[],
): Promise<MessageShape<O>> {
const anyFn = async (
req: UnaryRequest<I, O>,
): Promise<UnaryResponse<I, O>> => {
return {
message: normalize(
spec.method.output,
await spec.impl(req.message, mergeRequest(context, req)),
),
stream: false,
method: spec.method,
...responseCommon(context, spec),
};
};
const next = applyInterceptors(anyFn, interceptors);
const { message, header, trailer } = await next({
stream: false,
message: input,
method: spec.method,
...requestCommon(context, spec),
});
copyHeaders(header, context.responseHeader);
copyHeaders(trailer, context.responseTrailer);
return message;
}

Describe the solution you'd like

maybe allowed to change the spec.impl or put some magic in contextValues ?

Describe alternatives you've considered

give a proxy object for router.service, return warped func there

Additional context

For opt-in case, I have to add decorator for all methods, I hope I can do opt-out by check the auth in interceptor instead wrap the method when decorate.

@Auth()
class UserServiceImpl {
@AuthZ({})
 list(){
}
}


function getAuthZMeta(){
}
@wenerme wenerme added the enhancement New feature or request label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant