Exemple #1
0
    def easy_connect(url, credentials=None, ssl_verify=False):
        """Factory method to simplify creating connections to Jenkins servers

        :param str url:
            Full URL of the Jenkins instance to connect to. Must be
            a valid running Jenkins instance.
        :param tuple credentials:
            A 2-element tuple with the username and password for authenticating to the URL
            If omitted, credentials will be loaded from any pyjen config files found on the system
            If no credentials can be found, anonymous access will be used
        :param bool ssl_verify:
            Indicates whether the SSL certificate of the Jenkins instance should be checked upon connection.
            For Jenkins instances hosted behind HTTPS using self-signed certificates this may cause connection
            errors when enabled. Defaults to disabled (False)
        :returns:
            Jenkins object, pre-configured with the appropriate credentials and connection parameters for the given URL.
        :rtype: :class:`.Jenkins`
        """
        # If no explicit credentials provided, load credentials from any config files
        if credentials is None:
            config = JenkinsConfigParser()
            config.read(JenkinsConfigParser.get_default_configfiles())
            credentials = config.get_credentials(url)

        http_io = DataRequester(url, ssl_verify)
        http_io.credentials = credentials
        retval = Jenkins(http_io)
        return retval
Exemple #2
0
    def __init__(self, url, credentials=None, ssl_cert=True):
        super(Jenkins, self).__init__()
        self._log = logging.getLogger(__name__)

        # If no explicit credentials provided,
        # load credentials from any config files
        if credentials is None:
            config = JenkinsConfigParser()
            config.read(JenkinsConfigParser.get_default_configfiles())
            creds = config.get_credentials(url)
        else:
            creds = credentials

        self._api = JenkinsAPI(url, creds, ssl_cert)
Exemple #3
0
 def test_get_default_configfiles(self):
     default_config_files = JenkinsConfigParser.get_default_configfiles()
     
     # Currently we look in 2 locations for config files
     self.assertEqual(len(default_config_files), 2)
     
     # The least privileged location should be the users home folder
     self.assertTrue(default_config_files[0].startswith(os.path.join(os.path.expanduser("~"))))
     
     # the next most privileged location is the local working folder
     self.assertTrue(default_config_files[1].startswith(os.getcwd()))
     
     # In any case, each path must point to the expected config file name
     if platform.system() == "Windows":
         expected_filename = "pyjen.cfg"
     else:
         expected_filename = ".pyjen"
     for filename in default_config_files:
         self.assertTrue(filename.endswith(expected_filename))
Exemple #4
0
def test_get_default_configfiles():
    default_config_files = JenkinsConfigParser.get_default_configfiles()

    # Currently we look in 2 locations for config files
    assert len(default_config_files) == 2

    # The least privileged location should be the users home folder
    assert default_config_files[0].startswith(
        os.path.join(os.path.expanduser("~")))

    # the next most privileged location is the local working folder
    assert default_config_files[1].startswith(os.getcwd())

    # In any case, each path must point to the expected config file name
    if platform.system() == "Windows":
        expected_filename = "pyjen.cfg"
    else:
        expected_filename = ".pyjen"
    for filename in default_config_files:
        assert filename.endswith(expected_filename)