Skip to content

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

Open

Description

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions