示例#1
0
def storage_status():
    message = ''
    try:
        _storage = storage.load(_config.storage)
        key = toolkit.gen_random_string()
        value = toolkit.gen_random_string()
        _storage.put_content(key, value)
        stored_value = _storage.get_content(key)
        _storage.remove(key)
        if value != stored_value:
            message = 'Set value is different from what was received'
    except Exception as e:
        message = str(e)
    return {'storage': message}
示例#2
0
def redis_status():
    message = ''
    if not cache.redis_conn:
        cache.init()
    if not cache.redis_conn:
        return {'redis': 'unconfigured'}
    key = toolkit.gen_random_string()
    value = toolkit.gen_random_string()
    try:
        cache.redis_conn.setex(key, 5, value)
        if value != cache.redis_conn.get(key):
            message = 'Set value is different from what was received'
    except Exception:
        message = str(sys.exc_info()[1])
    return {'redis': message}
示例#3
0
def init():
    # Configure the secret key
    if cfg.secret_key:
        flask.Flask.secret_key = cfg.secret_key
    else:
        flask.Flask.secret_key = toolkit.gen_random_string(64)
    # Configure the email exceptions
    info = cfg.email_exceptions
    if info:
        mailhost = info['smtp_host']
        mailport = info.get('smtp_port')
        if mailport:
            mailhost = (mailhost, mailport)
        smtp_secure = info.get('smtp_secure', None)
        secure_args = _adapt_smtp_secure(smtp_secure)
        mail_handler = logging.handlers.SMTPHandler(
            mailhost=mailhost,
            fromaddr=info['from_addr'],
            toaddrs=[info['to_addr']],
            subject='Docker registry exception',
            credentials=(info['smtp_login'],
                         info['smtp_password']),
            secure=secure_args)
        mail_handler.setLevel(logging.ERROR)
        app.logger.addHandler(mail_handler)
示例#4
0
def generate_headers(namespace, repository, access):
    registry_endpoints = get_endpoints()
    # The token generated will be invalid against a real Index behind.
    token = 'Token signature={0},repository="{1}/{2}",access={3}'.format(
        toolkit.gen_random_string(), namespace, repository, access
    )
    return {"X-Docker-Endpoints": registry_endpoints, "WWW-Authenticate": token, "X-Docker-Token": token}
示例#5
0
def generate_headers(namespace, repository, access):
    cfg = config.load()
    registry_endpoints = cfg.registry_endpoints
    if not registry_endpoints:
        #registry_endpoints = socket.gethostname()
        registry_endpoints = flask.request.environ['HTTP_HOST']
    # The token generated will be invalid against a real Index behind.
    token = 'Token signature={0},repository="{1}/{2}",access={3}'.format(
            toolkit.gen_random_string(), namespace, repository, access)
    return {'X-Docker-Endpoints': registry_endpoints,
            'WWW-Authenticate': token,
            'X-Docker-Token': token}
示例#6
0
def init():
    # Configure the secret key
    if cfg.secret_key:
        Flask.secret_key = cfg.secret_key
    else:
        Flask.secret_key = gen_random_string(64)
    # Configure the email exceptions
    info = cfg.email_exceptions
    if info:
        import logging
        from logging.handlers import SMTPHandler
        mail_handler = SMTPHandler(mailhost=info['smtp_host'],
                fromaddr=info['from_addr'], toaddrs=[info['to_addr']],
                subject='Docker registry exception',
                credentials=(info['smtp_login'], info['smtp_password']))
        mail_handler.setLevel(logging.ERROR)
        app.logger.addHandler(mail_handler)
示例#7
0
def init():
    # Configure the secret key
    if cfg.secret_key:
        flask.Flask.secret_key = cfg.secret_key
    else:
        flask.Flask.secret_key = toolkit.gen_random_string(64)
    # Set the session duration time to 1 hour
    flask.Flask.permanent_session_lifetime = datetime.timedelta(seconds=3600)
    # Configure the email exceptions
    info = cfg.email_exceptions
    if info:
        mail_handler = logging.handlers.SMTPHandler(
            mailhost=info['smtp_host'],
            fromaddr=info['from_addr'],
            toaddrs=[info['to_addr']],
            subject='Docker registry exception',
            credentials=(info['smtp_login'],
                         info['smtp_password']))
        mail_handler.setLevel(logging.ERROR)
        app.logger.addHandler(mail_handler)
示例#8
0
def init():
    # Configure the secret key
    if cfg.secret_key:
        flask.Flask.secret_key = cfg.secret_key
    else:
        flask.Flask.secret_key = toolkit.gen_random_string(64)
    # Configure the email exceptions
    info = cfg.email_exceptions
    if info:
        mailhost = info['smtp_host']
        mailport = info.get('smtp_port')
        if mailport:
            mailhost = (mailhost, mailport)
        smtp_secure = info.get('smtp_secure', None)
        secure_args = _adapt_smtp_secure(smtp_secure)
        mail_handler = logging.handlers.SMTPHandler(
            mailhost=mailhost,
            fromaddr=info['from_addr'],
            toaddrs=[info['to_addr']],
            subject='Docker registry exception',
            credentials=(info['smtp_login'],
                         info['smtp_password']),
            secure=secure_args)
        mail_handler.setLevel(logging.ERROR)
        app.logger.addHandler(mail_handler)
    # Configure bugsnag
    info = cfg.bugsnag
    if info:
        if not bugsnag:
            raise _bugsnag_import_error
        root_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                                 '..'))
        bugsnag.configure(api_key=info,
                          project_root=root_path,
                          release_stage=cfg.flavor,
                          notify_release_stages=[cfg.flavor],
                          app_version=VERSION
                          )
        bugsnag.flask.handle_exceptions(app)
示例#9
0
def init():
    # Configure the secret key
    if cfg.secret_key:
        Flask.secret_key = cfg.secret_key
    else:
        Flask.secret_key = gen_random_string(64)
    # Set the session duration time to 1 hour
    Flask.permanent_session_lifetime = datetime.timedelta(seconds=3600)
    # Configure the email exceptions
    info = cfg.email_exceptions
    if info:
        import logging
        from logging.handlers import SMTPHandler

        mail_handler = SMTPHandler(
            mailhost=info["smtp_host"],
            fromaddr=info["from_addr"],
            toaddrs=[info["to_addr"]],
            subject="Docker registry exception",
            credentials=(info["smtp_login"], info["smtp_password"]),
        )
        mail_handler.setLevel(logging.ERROR)
        app.logger.addHandler(mail_handler)
示例#10
0
def init():
    # Configure the secret key
    if cfg.secret_key:
        flask.Flask.secret_key = cfg.secret_key
    else:
        flask.Flask.secret_key = toolkit.gen_random_string(64)
    # Configure the email exceptions
    info = cfg.email_exceptions
    if info:
        mailhost = info['smtp_host']
        mailport = info.get('smtp_port')
        if mailport:
            mailhost = (mailhost, mailport)
        smtp_secure = info.get('smtp_secure', None)
        secure_args = _adapt_smtp_secure(smtp_secure)
        mail_handler = logging.handlers.SMTPHandler(
            mailhost=mailhost,
            fromaddr=info['from_addr'],
            toaddrs=[info['to_addr']],
            subject='Docker registry exception',
            credentials=(info['smtp_login'], info['smtp_password']),
            secure=secure_args)
        mail_handler.setLevel(logging.ERROR)
        app.logger.addHandler(mail_handler)