Skip to content

Commit

Permalink
Improve DbC doc for get_access_token()
Browse files Browse the repository at this point in the history
and fix post-condition on `get_netrc_credentials()`
  • Loading branch information
Luc Hermitte committed Aug 20, 2024
1 parent 08d6c61 commit f9e06a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 8 additions & 1 deletion eof/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ def _file_is_0600(filename: Filename):


def get_netrc_credentials(host: str, netrc_file: Optional[Filename] = None) -> tuple[str, str]:
"""Get username and password from netrc file for a given host."""
"""
Get username and password from netrc file for a given host.
:return: username and password found for host in netrc_file
:postcondition: username and password are non empty strings.
"""
netrc_file = netrc_file or "~/.netrc"
netrc_file = Path(netrc_file).expanduser()
_logger.debug(f"Using {netrc_file=!r}")
Expand All @@ -98,6 +103,8 @@ def get_netrc_credentials(host: str, netrc_file: Optional[Filename] = None) -> t
username, _, password = auth
if username is None or password is None:
raise ValueError(f"No username/password found for {host} in ~/.netrc")
if not username or not password:
raise ValueError(f"Empty username/password found for {host} in ~/.netrc")
return username, password


Expand Down
4 changes: 3 additions & 1 deletion eof/dataspace_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,12 @@ def query_orbit_file_service(query: str) -> list[dict]:
return query_results


def get_access_token(username, password, token_2fa) -> str:
def get_access_token(username: str, password: str, token_2fa: Optional[str]) -> str:
"""Get an access token for the Copernicus Data Space Ecosystem (CDSE) API.
Code from https://documentation.dataspace.copernicus.eu/APIs/Token.html
:precondition: username and password are non empty strings.
"""
assert username and password, "Username and password values are expected!"

Expand Down

0 comments on commit f9e06a7

Please sign in to comment.