-
Notifications
You must be signed in to change notification settings - Fork 76
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
Comments
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. |
@inickles sorry that I missed this when it came in. How exactly does your example fail? My guess is that in order to impl This would probably be a breaking change, though, unless we went through the trouble of defining a new We may want to do the same with Sorry about the trouble. |
No worries! I consider this a minor enhancement request, nothing that needs addressing soon.
Yeah, that sounds right to me.
I wonder if we could set a default generic type parameter to the unit type and have it not break for existing users, so
Really, no worries at all. cc @sunshowers , as we'd discussed this issue a little bit ago. |
Keeping API traits in mind, which are by definition generic over a variety of contexts -- if we decide to allow more restricted contexts then I think we'd have to do it with respect to a trait. So in the trait MyContextTrait: ServerContext {
fn github_hmac_secret(&self) -> secrecy::SecretString;
}
#[dropshot::api_description]
trait MyApi {
type Context: MyContextTrait;
// ...
} Then you'd write I'm around 90% sure the types will work out if this mechanism is followed. |
I think it would be best to pass in the actual server context uniformly here to minimize confusion.
Oh interesting -- you might be able to do something like: trait ContextSpecificExclusiveExtractor<T: ServerContext> { ... }
impl<E: ExclusiveExtractor, T: ServerContext> ContextSpecificExclusiveExtrator<T> for E { ... } |
@sunshowers to be clear, you're saying that if we do what I proposed above (make Or are you saying that it wouldn't work at all to parameterize |
@davepacheco The former. If we add a type parameter to ExclusiveExtractor, then to make it compatible with API traits we'd have to use this kind of trait scheme. |
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:
where
MyContext
is: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.
The text was updated successfully, but these errors were encountered: