def get(cls, username, password): if username == 'espa_admin': cp = ConfigurationProvider() if pbkdf2_sha256.verify(password, cp.espa256): return username, cp.get('apiemailreceive'), 'espa', 'admin', '' else: msg = "ERR validating espa_admin, invalid password " logger.critical(msg) raise UserException(msg) else: eu = ers.get_user_info(username, password) return eu['username'], eu['email'], eu['firstName'], eu[ 'lastName'], eu['contact_id']
def get(cls, username, password): if username == 'espa_admin': try: cp = ConfigurationProvider() if pbkdf2_sha256.verify(password, cp.espa256): return username, cp.get( 'apiemailreceive'), 'espa', 'admin', '' else: raise UserException( "ERR validating espa_admin, invalid password ") except: # try/except added due to trouble sorting out issue when raise UserException( "ERR validating espa_admin, traceback: {0}".format( traceback.format_exc())) else: try: eu = ers.get_user_info(username, password) return eu['username'], eu['email'], eu['firstName'], eu[ 'lastName'], eu['contact_id'] except ERSApiException, e: raise UserException( "Error authenticating user in get() with ERS. " "message:{}".format(e.message))
from api.providers.configuration.configuration_provider import ConfigurationProvider config = ConfigurationProvider() LOG_FORMAT = ("%(asctime)s [%(levelname)s]: %(message)s in %(pathname)s:%(lineno)d") class DbgFilter(Filter): def filter(self, rec): return rec.levelno == logging.DEBUG ilogger = logging.getLogger("api") ilogger.setLevel(logging.DEBUG) ih = FileHandler("/var/log/uwsgi/espa-api-info.log") dh = FileHandler("/var/log/uwsgi/espa-api-debug.log") eh = SMTPHandler(mailhost='localhost', fromaddr=config.get('apiemailsender'), toaddrs=config.get('apiemailreceive').split(','), subject='ESPA API ERROR') ih.setLevel(logging.INFO) dh.setLevel(logging.DEBUG) eh.setLevel(logging.DEBUG) for handler in [ih, dh, eh]: ilogger.addHandler(handler) if isinstance(handler, logging.FileHandler): handler.setFormatter(Formatter(LOG_FORMAT)) if handler.level == logging.DEBUG: handler.addFilter(DbgFilter())
logging.getLogger('suds.client').setLevel(logging.DEBUG) logging.getLogger("requests").setLevel(logging.DEBUG) LOG_FORMAT = ( "%(asctime)s [%(levelname)s]: %(message)s in %(pathname)s:%(lineno)d") ilogger = logging.getLogger("api") ilogger.setLevel(logging.DEBUG) espa_log_dir = os.getenv('ESPA_LOG_DIR') if espa_log_dir and not os.getenv('ESPA_LOG_STDOUT'): ih = FileHandler(os.path.join(espa_log_dir, 'espa-api-info.log')) else: ih = StreamHandler(stream=sys.stdout) eh = SMTPHandler(mailhost='localhost', fromaddr=config.get('apiemailsender'), toaddrs=config.get('ESPA_API_EMAIL_RECEIVE').split(','), subject='ESPA API ERROR') if config.mode not in ('tst', 'dev'): ih.setLevel(logging.INFO) else: ih.setLevel(logging.DEBUG) eh.setLevel(logging.CRITICAL) for handler in [ih, eh]: ilogger.addHandler(handler) if isinstance(handler, logging.StreamHandler): handler.setFormatter(Formatter(LOG_FORMAT))