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

Does ZTapir endpoint execute code within a scope? #4055

Open
Kalin-Rudnicki opened this issue Sep 19, 2024 · 1 comment
Open

Does ZTapir endpoint execute code within a scope? #4055

Kalin-Rudnicki opened this issue Sep 19, 2024 · 1 comment

Comments

@Kalin-Rudnicki
Copy link

Looking at the function signatures for:

    def zServerSecurityLogic[R, U](
        f: SECURITY_INPUT => ZIO[R, ERROR_OUTPUT, U]
    ): ZPartialServerEndpoint[R, SECURITY_INPUT, U, INPUT, ERROR_OUTPUT, OUTPUT, C] =
      ZPartialServerEndpoint(e, f)

  def serverLogic[R0](logic: PRINCIPAL => INPUT => ZIO[R0, ERROR_OUTPUT, OUTPUT]): ZServerEndpoint[R with R0, C] =
    ServerEndpoint(
      endpoint,
      _ => securityLogic(_: SECURITY_INPUT).either.resurrect,
      _ => (u: PRINCIPAL) => (i: INPUT) => logic(u)(i).either.resurrect
    )

Within zServerSecurityLogic I would like to use ZIO.logAnnotateScoped(_, _) to add log context from within the JWT that will be there for all requests. If this is possible, it would be super ideal to add this here, as all endpoints are already calling a shared function that decodes the JWT.

If things are already executed within a scope, I believe the correct signatures would be: (?)

f: SECURITY_INPUT => ZIO[R & Scope, ERROR_OUTPUT, U]

logic: PRINCIPAL => INPUT => ZIO[R0 & Scope, ERROR_OUTPUT, OUTPUT]
@adamw
Copy link
Member

adamw commented Sep 23, 2024

It's not currently run in a scope, in fact the environment isn't touched at all. Though it might make sense to implement such a functionality. Here's the code for handling requests - I imagine the changes would have to be done there. Provided that you are using zio-http, of course.

If you'd like to attempt a PR, that would be great :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants