Skip to content

Instantly share code, notes, and snippets.

@radiaph
Last active January 21, 2021 21:53
Show Gist options
  • Save radiaph/fdeed3c40e6ce919815b2609ad185724 to your computer and use it in GitHub Desktop.
Save radiaph/fdeed3c40e6ce919815b2609ad185724 to your computer and use it in GitHub Desktop.
Spitball for combined ingest/overlay auth decorator
from functools import wraps
import flask
import flask_restplus
from disco.collections.common.model.auth_resource import AuthResource
from disco.collections.common.model.tenant.flowtype import FlowType
from disco.collections.webserver.api import auth
def _flow_type_specific_auth(permission):
def decorator(endpoint):
@wraps(endpoint)
def wrapped(self, *args, **kwargs):
params = flask.request.get_json()
flow_type = FlowType[params['flowType']]
resource = AuthResource.OVERLAY if flow_type.is_overlay else AuthResource.INGEST
return auth.either(permission, resource)(endpoint)(self, *args, **kwargs)
return wrapped
return decorator
def install(api, path):
@api.route(path + '/<string:tenant_id>')
class FlowCreateResource(flask_restplus.Resource):
@_flow_type_specific_auth('manage')
def post(self, tenant_id):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment