aboutsummaryrefslogtreecommitdiffstats
path: root/python_openapi_client/fatcat_openapi_client/configuration.py
diff options
context:
space:
mode:
Diffstat (limited to 'python_openapi_client/fatcat_openapi_client/configuration.py')
-rw-r--r--python_openapi_client/fatcat_openapi_client/configuration.py197
1 files changed, 138 insertions, 59 deletions
diff --git a/python_openapi_client/fatcat_openapi_client/configuration.py b/python_openapi_client/fatcat_openapi_client/configuration.py
index a62f555e..0cd7e1f2 100644
--- a/python_openapi_client/fatcat_openapi_client/configuration.py
+++ b/python_openapi_client/fatcat_openapi_client/configuration.py
@@ -5,9 +5,9 @@
Fatcat is a scalable, versioned, API-oriented catalog of bibliographic entities and file metadata. # noqa: E501
- OpenAPI spec version: 0.3.1
+ The version of the OpenAPI document: 0.3.1
Contact: webservices@archive.org
- Generated by: https://github.com/swagger-api/swagger-codegen.git
+ Generated by: https://openapi-generator.tech
"""
@@ -28,9 +28,9 @@ class TypeWithDefault(type):
super(TypeWithDefault, cls).__init__(name, bases, dct)
cls._default = None
- def __call__(cls):
+ def __call__(cls, **kwargs):
if cls._default is None:
- cls._default = type.__call__(cls)
+ cls._default = type.__call__(cls, **kwargs)
return copy.copy(cls._default)
def set_default(cls, default):
@@ -38,68 +38,104 @@ class TypeWithDefault(type):
class Configuration(object):
- """NOTE: This class is auto generated by the swagger code generator program.
+ """NOTE: This class is auto generated by OpenAPI Generator
- Ref: https://github.com/swagger-api/swagger-codegen
+ Ref: https://openapi-generator.tech
Do not edit the class manually.
+
+ :param host: Base url
+ :param api_key: Dict to store API key(s)
+ :param api_key_prefix: Dict to store API prefix (e.g. Bearer)
+ :param username: Username for HTTP basic authentication
+ :param password: Password for HTTP basic authentication
"""
- def __init__(self):
- """Constructor"""
- # Default Base url
- self.host = "https://api.fatcat.wiki/v0"
- # Temp file folder for downloading files
+ def __init__(self, host="https://api.fatcat.wiki/v0",
+ api_key={}, api_key_prefix={},
+ username="", password=""):
+ """Constructor
+ """
+ self.host = host
+ """Default Base url
+ """
self.temp_folder_path = None
-
+ """Temp file folder for downloading files
+ """
# Authentication Settings
- # dict to store API key(s)
- self.api_key = {}
- # dict to store API prefix (e.g. Bearer)
- self.api_key_prefix = {}
- # Username for HTTP basic authentication
- self.username = ""
- # Password for HTTP basic authentication
- self.password = ""
-
- # Logging Settings
+ self.api_key = api_key
+ """dict to store API key(s)
+ """
+ self.api_key_prefix = api_key_prefix
+ """dict to store API prefix (e.g. Bearer)
+ """
+ self.refresh_api_key_hook = None
+ """function hook to refresh API key if expired
+ """
+ self.username = username
+ """Username for HTTP basic authentication
+ """
+ self.password = password
+ """Password for HTTP basic authentication
+ """
self.logger = {}
+ """Logging Settings
+ """
self.logger["package_logger"] = logging.getLogger("fatcat_openapi_client")
self.logger["urllib3_logger"] = logging.getLogger("urllib3")
- # Log format
self.logger_format = '%(asctime)s %(levelname)s %(message)s'
- # Log stream handler
+ """Log format
+ """
self.logger_stream_handler = None
- # Log file handler
+ """Log stream handler
+ """
self.logger_file_handler = None
- # Debug file location
+ """Log file handler
+ """
self.logger_file = None
- # Debug switch
+ """Debug file location
+ """
self.debug = False
+ """Debug switch
+ """
- # SSL/TLS verification
- # Set this to false to skip verifying SSL certificate when calling API
- # from https server.
self.verify_ssl = True
- # Set this to customize the certificate file to verify the peer.
+ """SSL/TLS verification
+ Set this to false to skip verifying SSL certificate when calling API
+ from https server.
+ """
self.ssl_ca_cert = None
- # client certificate file
+ """Set this to customize the certificate file to verify the peer.
+ """
self.cert_file = None
- # client key file
+ """client certificate file
+ """
self.key_file = None
- # Set this to True/False to enable/disable SSL hostname verification.
+ """client key file
+ """
self.assert_hostname = None
+ """Set this to True/False to enable/disable SSL hostname verification.
+ """
- # urllib3 connection pool's maximum number of connections saved
- # per pool. urllib3 uses 1 connection as default value, but this is
- # not the best value when you are making a lot of possibly parallel
- # requests to the same host, which is often the case here.
- # cpu_count * 5 is used as default value to increase performance.
self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
+ """urllib3 connection pool's maximum number of connections saved
+ per pool. urllib3 uses 1 connection as default value, but this is
+ not the best value when you are making a lot of possibly parallel
+ requests to the same host, which is often the case here.
+ cpu_count * 5 is used as default value to increase performance.
+ """
- # Proxy URL
self.proxy = None
- # Safe chars for path_param
+ """Proxy URL
+ """
+ self.proxy_headers = None
+ """Proxy headers
+ """
self.safe_chars_for_path_param = ''
+ """Safe chars for path_param
+ """
+ self.retries = None
+ """Adding retries to override urllib3 default value 3
+ """
@property
def logger_file(self):
@@ -131,17 +167,6 @@ class Configuration(object):
self.logger_file_handler.setFormatter(self.logger_formatter)
for _, logger in six.iteritems(self.logger):
logger.addHandler(self.logger_file_handler)
- if self.logger_stream_handler:
- logger.removeHandler(self.logger_stream_handler)
- else:
- # If not set logging file,
- # then add stream handler and remove file handler.
- self.logger_stream_handler = logging.StreamHandler()
- self.logger_stream_handler.setFormatter(self.logger_formatter)
- for _, logger in six.iteritems(self.logger):
- logger.addHandler(self.logger_stream_handler)
- if self.logger_file_handler:
- logger.removeHandler(self.logger_file_handler)
@property
def debug(self):
@@ -203,11 +228,15 @@ class Configuration(object):
:param identifier: The identifier of apiKey.
:return: The token for api key authentication.
"""
- if (self.api_key.get(identifier) and
- self.api_key_prefix.get(identifier)):
- return self.api_key_prefix[identifier] + ' ' + self.api_key[identifier] # noqa: E501
- elif self.api_key.get(identifier):
- return self.api_key[identifier]
+ if self.refresh_api_key_hook is not None:
+ self.refresh_api_key_hook(self)
+ key = self.api_key.get(identifier)
+ if key:
+ prefix = self.api_key_prefix.get(identifier)
+ if prefix:
+ return "%s %s" % (prefix, key)
+ else:
+ return key
def get_basic_auth_token(self):
"""Gets HTTP basic authentication header (string).
@@ -231,7 +260,6 @@ class Configuration(object):
'key': 'Authorization',
'value': self.get_api_key_with_prefix('Authorization')
},
-
}
def to_debug_report(self):
@@ -243,5 +271,56 @@ class Configuration(object):
"OS: {env}\n"\
"Python Version: {pyversion}\n"\
"Version of the API: 0.3.1\n"\
- "SDK Package Version: 1.0.0".\
+ "SDK Package Version: 0.3.1".\
format(env=sys.platform, pyversion=sys.version)
+
+ def get_host_settings(self):
+ """Gets an array of host settings
+
+ :return: An array of host settings
+ """
+ return [
+ {
+ 'url': "https://api.fatcat.wiki/v0",
+ 'description': "No description provided",
+ }
+ ]
+
+ def get_host_from_settings(self, index, variables={}):
+ """Gets host URL based on the index and variables
+ :param index: array index of the host settings
+ :param variables: hash of variable and the corresponding value
+ :return: URL based on host settings
+ """
+
+ servers = self.get_host_settings()
+
+ # check array index out of bound
+ if index < 0 or index >= len(servers):
+ raise ValueError(
+ "Invalid index {} when selecting the host settings. Must be less than {}" # noqa: E501
+ .format(index, len(servers)))
+
+ server = servers[index]
+ url = server['url']
+
+ # go through variable and assign a value
+ for variable_name in server['variables']:
+ if variable_name in variables:
+ if variables[variable_name] in server['variables'][
+ variable_name]['enum_values']:
+ url = url.replace("{" + variable_name + "}",
+ variables[variable_name])
+ else:
+ raise ValueError(
+ "The variable `{}` in the host URL has invalid value {}. Must be {}." # noqa: E501
+ .format(
+ variable_name, variables[variable_name],
+ server['variables'][variable_name]['enum_values']))
+ else:
+ # use default value
+ url = url.replace(
+ "{" + variable_name + "}",
+ server['variables'][variable_name]['default_value'])
+
+ return url