-
Notifications
You must be signed in to change notification settings - Fork 107
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
Refactor authentication #435
Conversation
👈 Launch a binder notebook on this branch for commit 4564b3b I will automatically update this comment whenever this PR is modified 👈 Launch a binder notebook on this branch for commit 16b8d3f 👈 Launch a binder notebook on this branch for commit 083426c 👈 Launch a binder notebook on this branch for commit edfa362 👈 Launch a binder notebook on this branch for commit 72c5347 👈 Launch a binder notebook on this branch for commit 434bbf2 👈 Launch a binder notebook on this branch for commit e06765a 👈 Launch a binder notebook on this branch for commit 9e1f745 👈 Launch a binder notebook on this branch for commit a2a455f 👈 Launch a binder notebook on this branch for commit 1aacb1d 👈 Launch a binder notebook on this branch for commit 50db05e 👈 Launch a binder notebook on this branch for commit 12e21ba 👈 Launch a binder notebook on this branch for commit 10bc734 👈 Launch a binder notebook on this branch for commit 8033ed4 👈 Launch a binder notebook on this branch for commit 6cdddbf 👈 Launch a binder notebook on this branch for commit b7b8b7e 👈 Launch a binder notebook on this branch for commit 1172e9e 👈 Launch a binder notebook on this branch for commit abd950a 👈 Launch a binder notebook on this branch for commit 90354e6 👈 Launch a binder notebook on this branch for commit 7fedc2d 👈 Launch a binder notebook on this branch for commit e26c9a1 👈 Launch a binder notebook on this branch for commit a31b092 👈 Launch a binder notebook on this branch for commit 3aab79a 👈 Launch a binder notebook on this branch for commit ade942f 👈 Launch a binder notebook on this branch for commit f052b76 👈 Launch a binder notebook on this branch for commit 63b0275 👈 Launch a binder notebook on this branch for commit 1796a2c 👈 Launch a binder notebook on this branch for commit 4d7687b 👈 Launch a binder notebook on this branch for commit 3838044 👈 Launch a binder notebook on this branch for commit 693a9fa |
@betolink I'm curious if you have any thoughts on this approach for centralizing auth in icepyx so that it can easily be picked up across Query, Variables, and Read objects. Pulling out some relevant points from @rwegener2's great writeup above:
but...
She developed this Mixin approach, but we're still left with (assuming this isn't still outstanding in
Do you have any thoughts? |
Hi @JessicaS11 @rwegener2 this is still an outstanding issue with For icepyx, this mixing class looks good! maybe when we instantiate the class for the first time we could store the timestamp and return the same cached set of credentials until the time delta goes above say 50 minutes, a little like the |
Thanks for the feedback @betolink! I've cleaned up the PR and added:
The one question I had for @betolink:
We can talk about if it makes sense to merge this / how the best way to that. UPDATE: Just adding that after a conversation with Luis it sounds like earthaccess does not currently propagate the error message back to the user. I think it's fine for icepyx to raise the error and direct users to view the earthaccess output. No further action needed here. |
Co-authored-by: Jessica Scheick <[email protected]>
Co-authored-by: Jessica Scheick <[email protected]>
Current status
In writing those tests I did also end up changing a few lines of Todo
I’m going to pause on this PR for the rest of the day, but the last thing I’ve got on the todo list is updating the documentation to reflect that the user is no longer required to explicitly login. After that I'll re-request review. |
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Co-authored-by: Jessica Scheick <[email protected]>
Co-authored-by: Jessica Scheick <[email protected]>
@rwegener2 I'm running the basic data access notebook locally and... it fails. I've got valid authentication (it did show an error before bringing up the manual login box, but it did let me authenticate that way and I got valid credentials), but cannot actually do anything that's behind a login. The two failure cases I found are: UPDATE: I should have known better than to try and test icepyx code on a Wednesday. NSIDC system is down for maintenance (see banner at: https://nsidc.org/data/icesat-2). Wednesday is often their maintenance day... |
Ok, I'm trying it out now. @JessicaS11 I also get a failure, but mine is happening on
due to |
There are a few examples in there that are set up to fail to demo things for the user. With Run All Cells you're likely hitting up against one of those. |
Co-authored-by: Jessica Scheick <[email protected]>
I just:
Let me know if anything comes up while running the code @JessicaS11 🤞🏻 |
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.
looks like the features typo got reintroduced... what do you think about removing the "if you choose" language, since we'd ultimately like to discourage deprecated uses of the function.
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.
shoot, sorry about that features typo. I'll push that change now.
I see what you're saying about the "if you choose" language. What do you think of:
If you are unable to remove
earthdata_login()
calls from your workflow, you will also note that certain inputs, such asearthdata_uid
andregion_a.earthdata_login(earthdata_uid, email)
becomesregion_a.earthdata_login()
If you have different phrasing I'm happy with whatever you prefer.
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.
That looks great to me - it gently pushes folks towards removing it. If we want to mince words we could take out "you will also"... (science writing has gotten to me I guess). :)
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'm glad you've got such a tuned eye for writing! Definitely better to be concise. Both those changes of phrase are pushed
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.
Thanks for all your hard work on this, @rwegener2!
Please note that the uml will auto-rebuild after I approve and add a last commit (which will then require all the tests to re-pass before the merge button is available). And I think it's forced, but a squash merge would be greatly appreciated!
Yay, soooo exiting! Thanks for all of your attentive review @JessicaS11! Merging now! 🎊 |
What is done
This PR refactors Earthdata authentication to make it more extensible to additional classes that may want to authenticate. Related discussion #433
How it was done
Here I'm continuing the discussion from #433. @JessicaS11 made the good point that instead of creating our own EarthdataAuth class we should just try to reference the
auth
object that comes back fromearthaccess.login()
. (Ex. by setting aself.auth = earthaccess.login()
variable on all the classes that require authentication. Generally like this:I experimented with this but eventually realized the library would try to regenerate the objects very time
self.auth.get_s3_credentials(daac="NSIDC")
orself.auth.get_session()
was accessed. Forsession
that wouldn't matter so much because that is fast to access, but the s3 creds takes ~5 seconds to retrieve. This seemed like it might be a bit cumbersome over time. We could do separate attributes (self.session
orself.s3login_credentials
) and a@property
getter method to get around this, but that was starting to feel like a lot of code to copy and paste into every class that needed auth. The other major problem is that I don't think we want to make users login when the Query object is created. I think we'd like to let them run Queries and search for data, and only require login once the user tries to.order_granules()
.To avoid these challenges I created a mixin class. This differs from an inherited class in that it is built to extend the functionality of other classes with a small, specific set of attributes or functions. The
EarthdataAuthMixin
contains properties forauth
,session
, ands3login_credentials
. These set themselves (login) the first time they are accessed, and reference the previously created object in subsequent accesses. A bonus of this mixin method is that I was able to keep the.earthdata_login()
method, which should make it backwards compatible. The mixin could be added to any class that needs authentication and the user doesn't need to keep track of if s3 credentials or a regular session are needed.I'm curious what others think of this technique. It's a half step more complicated than the
self.auth=earthaccess.login()
technique. It felt to me like we gained in modularity and functionality enough to warrant the complication, but I'd love additional opinions.How it can be tested
Both the following code snippets should work:
Todo