-
Notifications
You must be signed in to change notification settings - Fork 0
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
[DR-3324] Only fetch DRS object via passport if one exists #80
[DR-3324] Only fetch DRS object via passport if one exists #80
Conversation
If fetching a DRS object via a passport fails even so, then fall back to fetching the object via a bearer token.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #80 +/- ##
============================================
+ Coverage 84.11% 84.56% +0.44%
- Complexity 228 231 +3
============================================
Files 36 36
Lines 806 810 +4
Branches 75 76 +1
============================================
+ Hits 678 685 +7
+ Misses 96 94 -2
+ Partials 32 31 -1
☔ View full report in Codecov by Sentry. |
Note: using @VisibleForTesting can be a code smell, but in this case there were no existing tests of DrsResolutionService and the code's public methods were not easy to unit test. I decided that it was better to add targeted unit test coverage for this time-sensitive bugfix than rush a refactor.
Update kinda-snarky comment about git-secrets usage, instead explain why we are using it.
Added unit test.
Kudos, SonarCloud Quality Gate passed! |
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.
This looks great! And thanks for the general doc cleanup too!
try { | ||
List<String> passports = authService.fetchPassports(bearerToken).orElse(List.of()); | ||
if (!passports.isEmpty()) { | ||
return drsApi.postObject(Map.of("passports", passports), objectId); |
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.
Too bad...I wish that the code gen would make postObject take a typed object. I'mm actually kinda surprised that it doesn't
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.
I agree with you… this seems like a similar issue to what we encountered with calling the TPS client in TDR. I was surprised that it didn't enforce the presence of a required argument.
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.
I've been poking a little...It's because (I think) the code gen only creates models for objects in the components.schemas
part of the openapi yaml and these are in components.requestBodies
. Trying to see if there's a way to have it generate models for those too
service/src/main/java/bio/terra/drshub/services/DrsResolutionService.java
Show resolved
Hide resolved
List<String> passports = authService.fetchPassports(bearerToken).orElse(List.of()); | ||
if (!passports.isEmpty()) { |
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.
IMO this is exactly the reason why an API that returns a collection shouldn't use Optional. The calling code needs to check for both the optional being present and the collection being non-empty. Returning an empty collection instead would make this code simpler. But it looks like Optional
is threaded through many places here so it wouldn't be easy to change this.
https://broadworkbench.atlassian.net/browse/DR-3324
DrsHub
asks TDR Production for the supported authorization mechanisms for a controlled access GTEx file:Seeing that PassportAuth is a supported type (dictated by the presence of both a PHS ID and consent code on the source snapshot), it tries to obtain a passport to use for fetching the DRS object.
Previous behavior
In cases where DRS OPTIONS indicate
PassportAuth
as a supported means of authorization, if a user Passport is not available, then DrsHub passed an empty string as a Passport when attempting object resolution.But the empty string is not a valid Passport: when DrsHub passed it to TDR, TDR passed it to the ECM client for decoding. ECM then throws an unhandled error:
Furthermore, DrsHub did not fall back to fetching the object via bearer token.
New behavior
In cases where DRS OPTIONS indicate
PassportAuth
as a supported means of authorization, DrsHub only attempts to fetch the object via POSTed passport if such a passport exists.If any part of this fails, DrsHub now falls back to fetching the object via bearer token.
Tests
I added targeted unit tests covering DRS object fetching, but there were no previous unit tests for
DrsResolutionService
: I believe this code remains largely uncovered by automated tests, but am also still finding my way around this repo.