def __call__()

in src/aws_secretsmanager_caching/decorators.py [0:0]


    def __call__(self, func):
        """
        Return a function with cached secret injected as first argument.

        :type func: object
        :param func: The function for injecting a single non-keyworded argument too.
        :return The function with the injected argument.
        """

        # Using functools.wraps preserves the metadata of the wrapped function
        @wraps(func)
        def _wrapped_func(*args, **kwargs):
            """
            Internal function to execute wrapped function
            """
            secret = self.cache.get_secret_string(secret_id=self.secret_id)

            # Prevent clobbering self arg in class methods
            if args and hasattr(args[0].__class__, func.__name__):
                new_args = (args[0], secret) + args[1:]
            else:
                new_args = (secret,) + args

            return func(*new_args, **kwargs)

        return _wrapped_func