Write a flask-restful version of cache-control. Remove the comments to add back in post methods.

This commit is contained in:
jakedt 2014-03-14 18:39:31 -04:00
parent 60015f0ae0
commit 092e236694
4 changed files with 18 additions and 5 deletions

View file

@ -6,7 +6,7 @@ from flask.ext.restful import abort
from app import app
from endpoints.api import resource, nickname, require_repo_read, RepositoryParamResource
from data import model
from util.cache import cache_control
from util.cache import cache_control_flask_restful
store = app.config['STORAGE']
@ -72,7 +72,7 @@ class RepositoryImage(RepositoryParamResource):
class RepositoryImageChanges(RepositoryParamResource):
""" Resource for handling repository image change lists. """
@cache_control(max_age=60*60) # Cache for one hour
@cache_control_flask_restful(max_age=60*60) # Cache for one hour
@require_repo_read
@nickname('getImageChanges')
def get(self, namespace, repository, image_id):

View file

@ -151,7 +151,7 @@ class RepositoryUserPermission(RepositoryParamResource):
'role': new_permission['role']},
repo=model.get_repository(namespace, repository))
return perm_view, 200 # 201 for post
return perm_view, 200
@require_repo_admin
@nickname('deleteUserPermissions')
@ -220,7 +220,7 @@ class RepositoryTeamPermission(RepositoryParamResource):
'role': new_permission['role']},
repo=model.get_repository(namespace, repository))
return role_view(perm), 200 # Should be 201 for post
return role_view(perm), 200
@require_repo_admin
@nickname('deleteTeamPermissions')

View file

@ -93,7 +93,7 @@ class OrganizationTeam(ApiResource):
get_authenticated_user().username)
log_action('org_set_team_role', orgname, {'team': teamname, 'role': details['role']})
return team_view(orgname, team), 200 # 201 for post
return team_view(orgname, team), 200
abort(403)

View file

@ -1,4 +1,5 @@
from functools import wraps
from flask.ext.restful.utils import unpack
def cache_control(max_age=55):
@ -12,6 +13,18 @@ def cache_control(max_age=55):
return wrap
def cache_control_flask_restful(max_age=55):
def wrap(f):
@wraps(f)
def add_max_age(*args, **kwargs):
response = f(*args, **kwargs)
body, status_code, headers = unpack(response)
headers['Cache-Control'] = 'max-age=%d' % max_age
return body, status_code, headers
return add_max_age
return wrap
def no_cache(f):
@wraps(f)
def add_no_cache(*args, **kwargs):