github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/clients/python/bacalhau_apiclient/configuration.py (about)

     1  # coding: utf-8
     2  
     3  """
     4      Bacalhau API
     5  
     6      This page is the reference of the Bacalhau REST API. Project docs are available at https://docs.bacalhau.org/. Find more information about Bacalhau at https://github.com/filecoin-project/bacalhau.  # noqa: E501
     7  
     8      OpenAPI spec version: 0.3.22.post4
     9      Contact: team@bacalhau.org
    10      Generated by: https://github.com/swagger-api/swagger-codegen.git
    11  """
    12  
    13  
    14  from __future__ import absolute_import
    15  
    16  import copy
    17  import logging
    18  import multiprocessing
    19  import sys
    20  import urllib3
    21  
    22  import six
    23  from six.moves import http_client as httplib
    24  
    25  
    26  class Configuration(object):
    27      """NOTE: This class is auto generated by the swagger code generator program.
    28  
    29      Ref: https://github.com/swagger-api/swagger-codegen
    30      Do not edit the class manually.
    31      """
    32  
    33      _default = None
    34  
    35      def __init__(self):
    36          """Constructor"""
    37          if self._default:
    38              for key in self._default.__dict__.keys():
    39                  self.__dict__[key] = copy.copy(self._default.__dict__[key])
    40              return
    41  
    42          # Default Base url
    43          self.host = "http://bootstrap.production.bacalhau.org:1234"
    44          # Temp file folder for downloading files
    45          self.temp_folder_path = None
    46  
    47          # Authentication Settings
    48          # dict to store API key(s)
    49          self.api_key = {}
    50          # dict to store API prefix (e.g. Bearer)
    51          self.api_key_prefix = {}
    52          # function to refresh API key if expired
    53          self.refresh_api_key_hook = None
    54          # Username for HTTP basic authentication
    55          self.username = ""
    56          # Password for HTTP basic authentication
    57          self.password = ""
    58  
    59          # Logging Settings
    60          self.logger = {}
    61          self.logger["package_logger"] = logging.getLogger("bacalhau_apiclient")
    62          self.logger["urllib3_logger"] = logging.getLogger("urllib3")
    63          # Log format
    64          self.logger_format = '%(asctime)s %(levelname)s %(message)s'
    65          # Log stream handler
    66          self.logger_stream_handler = None
    67          # Log file handler
    68          self.logger_file_handler = None
    69          # Debug file location
    70          self.logger_file = None
    71          # Debug switch
    72          self.debug = False
    73  
    74          # SSL/TLS verification
    75          # Set this to false to skip verifying SSL certificate when calling API
    76          # from https server.
    77          self.verify_ssl = True
    78          # Set this to customize the certificate file to verify the peer.
    79          self.ssl_ca_cert = None
    80          # client certificate file
    81          self.cert_file = None
    82          # client key file
    83          self.key_file = None
    84          # Set this to True/False to enable/disable SSL hostname verification.
    85          self.assert_hostname = None
    86  
    87          # urllib3 connection pool's maximum number of connections saved
    88          # per pool. urllib3 uses 1 connection as default value, but this is
    89          # not the best value when you are making a lot of possibly parallel
    90          # requests to the same host, which is often the case here.
    91          # cpu_count * 5 is used as default value to increase performance.
    92          self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
    93  
    94          # Proxy URL
    95          self.proxy = None
    96          # Safe chars for path_param
    97          self.safe_chars_for_path_param = ''
    98  
    99          # Disable client side validation
   100          self.client_side_validation = True
   101  
   102      @classmethod
   103      def set_default(cls, default):
   104          cls._default = default
   105  
   106      @property
   107      def logger_file(self):
   108          """The logger file.
   109  
   110          If the logger_file is None, then add stream handler and remove file
   111          handler. Otherwise, add file handler and remove stream handler.
   112  
   113          :param value: The logger_file path.
   114          :type: str
   115          """
   116          return self.__logger_file
   117  
   118      @logger_file.setter
   119      def logger_file(self, value):
   120          """The logger file.
   121  
   122          If the logger_file is None, then add stream handler and remove file
   123          handler. Otherwise, add file handler and remove stream handler.
   124  
   125          :param value: The logger_file path.
   126          :type: str
   127          """
   128          self.__logger_file = value
   129          if self.__logger_file:
   130              # If set logging file,
   131              # then add file handler and remove stream handler.
   132              self.logger_file_handler = logging.FileHandler(self.__logger_file)
   133              self.logger_file_handler.setFormatter(self.logger_formatter)
   134              for _, logger in six.iteritems(self.logger):
   135                  logger.addHandler(self.logger_file_handler)
   136                  if self.logger_stream_handler:
   137                      logger.removeHandler(self.logger_stream_handler)
   138          else:
   139              # If not set logging file,
   140              # then add stream handler and remove file handler.
   141              self.logger_stream_handler = logging.StreamHandler()
   142              self.logger_stream_handler.setFormatter(self.logger_formatter)
   143              for _, logger in six.iteritems(self.logger):
   144                  logger.addHandler(self.logger_stream_handler)
   145                  if self.logger_file_handler:
   146                      logger.removeHandler(self.logger_file_handler)
   147  
   148      @property
   149      def debug(self):
   150          """Debug status
   151  
   152          :param value: The debug status, True or False.
   153          :type: bool
   154          """
   155          return self.__debug
   156  
   157      @debug.setter
   158      def debug(self, value):
   159          """Debug status
   160  
   161          :param value: The debug status, True or False.
   162          :type: bool
   163          """
   164          self.__debug = value
   165          if self.__debug:
   166              # if debug status is True, turn on debug logging
   167              for _, logger in six.iteritems(self.logger):
   168                  logger.setLevel(logging.DEBUG)
   169              # turn on httplib debug
   170              httplib.HTTPConnection.debuglevel = 1
   171          else:
   172              # if debug status is False, turn off debug logging,
   173              # setting log level to default `logging.WARNING`
   174              for _, logger in six.iteritems(self.logger):
   175                  logger.setLevel(logging.WARNING)
   176              # turn off httplib debug
   177              httplib.HTTPConnection.debuglevel = 0
   178  
   179      @property
   180      def logger_format(self):
   181          """The logger format.
   182  
   183          The logger_formatter will be updated when sets logger_format.
   184  
   185          :param value: The format string.
   186          :type: str
   187          """
   188          return self.__logger_format
   189  
   190      @logger_format.setter
   191      def logger_format(self, value):
   192          """The logger format.
   193  
   194          The logger_formatter will be updated when sets logger_format.
   195  
   196          :param value: The format string.
   197          :type: str
   198          """
   199          self.__logger_format = value
   200          self.logger_formatter = logging.Formatter(self.__logger_format)
   201  
   202      def get_api_key_with_prefix(self, identifier):
   203          """Gets API key (with prefix if set).
   204  
   205          :param identifier: The identifier of apiKey.
   206          :return: The token for api key authentication.
   207          """
   208  
   209          if self.refresh_api_key_hook:
   210              self.refresh_api_key_hook(self)
   211  
   212          key = self.api_key.get(identifier)
   213          if key:
   214              prefix = self.api_key_prefix.get(identifier)
   215              if prefix:
   216                  return "%s %s" % (prefix, key)
   217              else:
   218                  return key
   219  
   220      def get_basic_auth_token(self):
   221          """Gets HTTP basic authentication header (string).
   222  
   223          :return: The token for basic HTTP authentication.
   224          """
   225          return urllib3.util.make_headers(
   226              basic_auth=self.username + ':' + self.password
   227          ).get('authorization')
   228  
   229      def auth_settings(self):
   230          """Gets Auth Settings dict for api client.
   231  
   232          :return: The Auth Settings information dict.
   233          """
   234          return {
   235  
   236          }
   237  
   238      def to_debug_report(self):
   239          """Gets the essential information for debugging.
   240  
   241          :return: The report for debugging.
   242          """
   243          return "Python SDK Debug Report:\n"\
   244                 "OS: {env}\n"\
   245                 "Python Version: {pyversion}\n"\
   246                 "Version of the API: 0.3.22.post4\n"\
   247                 "SDK Package Version: 0.3.22.post4".\
   248                 format(env=sys.platform, pyversion=sys.version)