aws_lambda_decorators/decorators.py
def validate(parameters, group_errors=False):
    """
    Validates a set of function parameters.

    Usage:
        @validate([ValidatedParameter(func_param_name="my_param", validators=[...])])
        def func(my_param)
            pass

    Args:
        parameters (list): A collection of ValidatedParameter type items.
        group_errors (bool): flag that indicates if error messages are to be grouped together
            (if set to False, validation will end on first error)
    """
    def decorator(func):
        def wrapper(*args, **kwargs):
            try:
                errors = []
                arg_dictionary = all_func_args(func, args, kwargs)
                for param in parameters:
                    param_val = arg_dictionary[param.func_param_name]
                    param_errors = param.validate(param_val, group_errors)
                    if param_errors:
                        errors.append({param.func_param_name: param_errors})
                        if not group_errors:
                            LOGGER.error(VALIDATE_ERROR_MESSAGE, errors)
                            return failure(errors)
            except Exception as ex:  # noqa: pylint - broad-except
                LOGGER.error(EXCEPTION_LOG_MESSAGE_PATHLESS, full_name(ex), str(ex), param.func_param_name)
                return failure(ERROR_MESSAGE)

            if group_errors and errors:
                LOGGER.error(VALIDATE_ERROR_MESSAGE, errors)
                return failure(errors)

            return func(*args, **kwargs)
        return wrapper
    return decorator

    Validates a set of function parameters.

    Usage:
        @validate([ValidatedParameter(func_param_name="my_param", validators=[...])])
        def func(my_param)
            pass

    Args:
        parameters (list): A collection of ValidatedParameter type items.
        group_errors (bool): flag that indicates if error messages are to be grouped together
            (if set to False, validation will end on first error)
    
Validates a set of function parameters.
Validates a set of function parameters .
def validate(parameters, group_errors=False):
    def decorator(func):
        def wrapper(*args, **kwargs):
            try:
                errors = []
                arg_dictionary = all_func_args(func, args, kwargs)
                for param in parameters:
                    param_val = arg_dictionary[param.func_param_name]
                    param_errors = param.validate(param_val, group_errors)
                    if param_errors:
                        errors.append({param.func_param_name: param_errors})
                        if not group_errors:
                            LOGGER.error(VALIDATE_ERROR_MESSAGE, errors)
                            return failure(errors)
            except Exception as ex:  
                LOGGER.error(EXCEPTION_LOG_MESSAGE_PATHLESS, full_name(ex), str(ex), param.func_param_name)
                return failure(ERROR_MESSAGE)
            if group_errors and errors:
                LOGGER.error(VALIDATE_ERROR_MESSAGE, errors)
                return failure(errors)
            return func(*args, **kwargs)
        return wrapper
    return decorator
def validate ( parameters , group_errors = False ) : def decorator ( func ) : def wrapper ( * args , ** kwargs ) : try : errors = [ ] arg_dictionary = all_func_args ( func , args , kwargs ) for param in parameters : param_val = arg_dictionary [ param . func_param_name ] param_errors = param . validate ( param_val , group_errors ) if param_errors : errors . append ( { param . func_param_name : param_errors } ) if not group_errors : LOGGER . error ( VALIDATE_ERROR_MESSAGE , errors ) return failure ( errors ) except Exception as ex : LOGGER . error ( EXCEPTION_LOG_MESSAGE_PATHLESS , full_name ( ex ) , str ( ex ) , param . func_param_name ) return failure ( ERROR_MESSAGE ) if group_errors and errors : LOGGER . error ( VALIDATE_ERROR_MESSAGE , errors ) return failure ( errors ) return func ( * args , ** kwargs ) return wrapper return decorator
Validates a set of function parameters.
Validates a set of function parameters .
"""
    Validates a set of function parameters.

    Usage:
        @validate([ValidatedParameter(func_param_name="my_param", validators=[...])])
        def func(my_param)
            pass

    Args:
        parameters (list): A collection of ValidatedParameter type items.
        group_errors (bool): flag that indicates if error messages are to be grouped together
            (if set to False, validation will end on first error)
    """ # noqa: pylint - broad-except
parameters
A collection of ValidatedParameter type items.
A collection of ValidatedParameter type items .
group_errors
flag that indicates if error messages are to be grouped together
(if set to False, validation will end on first error)
flag that indicates if error messages are to be grouped together ( if set to False validation will end on first error )