forked from loafle/openapi-generator-original
[Python] Conditionally set auth attributes (#4988)
* Enhance python API keys * Run python scripts under ./bin/openapi3 * fix unit test issue * Fix unit tests * Fix unit tests * Invoke bin scripts
This commit is contained in:
parent
b94fe7a40f
commit
fa0ef2be25
@ -520,9 +520,7 @@ class ApiClient(object):
|
|||||||
for auth in auth_settings:
|
for auth in auth_settings:
|
||||||
auth_setting = self.configuration.auth_settings().get(auth)
|
auth_setting = self.configuration.auth_settings().get(auth)
|
||||||
if auth_setting:
|
if auth_setting:
|
||||||
if not auth_setting['value']:
|
if auth_setting['in'] == 'cookie':
|
||||||
continue
|
|
||||||
elif auth_setting['in'] == 'cookie':
|
|
||||||
headers['Cookie'] = auth_setting['value']
|
headers['Cookie'] = auth_setting['value']
|
||||||
elif auth_setting['in'] == 'header':
|
elif auth_setting['in'] == 'header':
|
||||||
headers[auth_setting['key']] = auth_setting['value']
|
headers[auth_setting['key']] = auth_setting['value']
|
||||||
|
@ -22,15 +22,38 @@ class Configuration(object):
|
|||||||
Do not edit the class manually.
|
Do not edit the class manually.
|
||||||
|
|
||||||
:param host: Base url
|
:param host: Base url
|
||||||
:param api_key: Dict to store API key(s)
|
:param api_key: Dict to store API key(s).
|
||||||
|
Each entry in the dict specifies an API key.
|
||||||
|
The dict key is the name of the security scheme in the OAS specification.
|
||||||
|
The dict value is the API key secret.
|
||||||
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
|
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
|
||||||
|
The dict key is the name of the security scheme in the OAS specification.
|
||||||
|
The dict value is an API key prefix when generating the auth data.
|
||||||
:param username: Username for HTTP basic authentication
|
:param username: Username for HTTP basic authentication
|
||||||
:param password: Password for HTTP basic authentication
|
:param password: Password for HTTP basic authentication
|
||||||
|
|
||||||
|
:Example:
|
||||||
|
|
||||||
|
Given the following security scheme in the OpenAPI specification:
|
||||||
|
components:
|
||||||
|
securitySchemes:
|
||||||
|
cookieAuth: # name for the security scheme
|
||||||
|
type: apiKey
|
||||||
|
in: cookie
|
||||||
|
name: JSESSIONID # cookie name
|
||||||
|
|
||||||
|
You can programmatically set the cookie:
|
||||||
|
conf = {{{packageName}}}.Configuration(
|
||||||
|
api_key={'cookieAuth': 'abc123'}
|
||||||
|
api_key_prefix={'cookieAuth': 'JSESSIONID'}
|
||||||
|
)
|
||||||
|
The following cookie will be added to the HTTP request:
|
||||||
|
Cookie: JSESSIONID abc123
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, host="{{{basePath}}}",
|
def __init__(self, host="{{{basePath}}}",
|
||||||
api_key=None, api_key_prefix=None,
|
api_key=None, api_key_prefix=None,
|
||||||
username="", password=""):
|
username=None, password=None):
|
||||||
"""Constructor
|
"""Constructor
|
||||||
"""
|
"""
|
||||||
self.host = host
|
self.host = host
|
||||||
@ -247,8 +270,14 @@ class Configuration(object):
|
|||||||
|
|
||||||
:return: The token for basic HTTP authentication.
|
:return: The token for basic HTTP authentication.
|
||||||
"""
|
"""
|
||||||
|
username = ""
|
||||||
|
if self.username is not None:
|
||||||
|
username = self.username
|
||||||
|
password = ""
|
||||||
|
if self.password is not None:
|
||||||
|
password = self.password
|
||||||
return urllib3.util.make_headers(
|
return urllib3.util.make_headers(
|
||||||
basic_auth=self.username + ':' + self.password
|
basic_auth=username + ':' + password
|
||||||
).get('authorization')
|
).get('authorization')
|
||||||
|
|
||||||
def auth_settings(self):
|
def auth_settings(self):
|
||||||
@ -256,30 +285,30 @@ class Configuration(object):
|
|||||||
|
|
||||||
:return: The Auth Settings information dict.
|
:return: The Auth Settings information dict.
|
||||||
"""
|
"""
|
||||||
return {
|
auth = {}
|
||||||
{{#authMethods}}
|
{{#authMethods}}
|
||||||
{{#isApiKey}}
|
{{#isApiKey}}
|
||||||
'{{name}}':
|
if '{{keyParamName}}' in self.api_key:
|
||||||
{
|
auth['{{name}}'] = {
|
||||||
'type': 'api_key',
|
'type': 'api_key',
|
||||||
'in': {{#isKeyInCookie}}'cookie'{{/isKeyInCookie}}{{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{#isKeyInQuery}}'query'{{/isKeyInQuery}},
|
'in': {{#isKeyInCookie}}'cookie'{{/isKeyInCookie}}{{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{#isKeyInQuery}}'query'{{/isKeyInQuery}},
|
||||||
'key': '{{keyParamName}}',
|
'key': '{{keyParamName}}',
|
||||||
'value': self.get_api_key_with_prefix('{{keyParamName}}')
|
'value': self.get_api_key_with_prefix('{{keyParamName}}')
|
||||||
},
|
}
|
||||||
{{/isApiKey}}
|
{{/isApiKey}}
|
||||||
{{#isBasic}}
|
{{#isBasic}}
|
||||||
{{^isBasicBearer}}
|
{{^isBasicBearer}}
|
||||||
'{{name}}':
|
if self.username is not None and self.password is not None:
|
||||||
{
|
auth['{{name}}'] = {
|
||||||
'type': 'basic',
|
'type': 'basic',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'Authorization',
|
'key': 'Authorization',
|
||||||
'value': self.get_basic_auth_token()
|
'value': self.get_basic_auth_token()
|
||||||
},
|
}
|
||||||
{{/isBasicBearer}}
|
{{/isBasicBearer}}
|
||||||
{{#isBasicBearer}}
|
{{#isBasicBearer}}
|
||||||
'{{name}}':
|
if self.access_token is not None:
|
||||||
{
|
auth['{{name}}'] = {
|
||||||
'type': 'bearer',
|
'type': 'bearer',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
{{#bearerFormat}}
|
{{#bearerFormat}}
|
||||||
@ -287,20 +316,20 @@ class Configuration(object):
|
|||||||
{{/bearerFormat}}
|
{{/bearerFormat}}
|
||||||
'key': 'Authorization',
|
'key': 'Authorization',
|
||||||
'value': 'Bearer ' + self.access_token
|
'value': 'Bearer ' + self.access_token
|
||||||
},
|
}
|
||||||
{{/isBasicBearer}}
|
{{/isBasicBearer}}
|
||||||
{{/isBasic}}
|
{{/isBasic}}
|
||||||
{{#isOAuth}}
|
{{#isOAuth}}
|
||||||
'{{name}}':
|
if self.access_token is not None:
|
||||||
{
|
auth['{{name}}'] = {
|
||||||
'type': 'oauth2',
|
'type': 'oauth2',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'Authorization',
|
'key': 'Authorization',
|
||||||
'value': 'Bearer ' + self.access_token
|
'value': 'Bearer ' + self.access_token
|
||||||
},
|
}
|
||||||
{{/isOAuth}}
|
{{/isOAuth}}
|
||||||
{{/authMethods}}
|
{{/authMethods}}
|
||||||
}
|
return auth
|
||||||
|
|
||||||
def to_debug_report(self):
|
def to_debug_report(self):
|
||||||
"""Gets the essential information for debugging.
|
"""Gets the essential information for debugging.
|
||||||
|
@ -530,9 +530,7 @@ class ApiClient(object):
|
|||||||
for auth in auth_settings:
|
for auth in auth_settings:
|
||||||
auth_setting = self.configuration.auth_settings().get(auth)
|
auth_setting = self.configuration.auth_settings().get(auth)
|
||||||
if auth_setting:
|
if auth_setting:
|
||||||
if not auth_setting['value']:
|
if auth_setting['in'] == 'cookie':
|
||||||
continue
|
|
||||||
elif auth_setting['in'] == 'cookie':
|
|
||||||
headers['Cookie'] = auth_setting['value']
|
headers['Cookie'] = auth_setting['value']
|
||||||
elif auth_setting['in'] == 'header':
|
elif auth_setting['in'] == 'header':
|
||||||
headers[auth_setting['key']] = auth_setting['value']
|
headers[auth_setting['key']] = auth_setting['value']
|
||||||
|
@ -513,9 +513,7 @@ class ApiClient(object):
|
|||||||
for auth in auth_settings:
|
for auth in auth_settings:
|
||||||
auth_setting = self.configuration.auth_settings().get(auth)
|
auth_setting = self.configuration.auth_settings().get(auth)
|
||||||
if auth_setting:
|
if auth_setting:
|
||||||
if not auth_setting['value']:
|
if auth_setting['in'] == 'cookie':
|
||||||
continue
|
|
||||||
elif auth_setting['in'] == 'cookie':
|
|
||||||
headers['Cookie'] = auth_setting['value']
|
headers['Cookie'] = auth_setting['value']
|
||||||
elif auth_setting['in'] == 'header':
|
elif auth_setting['in'] == 'header':
|
||||||
headers[auth_setting['key']] = auth_setting['value']
|
headers[auth_setting['key']] = auth_setting['value']
|
||||||
|
@ -27,15 +27,38 @@ class Configuration(object):
|
|||||||
Do not edit the class manually.
|
Do not edit the class manually.
|
||||||
|
|
||||||
:param host: Base url
|
:param host: Base url
|
||||||
:param api_key: Dict to store API key(s)
|
:param api_key: Dict to store API key(s).
|
||||||
|
Each entry in the dict specifies an API key.
|
||||||
|
The dict key is the name of the security scheme in the OAS specification.
|
||||||
|
The dict value is the API key secret.
|
||||||
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
|
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
|
||||||
|
The dict key is the name of the security scheme in the OAS specification.
|
||||||
|
The dict value is an API key prefix when generating the auth data.
|
||||||
:param username: Username for HTTP basic authentication
|
:param username: Username for HTTP basic authentication
|
||||||
:param password: Password for HTTP basic authentication
|
:param password: Password for HTTP basic authentication
|
||||||
|
|
||||||
|
:Example:
|
||||||
|
|
||||||
|
Given the following security scheme in the OpenAPI specification:
|
||||||
|
components:
|
||||||
|
securitySchemes:
|
||||||
|
cookieAuth: # name for the security scheme
|
||||||
|
type: apiKey
|
||||||
|
in: cookie
|
||||||
|
name: JSESSIONID # cookie name
|
||||||
|
|
||||||
|
You can programmatically set the cookie:
|
||||||
|
conf = petstore_api.Configuration(
|
||||||
|
api_key={'cookieAuth': 'abc123'}
|
||||||
|
api_key_prefix={'cookieAuth': 'JSESSIONID'}
|
||||||
|
)
|
||||||
|
The following cookie will be added to the HTTP request:
|
||||||
|
Cookie: JSESSIONID abc123
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, host="http://petstore.swagger.io:80/v2",
|
def __init__(self, host="http://petstore.swagger.io:80/v2",
|
||||||
api_key=None, api_key_prefix=None,
|
api_key=None, api_key_prefix=None,
|
||||||
username="", password=""):
|
username=None, password=None):
|
||||||
"""Constructor
|
"""Constructor
|
||||||
"""
|
"""
|
||||||
self.host = host
|
self.host = host
|
||||||
@ -232,8 +255,14 @@ class Configuration(object):
|
|||||||
|
|
||||||
:return: The token for basic HTTP authentication.
|
:return: The token for basic HTTP authentication.
|
||||||
"""
|
"""
|
||||||
|
username = ""
|
||||||
|
if self.username is not None:
|
||||||
|
username = self.username
|
||||||
|
password = ""
|
||||||
|
if self.password is not None:
|
||||||
|
password = self.password
|
||||||
return urllib3.util.make_headers(
|
return urllib3.util.make_headers(
|
||||||
basic_auth=self.username + ':' + self.password
|
basic_auth=username + ':' + password
|
||||||
).get('authorization')
|
).get('authorization')
|
||||||
|
|
||||||
def auth_settings(self):
|
def auth_settings(self):
|
||||||
@ -241,36 +270,36 @@ class Configuration(object):
|
|||||||
|
|
||||||
:return: The Auth Settings information dict.
|
:return: The Auth Settings information dict.
|
||||||
"""
|
"""
|
||||||
return {
|
auth = {}
|
||||||
'api_key':
|
if 'api_key' in self.api_key:
|
||||||
{
|
auth['api_key'] = {
|
||||||
'type': 'api_key',
|
'type': 'api_key',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'api_key',
|
'key': 'api_key',
|
||||||
'value': self.get_api_key_with_prefix('api_key')
|
'value': self.get_api_key_with_prefix('api_key')
|
||||||
},
|
}
|
||||||
'api_key_query':
|
if 'api_key_query' in self.api_key:
|
||||||
{
|
auth['api_key_query'] = {
|
||||||
'type': 'api_key',
|
'type': 'api_key',
|
||||||
'in': 'query',
|
'in': 'query',
|
||||||
'key': 'api_key_query',
|
'key': 'api_key_query',
|
||||||
'value': self.get_api_key_with_prefix('api_key_query')
|
'value': self.get_api_key_with_prefix('api_key_query')
|
||||||
},
|
}
|
||||||
'http_basic_test':
|
if self.username is not None and self.password is not None:
|
||||||
{
|
auth['http_basic_test'] = {
|
||||||
'type': 'basic',
|
'type': 'basic',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'Authorization',
|
'key': 'Authorization',
|
||||||
'value': self.get_basic_auth_token()
|
'value': self.get_basic_auth_token()
|
||||||
},
|
}
|
||||||
'petstore_auth':
|
if self.access_token is not None:
|
||||||
{
|
auth['petstore_auth'] = {
|
||||||
'type': 'oauth2',
|
'type': 'oauth2',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'Authorization',
|
'key': 'Authorization',
|
||||||
'value': 'Bearer ' + self.access_token
|
'value': 'Bearer ' + self.access_token
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
return auth
|
||||||
|
|
||||||
def to_debug_report(self):
|
def to_debug_report(self):
|
||||||
"""Gets the essential information for debugging.
|
"""Gets the essential information for debugging.
|
||||||
|
@ -523,9 +523,7 @@ class ApiClient(object):
|
|||||||
for auth in auth_settings:
|
for auth in auth_settings:
|
||||||
auth_setting = self.configuration.auth_settings().get(auth)
|
auth_setting = self.configuration.auth_settings().get(auth)
|
||||||
if auth_setting:
|
if auth_setting:
|
||||||
if not auth_setting['value']:
|
if auth_setting['in'] == 'cookie':
|
||||||
continue
|
|
||||||
elif auth_setting['in'] == 'cookie':
|
|
||||||
headers['Cookie'] = auth_setting['value']
|
headers['Cookie'] = auth_setting['value']
|
||||||
elif auth_setting['in'] == 'header':
|
elif auth_setting['in'] == 'header':
|
||||||
headers[auth_setting['key']] = auth_setting['value']
|
headers[auth_setting['key']] = auth_setting['value']
|
||||||
|
@ -28,15 +28,38 @@ class Configuration(object):
|
|||||||
Do not edit the class manually.
|
Do not edit the class manually.
|
||||||
|
|
||||||
:param host: Base url
|
:param host: Base url
|
||||||
:param api_key: Dict to store API key(s)
|
:param api_key: Dict to store API key(s).
|
||||||
|
Each entry in the dict specifies an API key.
|
||||||
|
The dict key is the name of the security scheme in the OAS specification.
|
||||||
|
The dict value is the API key secret.
|
||||||
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
|
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
|
||||||
|
The dict key is the name of the security scheme in the OAS specification.
|
||||||
|
The dict value is an API key prefix when generating the auth data.
|
||||||
:param username: Username for HTTP basic authentication
|
:param username: Username for HTTP basic authentication
|
||||||
:param password: Password for HTTP basic authentication
|
:param password: Password for HTTP basic authentication
|
||||||
|
|
||||||
|
:Example:
|
||||||
|
|
||||||
|
Given the following security scheme in the OpenAPI specification:
|
||||||
|
components:
|
||||||
|
securitySchemes:
|
||||||
|
cookieAuth: # name for the security scheme
|
||||||
|
type: apiKey
|
||||||
|
in: cookie
|
||||||
|
name: JSESSIONID # cookie name
|
||||||
|
|
||||||
|
You can programmatically set the cookie:
|
||||||
|
conf = petstore_api.Configuration(
|
||||||
|
api_key={'cookieAuth': 'abc123'}
|
||||||
|
api_key_prefix={'cookieAuth': 'JSESSIONID'}
|
||||||
|
)
|
||||||
|
The following cookie will be added to the HTTP request:
|
||||||
|
Cookie: JSESSIONID abc123
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, host="http://petstore.swagger.io:80/v2",
|
def __init__(self, host="http://petstore.swagger.io:80/v2",
|
||||||
api_key=None, api_key_prefix=None,
|
api_key=None, api_key_prefix=None,
|
||||||
username="", password=""):
|
username=None, password=None):
|
||||||
"""Constructor
|
"""Constructor
|
||||||
"""
|
"""
|
||||||
self.host = host
|
self.host = host
|
||||||
@ -236,8 +259,14 @@ class Configuration(object):
|
|||||||
|
|
||||||
:return: The token for basic HTTP authentication.
|
:return: The token for basic HTTP authentication.
|
||||||
"""
|
"""
|
||||||
|
username = ""
|
||||||
|
if self.username is not None:
|
||||||
|
username = self.username
|
||||||
|
password = ""
|
||||||
|
if self.password is not None:
|
||||||
|
password = self.password
|
||||||
return urllib3.util.make_headers(
|
return urllib3.util.make_headers(
|
||||||
basic_auth=self.username + ':' + self.password
|
basic_auth=username + ':' + password
|
||||||
).get('authorization')
|
).get('authorization')
|
||||||
|
|
||||||
def auth_settings(self):
|
def auth_settings(self):
|
||||||
@ -245,36 +274,36 @@ class Configuration(object):
|
|||||||
|
|
||||||
:return: The Auth Settings information dict.
|
:return: The Auth Settings information dict.
|
||||||
"""
|
"""
|
||||||
return {
|
auth = {}
|
||||||
'api_key':
|
if 'api_key' in self.api_key:
|
||||||
{
|
auth['api_key'] = {
|
||||||
'type': 'api_key',
|
'type': 'api_key',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'api_key',
|
'key': 'api_key',
|
||||||
'value': self.get_api_key_with_prefix('api_key')
|
'value': self.get_api_key_with_prefix('api_key')
|
||||||
},
|
}
|
||||||
'api_key_query':
|
if 'api_key_query' in self.api_key:
|
||||||
{
|
auth['api_key_query'] = {
|
||||||
'type': 'api_key',
|
'type': 'api_key',
|
||||||
'in': 'query',
|
'in': 'query',
|
||||||
'key': 'api_key_query',
|
'key': 'api_key_query',
|
||||||
'value': self.get_api_key_with_prefix('api_key_query')
|
'value': self.get_api_key_with_prefix('api_key_query')
|
||||||
},
|
}
|
||||||
'http_basic_test':
|
if self.username is not None and self.password is not None:
|
||||||
{
|
auth['http_basic_test'] = {
|
||||||
'type': 'basic',
|
'type': 'basic',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'Authorization',
|
'key': 'Authorization',
|
||||||
'value': self.get_basic_auth_token()
|
'value': self.get_basic_auth_token()
|
||||||
},
|
}
|
||||||
'petstore_auth':
|
if self.access_token is not None:
|
||||||
{
|
auth['petstore_auth'] = {
|
||||||
'type': 'oauth2',
|
'type': 'oauth2',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'Authorization',
|
'key': 'Authorization',
|
||||||
'value': 'Bearer ' + self.access_token
|
'value': 'Bearer ' + self.access_token
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
return auth
|
||||||
|
|
||||||
def to_debug_report(self):
|
def to_debug_report(self):
|
||||||
"""Gets the essential information for debugging.
|
"""Gets the essential information for debugging.
|
||||||
|
@ -55,6 +55,29 @@ class ApiClientTests(unittest.TestCase):
|
|||||||
self.assertEqual('test_username', client.configuration.username)
|
self.assertEqual('test_username', client.configuration.username)
|
||||||
self.assertEqual('test_password', client.configuration.password)
|
self.assertEqual('test_password', client.configuration.password)
|
||||||
|
|
||||||
|
# test api key without prefix
|
||||||
|
config.api_key['api_key'] = '123456'
|
||||||
|
config.api_key_prefix['api_key'] = None
|
||||||
|
# update parameters based on auth setting
|
||||||
|
client.update_params_for_auth(header_params, query_params, auth_settings)
|
||||||
|
self.assertEqual(header_params['api_key'], '123456')
|
||||||
|
|
||||||
|
# test api key with empty prefix
|
||||||
|
config.api_key['api_key'] = '123456'
|
||||||
|
config.api_key_prefix['api_key'] = ''
|
||||||
|
# update parameters based on auth setting
|
||||||
|
client.update_params_for_auth(header_params, query_params, auth_settings)
|
||||||
|
self.assertEqual(header_params['api_key'], '123456')
|
||||||
|
|
||||||
|
# test api key with prefix specified in the api_key, useful when the prefix
|
||||||
|
# must include '=' sign followed by the API key secret without space.
|
||||||
|
config.api_key['api_key'] = 'PREFIX=123456'
|
||||||
|
config.api_key_prefix['api_key'] = None
|
||||||
|
# update parameters based on auth setting
|
||||||
|
client.update_params_for_auth(header_params, query_params, auth_settings)
|
||||||
|
self.assertEqual(header_params['api_key'], 'PREFIX=123456')
|
||||||
|
|
||||||
|
|
||||||
def test_select_header_accept(self):
|
def test_select_header_accept(self):
|
||||||
accepts = ['APPLICATION/JSON', 'APPLICATION/XML']
|
accepts = ['APPLICATION/JSON', 'APPLICATION/XML']
|
||||||
accept = self.api_client.select_header_accept(accepts)
|
accept = self.api_client.select_header_accept(accepts)
|
||||||
|
@ -73,6 +73,7 @@ class PetApiTests(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
config = Configuration()
|
config = Configuration()
|
||||||
config.host = HOST
|
config.host = HOST
|
||||||
|
config.access_token = 'ACCESS_TOKEN'
|
||||||
self.api_client = petstore_api.ApiClient(config)
|
self.api_client = petstore_api.ApiClient(config)
|
||||||
self.pet_api = petstore_api.PetApi(self.api_client)
|
self.pet_api = petstore_api.PetApi(self.api_client)
|
||||||
self.setUpModels()
|
self.setUpModels()
|
||||||
@ -115,6 +116,26 @@ class PetApiTests(unittest.TestCase):
|
|||||||
resp.close()
|
resp.close()
|
||||||
resp.release_conn()
|
resp.release_conn()
|
||||||
|
|
||||||
|
def test_config(self):
|
||||||
|
config = Configuration(host=HOST)
|
||||||
|
self.assertIsNotNone(config.get_host_settings())
|
||||||
|
self.assertEquals(config.get_basic_auth_token(),
|
||||||
|
urllib3.util.make_headers(basic_auth=":").get('authorization'))
|
||||||
|
self.assertEquals(len(config.auth_settings()), 1)
|
||||||
|
self.assertIn("petstore_auth", config.auth_settings().keys())
|
||||||
|
config.username = "user"
|
||||||
|
config.password = "password"
|
||||||
|
self.assertEquals(
|
||||||
|
config.get_basic_auth_token(),
|
||||||
|
urllib3.util.make_headers(basic_auth="user:password").get('authorization'))
|
||||||
|
self.assertEquals(len(config.auth_settings()), 2)
|
||||||
|
self.assertIn("petstore_auth", config.auth_settings().keys())
|
||||||
|
self.assertIn("http_basic_test", config.auth_settings().keys())
|
||||||
|
config.username = None
|
||||||
|
config.password = None
|
||||||
|
self.assertEquals(len(config.auth_settings()), 1)
|
||||||
|
self.assertIn("petstore_auth", config.auth_settings().keys())
|
||||||
|
|
||||||
def test_timeout(self):
|
def test_timeout(self):
|
||||||
mock_pool = MockPoolManager(self)
|
mock_pool = MockPoolManager(self)
|
||||||
self.api_client.rest_client.pool_manager = mock_pool
|
self.api_client.rest_client.pool_manager = mock_pool
|
||||||
@ -122,13 +143,13 @@ class PetApiTests(unittest.TestCase):
|
|||||||
mock_pool.expect_request('POST', 'http://localhost/v2/pet',
|
mock_pool.expect_request('POST', 'http://localhost/v2/pet',
|
||||||
body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)),
|
body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)),
|
||||||
headers={'Content-Type': 'application/json',
|
headers={'Content-Type': 'application/json',
|
||||||
'Authorization': 'Bearer ',
|
'Authorization': 'Bearer ACCESS_TOKEN',
|
||||||
'User-Agent': 'OpenAPI-Generator/1.0.0/python'},
|
'User-Agent': 'OpenAPI-Generator/1.0.0/python'},
|
||||||
preload_content=True, timeout=TimeoutWithEqual(total=5))
|
preload_content=True, timeout=TimeoutWithEqual(total=5))
|
||||||
mock_pool.expect_request('POST', 'http://localhost/v2/pet',
|
mock_pool.expect_request('POST', 'http://localhost/v2/pet',
|
||||||
body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)),
|
body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)),
|
||||||
headers={'Content-Type': 'application/json',
|
headers={'Content-Type': 'application/json',
|
||||||
'Authorization': 'Bearer ',
|
'Authorization': 'Bearer ACCESS_TOKEN',
|
||||||
'User-Agent': 'OpenAPI-Generator/1.0.0/python'},
|
'User-Agent': 'OpenAPI-Generator/1.0.0/python'},
|
||||||
preload_content=True, timeout=TimeoutWithEqual(connect=1, read=2))
|
preload_content=True, timeout=TimeoutWithEqual(connect=1, read=2))
|
||||||
|
|
||||||
@ -325,7 +346,7 @@ class PetApiTests(unittest.TestCase):
|
|||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Content-Type': 'multipart/form-data',
|
'Content-Type': 'multipart/form-data',
|
||||||
'User-Agent': 'OpenAPI-Generator/1.0.0/python',
|
'User-Agent': 'OpenAPI-Generator/1.0.0/python',
|
||||||
'Authorization': 'Bearer '
|
'Authorization': 'Bearer ACCESS_TOKEN'
|
||||||
},
|
},
|
||||||
post_params=[
|
post_params=[
|
||||||
('files', ('1px_pic1.png', b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x00\x00\x00\x00:~\x9bU\x00\x00\x00\nIDATx\x9cc\xfa\x0f\x00\x01\x05\x01\x02\xcf\xa0.\xcd\x00\x00\x00\x00IEND\xaeB`\x82', 'image/png')),
|
('files', ('1px_pic1.png', b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x00\x00\x00\x00:~\x9bU\x00\x00\x00\nIDATx\x9cc\xfa\x0f\x00\x01\x05\x01\x02\xcf\xa0.\xcd\x00\x00\x00\x00IEND\xaeB`\x82', 'image/png')),
|
||||||
|
@ -515,9 +515,7 @@ class ApiClient(object):
|
|||||||
for auth in auth_settings:
|
for auth in auth_settings:
|
||||||
auth_setting = self.configuration.auth_settings().get(auth)
|
auth_setting = self.configuration.auth_settings().get(auth)
|
||||||
if auth_setting:
|
if auth_setting:
|
||||||
if not auth_setting['value']:
|
if auth_setting['in'] == 'cookie':
|
||||||
continue
|
|
||||||
elif auth_setting['in'] == 'cookie':
|
|
||||||
headers['Cookie'] = auth_setting['value']
|
headers['Cookie'] = auth_setting['value']
|
||||||
elif auth_setting['in'] == 'header':
|
elif auth_setting['in'] == 'header':
|
||||||
headers[auth_setting['key']] = auth_setting['value']
|
headers[auth_setting['key']] = auth_setting['value']
|
||||||
|
@ -28,15 +28,38 @@ class Configuration(object):
|
|||||||
Do not edit the class manually.
|
Do not edit the class manually.
|
||||||
|
|
||||||
:param host: Base url
|
:param host: Base url
|
||||||
:param api_key: Dict to store API key(s)
|
:param api_key: Dict to store API key(s).
|
||||||
|
Each entry in the dict specifies an API key.
|
||||||
|
The dict key is the name of the security scheme in the OAS specification.
|
||||||
|
The dict value is the API key secret.
|
||||||
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
|
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
|
||||||
|
The dict key is the name of the security scheme in the OAS specification.
|
||||||
|
The dict value is an API key prefix when generating the auth data.
|
||||||
:param username: Username for HTTP basic authentication
|
:param username: Username for HTTP basic authentication
|
||||||
:param password: Password for HTTP basic authentication
|
:param password: Password for HTTP basic authentication
|
||||||
|
|
||||||
|
:Example:
|
||||||
|
|
||||||
|
Given the following security scheme in the OpenAPI specification:
|
||||||
|
components:
|
||||||
|
securitySchemes:
|
||||||
|
cookieAuth: # name for the security scheme
|
||||||
|
type: apiKey
|
||||||
|
in: cookie
|
||||||
|
name: JSESSIONID # cookie name
|
||||||
|
|
||||||
|
You can programmatically set the cookie:
|
||||||
|
conf = petstore_api.Configuration(
|
||||||
|
api_key={'cookieAuth': 'abc123'}
|
||||||
|
api_key_prefix={'cookieAuth': 'JSESSIONID'}
|
||||||
|
)
|
||||||
|
The following cookie will be added to the HTTP request:
|
||||||
|
Cookie: JSESSIONID abc123
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, host="http://petstore.swagger.io:80/v2",
|
def __init__(self, host="http://petstore.swagger.io:80/v2",
|
||||||
api_key=None, api_key_prefix=None,
|
api_key=None, api_key_prefix=None,
|
||||||
username="", password=""):
|
username=None, password=None):
|
||||||
"""Constructor
|
"""Constructor
|
||||||
"""
|
"""
|
||||||
self.host = host
|
self.host = host
|
||||||
@ -236,8 +259,14 @@ class Configuration(object):
|
|||||||
|
|
||||||
:return: The token for basic HTTP authentication.
|
:return: The token for basic HTTP authentication.
|
||||||
"""
|
"""
|
||||||
|
username = ""
|
||||||
|
if self.username is not None:
|
||||||
|
username = self.username
|
||||||
|
password = ""
|
||||||
|
if self.password is not None:
|
||||||
|
password = self.password
|
||||||
return urllib3.util.make_headers(
|
return urllib3.util.make_headers(
|
||||||
basic_auth=self.username + ':' + self.password
|
basic_auth=username + ':' + password
|
||||||
).get('authorization')
|
).get('authorization')
|
||||||
|
|
||||||
def auth_settings(self):
|
def auth_settings(self):
|
||||||
@ -245,36 +274,36 @@ class Configuration(object):
|
|||||||
|
|
||||||
:return: The Auth Settings information dict.
|
:return: The Auth Settings information dict.
|
||||||
"""
|
"""
|
||||||
return {
|
auth = {}
|
||||||
'api_key':
|
if 'api_key' in self.api_key:
|
||||||
{
|
auth['api_key'] = {
|
||||||
'type': 'api_key',
|
'type': 'api_key',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'api_key',
|
'key': 'api_key',
|
||||||
'value': self.get_api_key_with_prefix('api_key')
|
'value': self.get_api_key_with_prefix('api_key')
|
||||||
},
|
}
|
||||||
'api_key_query':
|
if 'api_key_query' in self.api_key:
|
||||||
{
|
auth['api_key_query'] = {
|
||||||
'type': 'api_key',
|
'type': 'api_key',
|
||||||
'in': 'query',
|
'in': 'query',
|
||||||
'key': 'api_key_query',
|
'key': 'api_key_query',
|
||||||
'value': self.get_api_key_with_prefix('api_key_query')
|
'value': self.get_api_key_with_prefix('api_key_query')
|
||||||
},
|
}
|
||||||
'http_basic_test':
|
if self.username is not None and self.password is not None:
|
||||||
{
|
auth['http_basic_test'] = {
|
||||||
'type': 'basic',
|
'type': 'basic',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'Authorization',
|
'key': 'Authorization',
|
||||||
'value': self.get_basic_auth_token()
|
'value': self.get_basic_auth_token()
|
||||||
},
|
}
|
||||||
'petstore_auth':
|
if self.access_token is not None:
|
||||||
{
|
auth['petstore_auth'] = {
|
||||||
'type': 'oauth2',
|
'type': 'oauth2',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'Authorization',
|
'key': 'Authorization',
|
||||||
'value': 'Bearer ' + self.access_token
|
'value': 'Bearer ' + self.access_token
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
return auth
|
||||||
|
|
||||||
def to_debug_report(self):
|
def to_debug_report(self):
|
||||||
"""Gets the essential information for debugging.
|
"""Gets the essential information for debugging.
|
||||||
|
@ -513,9 +513,7 @@ class ApiClient(object):
|
|||||||
for auth in auth_settings:
|
for auth in auth_settings:
|
||||||
auth_setting = self.configuration.auth_settings().get(auth)
|
auth_setting = self.configuration.auth_settings().get(auth)
|
||||||
if auth_setting:
|
if auth_setting:
|
||||||
if not auth_setting['value']:
|
if auth_setting['in'] == 'cookie':
|
||||||
continue
|
|
||||||
elif auth_setting['in'] == 'cookie':
|
|
||||||
headers['Cookie'] = auth_setting['value']
|
headers['Cookie'] = auth_setting['value']
|
||||||
elif auth_setting['in'] == 'header':
|
elif auth_setting['in'] == 'header':
|
||||||
headers[auth_setting['key']] = auth_setting['value']
|
headers[auth_setting['key']] = auth_setting['value']
|
||||||
|
@ -28,15 +28,38 @@ class Configuration(object):
|
|||||||
Do not edit the class manually.
|
Do not edit the class manually.
|
||||||
|
|
||||||
:param host: Base url
|
:param host: Base url
|
||||||
:param api_key: Dict to store API key(s)
|
:param api_key: Dict to store API key(s).
|
||||||
|
Each entry in the dict specifies an API key.
|
||||||
|
The dict key is the name of the security scheme in the OAS specification.
|
||||||
|
The dict value is the API key secret.
|
||||||
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
|
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
|
||||||
|
The dict key is the name of the security scheme in the OAS specification.
|
||||||
|
The dict value is an API key prefix when generating the auth data.
|
||||||
:param username: Username for HTTP basic authentication
|
:param username: Username for HTTP basic authentication
|
||||||
:param password: Password for HTTP basic authentication
|
:param password: Password for HTTP basic authentication
|
||||||
|
|
||||||
|
:Example:
|
||||||
|
|
||||||
|
Given the following security scheme in the OpenAPI specification:
|
||||||
|
components:
|
||||||
|
securitySchemes:
|
||||||
|
cookieAuth: # name for the security scheme
|
||||||
|
type: apiKey
|
||||||
|
in: cookie
|
||||||
|
name: JSESSIONID # cookie name
|
||||||
|
|
||||||
|
You can programmatically set the cookie:
|
||||||
|
conf = petstore_api.Configuration(
|
||||||
|
api_key={'cookieAuth': 'abc123'}
|
||||||
|
api_key_prefix={'cookieAuth': 'JSESSIONID'}
|
||||||
|
)
|
||||||
|
The following cookie will be added to the HTTP request:
|
||||||
|
Cookie: JSESSIONID abc123
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, host="http://petstore.swagger.io:80/v2",
|
def __init__(self, host="http://petstore.swagger.io:80/v2",
|
||||||
api_key=None, api_key_prefix=None,
|
api_key=None, api_key_prefix=None,
|
||||||
username="", password=""):
|
username=None, password=None):
|
||||||
"""Constructor
|
"""Constructor
|
||||||
"""
|
"""
|
||||||
self.host = host
|
self.host = host
|
||||||
@ -236,8 +259,14 @@ class Configuration(object):
|
|||||||
|
|
||||||
:return: The token for basic HTTP authentication.
|
:return: The token for basic HTTP authentication.
|
||||||
"""
|
"""
|
||||||
|
username = ""
|
||||||
|
if self.username is not None:
|
||||||
|
username = self.username
|
||||||
|
password = ""
|
||||||
|
if self.password is not None:
|
||||||
|
password = self.password
|
||||||
return urllib3.util.make_headers(
|
return urllib3.util.make_headers(
|
||||||
basic_auth=self.username + ':' + self.password
|
basic_auth=username + ':' + password
|
||||||
).get('authorization')
|
).get('authorization')
|
||||||
|
|
||||||
def auth_settings(self):
|
def auth_settings(self):
|
||||||
@ -245,36 +274,36 @@ class Configuration(object):
|
|||||||
|
|
||||||
:return: The Auth Settings information dict.
|
:return: The Auth Settings information dict.
|
||||||
"""
|
"""
|
||||||
return {
|
auth = {}
|
||||||
'api_key':
|
if 'api_key' in self.api_key:
|
||||||
{
|
auth['api_key'] = {
|
||||||
'type': 'api_key',
|
'type': 'api_key',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'api_key',
|
'key': 'api_key',
|
||||||
'value': self.get_api_key_with_prefix('api_key')
|
'value': self.get_api_key_with_prefix('api_key')
|
||||||
},
|
}
|
||||||
'api_key_query':
|
if 'api_key_query' in self.api_key:
|
||||||
{
|
auth['api_key_query'] = {
|
||||||
'type': 'api_key',
|
'type': 'api_key',
|
||||||
'in': 'query',
|
'in': 'query',
|
||||||
'key': 'api_key_query',
|
'key': 'api_key_query',
|
||||||
'value': self.get_api_key_with_prefix('api_key_query')
|
'value': self.get_api_key_with_prefix('api_key_query')
|
||||||
},
|
}
|
||||||
'http_basic_test':
|
if self.username is not None and self.password is not None:
|
||||||
{
|
auth['http_basic_test'] = {
|
||||||
'type': 'basic',
|
'type': 'basic',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'Authorization',
|
'key': 'Authorization',
|
||||||
'value': self.get_basic_auth_token()
|
'value': self.get_basic_auth_token()
|
||||||
},
|
}
|
||||||
'petstore_auth':
|
if self.access_token is not None:
|
||||||
{
|
auth['petstore_auth'] = {
|
||||||
'type': 'oauth2',
|
'type': 'oauth2',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'Authorization',
|
'key': 'Authorization',
|
||||||
'value': 'Bearer ' + self.access_token
|
'value': 'Bearer ' + self.access_token
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
return auth
|
||||||
|
|
||||||
def to_debug_report(self):
|
def to_debug_report(self):
|
||||||
"""Gets the essential information for debugging.
|
"""Gets the essential information for debugging.
|
||||||
|
@ -57,6 +57,7 @@ class PetApiTests(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
config = Configuration()
|
config = Configuration()
|
||||||
config.host = HOST
|
config.host = HOST
|
||||||
|
config.access_token = 'ACCESS_TOKEN'
|
||||||
self.api_client = petstore_api.ApiClient(config)
|
self.api_client = petstore_api.ApiClient(config)
|
||||||
self.pet_api = petstore_api.PetApi(self.api_client)
|
self.pet_api = petstore_api.PetApi(self.api_client)
|
||||||
self.setUpModels()
|
self.setUpModels()
|
||||||
@ -107,13 +108,13 @@ class PetApiTests(unittest.TestCase):
|
|||||||
mock_pool.expect_request('POST', HOST + '/pet',
|
mock_pool.expect_request('POST', HOST + '/pet',
|
||||||
body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)),
|
body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)),
|
||||||
headers={'Content-Type': 'application/json',
|
headers={'Content-Type': 'application/json',
|
||||||
'Authorization': 'Bearer ',
|
'Authorization': 'Bearer ACCESS_TOKEN',
|
||||||
'User-Agent': 'OpenAPI-Generator/1.0.0/python'},
|
'User-Agent': 'OpenAPI-Generator/1.0.0/python'},
|
||||||
preload_content=True, timeout=TimeoutWithEqual(total=5))
|
preload_content=True, timeout=TimeoutWithEqual(total=5))
|
||||||
mock_pool.expect_request('POST', HOST + '/pet',
|
mock_pool.expect_request('POST', HOST + '/pet',
|
||||||
body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)),
|
body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)),
|
||||||
headers={'Content-Type': 'application/json',
|
headers={'Content-Type': 'application/json',
|
||||||
'Authorization': 'Bearer ',
|
'Authorization': 'Bearer ACCESS_TOKEN',
|
||||||
'User-Agent': 'OpenAPI-Generator/1.0.0/python'},
|
'User-Agent': 'OpenAPI-Generator/1.0.0/python'},
|
||||||
preload_content=True, timeout=TimeoutWithEqual(connect=1, read=2))
|
preload_content=True, timeout=TimeoutWithEqual(connect=1, read=2))
|
||||||
|
|
||||||
|
@ -513,9 +513,7 @@ class ApiClient(object):
|
|||||||
for auth in auth_settings:
|
for auth in auth_settings:
|
||||||
auth_setting = self.configuration.auth_settings().get(auth)
|
auth_setting = self.configuration.auth_settings().get(auth)
|
||||||
if auth_setting:
|
if auth_setting:
|
||||||
if not auth_setting['value']:
|
if auth_setting['in'] == 'cookie':
|
||||||
continue
|
|
||||||
elif auth_setting['in'] == 'cookie':
|
|
||||||
headers['Cookie'] = auth_setting['value']
|
headers['Cookie'] = auth_setting['value']
|
||||||
elif auth_setting['in'] == 'header':
|
elif auth_setting['in'] == 'header':
|
||||||
headers[auth_setting['key']] = auth_setting['value']
|
headers[auth_setting['key']] = auth_setting['value']
|
||||||
|
@ -28,15 +28,38 @@ class Configuration(object):
|
|||||||
Do not edit the class manually.
|
Do not edit the class manually.
|
||||||
|
|
||||||
:param host: Base url
|
:param host: Base url
|
||||||
:param api_key: Dict to store API key(s)
|
:param api_key: Dict to store API key(s).
|
||||||
|
Each entry in the dict specifies an API key.
|
||||||
|
The dict key is the name of the security scheme in the OAS specification.
|
||||||
|
The dict value is the API key secret.
|
||||||
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
|
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
|
||||||
|
The dict key is the name of the security scheme in the OAS specification.
|
||||||
|
The dict value is an API key prefix when generating the auth data.
|
||||||
:param username: Username for HTTP basic authentication
|
:param username: Username for HTTP basic authentication
|
||||||
:param password: Password for HTTP basic authentication
|
:param password: Password for HTTP basic authentication
|
||||||
|
|
||||||
|
:Example:
|
||||||
|
|
||||||
|
Given the following security scheme in the OpenAPI specification:
|
||||||
|
components:
|
||||||
|
securitySchemes:
|
||||||
|
cookieAuth: # name for the security scheme
|
||||||
|
type: apiKey
|
||||||
|
in: cookie
|
||||||
|
name: JSESSIONID # cookie name
|
||||||
|
|
||||||
|
You can programmatically set the cookie:
|
||||||
|
conf = petstore_api.Configuration(
|
||||||
|
api_key={'cookieAuth': 'abc123'}
|
||||||
|
api_key_prefix={'cookieAuth': 'JSESSIONID'}
|
||||||
|
)
|
||||||
|
The following cookie will be added to the HTTP request:
|
||||||
|
Cookie: JSESSIONID abc123
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, host="http://petstore.swagger.io:80/v2",
|
def __init__(self, host="http://petstore.swagger.io:80/v2",
|
||||||
api_key=None, api_key_prefix=None,
|
api_key=None, api_key_prefix=None,
|
||||||
username="", password=""):
|
username=None, password=None):
|
||||||
"""Constructor
|
"""Constructor
|
||||||
"""
|
"""
|
||||||
self.host = host
|
self.host = host
|
||||||
@ -236,8 +259,14 @@ class Configuration(object):
|
|||||||
|
|
||||||
:return: The token for basic HTTP authentication.
|
:return: The token for basic HTTP authentication.
|
||||||
"""
|
"""
|
||||||
|
username = ""
|
||||||
|
if self.username is not None:
|
||||||
|
username = self.username
|
||||||
|
password = ""
|
||||||
|
if self.password is not None:
|
||||||
|
password = self.password
|
||||||
return urllib3.util.make_headers(
|
return urllib3.util.make_headers(
|
||||||
basic_auth=self.username + ':' + self.password
|
basic_auth=username + ':' + password
|
||||||
).get('authorization')
|
).get('authorization')
|
||||||
|
|
||||||
def auth_settings(self):
|
def auth_settings(self):
|
||||||
@ -245,44 +274,44 @@ class Configuration(object):
|
|||||||
|
|
||||||
:return: The Auth Settings information dict.
|
:return: The Auth Settings information dict.
|
||||||
"""
|
"""
|
||||||
return {
|
auth = {}
|
||||||
'api_key':
|
if 'api_key' in self.api_key:
|
||||||
{
|
auth['api_key'] = {
|
||||||
'type': 'api_key',
|
'type': 'api_key',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'api_key',
|
'key': 'api_key',
|
||||||
'value': self.get_api_key_with_prefix('api_key')
|
'value': self.get_api_key_with_prefix('api_key')
|
||||||
},
|
}
|
||||||
'api_key_query':
|
if 'api_key_query' in self.api_key:
|
||||||
{
|
auth['api_key_query'] = {
|
||||||
'type': 'api_key',
|
'type': 'api_key',
|
||||||
'in': 'query',
|
'in': 'query',
|
||||||
'key': 'api_key_query',
|
'key': 'api_key_query',
|
||||||
'value': self.get_api_key_with_prefix('api_key_query')
|
'value': self.get_api_key_with_prefix('api_key_query')
|
||||||
},
|
}
|
||||||
'bearer_test':
|
if self.access_token is not None:
|
||||||
{
|
auth['bearer_test'] = {
|
||||||
'type': 'bearer',
|
'type': 'bearer',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'format': 'JWT',
|
'format': 'JWT',
|
||||||
'key': 'Authorization',
|
'key': 'Authorization',
|
||||||
'value': 'Bearer ' + self.access_token
|
'value': 'Bearer ' + self.access_token
|
||||||
},
|
}
|
||||||
'http_basic_test':
|
if self.username is not None and self.password is not None:
|
||||||
{
|
auth['http_basic_test'] = {
|
||||||
'type': 'basic',
|
'type': 'basic',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'Authorization',
|
'key': 'Authorization',
|
||||||
'value': self.get_basic_auth_token()
|
'value': self.get_basic_auth_token()
|
||||||
},
|
}
|
||||||
'petstore_auth':
|
if self.access_token is not None:
|
||||||
{
|
auth['petstore_auth'] = {
|
||||||
'type': 'oauth2',
|
'type': 'oauth2',
|
||||||
'in': 'header',
|
'in': 'header',
|
||||||
'key': 'Authorization',
|
'key': 'Authorization',
|
||||||
'value': 'Bearer ' + self.access_token
|
'value': 'Bearer ' + self.access_token
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
return auth
|
||||||
|
|
||||||
def to_debug_report(self):
|
def to_debug_report(self):
|
||||||
"""Gets the essential information for debugging.
|
"""Gets the essential information for debugging.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user