コード例 #1
0
 def _init_session(self):
     """
     Set up the session, auth is handled here
     """
     session = requests.Session()
     session.headers = {'User-Agent': self.user_agent,
                        'Accept': 'application/json'}
     if self.authmethod == "BASIC":
         session.auth = (self.username, self.password)
     elif self.authmethod == "CERT":
         cert = rhsmCertificate.certpath()
         key = rhsmCertificate.keypath()
         session.cert = (cert, key)
     session.verify = self.cert_verify
     session.proxies = self.proxies
     if self.proxy_auth:
         # HACKY
         try:
             # Need to make a request that will fail to get proxies set up
             session.request(
                 "GET", "https://cert-api.access.redhat.com/r/insights")
         except requests.ConnectionError:
             pass
         # Major hack, requests/urllib3 does not make access to
         # proxy_headers easy
         proxy_mgr = session.adapters['https://'].proxy_manager[self.proxies['https']]
         auth_map = {'Proxy-Authorization': self.proxy_auth}
         proxy_mgr.proxy_headers = auth_map
         proxy_mgr.connection_pool_kw['_proxy_headers'] = auth_map
         conns = proxy_mgr.pools._container
         for conn in conns:
             connection = conns[conn]
             connection.proxy_headers = auth_map
     return session
コード例 #2
0
def _try_satellite6_configuration():
    """
    Try to autoconfigure for Satellite 6
    """
    try:
        from rhsm.config import initConfig
        rhsm_config = initConfig()

        logger.debug('Trying to autoconfigure...')
        cert = file(rhsmCertificate.certpath(), 'r').read()
        key = file(rhsmCertificate.keypath(), 'r').read()
        rhsm = rhsmCertificate(key, cert)

        # This will throw an exception if we are not registered
        logger.debug('Checking if system is subscription-manager registered')
        rhsm.getConsumerId()
        logger.debug('System is subscription-manager registered')

        rhsm_hostname = rhsm_config.get('server', 'hostname')
        rhsm_hostport = rhsm_config.get('server', 'port')
        rhsm_proxy_hostname = rhsm_config.get('server',
                                              'proxy_hostname').strip()
        rhsm_proxy_port = rhsm_config.get('server', 'proxy_port').strip()
        rhsm_proxy_user = rhsm_config.get('server', 'proxy_user').strip()
        rhsm_proxy_pass = rhsm_config.get('server', 'proxy_password').strip()
        proxy = None
        if rhsm_proxy_hostname != "":
            logger.debug("Found rhsm_proxy_hostname %s", rhsm_proxy_hostname)
            proxy = "http://"
            if rhsm_proxy_user != "" and rhsm_proxy_pass != "":
                logger.debug("Found user and password for rhsm_proxy")
                proxy = proxy + rhsm_proxy_user + ":" + rhsm_proxy_pass + "@"
            proxy = proxy + rhsm_proxy_hostname + ':' + rhsm_proxy_port
            logger.debug("RHSM Proxy: %s", proxy)
        logger.debug(
            "Found %sHost: %s, Port: %s",
            ('' if _is_rhn_or_rhsm(rhsm_hostname) else 'Satellite 6 Server '),
            rhsm_hostname, rhsm_hostport)
        rhsm_ca = rhsm_config.get('rhsm', 'repo_ca_cert')
        logger.debug("Found CA: %s", rhsm_ca)
        logger.debug("Setting authmethod to CERT")
        config['authmethod'] = 'CERT'

        # Directly connected to Red Hat, use cert auth directly with the api
        if _is_rhn_or_rhsm(rhsm_hostname):
            logger.debug("Connected to Red Hat Directly, using cert-api")
            rhsm_hostname = 'cert-api.access.redhat.com'
            rhsm_ca = None
        else:
            # Set the host path
            # 'rhsm_hostname' should really be named ~ 'rhsm_host_base_url'
            rhsm_hostname = rhsm_hostname + ':' + rhsm_hostport + '/redhat_access'

        logger.debug("Trying to set auto_configuration")
        set_auto_configuration(rhsm_hostname, rhsm_ca, proxy)
        return True
    except Exception as e:
        logger.debug(e)
        logger.debug('System is NOT subscription-manager registered')
        return False
コード例 #3
0
def _try_satellite6_configuration(config):
    """
    Try to autoconfigure for Satellite 6
    """
    try:
        from rhsm.config import initConfig
        rhsm_config = initConfig()

        logger.debug('Trying to autoconf Satellite 6')
        cert = file(rhsmCertificate.certpath(), 'r').read()
        key = file(rhsmCertificate.keypath(), 'r').read()
        rhsm = rhsmCertificate(key, cert)

        # This will throw an exception if we are not registered
        logger.debug('Checking if system is subscription-manager registered')
        rhsm.getConsumerId()
        logger.debug('System is subscription-manager registered')

        rhsm_hostname = rhsm_config.get('server', 'hostname')
        rhsm_hostport = rhsm_config.get('server', 'port')
        rhsm_proxy_hostname = rhsm_config.get('server', 'proxy_hostname').strip()
        rhsm_proxy_port = rhsm_config.get('server', 'proxy_port').strip()
        rhsm_proxy_user = rhsm_config.get('server', 'proxy_user').strip()
        rhsm_proxy_pass = rhsm_config.get('server', 'proxy_password').strip()
        proxy = None
        if rhsm_proxy_hostname != "":
            logger.debug("Found rhsm_proxy_hostname %s", rhsm_proxy_hostname)
            proxy = "http://"
            if rhsm_proxy_user != "" and rhsm_proxy_pass != "":
                logger.debug("Found user and password for rhsm_proxy")
                proxy = proxy + rhsm_proxy_user + ":" + rhsm_proxy_pass + "@"
                proxy = proxy + rhsm_proxy_hostname + rhsm_proxy_port
            else:
                proxy = proxy + rhsm_proxy_hostname + ':' + rhsm_proxy_port
                logger.debug("RHSM Proxy: %s", proxy)
        logger.debug("Found Satellite Server Host: %s, Port: %s",
                     rhsm_hostname, rhsm_hostport)
        rhsm_ca = rhsm_config.get('rhsm', 'repo_ca_cert')
        logger.debug("Found CA: %s", rhsm_ca)
        logger.debug("Setting authmethod to CERT")
        config.set(APP_NAME, 'authmethod', 'CERT')

        # Directly connected to Red Hat, use cert auth directly with the api
        if rhsm_hostname == 'subscription.rhn.redhat.com':
            logger.debug("Connected to Red Hat Directly, using cert-api")
            rhsm_hostname = 'cert-api.access.redhat.com'
            rhsm_ca = None
        else:
            # Set the host path
            # 'rhsm_hostname' should really be named ~ 'rhsm_host_base_url'
            rhsm_hostname = rhsm_hostname + ':' + rhsm_hostport + '/redhat_access'

        logger.debug("Trying to set auto_configuration")
        set_auto_configuration(config, rhsm_hostname, rhsm_ca, proxy)
        return True
    except Exception as e:
        logger.debug(e)
        logger.debug('System is NOT subscription-manager registered')
        return False
コード例 #4
0
 def _init_session(self):
     """
     Set up the session, auth is handled here
     """
     session = requests.Session()
     session.headers = {
         'User-Agent': self.user_agent,
         'Accept': 'application/json'
     }
     if self.systemid is not None:
         session.headers.update({'systemid': self.systemid})
     if self.authmethod == "BASIC":
         session.auth = (self.username, self.password)
     elif self.authmethod == "CERT":
         cert = rhsmCertificate.certpath()
         key = rhsmCertificate.keypath()
         if rhsmCertificate.exists():
             session.cert = (cert, key)
         else:
             logger.error('ERROR: Certificates not found.')
     session.verify = self.cert_verify
     session.proxies = self.proxies
     session.trust_env = False
     if self.proxy_auth:
         # HACKY
         try:
             # Need to make a request that will fail to get proxies set up
             net_logger.info(
                 "GET https://cert-api.access.redhat.com/r/insights")
             session.request(
                 "GET", "https://cert-api.access.redhat.com/r/insights")
         except requests.ConnectionError:
             pass
         # Major hack, requests/urllib3 does not make access to
         # proxy_headers easy
         proxy_mgr = session.adapters['https://'].proxy_manager[
             self.proxies['https']]
         auth_map = {'Proxy-Authorization': self.proxy_auth}
         proxy_mgr.proxy_headers = auth_map
         proxy_mgr.connection_pool_kw['_proxy_headers'] = auth_map
         conns = proxy_mgr.pools._container
         for conn in conns:
             connection = conns[conn]
             connection.proxy_headers = auth_map
     return session
コード例 #5
0
 def _init_session(self):
     """
     Set up the session, auth is handled here
     """
     session = requests.Session()
     session.headers = {
         'User-Agent': self.user_agent,
         'Accept': 'application/json'
     }
     if self.authmethod == "BASIC":
         session.auth = (self.username, self.password)
     elif self.authmethod == "CERT":
         cert = rhsmCertificate.certpath()
         key = rhsmCertificate.keypath()
         session.cert = (cert, key)
     session.verify = self.cert_verify
     session.proxies = self.proxies
     if self.proxy_auth:
         # HACKY
         try:
             # Need to make a request that will fail to get proxies set up
             session.request(
                 "GET", "https://cert-api.access.redhat.com/r/insights")
         except requests.ConnectionError as e:
             pass
         # Major hack, requests/urllib3 does not make access to
         # proxy_headers easy
         session.adapters['https://'].\
           proxy_manager[self.proxies['https']].\
           proxy_headers = {'Proxy-Authorization': self.proxy_auth}
         session.adapters['https://'].\
           proxy_manager[self.proxies['https']].\
           connection_pool_kw['_proxy_headers'] = {'Proxy-Authorization': self.proxy_auth}
         conns = session.adapters['https://'].\
                   proxy_manager[self.proxies['https']].pools._container
         for conn in conns:
             connection = conns[conn]
             connection.proxy_headers = {
                 'Proxy-Authorization': self.proxy_auth
             }
     return session
コード例 #6
0
def _try_satellite6_configuration(config):
    """
    Try to autoconfigure for Satellite 6
    """
    try:
        from rhsm.config import initConfig
        RHSM_CONFIG = initConfig()

        logger.debug('Trying to autoconf Satellite 6')
        cert = file(rhsmCertificate.certpath(), 'r').read()
        key = file(rhsmCertificate.keypath(), 'r').read()
        rhsm = rhsmCertificate(key, cert)

        # This will throw an exception if we are not registered
        logger.debug('Checking if system is subscription-manager registered')
        rhsm.getConsumerId()
        logger.debug('System is subscription-manager registered')

        rhsm_hostname = RHSM_CONFIG.get('server', 'hostname')
        logger.debug("Found Satellite Server: %s", rhsm_hostname)
        rhsm_ca = RHSM_CONFIG.get('rhsm', 'repo_ca_cert')
        logger.debug("Found CA: %s", rhsm_ca)
        logger.debug("Setting authmethod to CERT")
        config.set(APP_NAME, 'authmethod', 'CERT')

        # Directly connected to Red Hat, use cert auth directly with the api
        if rhsm_hostname == 'subscription.rhn.redhat.com':
            logger.debug("Connected to RH Directly, using cert-api")
            rhsm_hostname = 'cert-api.access.redhat.com'
            rhsm_ca = None
        else:
            # Set the cert verify CA, and path
            rhsm_hostname = rhsm_hostname + '/redhat_access'

        logger.debug("Trying to set auto_configuration")
        set_auto_configuration(config, rhsm_hostname, rhsm_ca)
        return True
    except:
        logger.debug('System is NOT subscription-manager registered')
        return False