mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-05-09 15:54:12 +00:00
52 lines
1.3 KiB
Plaintext
52 lines
1.3 KiB
Plaintext
import base64
|
|
import urllib3
|
|
|
|
|
|
def get_api_key_with_prefix(key):
|
|
global api_key
|
|
global api_key_prefix
|
|
|
|
if api_key.get(key) and api_key_prefix.get(key):
|
|
return api_key_prefix[key] + ' ' + api_key[key]
|
|
elif api_key.get(key):
|
|
return api_key[key]
|
|
|
|
def get_basic_auth_token():
|
|
global username
|
|
global password
|
|
|
|
if username and password:
|
|
return urllib3.util.make_headers(basic_auth=username + ':' + password).get('authorization')
|
|
|
|
def auth_settings():
|
|
return { {{#authMethods}}{{#isApiKey}}
|
|
'{{name}}': {
|
|
'type': 'api_key',
|
|
'in': {{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{#isKeyInQuery}}'query'{{/isKeyInQuery}},
|
|
'key': '{{keyParamName}}',
|
|
'value': get_api_key_with_prefix('{{keyParamName}}')
|
|
},
|
|
{{/isApiKey}}{{#isBasic}}
|
|
'{{name}}': {
|
|
'type': 'basic',
|
|
'in': 'header',
|
|
'key': 'Authorization',
|
|
'value': get_basic_auth_token()
|
|
},
|
|
{{/isBasic}}{{/authMethods}}
|
|
}
|
|
|
|
|
|
|
|
# Default Base url
|
|
host = "{{basePath}}"
|
|
|
|
# Authentication settings
|
|
|
|
api_key = {}
|
|
api_key_prefix = {}
|
|
username = ''
|
|
password = ''
|
|
|
|
|