add us-west-2 check to API and improve auth repr#424
add us-west-2 check to API and improve auth repr#424JessicaS11 wants to merge 18 commits intomainfrom
Conversation
|
We can probably change the print statement to raise a ValueError with the same message. That way, it is a formal error message that will interrupt the library from opening the bucket out-of-region with a long, cryptic error message. |
|
Thanks to @battistowx during today's earthaccess cowork session for moving this forward with me! @andypbarrett @betolink Any thoughts on what info we want to be in the auth repr? I'm happy to move that to a separate PR if we want to move forward with the s3check portion of this one. |
earthaccess/__init__.py
Outdated
| "get_s3fs_session", | ||
| "get_s3_credentials", | ||
| "granule_query", | ||
| "get_edl_token" "granule_query", |
There was a problem hiding this comment.
Warning: these strings will concatenate :)
| def __repr__(self) -> str: | ||
| print_str = "Authentication Info\n" + "-------------------\n" | ||
| for k, v in self.auth_info.items(): | ||
| print_str += str("{}: {}\n".format(k, v)) | ||
|
|
||
| return print_str |
There was a problem hiding this comment.
I strongly discourage this implementation of __repr__ for at least 2 reasons:
- (minor) this is arguably an "abuse" of
__repr__, which should generally be: "If at all possible, this should look like a valid Python expression that could be used to recreate an object with the same value (given an appropriate environment)." (see https://docs.python.org/3/reference/datamodel.html#object.__repr__) - (very important) this can lead to inadvertent leaking of the user's token(s) during logging since
auth_infoincludes those tokens
There was a problem hiding this comment.
What about something like (and get rid of the auth_info function) instead:
def __str__(self) -> str:
print_str = str("Authenticated?: {}\n".format(self.authenticated))
print_str += str("View your token with `.tokens`")
return print_str
ca7e907 to
f18335e
Compare
|
Can someone comment if any of this is still relevant given #1011? I've cleaned up the conflicts to make it easier to see what's going on. |
Per #231, we've added API access to
store._running_in_us_west_2()in the form of a printed statement that the user is (or is not) running in AWS region us-west-2. In the process of implementing this, it became clear thatget_edl_token()had not been added to__init__.py, so that was added as well. It also adds a repr for theauthobject via aauth.auth_info()property.I'm seeking input on:
earthaccess.region()function instead.auth.__repr__? Currently it's not much better than the object ID:store._running_in_us_west_2()isn't tested. Shouldauth.auth_info()have a dictionary typing/keyword matching test?