Example #1
0
    def validate_config(self, repo, config, related_repos):
        _LOG.info("validate_config invoked, config values are: %s" % (config.repo_plugin_config))
        for key in REQUIRED_CONFIG_KEYS:
            if key not in config.keys():
                msg = _("Missing required configuration key: %(key)s" % {"key":key})
                _LOG.error(msg)
                return False, msg

        for key in config.keys():
            if key not in REQUIRED_CONFIG_KEYS and key not in OPTIONAL_CONFIG_KEYS:
                msg = _("Configuration key '%(key)s' is not supported" % {"key":key})
                _LOG.error(msg)
                return False, msg
            if key == 'feed_url':
                feed_url = config.get('feed_url')
                if not util.validate_feed(feed_url):
                    msg = _("feed_url [%s] does not start with a valid protocol" % feed_url)
                    _LOG.error(msg)
                    return False, msg
            if key == 'ssl_verify':
                ssl_verify = config.get('ssl_verify')
                if ssl_verify is not None and not isinstance(ssl_verify, bool) :
                    msg = _("ssl_verify should be a boolean; got %s instead" % ssl_verify)
                    _LOG.error(msg)
                    return False, msg

            if key == 'ssl_ca_cert':
                ssl_ca_cert = config.get('ssl_ca_cert').encode('utf-8')
                if ssl_ca_cert is not None:
                    if not util.validate_cert(ssl_ca_cert) :
                        msg = _("ssl_ca_cert is not a valid certificate")
                        _LOG.error(msg)
                        return False, msg
                    # ssl_ca_cert is valid, proceed to store it in our repo.working_dir
                    ssl_ca_cert_filename = os.path.join(repo.working_dir, "ssl_ca_cert")
                    try:
                        try:
                            ssl_ca_cert_file = open(ssl_ca_cert_filename, "w")
                            ssl_ca_cert_file.write(ssl_ca_cert)
                        finally:
                            if ssl_ca_cert_file:
                                ssl_ca_cert_file.close()
                    except Exception, e:
                        msg = _("Unable to write ssl_ca_cert to %s" % ssl_ca_cert_filename)
                        _LOG.error(e)
                        _LOG.error(msg)
                        return False, msg

            if key == 'ssl_client_cert':
                ssl_client_cert = config.get('ssl_client_cert').encode('utf-8')
                if ssl_client_cert is not None:
                    if not util.validate_cert(ssl_client_cert) :
                        msg = _("ssl_client_cert is not a valid certificate")
                        _LOG.error(msg)
                        return False, msg
                    # ssl_client_cert is valid, proceed to store it in our repo.working_dir
                    ssl_client_cert_filename = os.path.join(repo.working_dir, "ssl_client_cert")
                    try:
                        try:
                            ssl_client_cert_file = open(ssl_client_cert_filename, "w")
                            ssl_client_cert_file.write(ssl_client_cert)
                        finally:
                            if ssl_client_cert_file:
                                ssl_client_cert_file.close()
                    except Exception, e:
                        msg = _("Unable to write ssl_client_cert to %s" % ssl_client_cert_filename)
                        _LOG.error(e)
                        _LOG.error(msg)
                        return False, msg
Example #2
0
                try:
                    try:
                        ssl_client_key_file = open(ssl_client_key_filename, "w")
                        ssl_client_key_file.write(ssl_client_key)
                    finally:
                        if ssl_client_key_file:
                            ssl_client_key_file.close()
                except Exception, e:
                    msg = _("Unable to write ssl_client_cert to %s" % ssl_client_cert_filename)
                    _LOG.error(e)
                    _LOG.error(msg)
                    return False, msg

            if key == 'proxy_url':
                proxy_url = config.get('proxy_url')
                if proxy_url is not None and not util.validate_feed(proxy_url):
                    msg = _("Invalid proxy url: %s" % proxy_url)
                    _LOG.error(msg)
                    return False, msg

            if key == 'proxy_port':
                proxy_port = config.get('proxy_port')
                if proxy_port is not None and isinstance(proxy_port, int):
                    msg = _("Invalid proxy port: %s" % proxy_port)
                    _LOG.error(msg)
                    return False, msg

            if key == 'verify_checksum':
                verify_checksum = config.get('verify_checksum')
                if verify_checksum is not None and not isinstance(verify_checksum, bool) :
                    msg = _("verify_checksum should be a boolean; got %s instead" % verify_checksum)