-
Notifications
You must be signed in to change notification settings - Fork 109
impl(auth): accept trust boundary header to build auth headers #4528
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
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4528 +/- ##
==========================================
- Coverage 95.03% 95.00% -0.04%
==========================================
Files 195 195
Lines 7428 7440 +12
==========================================
+ Hits 7059 7068 +9
- Misses 369 372 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
coryan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More questions and suggestions than hard requirements. Maybe explain why the constant needs to go in a different place.
|
@coryan I started with the suggestion to accept a header map, but them each consumer of the |
|
One thing that I'm still not particularly happy is that there are more |
|
@coryan I moved to use
|
coryan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coryan I moved to use
Option<&'a str>and added the lifetime 'a to other parts of the code to avoid clones.
I think the code looks good enough to merge and then iterate. I still think we could improve it.
I think there are two options here, which I'm not sure which one is better, but both works:
- Have a
new(&token)and abuild()method that return theCacheableResource(the one that I pushed here). I need theAuthHeadersBuilderto be it's own struct instead of just extendingHeaderMap, as I need to know if is a Bearer token or API Key and also hold the&token.
Couldn't you create the header map in new() or for_api_key(), but only if the token is a CacheableResource::New? That is, do the cacheable thing early instead of when calling .build()?
|
|
||
| AuthHeadersBuilder::new(&token) | ||
| .maybe_quota_project_id(self.quota_project_id.as_deref()) | ||
| .build() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an example, this code could read:
match &token {
CacheableResource::NotModified => Ok(CacheableResource::NotModified),
CacheableResource::New { entity_tag, data } => {
let headers = HeaderMapBuilder::from_bearer_token(data)?
.maybe_quota_project_id(self.quota_project_id.as_deref())?
.build();
Ok(CacheableResource::New { entity_tag.clone(), headers })
},
}and if we want to say "monad", we could implement .map() and transpose() functions for CacheableResource so we can say:
token.map(|data| -> Result<HeaderMap> {
let headers = HeaderMapBuilder::from_bearer_token(data)?
.maybe_quota_project_id(self.quota_project_id.as_deref())?
.build();
Ok(headers)
})
.transpose() // `CacheableResource<Result<T>>` to `Result<CacheableResource<T>>`
},
}
coryan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved to unblock you, but as I said, this could be better.
Towards #4186