Ejemplo n.º 1
0
 def _authenticate(self, url):
     if url.startswith("uln:///"):
         self.uln_url = "https://" + DEFAULT_UP2DATE_URL
         label = url[7:]
     elif url.startswith("uln://"):
         parts = url[6:].split("/")
         self.uln_url = "https://" + parts[0]
         label = parts[1]
     else:
         raise RhnSyncException(
             "url format error, url must start with uln://")
     self.uln_user = self.yumbase.conf.username
     self.uln_pass = self.yumbase.conf.password
     self.url = self.uln_url + "/XMLRPC/GET-REQ/" + label
     print("The download URL is: " + self.url)
     if self.proxy_addr:
         print("Trying proxy " + self.proxy_addr)
     slist = ServerList([
         self.uln_url + "/rpc/api",
     ])
     s = RetryServer(slist.server(),
                     refreshCallback=None,
                     proxy=self.proxy_addr,
                     username=self.proxy_user,
                     password=self.proxy_pass,
                     timeout=5)
     s.addServerList(slist)
     self.key = s.auth.login(self.uln_user, self.uln_pass)
Ejemplo n.º 2
0
 def __init__(self,
              url,
              name,
              org="1",
              channel_label="",
              no_mirrors=False,
              ca_cert_file=None,
              client_cert_file=None,
              client_key_file=None):
     if url[:6] != "uln://":
         raise RhnSyncException(
             "url format error, url must start with uln://")
     yum_ContentSource.__init__(self,
                                url,
                                name,
                                yumsrc_conf=ULNSRC_CONF,
                                org=org,
                                channel_label=channel_label,
                                no_mirrors=no_mirrors,
                                ca_cert_file=ca_cert_file,
                                client_cert_file=client_cert_file,
                                client_key_file=client_key_file)
     self.uln_url = None
     self.uln_user = None
     self.uln_pass = None
     self.key = None
Ejemplo n.º 3
0
 def __init__(self,
              url,
              name,
              insecure=False,
              interactive=True,
              yumsrc_conf=ULNAuth.ULN_CONF_PATH,
              org=1,
              channel_label="",
              no_mirrors=False,
              ca_cert_file=None,
              client_cert_file=None,
              client_key_file=None):
     if url[:6] != "uln://":
         raise RhnSyncException(
             "url format error, url must start with uln://")
     yum_ContentSource.__init__(self,
                                url=url,
                                name=name,
                                insecure=insecure,
                                interactive=interactive,
                                yumsrc_conf=yumsrc_conf,
                                org=org,
                                channel_label=channel_label,
                                no_mirrors=no_mirrors,
                                ca_cert_file=ca_cert_file,
                                client_cert_file=client_cert_file,
                                client_key_file=client_key_file)
     self.uln_token = None
Ejemplo n.º 4
0
 def __init__(self, url, name):
     if url[:6] != "uln://":
         raise RhnSyncException("url format error, url must start with uln://")
     yum_ContentSource.__init__(self, url, name, ULNSRC_CONF)
     self.uln_url = None
     self.uln_user = None
     self.uln_pass = None
     self.key = None
Ejemplo n.º 5
0
    def _openSocketStream(self, method, params):
        """Wraps the gzipstream.GzipStream instantiation in a test block so we
           can open normally if stream is not gzipped."""

        stream = None
        retryYN = 0
        wait = 0.33
        lastErrorMsg = ''
        cfg = config.initUp2dateConfig()
        for i in range(cfg['networkRetries']):
            server = self.getServer(retryYN)
            if server is None:
                log2(-1,
                     2,
                     'ERROR: server unable to initialize, attempt %s' % i,
                     stream=sys.stderr)
                retryYN = 1
                time.sleep(wait)
                continue
            func = getattr(server, method)
            try:
                stream = func(*params)
                if CFG.SYNC_TO_TEMP:
                    import tempfile
                    cached = tempfile.NamedTemporaryFile()
                    stream.read_to_file(cached)
                    cached.seek(0)
                    return cached
                else:
                    return stream
            except rpclib.xmlrpclib.ProtocolError:
                e = sys.exc_info()[1]
                p = tuple(['<the systemid>'] + list(params[1:]))
                lastErrorMsg = 'ERROR: server.%s%s: %s' % (method, p, e)
                log2(-1, 2, lastErrorMsg, stream=sys.stderr)
                retryYN = 1
                time.sleep(wait)
                # do not reraise this exception!
            except (KeyboardInterrupt, SystemExit):
                raise
            except rpclib.xmlrpclib.Fault:
                e = sys.exc_info()[1]
                lastErrorMsg = e.faultString
                break
            except Exception:  # pylint: disable=E0012, W0703
                e = sys.exc_info()[1]
                p = tuple(['<the systemid>'] + list(params[1:]))
                lastErrorMsg = 'ERROR: server.%s%s: %s' % (method, p, e)
                log2(-1, 2, lastErrorMsg, stream=sys.stderr)
                break
                # do not reraise this exception!
        if lastErrorMsg:
            raise_with_tb(RhnSyncException(lastErrorMsg), sys.exc_info()[2])
        # Returns a stream
        # Should never be reached
        return stream
Ejemplo n.º 6
0
    def get_hostname(self, url: str) -> tuple:
        """
        Get label from the URL (a hostname).

        :raises RhnSyncException: if URL is wrongly formatted.
        :returns: tuple (hostname, label)
        """
        if url.startswith("uln:///"):
            return "https://" + self.ULN_DEFAULT_HOST, url[7:]
        elif url.startswith("uln://"):
            parts = url[6:].split("/")
            return "https://" + parts[0], "/".join(parts[1:])
        else:
            raise RhnSyncException("URL must start with 'uln://'.")
Ejemplo n.º 7
0
 def __init__(self, url, name, insecure=False, interactive=True, yumsrc_conf=ULNAuth.ULN_CONF_PATH,
              org=1, channel_label="", no_mirrors=False,
              ca_cert_file=None, client_cert_file=None, client_key_file=None, channel_arch="",
              http_headers=None):
     if url[:6] != "uln://":
         raise RhnSyncException("url format error, url must start with uln://")
     # Make sure baseurl ends with / and urljoin will work correctly
     if url[-1] != '/':
         url += '/'
     yum_ContentSource.__init__(self, url=url, name=name, insecure=insecure,
                                interactive=interactive, yumsrc_conf=yumsrc_conf, org=org,
                                channel_label=channel_label, no_mirrors=no_mirrors,
                                ca_cert_file=ca_cert_file, client_cert_file=client_cert_file,
                                client_key_file=client_key_file)
     self.uln_token = None
Ejemplo n.º 8
0
    def get_credentials(self) -> tuple:
        """
        Get credentials from the uln.conf

        :raises AssertionError: if configuration does not contain required sections.
        :returns: tuple of username and password
        """
        if not os.path.exists(self.ULN_CONF_PATH):
            raise RhnSyncException("'{}' does not exists".format(
                self.ULN_CONF_PATH))
        elif not os.access(self.ULN_CONF_PATH, os.R_OK):
            raise RhnSyncException("Permission denied to '{}'".format(
                self.ULN_CONF_PATH))

        config = configparser.ConfigParser()
        config.read(self.ULN_CONF_PATH)
        if "main" in config:
            sct = config["main"]
            username, password = sct.get("username"), sct.get("password")
        else:
            username = password = None
        assert username is not None and password is not None, "Credentials were not found in the configuration"

        return username, password