From 80859a11bbde71d4daaebb32cd817f7e20623259 Mon Sep 17 00:00:00 2001 From: Florian Castellane Date: Thu, 27 Oct 2022 14:15:02 +0900 Subject: [PATCH] fix: make swagger work --- swagger_client/configuration.py | 36 ++++++++++++++++----------------- with-swagger.py | 18 +++++++++++------ 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/swagger_client/configuration.py b/swagger_client/configuration.py index f3240e1..f02ba3b 100644 --- a/swagger_client/configuration.py +++ b/swagger_client/configuration.py @@ -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 = {} @@ -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. @@ -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() + # }, } diff --git a/with-swagger.py b/with-swagger.py index 4abee0a..443795c 100755 --- a/with-swagger.py +++ b/with-swagger.py @@ -3,21 +3,27 @@ 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)) @@ -25,7 +31,7 @@ # body = swagger_client.AddBuiltInRoleCommand() # AddBuiltInRoleCommand | if __name__ == '__main__': - logging.basicConfig(level=logging.DEBUG) + try: pprint(search_api.search(query=''))