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
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)
def logout(request): bundle = SpongeBundle(request.user.username) bundle.delete() django_logout(request) url = reverse('django.contrib.auth.views.login') + "?next=/" return HttpResponseRedirect(url)