So I tried to write a decorator function to secure the access to a function with a "password string" auth. The decorator function looks like this:
from functools import wraps
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
if "auth" in kwargs.keys():
if kwargs["auth"] == "12345":
func(*args, **kwargs)
return
print("Not authorized.")
return wrapper
The definition of the example function I want to secure looks like this:
@decorator
def add(list, elem, auth):
list.append(elem)
In my main code, I am calling add() like this:
def main():
lst = [3,5]
add(lst, 2, auth="12345")
print(lst)
if __name__ == "__main__":
main()
My goal is to be able to do this, without explicitly mentioning auth in add()'s definition, so I can just do this:
@decorator
def add(list, elem):
list.append(elem)
Is this even possible?