From be4388302069e59996438f083ab738470a68860c Mon Sep 17 00:00:00 2001 From: Petr Kocandrle Date: Thu, 25 Jul 2013 21:24:02 +0200 Subject: [PATCH] Add kerberos authentication requester using requests_kerberos --- jenkinsapi/utils/krb_requester.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 jenkinsapi/utils/krb_requester.py diff --git a/jenkinsapi/utils/krb_requester.py b/jenkinsapi/utils/krb_requester.py new file mode 100644 index 0000000..bf27297 --- /dev/null +++ b/jenkinsapi/utils/krb_requester.py @@ -0,0 +1,34 @@ +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 -- 2.7.4