Esempio n. 1
0
class PulpAuthentication():
    """ Authenticates against the Pulp server in the Pulp client
    config (/etc/pulp/client.conf) """
    supports_object_permissions = False
    supports_anonymous_user = False
    supports_inactive_user = False
    
    def __init__(self):
        self.server = get_pulp_server()
        self.userapi = UserAPI()
    
    def authenticate(self, username, password=None):
        """ authenticate a user """
        try:
            self.server.set_basic_auth_credentials(username, password)
            logging.info("Successfully logged in with password")
            cert = self.userapi.admin_certificate()
            bundle = SpongeBundle(username)
            bundle.write(cert)
            self.server = get_pulp_server(new=True)
            self.server.set_ssl_credentials(bundle.crtpath())
            udata = self.userapi.user(username)
            logger.info("%s logged in successfully" % username)
        except server.ServerRequestError, err:
            logger.warning("Login failure for %s: %s" % (username, err[1]))
            return None
        except Exception, err:
            logger.warning(traceback.format_exc())
            return None
Esempio n. 2
0
    def setup_pulp(self):
        """ instantiate pulp server object and log in """
        config = ConsumerConfig()
        userapi = UserAPI()
        serveropts = config.server
        pulpserver = server.PulpServer(serveropts['host'],
                                       int(serveropts['port']),
                                       serveropts['scheme'],
                                       serveropts['path'])
        server.set_active_server(pulpserver)

        bundle = SpongeBundle(SpongeConfig.get("scheduler_username"))
        try:
            server.active_server.set_basic_auth_credentials(SpongeConfig.get("scheduler_username"),
                                                            SpongeConfig.get("scheduler_password"))
            crt = userapi.admin_certificate()
            bundle.write(crt)
        except server.ServerRequestError, err:
            self.stderr.write("Could not authenticate to Pulp: %s\n" % err[1])
            self.stderr.write("Ensure that the scheduler username and password are set properly in Sponge\n")
            raise SystemExit(1)