Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

pass parameters to decorators #14

Description

@ed-sparkes

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions