From: salimfadhley Date: Tue, 5 Mar 2013 09:29:46 +0000 (+0000) Subject: Make kerberos optional. Version bump. X-Git-Tag: v0.2.23~253 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9e45eb4a4a71b894dcb3c38c42736d5e8a285082;p=tools%2Fpython-jenkinsapi.git Make kerberos optional. Version bump. --- diff --git a/doc/build.xml b/doc/build.xml index d9a9c73..b00771b 100644 --- a/doc/build.xml +++ b/doc/build.xml @@ -1,42 +1,42 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jenkinsapi/__init__.py b/jenkinsapi/__init__.py index c006aed..61b703d 100644 --- a/jenkinsapi/__init__.py +++ b/jenkinsapi/__init__.py @@ -1,46 +1,46 @@ -""" -About this library -================== - -Jenkins is the market leading continuous integration system, originally created by Kohsuke Kawaguchi. This API makes Jenkins even easier to use by providing an easy to use conventional python interface. - -Jenkins (and It's predecessor Hudson) are fantastic projects - but they are somewhat Java-centric. Thankfully the designers have provided an excellent and complete REST interface. This library wraps up that interface as more conventional python objects in order to make most Jenkins oriented tasks simpler. - -This library can help you: - - * Query the test-results of a completed build - * Get a objects representing the latest builds of a job - * Search for artefacts by simple criteria - * Block until jobs are complete - * Install artefacts to custom-specified directory structures - * username/password auth support for jenkins instances with auth turned on - * Ability to search for builds by subversion revision - * Ability to add/remove/query jenkins slaves - -Installing JenkinsAPI -===================== - -Egg-files for this project are hosted on PyPi. Most Python users should be able to use pip or distribute to automatically install this project. - -Most users can do the following: - -easy_install jenkinsapi - -If you'd like to install in multi-version mode: - -easy_install -m jenkinsapi - -Project Authors -=============== - - * Salim Fadhley (sal@stodge.org) - * Ramon van Alteren (ramon@vanalteren.nl) - * Ruslan Lutsenko (ruslan.lutcenko@gmail.com) - -Current code lives on github: https://github.com/salimfadhley/jenkinsapi - -""" -__all__= [ "command_line", "utils", - "api", "artifact", "build", "config", "constants", "exceptions", "fingerprint", - "jenkins", "jenkinsbase", "job", "node", "result_set", "result", "view"] +""" +About this library +================== + +Jenkins is the market leading continuous integration system, originally created by Kohsuke Kawaguchi. This API makes Jenkins even easier to use by providing an easy to use conventional python interface. + +Jenkins (and It's predecessor Hudson) are fantastic projects - but they are somewhat Java-centric. Thankfully the designers have provided an excellent and complete REST interface. This library wraps up that interface as more conventional python objects in order to make most Jenkins oriented tasks simpler. + +This library can help you: + + * Query the test-results of a completed build + * Get a objects representing the latest builds of a job + * Search for artefacts by simple criteria + * Block until jobs are complete + * Install artefacts to custom-specified directory structures + * username/password auth support for jenkins instances with auth turned on + * Ability to search for builds by subversion revision + * Ability to add/remove/query jenkins slaves + +Installing JenkinsAPI +===================== + +Egg-files for this project are hosted on PyPi. Most Python users should be able to use pip or distribute to automatically install this project. + +Most users can do the following: + +easy_install jenkinsapi + +If you'd like to install in multi-version mode: + +easy_install -m jenkinsapi + +Project Authors +=============== + + * Salim Fadhley (sal@stodge.org) + * Ramon van Alteren (ramon@vanalteren.nl) + * Ruslan Lutsenko (ruslan.lutcenko@gmail.com) + +Current code lives on github: https://github.com/salimfadhley/jenkinsapi + +""" +__all__= [ "command_line", "utils", + "api", "artifact", "build", "config", "constants", "exceptions", "fingerprint", + "jenkins", "jenkinsbase", "job", "node", "result_set", "result", "view"] __docformat__ = "epytext" \ No newline at end of file diff --git a/jenkinsapi/jenkins.py b/jenkinsapi/jenkins.py index 16c2641..2c44fdf 100644 --- a/jenkinsapi/jenkins.py +++ b/jenkinsapi/jenkins.py @@ -1,21 +1,29 @@ -from jenkinsapi.jenkinsbase import JenkinsBase +from jenkinsapi.exceptions import UnknownJob, NotAuthorized from jenkinsapi.fingerprint import Fingerprint +from jenkinsapi.jenkinsbase import JenkinsBase from jenkinsapi.job import Job -from jenkinsapi.view import View from jenkinsapi.node import Node -from jenkinsapi.exceptions import UnknownJob, NotAuthorized -from utils.urlopener import mkurlopener, mkkrbopener, mkopener, NoAuto302Handler +from jenkinsapi.view import View +from utils.urlopener import mkurlopener, mkopener, NoAuto302Handler +import cookielib import logging import time -import urllib2 import urllib +import urllib2 import urlparse -import cookielib + try: import json except ImportError: import simplejson as json +try: + # Kerberos is now an extras_require - please see + # http://pythonhosted.org/distribute/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies + from utils.urlopener_kerberos import mkkrbopener +except ImportError: + mkkrbopener = None + log = logging.getLogger(__name__) class Jenkins(JenkinsBase): @@ -78,6 +86,8 @@ class Jenkins(JenkinsBase): return mkopener(*hdrs) def get_krb_opener(self): + if not mkkrbopener: + raise NotImplementedError('JenkinsAPI was installed without Kerberos support.') return mkkrbopener(self.baseurl) def login(self): diff --git a/jenkinsapi/utils/urlopener.py b/jenkinsapi/utils/urlopener.py index d13fd5d..63d7ec8 100644 --- a/jenkinsapi/utils/urlopener.py +++ b/jenkinsapi/utils/urlopener.py @@ -1,6 +1,5 @@ import urllib2 import base64 -import kerberos as krb from urlparse import urlparse import logging @@ -32,19 +31,7 @@ class PreemptiveBasicAuthHandler(urllib2.BaseHandler): def https_request(self,req): return self.http_request(req) -class KerberosAuthHandler(urllib2.BaseHandler): - """ - A BaseHandler class that will add Kerberos Auth headers to a request - """ - def __init__(self,tgt): - self.tgt = tgt - def http_request(self,req): - req.add_unredirected_header('Authorization', 'Negotiate %s' % self.tgt) - return req - - def https_request(self,req): - return self.http_request(req) def mkurlopener( jenkinsuser, jenkinspass, jenkinsurl, proxyhost, proxyport, proxyuser, proxypass ): @@ -68,20 +55,6 @@ def mkurlopener( jenkinsuser, jenkinspass, jenkinsurl, proxyhost, proxyport, pro opener = urllib2.build_opener(*handlers) return opener.open -def mkkrbopener( jenkinsurl ): - """ - Creates an url opener that works with kerberos auth - - :param jenkinsurl: jenkins url, str - :return: urllib2.opener configured for kerberos auth - """ - handlers = [] - for handler in get_kerberos_auth_handler(jenkinsurl=jenkinsurl): - handlers.append(handler) - opener = urllib2.build_opener(*handlers) - return opener.open - - def mkopener(*handlers): opener = urllib2.build_opener(*handlers) return opener.open @@ -131,26 +104,7 @@ def get_proxy_handler(proxyhost, proxyport, proxyuser, proxypass): return [proxy_handler, proxy_auth_handler] -def get_kerberos_auth_handler(jenkinsurl): - """ - Get a handler which enabled authentication over GSSAPI - :param jenkinsurl: jenkins base url, str - :return: a list of handlers - """ - jenkinsnetloc = urlparse(jenkinsurl).netloc - assert type( jenkinsnetloc ) == str, "Jenkins network location should be a string, got %s" % repr( jenkinsnetloc ) - - _ignore, ctx = krb.authGSSClientInit('HTTP@%s' % jenkinsnetloc, gssflags=krb.GSS_C_DELEG_FLAG|krb.GSS_C_MUTUAL_FLAG|krb.GSS_C_SEQUENCE_FLAG) - rc = krb.authGSSClientStep(ctx,'') - if rc != krb.AUTH_GSS_CONTINUE: - return [] - tgt = krb.authGSSClientResponse(ctx) - if not tgt: - return [] - - krb_handler = KerberosAuthHandler(tgt) - return [ krb_handler ] class NoAuto302Handler(urllib2.HTTPRedirectHandler): def http_error_302(self, req, fp, code, msg, hdrs): diff --git a/jenkinsapi/utils/urlopener_kerberos.py b/jenkinsapi/utils/urlopener_kerberos.py new file mode 100644 index 0000000..20d4953 --- /dev/null +++ b/jenkinsapi/utils/urlopener_kerberos.py @@ -0,0 +1,50 @@ +import urllib2 +import kerberos as krb + +class KerberosAuthHandler(urllib2.BaseHandler): + """ + A BaseHandler class that will add Kerberos Auth headers to a request + """ + def __init__(self,tgt): + self.tgt = tgt + + def http_request(self,req): + req.add_unredirected_header('Authorization', 'Negotiate %s' % self.tgt) + return req + + def https_request(self,req): + return self.http_request(req) + +def mkkrbopener( jenkinsurl ): + """ + Creates an url opener that works with kerberos auth + + :param jenkinsurl: jenkins url, str + :return: urllib2.opener configured for kerberos auth + """ + handlers = [] + for handler in get_kerberos_auth_handler(jenkinsurl=jenkinsurl): + handlers.append(handler) + opener = urllib2.build_opener(*handlers) + return opener.open + +def get_kerberos_auth_handler(jenkinsurl): + """ + Get a handler which enabled authentication over GSSAPI + + :param jenkinsurl: jenkins base url, str + :return: a list of handlers + """ + jenkinsnetloc = urlparse(jenkinsurl).netloc + assert type( jenkinsnetloc ) == str, "Jenkins network location should be a string, got %s" % repr( jenkinsnetloc ) + + _ignore, ctx = krb.authGSSClientInit('HTTP@%s' % jenkinsnetloc, gssflags=krb.GSS_C_DELEG_FLAG|krb.GSS_C_MUTUAL_FLAG|krb.GSS_C_SEQUENCE_FLAG) + rc = krb.authGSSClientStep(ctx,'') + if rc != krb.AUTH_GSS_CONTINUE: + return [] + tgt = krb.authGSSClientResponse(ctx) + if not tgt: + return [] + + krb_handler = KerberosAuthHandler(tgt) + return [ krb_handler ] \ No newline at end of file diff --git a/setup.py b/setup.py index 1089c73..5bf6196 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup import os PROJECT_ROOT, _ = os.path.split(__file__) -VERSION = REVISION = '0.1.12' +VERSION = REVISION = '0.1.13' PROJECT_NAME = 'JenkinsAPI' PROJECT_AUTHORS = "Salim Fadhley, Ramon van Alteren, Ruslan Lutsenko" PROJECT_EMAILS = 'salimfadhley@gmail.com, ramon@vanalteren.nl, ruslan.lutcenko@gmail.com' @@ -18,8 +18,6 @@ GLOBAL_ENTRY_POINTS = { "console_scripts": ["jenkins_invoke=jenkinsapi.command_line.jenkins_invoke:main"] } -# Actual setup - setup(name=PROJECT_NAME.lower(), version=VERSION, author=PROJECT_AUTHORS, @@ -27,7 +25,10 @@ setup(name=PROJECT_NAME.lower(), packages=["jenkinsapi", 'jenkinsapi.utils', 'jenkinsapi.command_line'], zip_safe=True, include_package_data=False, - install_requires=['kerberos'], + install_requires=[], + extras_require={ + 'kerberos': ['kerberos'] + }, entry_points=GLOBAL_ENTRY_POINTS, url=PROJECT_URL, description=SHORT_DESCRIPTION,