Merge pull request #1126 from coreos-inc/torrentfixes
Various fixes for the torrent feature branch
This commit is contained in:
commit
7d67fd2c86
8 changed files with 60 additions and 52 deletions
|
@ -18,7 +18,7 @@ from endpoints.api import (truthy_bool, format_date, nickname, log_action, valid
|
||||||
request_error, require_scope, Unauthorized, NotFound, InvalidRequest,
|
request_error, require_scope, Unauthorized, NotFound, InvalidRequest,
|
||||||
path_param, ExceedsLicenseException)
|
path_param, ExceedsLicenseException)
|
||||||
from endpoints.api.billing import lookup_allowed_private_repos, get_namespace_plan
|
from endpoints.api.billing import lookup_allowed_private_repos, get_namespace_plan
|
||||||
from endpoints.common import check_repository_usage
|
from endpoints.api.subscribe import check_repository_usage
|
||||||
|
|
||||||
from auth.permissions import (ModifyRepositoryPermission, AdministerRepositoryPermission,
|
from auth.permissions import (ModifyRepositoryPermission, AdministerRepositoryPermission,
|
||||||
CreateRepositoryPermission)
|
CreateRepositoryPermission)
|
||||||
|
|
|
@ -5,7 +5,6 @@ import stripe
|
||||||
|
|
||||||
from app import billing
|
from app import billing
|
||||||
from endpoints.api import request_error, log_action, NotFound
|
from endpoints.api import request_error, log_action, NotFound
|
||||||
from endpoints.common import check_repository_usage
|
|
||||||
from data import model
|
from data import model
|
||||||
from data.billing import PLANS
|
from data.billing import PLANS
|
||||||
|
|
||||||
|
@ -15,6 +14,20 @@ import features
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def check_repository_usage(user_or_org, plan_found):
|
||||||
|
private_repos = model.user.get_private_repo_count(user_or_org.username)
|
||||||
|
if plan_found is None:
|
||||||
|
repos_allowed = 0
|
||||||
|
else:
|
||||||
|
repos_allowed = plan_found['privateRepos']
|
||||||
|
|
||||||
|
if private_repos > repos_allowed:
|
||||||
|
model.notification.create_unique_notification('over_private_usage', user_or_org,
|
||||||
|
{'namespace': user_or_org.username})
|
||||||
|
else:
|
||||||
|
model.notification.delete_notifications_by_kind(user_or_org, 'over_private_usage')
|
||||||
|
|
||||||
|
|
||||||
def carderror_response(exc):
|
def carderror_response(exc):
|
||||||
return {'carderror': exc.message}, 402
|
return {'carderror': exc.message}, 402
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,10 @@ from flask.ext.principal import identity_changed
|
||||||
from random import SystemRandom
|
from random import SystemRandom
|
||||||
from cachetools import lru_cache
|
from cachetools import lru_cache
|
||||||
|
|
||||||
from data import model
|
|
||||||
from app import app, oauth_apps, LoginWrappedDBUser
|
from app import app, oauth_apps, LoginWrappedDBUser
|
||||||
|
|
||||||
from auth.permissions import QuayDeferredPermissionUser
|
from auth.permissions import QuayDeferredPermissionUser
|
||||||
from auth import scopes
|
from auth import scopes
|
||||||
from endpoints.api.discovery import swagger_route_data
|
|
||||||
from werkzeug.routing import BaseConverter
|
from werkzeug.routing import BaseConverter
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from config import frontend_visible_config
|
from config import frontend_visible_config
|
||||||
|
@ -79,15 +77,6 @@ def route_hide_if(value):
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
def get_route_data():
|
|
||||||
global route_data
|
|
||||||
if route_data:
|
|
||||||
return route_data
|
|
||||||
|
|
||||||
route_data = swagger_route_data(include_internal=True, compact=True)
|
|
||||||
return route_data
|
|
||||||
|
|
||||||
|
|
||||||
def truthy_param(param):
|
def truthy_param(param):
|
||||||
return param not in {False, 'false', 'False', '0', 'FALSE', '', 'null'}
|
return param not in {False, 'false', 'False', '0', 'FALSE', '', 'null'}
|
||||||
|
|
||||||
|
@ -139,7 +128,7 @@ def _get_version_number():
|
||||||
except IOError:
|
except IOError:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def render_page_template(name, **kwargs):
|
def render_page_template(name, route_data=None, **kwargs):
|
||||||
debugging = app.config.get('DEBUGGING', False)
|
debugging = app.config.get('DEBUGGING', False)
|
||||||
if debugging:
|
if debugging:
|
||||||
# If DEBUGGING is enabled, then we load the full set of individual JS and CSS files
|
# If DEBUGGING is enabled, then we load the full set of individual JS and CSS files
|
||||||
|
@ -187,7 +176,7 @@ def render_page_template(name, **kwargs):
|
||||||
version_number = ' - ' + _get_version_number()
|
version_number = ' - ' + _get_version_number()
|
||||||
|
|
||||||
resp = make_response(render_template(name,
|
resp = make_response(render_template(name,
|
||||||
route_data=json.dumps(get_route_data()),
|
route_data=json.dumps(route_data),
|
||||||
external_styles=external_styles,
|
external_styles=external_styles,
|
||||||
external_scripts=external_scripts,
|
external_scripts=external_scripts,
|
||||||
main_styles=add_cachebusters(main_styles),
|
main_styles=add_cachebusters(main_styles),
|
||||||
|
@ -214,17 +203,3 @@ def render_page_template(name, **kwargs):
|
||||||
resp.headers['X-FRAME-OPTIONS'] = 'DENY'
|
resp.headers['X-FRAME-OPTIONS'] = 'DENY'
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
def check_repository_usage(user_or_org, plan_found):
|
|
||||||
private_repos = model.user.get_private_repo_count(user_or_org.username)
|
|
||||||
if plan_found is None:
|
|
||||||
repos_allowed = 0
|
|
||||||
else:
|
|
||||||
repos_allowed = plan_found['privateRepos']
|
|
||||||
|
|
||||||
if private_repos > repos_allowed:
|
|
||||||
model.notification.create_unique_notification('over_private_usage', user_or_org,
|
|
||||||
{'namespace': user_or_org.username})
|
|
||||||
else:
|
|
||||||
model.notification.delete_notifications_by_kind(user_or_org, 'over_private_usage')
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@ import requests
|
||||||
from flask import request, redirect, url_for, Blueprint
|
from flask import request, redirect, url_for, Blueprint
|
||||||
from flask.ext.login import current_user
|
from flask.ext.login import current_user
|
||||||
|
|
||||||
from endpoints.common import render_page_template, common_login, route_show_if
|
from endpoints.common import common_login, route_show_if
|
||||||
|
from endpoints.web import render_page_template_with_routedata
|
||||||
from app import app, analytics, get_app_url, github_login, google_login, dex_login
|
from app import app, analytics, get_app_url, github_login, google_login, dex_login
|
||||||
from data import model
|
from data import model
|
||||||
from util.names import parse_repository_name
|
from util.names import parse_repository_name
|
||||||
|
@ -22,10 +23,12 @@ oauthlogin = Blueprint('oauthlogin', __name__)
|
||||||
|
|
||||||
def render_ologin_error(service_name,
|
def render_ologin_error(service_name,
|
||||||
error_message='Could not load user data. The token may have expired.'):
|
error_message='Could not load user data. The token may have expired.'):
|
||||||
return render_page_template('ologinerror.html', service_name=service_name,
|
user_creation = features.USER_CREATION and features.DIRECT_LOGIN
|
||||||
|
return render_page_template_with_routedata('ologinerror.html',
|
||||||
|
service_name=service_name,
|
||||||
error_message=error_message,
|
error_message=error_message,
|
||||||
service_url=get_app_url(),
|
service_url=get_app_url(),
|
||||||
user_creation=features.USER_CREATION and features.DIRECT_LOGIN)
|
user_creation=user_creation)
|
||||||
|
|
||||||
|
|
||||||
def get_user(service, token):
|
def get_user(service, token):
|
||||||
|
|
|
@ -24,6 +24,7 @@ from buildtrigger.customhandler import CustomBuildTrigger
|
||||||
from buildtrigger.triggerutil import TriggerProviderException
|
from buildtrigger.triggerutil import TriggerProviderException
|
||||||
from data import model
|
from data import model
|
||||||
from data.database import db
|
from data.database import db
|
||||||
|
from endpoints.api.discovery import swagger_route_data
|
||||||
from endpoints.common import common_login, render_page_template, route_show_if, param_required
|
from endpoints.common import common_login, render_page_template, route_show_if, param_required
|
||||||
from endpoints.csrf import csrf_protect, generate_csrf_token, verify_csrf
|
from endpoints.csrf import csrf_protect, generate_csrf_token, verify_csrf
|
||||||
from endpoints.decorators import anon_protect, anon_allowed
|
from endpoints.decorators import anon_protect, anon_allowed
|
||||||
|
@ -38,6 +39,20 @@ from util.useremails import send_email_changed
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
_route_data = None
|
||||||
|
|
||||||
|
def _get_route_data():
|
||||||
|
global _route_data
|
||||||
|
if _route_data:
|
||||||
|
return _route_data
|
||||||
|
|
||||||
|
_route_data = swagger_route_data(include_internal=True, compact=True)
|
||||||
|
return _route_data
|
||||||
|
|
||||||
|
|
||||||
|
def render_page_template_with_routedata(name, *args, **kwargs):
|
||||||
|
return render_page_template(name, _get_route_data(), *args, **kwargs)
|
||||||
|
|
||||||
# Capture the unverified SSL errors.
|
# Capture the unverified SSL errors.
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logging.captureWarnings(True)
|
logging.captureWarnings(True)
|
||||||
|
@ -51,17 +66,17 @@ JWT_ISSUER = app.config.get('JWT_AUTH_TOKEN_ISSUER')
|
||||||
@web.route('/', methods=['GET'], defaults={'path': ''})
|
@web.route('/', methods=['GET'], defaults={'path': ''})
|
||||||
@no_cache
|
@no_cache
|
||||||
def index(path, **kwargs):
|
def index(path, **kwargs):
|
||||||
return render_page_template('index.html', **kwargs)
|
return render_page_template_with_routedata('index.html', **kwargs)
|
||||||
|
|
||||||
|
|
||||||
@web.route('/500', methods=['GET'])
|
@web.route('/500', methods=['GET'])
|
||||||
def internal_error_display():
|
def internal_error_display():
|
||||||
return render_page_template('500.html')
|
return render_page_template_with_routedata('500.html')
|
||||||
|
|
||||||
@web.errorhandler(404)
|
@web.errorhandler(404)
|
||||||
@web.route('/404', methods=['GET'])
|
@web.route('/404', methods=['GET'])
|
||||||
def not_found_error_display(e = None):
|
def not_found_error_display(e = None):
|
||||||
resp = render_page_template('404.html')
|
resp = render_page_template_with_routedata('404.html')
|
||||||
resp.status_code = 404
|
resp.status_code = 404
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
@ -265,19 +280,19 @@ def dbrevision_health():
|
||||||
@web.route('/tos', methods=['GET'])
|
@web.route('/tos', methods=['GET'])
|
||||||
@no_cache
|
@no_cache
|
||||||
def tos():
|
def tos():
|
||||||
return render_page_template('tos.html')
|
return render_page_template_with_routedata('tos.html')
|
||||||
|
|
||||||
|
|
||||||
@web.route('/disclaimer', methods=['GET'])
|
@web.route('/disclaimer', methods=['GET'])
|
||||||
@no_cache
|
@no_cache
|
||||||
def disclaimer():
|
def disclaimer():
|
||||||
return render_page_template('disclaimer.html')
|
return render_page_template_with_routedata('disclaimer.html')
|
||||||
|
|
||||||
|
|
||||||
@web.route('/privacy', methods=['GET'])
|
@web.route('/privacy', methods=['GET'])
|
||||||
@no_cache
|
@no_cache
|
||||||
def privacy():
|
def privacy():
|
||||||
return render_page_template('privacy.html')
|
return render_page_template_with_routedata('privacy.html')
|
||||||
|
|
||||||
|
|
||||||
@web.route('/robots.txt', methods=['GET'])
|
@web.route('/robots.txt', methods=['GET'])
|
||||||
|
@ -352,7 +367,7 @@ def confirm_repo_email():
|
||||||
try:
|
try:
|
||||||
record = model.repository.confirm_email_authorization_for_repo(code)
|
record = model.repository.confirm_email_authorization_for_repo(code)
|
||||||
except model.DataModelException as ex:
|
except model.DataModelException as ex:
|
||||||
return render_page_template('confirmerror.html', error_message=ex.message)
|
return render_page_template_with_routedata('confirmerror.html', error_message=ex.message)
|
||||||
|
|
||||||
message = """
|
message = """
|
||||||
Your E-mail address has been authorized to receive notifications for repository
|
Your E-mail address has been authorized to receive notifications for repository
|
||||||
|
@ -361,7 +376,7 @@ def confirm_repo_email():
|
||||||
record.repository.namespace_user.username, record.repository.name,
|
record.repository.namespace_user.username, record.repository.name,
|
||||||
record.repository.namespace_user.username, record.repository.name)
|
record.repository.namespace_user.username, record.repository.name)
|
||||||
|
|
||||||
return render_page_template('message.html', message=message)
|
return render_page_template_with_routedata('message.html', message=message)
|
||||||
|
|
||||||
|
|
||||||
@web.route('/confirm', methods=['GET'])
|
@web.route('/confirm', methods=['GET'])
|
||||||
|
@ -375,7 +390,7 @@ def confirm_email():
|
||||||
try:
|
try:
|
||||||
user, new_email, old_email = model.user.confirm_user_email(code)
|
user, new_email, old_email = model.user.confirm_user_email(code)
|
||||||
except model.DataModelException as ex:
|
except model.DataModelException as ex:
|
||||||
return render_page_template('confirmerror.html', error_message=ex.message)
|
return render_page_template_with_routedata('confirmerror.html', error_message=ex.message)
|
||||||
|
|
||||||
if new_email:
|
if new_email:
|
||||||
send_email_changed(user.username, old_email, new_email)
|
send_email_changed(user.username, old_email, new_email)
|
||||||
|
@ -467,9 +482,9 @@ def oauth_local_handler():
|
||||||
return
|
return
|
||||||
|
|
||||||
if not request.args.get('scope'):
|
if not request.args.get('scope'):
|
||||||
return render_page_template("message.html", message="Authorization canceled")
|
return render_page_template_with_routedata("message.html", message="Authorization canceled")
|
||||||
else:
|
else:
|
||||||
return render_page_template("generatedtoken.html")
|
return render_page_template_with_routedata("generatedtoken.html")
|
||||||
|
|
||||||
|
|
||||||
@web.route('/oauth/denyapp', methods=['POST'])
|
@web.route('/oauth/denyapp', methods=['POST'])
|
||||||
|
@ -533,7 +548,7 @@ def request_authorization_code():
|
||||||
|
|
||||||
# Show the authorization page.
|
# Show the authorization page.
|
||||||
has_dangerous_scopes = any([check_scope['dangerous'] for check_scope in scope_info])
|
has_dangerous_scopes = any([check_scope['dangerous'] for check_scope in scope_info])
|
||||||
return render_page_template('oauthorize.html', scopes=scope_info,
|
return render_page_template_with_routedata('oauthorize.html', scopes=scope_info,
|
||||||
has_dangerous_scopes=has_dangerous_scopes,
|
has_dangerous_scopes=has_dangerous_scopes,
|
||||||
application=oauth_app_view,
|
application=oauth_app_view,
|
||||||
enumerate=enumerate, client_id=client_id,
|
enumerate=enumerate, client_id=client_id,
|
||||||
|
|
|
@ -59,3 +59,4 @@ jsonpath-rw
|
||||||
bintrees
|
bintrees
|
||||||
redlock
|
redlock
|
||||||
semantic-version
|
semantic-version
|
||||||
|
bencode
|
|
@ -4,6 +4,7 @@ APScheduler==3.0.3
|
||||||
autobahn==0.9.3-3
|
autobahn==0.9.3-3
|
||||||
Babel==1.3
|
Babel==1.3
|
||||||
beautifulsoup4==4.4.0
|
beautifulsoup4==4.4.0
|
||||||
|
bencode==1.0
|
||||||
bintrees==2.0.3
|
bintrees==2.0.3
|
||||||
blinker==1.3
|
blinker==1.3
|
||||||
boto==2.38.0
|
boto==2.38.0
|
||||||
|
|
|
@ -56,7 +56,7 @@ class ImageStoragePlacement(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
def image_json_path(storage_uuid):
|
def image_json_path(storage_uuid):
|
||||||
base_path = storage.image_path(storage_uuid)
|
base_path = storage._image_path(storage_uuid)
|
||||||
return '{0}json'.format(base_path)
|
return '{0}json'.format(base_path)
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue