Beispiel #1
0
    def save_connection_config(self) -> None:
        if self.name and self.url:
            config_parser = RawConfigParser()
            config_parser.add_section(SECTION_TITLE)
            config_parser.set(SECTION_TITLE, 'url', self.url)

            if self._requires_auth:
                config_parser.set(SECTION_TITLE, 'username',
                                  self._auth['username'])
                password = encode(encode_password(), self._auth['password'])
                config_parser.set(SECTION_TITLE, 'password', password)

            if self.jenkins_views:
                config_parser.set(SECTION_TITLE, 'views',
                                  ','.join(self.view_names))

                for view in self.views:
                    view.save_view_config()

            save_argus_config(
                config_parser,
                build_config_file(jenkins_connections_dir, self.name))
        else:
            raise ConfigError(
                'No data to save in JenkinsConnection config file.')
Beispiel #2
0
    def save_view_config(self) -> None:
        config_parser = RawConfigParser()
        config_parser.add_section(SECTION_TITLE)
        config_parser.set(SECTION_TITLE, 'job_names', ','.join(self.job_names))

        save_argus_config(config_parser,
                          build_config_file(jenkins_views_dir, self.name))
Beispiel #3
0
 def load_view_config(jenkins_connection, view_name):
     config_file = build_config_file(jenkins_views_dir, view_name)
     if os.path.isfile(config_file):
         config_parser = RawConfigParser()
         config_parser.read(config_file)
         if config_parser.has_option(SECTION_TITLE, 'job_names'):
             job_names = config_parser.get(SECTION_TITLE, 'job_names').split(',')
             jenkins_view = JenkinsView(view_name, job_names)
         else:
             jenkins_view = JenkinsView(view_name)
         jenkins_connection.jenkins_views[jenkins_view.name] = jenkins_view
     else:
         print('No config file for {}.'.format(view_name))
Beispiel #4
0
    def load_connection_config(jenkins_manager: 'JenkinsManager',
                               connection_name: str) -> None:
        config_file = build_config_file(jenkins_connections_dir,
                                        connection_name)
        if os.path.isfile(config_file):
            config_parser = RawConfigParser()
            config_parser.read(config_file)
            url = config_parser.get(SECTION_TITLE, 'url')
            auth = {}

            if config_parser.has_option(SECTION_TITLE, 'password'):
                auth['username'] = config_parser.get(SECTION_TITLE, 'username')
                auth['password'] = decode(
                    encode_password(),
                    config_parser.get(SECTION_TITLE, 'password'))

            try:
                jenkins_connection = JenkinsConnection(connection_name,
                                                       url,
                                                       auth=auth)
                if config_parser.has_option(SECTION_TITLE, 'views'):
                    view_names = config_parser.get(SECTION_TITLE,
                                                   'views').split(',')
                    print('Loading Jenkins views for connection: {}'.format(
                        connection_name))
                    for view_name in view_names:
                        JenkinsView.load_view_config(jenkins_connection,
                                                     view_name)
                jenkins_manager.jenkins_connections[
                    jenkins_connection.name] = jenkins_connection
            except Exception as e:
                print(
                    'WARNING! Error occurred during creation of Jenkins instance: {}.'
                    .format(e))
                print(
                    'Skipping addition of this instance. Check routing to url: {}'
                    .format(url))
                pause()
        else:
            'No config file for {}.'.format(connection_name)