Skip to content

Commit

Permalink
using user-agent to start tracing client usage
Browse files Browse the repository at this point in the history
  • Loading branch information
betolink committed Feb 3, 2024
1 parent 0ead9db commit c692069
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions earthaccess/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@
from typing import Any, Dict, List, Optional
from urllib.parse import urlparse


import requests # type: ignore
from tinynetrc import Netrc

from .daac import DAACS

import importlib.metadata

try:

Check failure on line 17 in earthaccess/auth.py

View workflow job for this annotation

GitHub Actions / check-with-ruff

Ruff (I001)

earthaccess/auth.py:1:1: I001 Import block is un-sorted or un-formatted
user_agent = f"earthaccess v{importlib.metadata.version('earthacess')}"
except importlib.metadata.PackageNotFoundError:
user_agent = "earthaccess"


logger = logging.getLogger(__name__)


Expand All @@ -31,6 +40,9 @@ def __init__(
self, username: Optional[str] = None, password: Optional[str] = None
) -> None:
super().__init__()
self.headers.update({"User-Agent": user_agent})


if username and password:
self.auth = (username, password)

Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ def test_auth_gets_proper_credentials(self, user_input, user_password) -> bool:

# Test
auth = Auth()
session = auth.get_session()
headers = session.headers
self.assertEqual(auth.authenticated, False)
auth.login(strategy="interactive")
self.assertEqual(auth.authenticated, True)
self.assertTrue(auth.token in json_response)

# test that we are creaintg a session with the proper headers
self.assertTrue("User-Agent" in headers)
self.assertTrue("earthaccess" in headers["User-Agent"])

@responses.activate
@mock.patch("getpass.getpass")
@mock.patch("builtins.input")
Expand Down

0 comments on commit c692069

Please sign in to comment.