Developer Documentation (Auslib Package)

auslib.AUS

class auslib.AUS.AUS
evaluateRules(updateQuery)
class auslib.AUS.AUSRandom(min=0, max=99)

Abstract getting a randint to make it easier to test the range of possible values

getInt()
getRange()
auslib.AUS.getFallbackChannel(channel)
auslib.AUS.isForbiddenUrl(url, product, whitelistedDomains)
auslib.AUS.isSpecialURL(url, specialForceHosts)

auslib.config

class auslib.config.AUSConfig(filename)

Bases: object

getCaches()
getDburi()
getDomainWhitelist()
getLogLevel()
getLogfile()
loglevels = {'DEBUG': 10, 'INFO': 20, 'WARNING': 30, 'CRITICAL': 50, 'ERROR': 40}
required_options = {'logging': ['logfile'], 'database': ['dburi']}
validate()
class auslib.config.AdminConfig(filename)

Bases: auslib.config.AUSConfig

getPageTitle()
getSecretKey()
getSystemAccounts()
required_options = {'app': ['secret_key'], 'site-specific': ['page_title'], 'logging': ['logfile'], 'database': ['dburi']}
class auslib.config.ClientConfig(filename)

Bases: auslib.config.AUSConfig

getSpecialForceHosts()

auslib.dockerflow

auslib.dockerflow.create_dockerflow_endpoints(app, heartbeat_database_fn=None)

Wrapper that creates the endpoints required by CloudOps’ Dockerflow spec: https://github.com/mozilla-services/Dockerflow. This gets used by both the admin and public apps. :param heartbeat_database_fn: Function that calls the database when reponding to /__heartbeat__. A database object is passed to this function.

If heartbeat_database_fn is None, a default function is be set. The default function writes in a dummy table. Even though we respond to GET, we do insert/update something in the database. This allows us to see if the connection to the database exists, is active, and if the credentials given are the correct ones. For more context see bug 1289178.

auslib.errors

exception auslib.errors.BadDataError

Bases: exceptions.Exception

Raised when a client sends data that appears to be invalid.

auslib.global_state

class auslib.global_state.DbWrapper

Bases: object

setDb(dburi)

auslib.log

class auslib.log.BalrogLogger(name, level=0)

Bases: logging.Logger

makeRecord(name, level, fn, lno, msg, args, exc_info, func=None, extra=None)
class auslib.log.JsonLogFormatter(fmt=None, datefmt=None, logger_name='Balrog')

Bases: logging.Formatter

Log formatter that outputs machine-readable json.

This log formatter outputs JSON format messages that are compatible with Mozilla’s standard heka-based log aggregation infrastructure.

See also: https://mana.mozilla.org/wiki/display/CLOUDSERVICES/Logging+Standard https://mana.mozilla.org/wiki/pages/viewpage.action?pageId=42895640

Adapted from: https://github.com/mozilla-services/mozservices/blob/master/mozsvc/util.py#L106

DEFAULT_SYSLOG_LEVEL = 7
EXCLUDED_LOGRECORD_ATTRS = set(['relativeCreated', 'process', 'module', 'funcName', 'message', 'filename', 'levelno', 'processName', 'lineno', 'asctime', 'msg', 'args', 'exc_text', 'name', 'thread', 'created', 'threadName', 'stack_info', 'msecs', 'pathname', 'exc_info', 'levelname'])
LOGGING_FORMAT_VERSION = '2.0'
SYSLOG_LEVEL_MAP = {40: 3, 50: 2, 20: 6, 10: 7, 30: 4}
format(record)

Map from Python LogRecord attributes to JSON log format fields

auslib.log.configure_logging(stream=<open file '<stdout>', mode 'w'>, formatter=<class 'auslib.log.JsonLogFormatter'>, format_='%(asctime)s - %(levelname)s - PID: %(process)s - Request: %(requestid)s - %(name)s.%(funcName)s#%(lineno)s: %(message)s', level=10)
auslib.log.safer_format_traceback(exc_typ, exc_val, exc_tb)

Format an exception traceback into safer string. We don’t want to let users write arbitrary data into our logfiles, which could happen if they e.g. managed to trigger a ValueError with a carefully-crafted payload. This function formats the traceback using “%r” for the actual exception data, which passes it through repr() so that any special chars are safely escaped.