docusign_esign.client.configuration

DocuSign REST API

The DocuSign REST API provides you with a powerful, convenient, and simple Web services API for interacting with DocuSign.

OpenAPI spec version: v2 Contact: devcenter@docusign.com Generated by: https://github.com/swagger-api/swagger-codegen.git

  1# coding: utf-8
  2
  3"""
  4    DocuSign REST API
  5
  6    The DocuSign REST API provides you with a powerful, convenient, and simple Web services API for interacting with DocuSign.
  7
  8    OpenAPI spec version: v2
  9    Contact: devcenter@docusign.com
 10    Generated by: https://github.com/swagger-api/swagger-codegen.git
 11"""
 12
 13
 14from __future__ import absolute_import
 15
 16import urllib3
 17
 18import sys
 19import logging
 20
 21from six import iteritems, PY3
 22from six.moves import http_client as httplib
 23
 24
 25def singleton(cls, *args, **kw):
 26    instances = {}
 27
 28    def _singleton():
 29        if cls not in instances:
 30            instances[cls] = cls(*args, **kw)
 31        return instances[cls]
 32    return _singleton
 33
 34
 35@singleton
 36class Configuration(object):
 37    """
 38    NOTE: This class is auto generated by the swagger code generator program.
 39    Ref: https://github.com/swagger-api/swagger-codegen
 40    Do not edit the class manually.
 41    """
 42
 43    def __init__(self):
 44        """
 45        Constructor
 46        """
 47        # Default Base url
 48        self.host = "https://www.docusign.net/restapi"
 49        # Default api client
 50        self.api_client = None
 51        # Temp file folder for downloading files
 52        self.temp_folder_path = None
 53
 54        # Authentication Settings
 55        # dict to store API key(s)
 56        self.api_key = {}
 57        # dict to store API prefix (e.g. Bearer)
 58        self.api_key_prefix = {}
 59        # Username for HTTP basic authentication
 60        self.username = ""
 61        # Password for HTTP basic authentication
 62        self.password = ""
 63
 64        # access token for OAuth
 65        self.access_token = ""
 66
 67        # Logging Settings
 68        self.logger = {}
 69        self.logger["package_logger"] = logging.getLogger("docusign_esign")
 70        self.logger["urllib3_logger"] = logging.getLogger("urllib3")
 71        # Log format
 72        self.logger_format = '%(asctime)s %(levelname)s %(message)s'
 73        # Log stream handler
 74        self.logger_stream_handler = None
 75        # Log file handler
 76        self.logger_file_handler = None
 77        # Debug file location
 78        self.logger_file = None
 79        # Debug switch
 80        self.debug = False
 81
 82        # SSL/TLS verification
 83        # Set this to false to skip verifying SSL certificate when calling API from https server.
 84        self.verify_ssl = True
 85        # Set this to customize the certificate file to verify the peer.
 86        self.ssl_ca_cert = None
 87        # client certificate file
 88        self.cert_file = None
 89        # client key file
 90        self.key_file = None
 91
 92        if PY3:
 93            self.user_agent = 'Swagger-Codegen/v2.1/3.12.0/python3'
 94        else:
 95            self.user_agent = 'Swagger-Codegen/v2.1/3.12.0/python2'
 96
 97    @property
 98    def logger_file(self):
 99        """
100        Gets the logger_file.
101        """
102        return self.__logger_file
103
104    @logger_file.setter
105    def logger_file(self, value):
106        """
107        Sets the logger_file.
108
109        If the logger_file is None, then add stream handler and remove file handler.
110        Otherwise, add file handler and remove stream handler.
111
112        :param value: The logger_file path.
113        :type: str
114        """
115        self.__logger_file = value
116        if self.__logger_file:
117            # If set logging file,
118            # then add file handler and remove stream handler.
119            self.logger_file_handler = logging.FileHandler(self.__logger_file)
120            self.logger_file_handler.setFormatter(self.logger_formatter)
121            for _, logger in iteritems(self.logger):
122                logger.addHandler(self.logger_file_handler)
123                if self.logger_stream_handler:
124                    logger.removeHandler(self.logger_stream_handler)
125        else:
126            # If not set logging file,
127            # then add stream handler and remove file handler.
128            self.logger_stream_handler = logging.StreamHandler()
129            self.logger_stream_handler.setFormatter(self.logger_formatter)
130            for _, logger in iteritems(self.logger):
131                logger.addHandler(self.logger_stream_handler)
132                if self.logger_file_handler:
133                    logger.removeHandler(self.logger_file_handler)
134
135    @property
136    def debug(self):
137        """
138        Gets the debug status.
139        """
140        return self.__debug
141
142    @debug.setter
143    def debug(self, value):
144        """
145        Sets the debug status.
146
147        :param value: The debug status, True or False.
148        :type: bool
149        """
150        self.__debug = value
151        if self.__debug:
152            # if debug status is True, turn on debug logging
153            for _, logger in iteritems(self.logger):
154                logger.setLevel(logging.DEBUG)
155            # turn on httplib debug
156            httplib.HTTPConnection.debuglevel = 1
157        else:
158            # if debug status is False, turn off debug logging,
159            # setting log level to default `logging.WARNING`
160            for _, logger in iteritems(self.logger):
161                logger.setLevel(logging.WARNING)
162            # turn off httplib debug
163            httplib.HTTPConnection.debuglevel = 0
164
165    @property
166    def logger_format(self):
167        """
168        Gets the logger_format.
169        """
170        return self.__logger_format
171
172    @logger_format.setter
173    def logger_format(self, value):
174        """
175        Sets the logger_format.
176
177        The logger_formatter will be updated when sets logger_format.
178
179        :param value: The format string.
180        :type: str
181        """
182        self.__logger_format = value
183        self.logger_formatter = logging.Formatter(self.__logger_format)
184
185    def get_api_key_with_prefix(self, identifier):
186        """
187        Gets API key (with prefix if set).
188
189        :param identifier: The identifier of apiKey.
190        :return: The token for api key authentication.
191        """
192        if self.api_key.get(identifier) and self.api_key_prefix.get(identifier):
193            return self.api_key_prefix[identifier] + ' ' + self.api_key[identifier]
194        elif self.api_key.get(identifier):
195            return self.api_key[identifier]
196
197    def get_basic_auth_token(self):
198        """
199        Gets HTTP basic authentication header (string).
200
201        :return: The token for basic HTTP authentication.
202        """
203        return urllib3.util.make_headers(basic_auth=self.username + ':' + self.password)\
204                           .get('authorization')
205
206    def auth_settings(self):
207        """
208        Gets Auth Settings dict for api client.
209
210        :return: The Auth Settings information dict.
211        """
212        return {
213
214            'docusignAccessCode':
215                {
216                    'type': 'oauth2',
217                    'in': 'header',
218                    'key': 'Authorization',
219                    'value': 'Bearer ' + self.access_token
220                },
221
222        }
223
224    def to_debug_report(self):
225        """
226        Gets the essential information for debugging.
227
228        :return: The report for debugging.
229        """
230        return "Python SDK Debug Report:\n"\
231               "OS: {env}\n"\
232               "Python Version: {pyversion}\n"\
233               "Version of the API: v2\n"\
234               "SDK Package Version: 1.0.0".\
235               format(env=sys.platform, pyversion=sys.version)
def singleton(cls, *args, **kw)
26def singleton(cls, *args, **kw):
27    instances = {}
28
29    def _singleton():
30        if cls not in instances:
31            instances[cls] = cls(*args, **kw)
32        return instances[cls]
33    return _singleton
def Configuration()
29    def _singleton():
30        if cls not in instances:
31            instances[cls] = cls(*args, **kw)
32        return instances[cls]