Skip to content

Commit bf5d0ce

Browse files
refactor(adms): drop vestigial _auth wrapper around IasTokenFetcher
Per reviewer feedback (NicoleMGomes, PR #138): after the relocation refactor moved IasTokenFetcher into the adms package, the _auth wrapper (config adaptation + AuthError conversion) became pure boilerplate wrapping a sibling class. Inline the adaptation into _ias_fetcher (constructor now takes AdmsConfig directly) and drop the duplicate AuthError by importing from adms.exceptions. Consolidates two overlapping test files into test_ias_fetcher.py.
1 parent 341c857 commit bf5d0ce

8 files changed

Lines changed: 64 additions & 260 deletions

File tree

src/sap_cloud_sdk/adms/_auth.py

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/sap_cloud_sdk/adms/_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from requests import Response
2525
from requests.exceptions import RequestException
2626

27-
from sap_cloud_sdk.adms._auth import IasTokenFetcher
27+
from sap_cloud_sdk.adms._ias_fetcher import IasTokenFetcher
2828
from sap_cloud_sdk.adms.config import AdmsConfig
2929
from sap_cloud_sdk.adms.exceptions import DocumentNotFoundError, HttpError
3030
from sap_cloud_sdk.adms._async_http import AsyncHttpClient

src/sap_cloud_sdk/adms/_ias_fetcher.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
"""Generic SAP IAS (Identity Authentication Service) token fetcher.
1+
"""SAP IAS (Identity Authentication Service) token fetcher for ADMS.
22
33
Provides:
44
- :class:`IasTokenFetcher` — client_credentials + jwt-bearer token acquisition
5-
against any SAP IAS tenant, with pluggable :class:`~._token_cache.TokenCache`.
6-
7-
This module is **service-agnostic**: pass raw ``ias_url``, ``client_id``, and
8-
``client_secret`` directly. Service-specific config adapters (e.g. the DMS
9-
module's ``IasTokenFetcher``) subclass this and adapt their own config objects.
5+
against the SAP IAS tenant, with pluggable :class:`~._token_cache.TokenCache`.
106
117
Token caching:
128
By default tokens are cached in-process via :class:`InMemoryTokenCache`.
@@ -22,6 +18,8 @@
2218
import requests
2319

2420
from sap_cloud_sdk.adms._token_cache import InMemoryTokenCache, TokenCache
21+
from sap_cloud_sdk.adms.config import AdmsConfig
22+
from sap_cloud_sdk.adms.exceptions import AuthError
2523

2624
# Grant types (RFC 6749 / RFC 7523)
2725
_GRANT_CLIENT_CREDENTIALS = "client_credentials"
@@ -40,10 +38,6 @@
4038
_TOKEN_REQUEST_TIMEOUT_SECONDS = 10
4139

4240

43-
class AuthError(Exception):
44-
"""Raised when IAS token acquisition or exchange fails."""
45-
46-
4741
class IasTokenFetcher:
4842
"""Fetches and caches OAuth2 access tokens from SAP IAS.
4943
@@ -54,42 +48,43 @@ class IasTokenFetcher:
5448
services can enforce per-user permissions.
5549
5650
Args:
57-
ias_url: IAS tenant base URL, e.g. ``https://tenant.accounts.ondemand.com``.
58-
client_id: IAS OAuth2 client ID.
59-
client_secret: IAS OAuth2 client secret.
51+
config: :class:`~sap_cloud_sdk.adms.config.AdmsConfig` with IAS
52+
credentials (``ias_url``, ``client_id``, ``client_secret``,
53+
optional ``resource``).
6054
session: Optional ``requests.Session`` to reuse (useful for testing).
6155
cache: Pluggable :class:`TokenCache`. Defaults to
6256
:class:`InMemoryTokenCache`. Pass a :class:`RedisTokenCache` for
6357
multi-instance deployments.
6458
6559
Example::
6660
67-
from sap_cloud_sdk.adms import IasTokenFetcher
68-
fetcher = IasTokenFetcher(
61+
from sap_cloud_sdk.adms._ias_fetcher import IasTokenFetcher
62+
from sap_cloud_sdk.adms.config import AdmsConfig
63+
64+
config = AdmsConfig(
65+
service_url="https://adm.example.com",
6966
ias_url="https://tenant.accounts.ondemand.com",
7067
client_id="my-client",
7168
client_secret="my-secret",
7269
)
70+
fetcher = IasTokenFetcher(config)
7371
token = fetcher.get_token()
7472
headers = {"Authorization": f"Bearer {token}"}
7573
"""
7674

7775
def __init__(
7876
self,
79-
ias_url: str,
80-
client_id: str,
81-
client_secret: str,
77+
config: AdmsConfig,
8278
session: Optional[requests.Session] = None,
8379
cache: Optional[TokenCache] = None,
84-
resource: Optional[str] = None,
8580
) -> None:
86-
self._ias_url = ias_url.rstrip("/")
87-
self._client_id = client_id
88-
self._client_secret = client_secret
81+
self._ias_url = config.ias_url.rstrip("/")
82+
self._client_id = config.client_id
83+
self._client_secret = config.client_secret
8984
self._session = session or requests.Session()
9085
self._token_url = self._ias_url + "/oauth2/token"
9186
self._cache: TokenCache = cache or InMemoryTokenCache()
92-
self._resource: Optional[str] = resource
87+
self._resource: Optional[str] = config.resource
9388

9489
# ------------------------------------------------------------------
9590
# Public API

src/sap_cloud_sdk/adms/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import httpx
3131

32-
from sap_cloud_sdk.adms._auth import IasTokenFetcher
32+
from sap_cloud_sdk.adms._ias_fetcher import IasTokenFetcher
3333
from sap_cloud_sdk.adms._http import (
3434
AdmsHttp,
3535
AsyncAdmsHttp,

tests/adms/unit/test_auth.py

Lines changed: 0 additions & 134 deletions
This file was deleted.

tests/adms/unit/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pytest
1010

1111
from sap_cloud_sdk.adms import create_client
12-
from sap_cloud_sdk.adms._auth import IasTokenFetcher
12+
from sap_cloud_sdk.adms._ias_fetcher import IasTokenFetcher
1313
from sap_cloud_sdk.adms._http import AdmsHttp, AsyncAdmsHttp
1414
from sap_cloud_sdk.adms._models import (
1515
AllowedDomain,

tests/adms/unit/test_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77
import requests
88

9-
from sap_cloud_sdk.adms._auth import IasTokenFetcher
9+
from sap_cloud_sdk.adms._ias_fetcher import IasTokenFetcher
1010
from sap_cloud_sdk.adms._http import AdmsHttp, quote_odata_guid_key, quote_odata_string_key
1111
from sap_cloud_sdk.adms.config import AdmsConfig
1212
from sap_cloud_sdk.adms.exceptions import DocumentNotFoundError, HttpError

0 commit comments

Comments
 (0)