from jenkinsapi.utils.requester import Requester
from requests_kerberos import HTTPKerberosAuth, OPTIONAL


class KrbRequester(Requester):

    """
    A class which carries out HTTP requests with Kerberos/GSSAPI authentication.
    """

    def __init__(self, ssl_verify=None, baseurl=None, mutual_auth=OPTIONAL):
        """
        :param ssl_verify: flag indicating if server certificate in HTTPS requests should be verified
        :param baseurl: Jenkins' base URL
        :param mutual_auth: type of mutual authentication, use one of REQUIRED, OPTIONAL or DISABLED
                            from requests_kerberos package
        """
        args = {}
        if ssl_verify:
            args["ssl_verify"] = ssl_verify
        if baseurl:
            args["baseurl"] = baseurl
        super(KrbRequester, self).__init__(**args)
        self.mutual_auth = mutual_auth

    def get_request_dict(self, url, params, data, headers):
        req_dict = super(KrbRequester, self).get_request_dict(url=url, params=params,
                                                              data=data, headers=headers)
        if self.mutual_auth:
            auth = HTTPKerberosAuth(self.mutual_auth)
        else:
            auth = HTTPKerberosAuth()
        req_dict['auth'] = auth
        return req_dict

Add kerberos authentication requester using requests_kerberos
Add kerberos authentication requester using requests_kerberos
