Skip to content

Commit

Permalink
fix: make swagger work
Browse files Browse the repository at this point in the history
  • Loading branch information
LIII-XXII committed Oct 27, 2022
1 parent 3c6ce03 commit 80859a1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
36 changes: 18 additions & 18 deletions swagger_client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def __init__(self):
self.api_key_prefix = {}
# function to refresh API key if expired
self.refresh_api_key_hook = None
# Username for HTTP basic authentication
self.username = ""
# Password for HTTP basic authentication
self.password = ""
# # Username for HTTP basic authentication
# self.username = ""
# # Password for HTTP basic authentication
# self.password = ""

# Logging Settings
self.logger = {}
Expand Down Expand Up @@ -217,14 +217,14 @@ def get_api_key_with_prefix(self, identifier):
else:
return key

def get_basic_auth_token(self):
"""Gets HTTP basic authentication header (string).
# def get_basic_auth_token(self):
# """Gets HTTP basic authentication header (string).

:return: The token for basic HTTP authentication.
"""
return urllib3.util.make_headers(
basic_auth=self.username + ':' + self.password
).get('authorization')
# :return: The token for basic HTTP authentication.
# """
# return urllib3.util.make_headers(
# basic_auth=self.username + ':' + self.password
# ).get('authorization')

def auth_settings(self):
"""Gets Auth Settings dict for api client.
Expand All @@ -239,13 +239,13 @@ def auth_settings(self):
'key': 'Authorization',
'value': self.get_api_key_with_prefix('Authorization')
},
'basic':
{
'type': 'basic',
'in': 'header',
'key': 'Authorization',
'value': self.get_basic_auth_token()
},
# 'basic':
# {
# 'type': 'basic',
# 'in': 'header',
# 'key': 'Authorization',
# 'value': self.get_basic_auth_token()
# },

}

Expand Down
18 changes: 12 additions & 6 deletions with-swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,35 @@
import logging
import os
import time
from sys import argv, exit


from pprint import pprint

import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
from sys import argv, exit

logging.basicConfig(level=logging.INFO)

LOGGER = logging.getLogger(argv[0])
SOURCE_GRAFANA_TOKEN = os.getenv('SOURCE_GRAFANA_TOKEN')
GRAFANA_URL = os.getenv('GRAFANA_URL')
GRAFANA_URL = os.getenv('GRAFANA_URL') + '/api'

# Configure API key authorization: api_key
configuration = swagger_client.Configuration()
configuration.api_key['Authorization'] = SOURCE_GRAFANA_TOKEN
configuration.debug = True # very verbose!
configuration.api_key = {'Authorization': SOURCE_GRAFANA_TOKEN}
configuration.host = GRAFANA_URL
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
configuration.api_key_prefix['Authorization'] = 'Bearer'
configuration.api_key_prefix = {'Authorization': 'Bearer'}

# create an instance of the API class
api_instance = swagger_client.AccessControlApi(swagger_client.ApiClient(configuration))
search_api = swagger_client.SearchApi(swagger_client.ApiClient(configuration))
# body = swagger_client.AddBuiltInRoleCommand() # AddBuiltInRoleCommand |

if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)


try:
pprint(search_api.search(query=''))
Expand Down

0 comments on commit 80859a1

Please sign in to comment.