Skip to content

Commit 9bac693

Browse files
committed
lint
1 parent f36d242 commit 9bac693

2 files changed

Lines changed: 22 additions & 20 deletions

File tree

pyiceberg/catalog/rest/auth.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
import base64
1819
from abc import ABC, abstractmethod
1920
from typing import Optional
21+
2022
from requests import PreparedRequest
2123
from requests.auth import AuthBase
2224

23-
import base64
2425

2526
class AuthManager(ABC):
2627
"""
27-
Abstract base class for Authentication Managers used to supply authorization headers
28-
to HTTP clients (e.g. requests.Session).
29-
28+
Abstract base class for Authentication Managers used to supply authorization headers to HTTP clients (e.g. requests.Session).
29+
3030
Subclasses must implement the `auth_header` method to return an Authorization header value.
3131
"""
32+
3233
@abstractmethod
3334
def auth_header(self) -> Optional[str]:
3435
"""Return the Authorization header value, or None if not applicable."""
35-
pass
3636

3737

3838
class NoopAuthManager(AuthManager):
@@ -41,7 +41,7 @@ def auth_header(self) -> Optional[str]:
4141

4242

4343
class BasicAuthManager(AuthManager):
44-
def __init__(self, username: str, password: str):
44+
def __init__(self, username: str, password: str):
4545
credentials = f"{username}:{password}"
4646
self._token = base64.b64encode(credentials.encode()).decode()
4747

@@ -50,24 +50,24 @@ def auth_header(self) -> str:
5050

5151

5252
class AuthManagerAdapter(AuthBase):
53-
"""
54-
A `requests.auth.AuthBase` adapter that integrates an `AuthManager`
55-
into a `requests.Session` to automatically attach the appropriate
56-
Authorization header to every request.
53+
"""A `requests.auth.AuthBase` adapter that integrates an `AuthManager` into a `requests.Session` to automatically attach the appropriate Authorization header to every request.
5754
5855
This adapter is useful when working with `requests.Session.auth`
5956
and allows reuse of authentication strategies defined by `AuthManager`.
6057
"""
58+
6159
def __init__(self, auth_manager: AuthManager):
6260
"""
63-
Args:
64-
auth_manager (AuthManager): An instance of an AuthManager subclass.
61+
Initialize AuthManagerAdapter.
62+
63+
Args:
64+
auth_manager (AuthManager): An instance of an AuthManager subclass.
6565
"""
6666
self.auth_manager = auth_manager
6767

6868
def __call__(self, r: PreparedRequest) -> PreparedRequest:
6969
"""
70-
Modifies the outgoing request to include the Authorization header.
70+
Modify the outgoing request to include the Authorization header.
7171
7272
Args:
7373
r (requests.PreparedRequest): The HTTP request being prepared.
@@ -77,5 +77,5 @@ def __call__(self, r: PreparedRequest) -> PreparedRequest:
7777
"""
7878
auth_header = self.auth_manager.auth_header()
7979
if auth_header:
80-
r.headers['Authorization'] = auth_header
80+
r.headers["Authorization"] = auth_header
8181
return r

tests/catalog/test_rest_auth.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from pyiceberg.catalog.rest.auth import AuthManagerAdapter, NoopAuthManager, BasicAuthManager
19-
2018
import base64
19+
2120
import pytest
2221
import requests
2322
from requests_mock import Mocker
2423

24+
from pyiceberg.catalog.rest.auth import AuthManagerAdapter, BasicAuthManager, NoopAuthManager
25+
2526
TEST_URI = "https://iceberg-test-catalog/"
2627

28+
2729
@pytest.fixture
2830
def rest_mock(requests_mock: Mocker) -> Mocker:
2931
requests_mock.get(
@@ -34,19 +36,19 @@ def rest_mock(requests_mock: Mocker) -> Mocker:
3436
return requests_mock
3537

3638

37-
def test_noop_auth_header(rest_mock: Mocker):
39+
def test_noop_auth_header(rest_mock: Mocker) -> None:
3840
auth_manager = NoopAuthManager()
3941
session = requests.Session()
4042
session.auth = AuthManagerAdapter(auth_manager)
4143

42-
response = session.get(TEST_URI)
44+
session.get(TEST_URI)
4345
history = rest_mock.request_history
4446
assert len(history) == 1
4547
actual_headers = history[0].headers
4648
assert "Authorization" not in actual_headers
4749

4850

49-
def test_basic_auth_header(rest_mock: Mocker):
51+
def test_basic_auth_header(rest_mock: Mocker) -> None:
5052
username = "testuser"
5153
password = "testpassword"
5254
expected_token = base64.b64encode(f"{username}:{password}".encode()).decode()
@@ -56,7 +58,7 @@ def test_basic_auth_header(rest_mock: Mocker):
5658
session = requests.Session()
5759
session.auth = AuthManagerAdapter(auth_manager)
5860

59-
response = session.get(TEST_URI)
61+
session.get(TEST_URI)
6062
history = rest_mock.request_history
6163
assert len(history) == 1
6264
actual_headers = history[0].headers

0 commit comments

Comments
 (0)