From fc55730db8c4d97b2a49dfcbc91397ef9298975c Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Mon, 26 Oct 2015 12:14:31 -0400 Subject: [PATCH] Add a feature flag to advertise v2 endpoints --- config.py | 3 +++ endpoints/v2/__init__.py | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index e4061b16c..76601e5ae 100644 --- a/config.py +++ b/config.py @@ -189,6 +189,9 @@ class DefaultConfig(object): # Feature Flag: Whether users can directly login to the UI. FEATURE_DIRECT_LOGIN = True + # Feature Flag: Whether the v2/ endpoint is visible + FEATURE_ADVERTISE_V2 = True + BUILD_MANAGER = ('enterprise', {}) DISTRIBUTED_STORAGE_CONFIG = { diff --git a/endpoints/v2/__init__.py b/endpoints/v2/__init__.py index 837b4ac51..cee31aab3 100644 --- a/endpoints/v2/__init__.py +++ b/endpoints/v2/__init__.py @@ -6,7 +6,8 @@ import logging from flask import Blueprint, make_response, url_for, request, jsonify from functools import wraps from urlparse import urlparse -from util import get_app_url + +import features from app import metric_queue from endpoints.decorators import anon_protect, anon_allowed @@ -18,6 +19,7 @@ from auth.permissions import (ReadRepositoryPermission, ModifyRepositoryPermissi from data import model from util.http import abort from util.saas.metricqueue import time_blueprint +from util import get_app_url from app import app @@ -62,7 +64,20 @@ def get_input_stream(flask_request): return flask_request.stream +# TODO remove when v2 is deployed everywhere +def route_show_if(value): + def decorator(f): + @wraps(f) + def decorated_function(*args, **kwargs): + if not value: + abort(404) + + return f(*args, **kwargs) + return decorated_function + return decorator + @v2_bp.route('/') +@route_show_if(features.ADVERTISE_V2) @process_jwt_auth @anon_allowed def v2_support_enabled(): @@ -86,4 +101,3 @@ from endpoints.v2 import manifest from endpoints.v2 import blob from endpoints.v2 import tag from endpoints.v2 import catalog -