Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass parameters to decorators #14

Open
ed-sparkes opened this issue Dec 3, 2019 · 0 comments
Open

pass parameters to decorators #14

ed-sparkes opened this issue Dec 3, 2019 · 0 comments

Comments

@ed-sparkes
Copy link

Hi is there a way to define a decorator with paramaters like the CORS one.

Many thanks for help and thoughts, not sure if i am just not understanding the syntax to use or its not possible,

I have two use cases.

  1. On exception be able to define a friendly message per handler for error responses
@on_exception
def handle_errors(exception,friendlyMesssage="Something went wrong"):
    print(exception)
    return {'statusCode': 500, 'body':friendlyMesssage}

@handle_errors(friendlyMesssage="Failed to get something")
def getSomething(event, context):
   #do something
  1. On before - i am writing a middleware to implenent RBAC (role based access control) and want o provide the list of permissions required to call the function
@before
def rbac(event, context,permissions=[]):
    print(f'required permissions {" ".join(str(x) for x in permissions)}')
    # actually do the validation

@rbac(permissions=["get:dogs","put:badgers"])
def getSomething(event, context):
   #do something
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant