From 41ac9019c6574d7ba0828fc6b222efd557e691f9 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 20 Jul 2017 13:46:20 -0400 Subject: [PATCH] Small formatting improvements to common --- endpoints/common.py | 75 +++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/endpoints/common.py b/endpoints/common.py index 96fe48069..79a06fa2f 100644 --- a/endpoints/common.py +++ b/endpoints/common.py @@ -2,9 +2,7 @@ import logging import datetime import os -from functools import wraps - -from flask import make_response, render_template, request, abort, session +from flask import make_response, render_template, request, session from flask_login import login_user from flask_principal import identity_changed @@ -26,6 +24,7 @@ logger = logging.getLogger(__name__) def common_login(db_user, permanent_session=True): + """ Performs login of the given user, with optional non-permanence on the session. """ if login_user(LoginWrappedDBUser(db_user.uuid, db_user)): logger.debug('Successfully signed in as: %s (%s)' % (db_user.username, db_user.uuid)) new_identity = QuayDeferredPermissionUser.for_user(db_user) @@ -63,10 +62,11 @@ def _list_files(path, extension): return os.path.join(dp, f)[len('static/'):] filepath = os.path.join('static/', path) - return [join_path(dp, f) for dp, dn, files in os.walk(filepath) for f in files if matches(f)] + return [join_path(dp, f) for dp, _, files in os.walk(filepath) for f in files if matches(f)] def render_page_template(name, route_data=None, **kwargs): + """ Renders the page template with the given name as the response and returns its contents. """ library_styles = [] main_styles = [] library_scripts = [] @@ -110,39 +110,40 @@ def render_page_template(name, route_data=None, **kwargs): if not features.BILLING: version_number = 'Quay %s' % __version__ - resp = make_response(render_template(name, - route_data=route_data, - external_styles=external_styles, - external_scripts=external_scripts, - main_styles=main_styles, - library_styles=library_styles, - main_scripts=main_scripts, - library_scripts=library_scripts, - feature_set=features.get_features(), - config_set=frontend_visible_config(app.config), - oauth_set=get_oauth_config(), - external_login_set=get_external_login_config(), - scope_set=scopes.app_scopes(app.config), - vuln_priority_set=PRIORITY_LEVELS, - enterprise_logo=app.config.get('ENTERPRISE_LOGO_URL', ''), - mixpanel_key=app.config.get('MIXPANEL_KEY', ''), - munchkin_key=app.config.get('MARKETO_MUNCHKIN_ID', ''), - recaptcha_key=app.config.get('RECAPTCHA_SITE_KEY', ''), - google_tagmanager_key=app.config.get('GOOGLE_TAGMANAGER_KEY', ''), - google_anaytics_key=app.config.get('GOOGLE_ANALYTICS_KEY', ''), - sentry_public_dsn=app.config.get('SENTRY_PUBLIC_DSN', ''), - is_debug=str(app.config.get('DEBUGGING', False)).lower(), - show_chat=features.SUPPORT_CHAT, - aci_conversion=features.ACI_CONVERSION, - has_billing=features.BILLING, - contact_href=contact_href, - hostname=app.config['SERVER_HOSTNAME'], - preferred_scheme=app.config['PREFERRED_URL_SCHEME'], - version_number=version_number, - license_insufficient=license_validator.insufficient, - license_expiring=license_validator.expiring_soon, - current_year=datetime.datetime.now().year, - **kwargs)) + contents = render_template(name, + route_data=route_data, + external_styles=external_styles, + external_scripts=external_scripts, + main_styles=main_styles, + library_styles=library_styles, + main_scripts=main_scripts, + library_scripts=library_scripts, + feature_set=features.get_features(), + config_set=frontend_visible_config(app.config), + oauth_set=get_oauth_config(), + external_login_set=get_external_login_config(), + scope_set=scopes.app_scopes(app.config), + vuln_priority_set=PRIORITY_LEVELS, + enterprise_logo=app.config.get('ENTERPRISE_LOGO_URL', ''), + mixpanel_key=app.config.get('MIXPANEL_KEY', ''), + munchkin_key=app.config.get('MARKETO_MUNCHKIN_ID', ''), + recaptcha_key=app.config.get('RECAPTCHA_SITE_KEY', ''), + google_tagmanager_key=app.config.get('GOOGLE_TAGMANAGER_KEY', ''), + google_anaytics_key=app.config.get('GOOGLE_ANALYTICS_KEY', ''), + sentry_public_dsn=app.config.get('SENTRY_PUBLIC_DSN', ''), + is_debug=str(app.config.get('DEBUGGING', False)).lower(), + show_chat=features.SUPPORT_CHAT, + aci_conversion=features.ACI_CONVERSION, + has_billing=features.BILLING, + contact_href=contact_href, + hostname=app.config['SERVER_HOSTNAME'], + preferred_scheme=app.config['PREFERRED_URL_SCHEME'], + version_number=version_number, + license_insufficient=license_validator.insufficient, + license_expiring=license_validator.expiring_soon, + current_year=datetime.datetime.now().year, + **kwargs) + resp = make_response(contents) resp.headers['X-FRAME-OPTIONS'] = 'DENY' return resp