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

Unable to implement an extractor the references my app-specific server context #972

Open
inickles opened this issue Apr 18, 2024 · 2 comments

Comments

@inickles
Copy link

I was looking to implement an ExclusiveExtractor that references data in my server context, and at first glance I thought I was going to be able to, but now I'm not seeing how I can specify my concrete type to be able to do so.
I want to do something like:

#[async_trait]
impl<T> ExclusiveExtractor for VerifiedGithubBody<T>
where
    T: Sync + Send,
{
    async fn from_request(
        rqctx: &RequestContext<MyContext>,
        request: hyper::Request<hyper::Body>,
    ) -> Result<Self, HttpError> {
        let context = rqctx.context();
        let hmac_secret = context.github_hmac_secret;

        ...
    }
...
}

where MyContext is:

pub(crate) struct MyContext{
    pub(crate) github_hmac_secret: secrecy::SecretString,
}

but that doesn't work.

I can do all the work of this in the endpoint handler, which is fine, but it would be my preference to do this kind of thing in an extractor. Alternatively, I could pass that access that data via other means, such as environment variables, but it is also my preference to not use that for secrets. The server context seems like an appropriate place to store that.

@jclulow
Copy link
Collaborator

jclulow commented Apr 19, 2024

@inickles
Copy link
Author

Have you see what @augustuswm did in https://github.com/oxidecomputer/dropshot-verified-body/blob/main/src/services/github.rs ?

I did, yeah, that's kind of how I got here. I noticed it was getting the key from env (https://github.com/oxidecomputer/dropshot-verified-body/blob/main/src/services/github.rs#L40) and him and I were discussing how we'd like for that to come from the context instead, so I thought I'd work up a PR for it. But then I got stuck here.

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