-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ondrej Scecina
committed
Dec 2, 2024
1 parent
de929af
commit a7a9404
Showing
8 changed files
with
61 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,46 @@ | ||
from urllib.parse import parse_qs, urlencode, urlparse | ||
|
||
import aiohttp | ||
from aiohttp.client import ClientSession | ||
from opal_client.logger import logger | ||
from urllib.parse import urlencode, urlparse, parse_qs | ||
|
||
from .updater import DefaultDataUpdater | ||
|
||
|
||
class OAuth2DataUpdater(DefaultDataUpdater): | ||
async def _load_policy_data_config(self, url: str, headers) -> aiohttp.ClientResponse: | ||
async def _load_policy_data_config( | ||
self, url: str, headers | ||
) -> aiohttp.ClientResponse: | ||
await self._authenticator.authenticate(headers) | ||
|
||
async with ClientSession(headers=headers) as session: | ||
response = await session.get(url, **self._ssl_context_kwargs, allow_redirects=False) | ||
response = await session.get( | ||
url, **self._ssl_context_kwargs, allow_redirects=False | ||
) | ||
|
||
if response.status == 307: | ||
return await self._load_redirected_policy_data_config(response.headers['location'], headers) | ||
return await self._load_redirected_policy_data_config( | ||
response.headers['location'], headers | ||
) | ||
else: | ||
return response | ||
|
||
async def _load_redirected_policy_data_config(self, url: str, headers): | ||
redirect_url = self.__redirect_url(url) | ||
|
||
logger.info("Redirecting to data-sources configuration '{source}'", source=redirect_url) | ||
logger.info( | ||
"Redirecting to data-sources configuration '{source}'", source=redirect_url | ||
) | ||
|
||
async with ClientSession(headers=headers) as session: | ||
return await session.get(redirect_url, **self._ssl_context_kwargs, allow_redirects=False) | ||
return await session.get( | ||
redirect_url, **self._ssl_context_kwargs, allow_redirects=False | ||
) | ||
|
||
def __redirect_url(self, url: str) -> str: | ||
u = urlparse(url) | ||
query = parse_qs(u.query, keep_blank_values=True) | ||
query.pop('token', None) | ||
query.pop("token", None) | ||
u = u._replace(query=urlencode(query, True)) | ||
|
||
return u.geturl() | ||
return u.geturl() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters