[Python] - Migrate enable per request authentification in new python codegen (#11279)

* LDS-2166 : add request auth to api client and api call

Can now overwrite request auth by request

Envoyé depuis mon iPhone.
P.S. : Ce commit est certifié sans gluten

* LDS-2166 : Add samples

Envoyé depuis mon iPhone.
P.S. : Ce commit est certifié sans gluten

* LDS-2166 : fix test

Envoyé depuis mon iPhone.
P.S. : Ce commit est certifié sans gluten

* LDS-2166 : Fixing test in python_disallowAdditionalPropertiesIfNotPresent

Envoyé depuis mon iPhone.
P.S. : Ce commit est certifié sans gluten

* LDS-2166 : add removed line break

Envoyé depuis mon iPhone.
P.S. : Ce commit est certifié sans gluten

* LDS-2166 : add name for _request_auth params

Add None when _content_type is not set

Envoyé depuis mon iPhone.
P.S. : Ce commit est certifié sans gluten

* LDS-2166 : add tabulation

Envoyé depuis mon iPhone.
P.S. : Ce commit est certifié sans gluten

* LDS-2166 : fix missing values

Envoyé depuis mon iPhone.
P.S. : Ce commit est certifié sans gluten

* LDS-2166 : generate sample

Add _request_auth in sample

Envoyé depuis mon iPhone.
P.S. : Ce commit est certifié sans gluten

* Request auth can now use multiple auth

Request auth is now a list of dict

Envoyé depuis mon iPhone.
P.S. : Ce commit est certifié sans gluten

* Add request_auths in test

Envoyé depuis mon iPhone.
P.S. : Ce commit est certifié sans gluten

Co-authored-by: Géry THRASIBULE <g.thrasibule@lecomptoirdespharmacies.fr>
This commit is contained in:
LeComptoirDesPharmacies
2022-03-20 21:12:59 +01:00
committed by GitHub
parent bc2624d307
commit 87a5182c24
33 changed files with 940 additions and 128 deletions

View File

@@ -253,6 +253,10 @@ class UsageApi(object):
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
_request_auths (list): set to override the auth_settings for an a single
request; this effectively ignores the authentication
in the spec for a single request.
Default is None
async_req (bool): execute request asynchronously
Returns:
@@ -284,6 +288,7 @@ class UsageApi(object):
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['_request_auths'] = kwargs.get('_request_auths', None)
return self.any_key_endpoint.call_with_http_info(**kwargs)
def both_keys(
@@ -326,6 +331,10 @@ class UsageApi(object):
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
_request_auths (list): set to override the auth_settings for an a single
request; this effectively ignores the authentication
in the spec for a single request.
Default is None
async_req (bool): execute request asynchronously
Returns:
@@ -357,6 +366,7 @@ class UsageApi(object):
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['_request_auths'] = kwargs.get('_request_auths', None)
return self.both_keys_endpoint.call_with_http_info(**kwargs)
def key_in_header(
@@ -399,6 +409,10 @@ class UsageApi(object):
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
_request_auths (list): set to override the auth_settings for an a single
request; this effectively ignores the authentication
in the spec for a single request.
Default is None
async_req (bool): execute request asynchronously
Returns:
@@ -430,6 +444,7 @@ class UsageApi(object):
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['_request_auths'] = kwargs.get('_request_auths', None)
return self.key_in_header_endpoint.call_with_http_info(**kwargs)
def key_in_query(
@@ -472,6 +487,10 @@ class UsageApi(object):
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
_request_auths (list): set to override the auth_settings for an a single
request; this effectively ignores the authentication
in the spec for a single request.
Default is None
async_req (bool): execute request asynchronously
Returns:
@@ -503,5 +522,6 @@ class UsageApi(object):
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['_request_auths'] = kwargs.get('_request_auths', None)
return self.key_in_query_endpoint.call_with_http_info(**kwargs)

View File

@@ -132,7 +132,8 @@ class ApiClient(object):
_request_timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
_host: typing.Optional[str] = None,
_check_type: typing.Optional[bool] = None,
_content_type: typing.Optional[str] = None
_content_type: typing.Optional[str] = None,
_request_auths: typing.Optional[typing.List[typing.Dict[str, typing.Any]]] = None
):
config = self.configuration
@@ -182,7 +183,8 @@ class ApiClient(object):
# auth setting
self.update_params_for_auth(header_params, query_params,
auth_settings, resource_path, method, body)
auth_settings, resource_path, method, body,
request_auths=_request_auths)
# request url
if _host is None:
@@ -350,7 +352,8 @@ class ApiClient(object):
_preload_content: bool = True,
_request_timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
_host: typing.Optional[str] = None,
_check_type: typing.Optional[bool] = None
_check_type: typing.Optional[bool] = None,
_request_auths: typing.Optional[typing.List[typing.Dict[str, typing.Any]]] = None
):
"""Makes the HTTP request (synchronous) and returns deserialized data.
@@ -398,6 +401,10 @@ class ApiClient(object):
:param _check_type: boolean describing if the data back from the server
should have its type checked.
:type _check_type: bool, optional
:param _request_auths: set to override the auth_settings for an a single
request; this effectively ignores the authentication
in the spec for a single request.
:type _request_auths: list, optional
:return:
If async_req parameter is True,
the request will be called asynchronously.
@@ -412,7 +419,7 @@ class ApiClient(object):
response_type, auth_settings,
_return_http_data_only, collection_formats,
_preload_content, _request_timeout, _host,
_check_type)
_check_type, _request_auths=_request_auths)
return self.pool.apply_async(self.__call_api, (resource_path,
method, path_params,
@@ -425,7 +432,7 @@ class ApiClient(object):
collection_formats,
_preload_content,
_request_timeout,
_host, _check_type))
_host, _check_type, None, _request_auths))
def request(self, method, url, query_params=None, headers=None,
post_params=None, body=None, _preload_content=True,
@@ -597,7 +604,7 @@ class ApiClient(object):
return content_types[0]
def update_params_for_auth(self, headers, queries, auth_settings,
resource_path, method, body):
resource_path, method, body, request_auths=None):
"""Updates header and query params based on authentication setting.
:param headers: Header parameters dict to be updated.
@@ -607,24 +614,34 @@ class ApiClient(object):
:param method: A string representation of the HTTP request method.
:param body: A object representing the body of the HTTP request.
The object type is the return value of _encoder.default().
:param request_auths: if set, the provided settings will
override the token in the configuration.
"""
if not auth_settings:
return
if request_auths:
for auth_setting in request_auths:
self._apply_auth_params(headers, queries, resource_path, method, body, auth_setting)
return
for auth in auth_settings:
auth_setting = self.configuration.auth_settings().get(auth)
if auth_setting:
if auth_setting['in'] == 'cookie':
headers['Cookie'] = auth_setting['value']
elif auth_setting['in'] == 'header':
if auth_setting['type'] != 'http-signature':
headers[auth_setting['key']] = auth_setting['value']
elif auth_setting['in'] == 'query':
queries.append((auth_setting['key'], auth_setting['value']))
else:
raise ApiValueError(
'Authentication token must be in `query` or `header`'
)
self._apply_auth_params(headers, queries, resource_path, method, body, auth_setting)
def _apply_auth_params(self, headers, queries, resource_path, method, body, auth_setting):
if auth_setting['in'] == 'cookie':
headers['Cookie'] = auth_setting['value']
elif auth_setting['in'] == 'header':
if auth_setting['type'] != 'http-signature':
headers[auth_setting['key']] = auth_setting['value']
elif auth_setting['in'] == 'query':
queries.append((auth_setting['key'], auth_setting['value']))
else:
raise ApiValueError(
'Authentication token must be in `query` or `header`'
)
class Endpoint(object):
@@ -674,7 +691,8 @@ class Endpoint(object):
'_check_input_type',
'_check_return_type',
'_content_type',
'_spec_property_naming'
'_spec_property_naming',
'_request_auths'
])
self.params_map['nullable'].extend(['_request_timeout'])
self.validations = root_map['validations']
@@ -689,7 +707,8 @@ class Endpoint(object):
'_check_input_type': (bool,),
'_check_return_type': (bool,),
'_spec_property_naming': (bool,),
'_content_type': (none_type, str)
'_content_type': (none_type, str),
'_request_auths': (none_type, list)
}
self.openapi_types.update(extra_types)
self.attribute_map = root_map['attribute_map']
@@ -864,4 +883,5 @@ class Endpoint(object):
_preload_content=kwargs['_preload_content'],
_request_timeout=kwargs['_request_timeout'],
_host=_host,
_request_auths=kwargs['_request_auths'],
collection_formats=params['collection_format'])