ingen-lib 2.1.1__tar.gz → 2.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ingen_lib-2.1.1/ingen_lib.egg-info → ingen_lib-2.1.2}/PKG-INFO +1 -1
- ingen_lib-2.1.2/ingen/utils/app_http/auth.py +262 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/app_http/http_util.py +6 -18
- {ingen_lib-2.1.1 → ingen_lib-2.1.2/ingen_lib.egg-info}/PKG-INFO +1 -1
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen_lib.egg-info/SOURCES.txt +1 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/setup.py +1 -1
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/LICENSE +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/MANIFEST.in +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/README.md +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/__main__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/data_source/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/data_source/api_source.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/data_source/data_source_type.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/data_source/dataframe_store.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/data_source/file_source.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/data_source/json_source.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/data_source/mysql_source.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/data_source/rawdata_source.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/data_source/source.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/data_source/source_factory.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/formatters/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/formatters/common_formatters.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/formatters/formatter.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/formatters/utils.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/generators/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/generators/base_interface_generator.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/generators/interface_generator.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/lib/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/lib/cryptor.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/logger.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/metadata/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/metadata/metadata.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/metadata/metadata_parser.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/post_processor/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/post_processor/common_post_processor.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/post_processor/post_processor.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/pre_processor/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/pre_processor/aggregator.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/pre_processor/aggregators.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/pre_processor/drop_duplicates.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/pre_processor/filter.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/pre_processor/json_array_expander.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/pre_processor/mask.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/pre_processor/melt.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/pre_processor/merger.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/pre_processor/not_equals_filter.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/pre_processor/outer_join.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/pre_processor/pre_processor.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/pre_processor/process.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/pre_processor/union.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/reader/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/reader/api_reader.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/reader/data_source.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/reader/file_reader.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/reader/json_reader.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/reader/mysql_reader.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/reader/rawdata_reader.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/reader/xml_file_reader.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/app_http/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/app_http/aiohttp_retry.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/app_http/http_request.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/app_http/success_criterias.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/app_secrets.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/interpolators/Interpolator.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/interpolators/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/interpolators/common_interpolators.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/json_df_convertors.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/path_parser.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/properties.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/run_configuration.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/sql_query_parser.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/timer.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/url_constructor.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/utils/utils.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/validation/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/validation/common_validations.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/validation/notification.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/validation/send_email.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/validation/validations.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/dataframe_writer.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/json_util.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/json_writer/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/json_writer/convertors/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/json_writer/convertors/convertor_factory.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/json_writer/convertors/df_to_multiple_json_convertor.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/json_writer/convertors/df_to_single_json_convertor.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/json_writer/destinations/__init__.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/json_writer/destinations/api_destination.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/json_writer/destinations/destination_factory.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/json_writer/destinations/file_destination.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/json_writer/json_writer.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/old_json_writer.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/split_file_writer.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/util.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/writer.py +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen_lib.egg-info/dependency_links.txt +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen_lib.egg-info/requires.txt +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen_lib.egg-info/top_level.txt +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/pyproject.toml +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/requirements.txt +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/setup.cfg +0 -0
- {ingen_lib-2.1.1 → ingen_lib-2.1.2}/test/test_interface_generator.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ingen-lib
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.2
|
|
4
4
|
Summary: A Python script suite that generates interface files based on the given interface metadata/config file
|
|
5
5
|
Home-page: https://github.com/blackrock/interface-generator
|
|
6
6
|
Maintainer: Swarna Dhakad, Piyush Ranjan, Jatin Varlyani, Pooja Katariya
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# Copyright (c) 2023 BlackRock, Inc.
|
|
2
|
+
# All Rights Reserved.
|
|
3
|
+
|
|
4
|
+
import asyncio
|
|
5
|
+
import base64
|
|
6
|
+
import logging
|
|
7
|
+
import time
|
|
8
|
+
from dataclasses import dataclass, field
|
|
9
|
+
from typing import Optional
|
|
10
|
+
|
|
11
|
+
from aiohttp import BasicAuth
|
|
12
|
+
|
|
13
|
+
from ingen.utils.properties import properties
|
|
14
|
+
|
|
15
|
+
log = logging.getLogger()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class OAuth2Token:
|
|
19
|
+
"""Wraps an OAuth 2.0 token response with expiry tracking.
|
|
20
|
+
|
|
21
|
+
A typical token response contains:
|
|
22
|
+
access_token (str): The token to use in API calls
|
|
23
|
+
token_type (str): Usually "Bearer"
|
|
24
|
+
expires_in (int): Token lifetime in seconds
|
|
25
|
+
refresh_token (str, optional): Token to obtain a new access_token
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(self, token_data):
|
|
29
|
+
self._data = token_data
|
|
30
|
+
if token_data.get('expires_in') is not None:
|
|
31
|
+
self._data['expires_at'] = int(time.time()) + int(token_data['expires_in'])
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def access_token(self):
|
|
35
|
+
return self._data.get('access_token')
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def refresh_token(self):
|
|
39
|
+
return self._data.get('refresh_token')
|
|
40
|
+
|
|
41
|
+
def is_expired(self, leeway=60):
|
|
42
|
+
"""Check if the token is expired (or will expire within leeway seconds).
|
|
43
|
+
|
|
44
|
+
:param leeway: Seconds before actual expiry to consider the token expired.
|
|
45
|
+
:return: True if expired, False if valid, None if no expiry info.
|
|
46
|
+
"""
|
|
47
|
+
expires_at = self._data.get('expires_at')
|
|
48
|
+
if expires_at is None:
|
|
49
|
+
return None
|
|
50
|
+
return (expires_at - leeway) < time.time()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class OAuth2Client:
|
|
54
|
+
"""Manages the OAuth 2.0 token lifecycle for a single auth configuration.
|
|
55
|
+
|
|
56
|
+
Handles token fetching, caching, and refresh for client_credentials
|
|
57
|
+
and password grant types.
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
def __init__(self, auth_config):
|
|
61
|
+
self._grant_type = auth_config.get('grant_type')
|
|
62
|
+
self._token_url = auth_config.get('token_url')
|
|
63
|
+
scope = auth_config.get('scope')
|
|
64
|
+
self._scope = ' '.join(scope) if isinstance(scope, list) else scope
|
|
65
|
+
self._auth_method = auth_config.get('method', 'client_secret_basic')
|
|
66
|
+
|
|
67
|
+
self._validate_config(auth_config)
|
|
68
|
+
|
|
69
|
+
self._client_id = properties.get_property('api_auth.client_id')
|
|
70
|
+
self._client_secret = properties.get_property('api_auth.client_secret')
|
|
71
|
+
|
|
72
|
+
self._username = None
|
|
73
|
+
self._password = None
|
|
74
|
+
if self._grant_type == 'password':
|
|
75
|
+
self._username = properties.get_property('api_auth.username')
|
|
76
|
+
self._password = properties.get_property('api_auth.password')
|
|
77
|
+
|
|
78
|
+
self._token = None
|
|
79
|
+
self._lock = asyncio.Lock()
|
|
80
|
+
|
|
81
|
+
@staticmethod
|
|
82
|
+
def _validate_config(auth_config):
|
|
83
|
+
"""Validate that all required fields are present in the auth config."""
|
|
84
|
+
required = ['token_url']
|
|
85
|
+
missing = [f for f in required if not auth_config.get(f)]
|
|
86
|
+
if missing:
|
|
87
|
+
raise ValueError(f"OAuth2 auth config missing required fields: {missing}")
|
|
88
|
+
|
|
89
|
+
async def ensure_active_token(self, session):
|
|
90
|
+
"""Return a valid token, fetching or refreshing as needed.
|
|
91
|
+
|
|
92
|
+
Uses asyncio.Lock to prevent concurrent token refresh from multiple consumer tasks.
|
|
93
|
+
|
|
94
|
+
:param session: aiohttp.ClientSession
|
|
95
|
+
:return: OAuth2Token
|
|
96
|
+
"""
|
|
97
|
+
async with self._lock:
|
|
98
|
+
if self._token and not self._token.is_expired():
|
|
99
|
+
return self._token
|
|
100
|
+
|
|
101
|
+
if self._token and self._token.refresh_token:
|
|
102
|
+
return await self._refresh_token(session)
|
|
103
|
+
|
|
104
|
+
return await self._fetch_token(session)
|
|
105
|
+
|
|
106
|
+
def _attach_client_credentials(self, headers, body):
|
|
107
|
+
"""Attach client credentials to the request per auth method.
|
|
108
|
+
|
|
109
|
+
:param headers: dict of HTTP headers (mutated in place)
|
|
110
|
+
:param body: dict of POST body params (mutated in place)
|
|
111
|
+
"""
|
|
112
|
+
if self._auth_method == 'client_secret_basic':
|
|
113
|
+
credentials = f"{self._client_id}:{self._client_secret}"
|
|
114
|
+
encoded = base64.b64encode(credentials.encode('latin1')).decode('latin1')
|
|
115
|
+
headers['Authorization'] = f"Basic {encoded}"
|
|
116
|
+
elif self._auth_method == 'client_secret_post':
|
|
117
|
+
body['client_id'] = self._client_id
|
|
118
|
+
body['client_secret'] = self._client_secret
|
|
119
|
+
|
|
120
|
+
async def _fetch_token(self, session):
|
|
121
|
+
"""Fetch a new access token from the token endpoint.
|
|
122
|
+
|
|
123
|
+
:param session: aiohttp.ClientSession
|
|
124
|
+
:return: OAuth2Token
|
|
125
|
+
"""
|
|
126
|
+
body = {'grant_type': self._grant_type}
|
|
127
|
+
if self._scope:
|
|
128
|
+
body['scope'] = self._scope
|
|
129
|
+
if self._grant_type == 'password':
|
|
130
|
+
body['username'] = self._username
|
|
131
|
+
body['password'] = self._password
|
|
132
|
+
|
|
133
|
+
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
|
|
134
|
+
self._attach_client_credentials(headers, body)
|
|
135
|
+
|
|
136
|
+
log.info(f"Fetching OAuth2 token from {self._token_url} (grant_type={self._grant_type})")
|
|
137
|
+
async with session.post(self._token_url, data=body, headers=headers) as response:
|
|
138
|
+
if response.status != 200:
|
|
139
|
+
text = await response.text()
|
|
140
|
+
raise ConnectionError(
|
|
141
|
+
f"OAuth2 token request failed with status {response.status}: {text}"
|
|
142
|
+
)
|
|
143
|
+
token_data = await response.json()
|
|
144
|
+
|
|
145
|
+
self._token = OAuth2Token(token_data)
|
|
146
|
+
log.info("OAuth2 token acquired successfully")
|
|
147
|
+
return self._token
|
|
148
|
+
|
|
149
|
+
async def _refresh_token(self, session):
|
|
150
|
+
"""Refresh the access token using the refresh_token grant.
|
|
151
|
+
|
|
152
|
+
:param session: aiohttp.ClientSession
|
|
153
|
+
:return: OAuth2Token
|
|
154
|
+
"""
|
|
155
|
+
body = {
|
|
156
|
+
'grant_type': 'refresh_token',
|
|
157
|
+
'refresh_token': self._token.refresh_token,
|
|
158
|
+
}
|
|
159
|
+
if self._scope:
|
|
160
|
+
body['scope'] = self._scope
|
|
161
|
+
|
|
162
|
+
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
|
|
163
|
+
self._attach_client_credentials(headers, body)
|
|
164
|
+
|
|
165
|
+
log.info(f"Refreshing OAuth2 token from {self._token_url}")
|
|
166
|
+
async with session.post(self._token_url, data=body, headers=headers) as response:
|
|
167
|
+
if response.status != 200:
|
|
168
|
+
text = await response.text()
|
|
169
|
+
log.warning(f"OAuth2 token refresh failed ({response.status}), re-authenticating")
|
|
170
|
+
return await self._fetch_token(session)
|
|
171
|
+
token_data = await response.json()
|
|
172
|
+
|
|
173
|
+
if 'refresh_token' not in token_data and self._token.refresh_token:
|
|
174
|
+
token_data['refresh_token'] = self._token.refresh_token
|
|
175
|
+
|
|
176
|
+
self._token = OAuth2Token(token_data)
|
|
177
|
+
log.info("OAuth2 token refreshed successfully")
|
|
178
|
+
return self._token
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
# Module-level cache of OAuth2Client instances, keyed by (token_url, scope, method)
|
|
182
|
+
_oauth2_clients = {}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
@dataclass
|
|
186
|
+
class AuthResult:
|
|
187
|
+
"""Result of auth resolution. Carries either BasicAuth or Bearer token headers."""
|
|
188
|
+
auth: Optional[BasicAuth] = None
|
|
189
|
+
headers: Optional[dict] = field(default_factory=dict)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def basic_auth_handler(auth_config):
|
|
193
|
+
"""Handle BasicAuth authentication.
|
|
194
|
+
|
|
195
|
+
:param auth_config: dict with auth configuration from YAML
|
|
196
|
+
:return: AuthResult with aiohttp.BasicAuth
|
|
197
|
+
"""
|
|
198
|
+
try:
|
|
199
|
+
user = properties.get_property('api_auth.username')
|
|
200
|
+
password = properties.get_property('api_auth.password')
|
|
201
|
+
return AuthResult(auth=BasicAuth(user, password))
|
|
202
|
+
except Exception as e:
|
|
203
|
+
log.exception(f"Error while getting the property username/pwd for api call: {e}")
|
|
204
|
+
return AuthResult()
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
async def oauth2_auth_handler(session, auth_config):
|
|
208
|
+
"""Handle OAuth2 authentication (client_credentials and password grants).
|
|
209
|
+
|
|
210
|
+
:param session: aiohttp.ClientSession
|
|
211
|
+
:param auth_config: dict with auth configuration from YAML
|
|
212
|
+
:return: AuthResult with Bearer token header
|
|
213
|
+
"""
|
|
214
|
+
scope = auth_config.get('scope', '')
|
|
215
|
+
if isinstance(scope, list):
|
|
216
|
+
scope = ' '.join(scope)
|
|
217
|
+
cache_key = (auth_config.get('token_url'), scope, auth_config.get('method', 'client_secret_basic'))
|
|
218
|
+
if cache_key not in _oauth2_clients:
|
|
219
|
+
_oauth2_clients[cache_key] = OAuth2Client(auth_config)
|
|
220
|
+
|
|
221
|
+
client = _oauth2_clients[cache_key]
|
|
222
|
+
token = await client.ensure_active_token(session)
|
|
223
|
+
return AuthResult(headers={'Authorization': f"Bearer {token.access_token}"})
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def pre_obtained_token_handler(auth_config):
|
|
227
|
+
"""Handle pre-obtained token authentication.
|
|
228
|
+
|
|
229
|
+
:param auth_config: dict with auth configuration from YAML
|
|
230
|
+
:return: AuthResult with Bearer token header
|
|
231
|
+
"""
|
|
232
|
+
access_token = properties.get_property('api_auth.access_token')
|
|
233
|
+
if not access_token:
|
|
234
|
+
raise ValueError("Could not read access token from properties. "
|
|
235
|
+
"Check property key: api_auth.access_token")
|
|
236
|
+
return AuthResult(headers={'Authorization': f"Bearer {access_token}"})
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
async def get_auth(session, auth_config):
|
|
240
|
+
"""Top-level auth dispatcher. Resolves auth config to an AuthResult.
|
|
241
|
+
|
|
242
|
+
:param session: aiohttp.ClientSession
|
|
243
|
+
:param auth_config: dict with 'type' key, or None for no auth
|
|
244
|
+
:return: AuthResult
|
|
245
|
+
"""
|
|
246
|
+
if not auth_config:
|
|
247
|
+
return AuthResult()
|
|
248
|
+
|
|
249
|
+
auth_type = auth_config.get('type')
|
|
250
|
+
|
|
251
|
+
if auth_type == 'BasicAuth':
|
|
252
|
+
return basic_auth_handler(auth_config)
|
|
253
|
+
elif auth_type == 'OAuth2':
|
|
254
|
+
grant_type = auth_config.get('grant_type')
|
|
255
|
+
if grant_type == 'token':
|
|
256
|
+
return pre_obtained_token_handler(auth_config)
|
|
257
|
+
elif grant_type in ('client_credentials', 'password'):
|
|
258
|
+
return await oauth2_auth_handler(session, auth_config)
|
|
259
|
+
else:
|
|
260
|
+
raise ValueError(f"Unsupported OAuth2 grant_type: {grant_type}")
|
|
261
|
+
else:
|
|
262
|
+
raise ValueError(f"Unsupported auth type: {auth_type}")
|
|
@@ -6,11 +6,11 @@ import logging
|
|
|
6
6
|
from asyncio import CancelledError
|
|
7
7
|
|
|
8
8
|
import aiohttp
|
|
9
|
-
from aiohttp import ClientSession
|
|
9
|
+
from aiohttp import ClientSession
|
|
10
10
|
|
|
11
|
+
from ingen.utils.app_http.auth import get_auth
|
|
11
12
|
from ingen.utils.app_http.aiohttp_retry import http_retry_request, HTTPResponse
|
|
12
13
|
from ingen.utils.app_http.success_criterias import status_criteria, DEFAULT_STATUS_CRITERIA_OPTIONS
|
|
13
|
-
from ingen.utils.properties import Properties
|
|
14
14
|
|
|
15
15
|
log = logging.getLogger()
|
|
16
16
|
|
|
@@ -86,6 +86,8 @@ async def fetch(session, queue, request_params, results):
|
|
|
86
86
|
while True:
|
|
87
87
|
try:
|
|
88
88
|
request = await queue.get()
|
|
89
|
+
auth_result = await get_auth(session, request.auth)
|
|
90
|
+
merged_headers = {**(request.headers or {}), **(auth_result.headers or {})}
|
|
89
91
|
response = await http_retry_request(session,
|
|
90
92
|
request.method,
|
|
91
93
|
request.url,
|
|
@@ -96,8 +98,8 @@ async def fetch(session, queue, request_params, results):
|
|
|
96
98
|
status_criteria),
|
|
97
99
|
criteria_options=request_params.get('criteria_options',
|
|
98
100
|
DEFAULT_STATUS_CRITERIA_OPTIONS),
|
|
99
|
-
auth=
|
|
100
|
-
headers=
|
|
101
|
+
auth=auth_result.auth,
|
|
102
|
+
headers=merged_headers,
|
|
101
103
|
data=request.data)
|
|
102
104
|
except CancelledError:
|
|
103
105
|
log.info("Task cancelled.")
|
|
@@ -110,17 +112,3 @@ async def fetch(session, queue, request_params, results):
|
|
|
110
112
|
log.info(f"Processed request {len(results)} / {request_params.get('size')}")
|
|
111
113
|
queue.task_done()
|
|
112
114
|
|
|
113
|
-
|
|
114
|
-
def api_auth(auth):
|
|
115
|
-
"""
|
|
116
|
-
Method responsible for authenticating API. aiohttp.BasicAuth is used for it.
|
|
117
|
-
:param auth: Dictionary that contains auth.type, auth.username and auth.pwd.
|
|
118
|
-
:return: aiohttp.BasicAuth if auth.type is BasicAuth, None otherwise.
|
|
119
|
-
"""
|
|
120
|
-
if auth and auth.get('type') == 'BasicAuth':
|
|
121
|
-
try:
|
|
122
|
-
user = Properties.get_property('api_auth.username')
|
|
123
|
-
password = Properties.get_property('api_auth.password')
|
|
124
|
-
return BasicAuth(user, password)
|
|
125
|
-
except Exception as e:
|
|
126
|
-
log.exception(f"Error while getting the property username/pwd for api call: {e} ")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ingen-lib
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.2
|
|
4
4
|
Summary: A Python script suite that generates interface files based on the given interface metadata/config file
|
|
5
5
|
Home-page: https://github.com/blackrock/interface-generator
|
|
6
6
|
Maintainer: Swarna Dhakad, Piyush Ranjan, Jatin Varlyani, Pooja Katariya
|
|
@@ -66,6 +66,7 @@ ingen/utils/url_constructor.py
|
|
|
66
66
|
ingen/utils/utils.py
|
|
67
67
|
ingen/utils/app_http/__init__.py
|
|
68
68
|
ingen/utils/app_http/aiohttp_retry.py
|
|
69
|
+
ingen/utils/app_http/auth.py
|
|
69
70
|
ingen/utils/app_http/http_request.py
|
|
70
71
|
ingen/utils/app_http/http_util.py
|
|
71
72
|
ingen/utils/app_http/success_criterias.py
|
|
@@ -11,7 +11,7 @@ MAIN_PKG = 'ingen'
|
|
|
11
11
|
VERSION_PY_FILE = os.path.join(MAIN_PKG, 'version.py')
|
|
12
12
|
|
|
13
13
|
setup(name=PKG_NAME,
|
|
14
|
-
version='v2.1.
|
|
14
|
+
version='v2.1.2',
|
|
15
15
|
packages=setuptools.find_packages(include=['ingen', 'ingen.*']),
|
|
16
16
|
package_data={},
|
|
17
17
|
description='A Python script suite that generates interface files based on the given interface metadata/config '
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/json_writer/convertors/convertor_factory.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/json_writer/destinations/api_destination.py
RENAMED
|
File without changes
|
{ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/json_writer/destinations/destination_factory.py
RENAMED
|
File without changes
|
{ingen_lib-2.1.1 → ingen_lib-2.1.2}/ingen/writer/json_writer/destinations/file_destination.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|