stacker/blueprints/base.py
def resolve_variable(var_name, var_def, provided_variable, blueprint_name):
    """Resolve a provided variable value against the variable definition.

    Args:
        var_name (str): The name of the defined variable on a blueprint.
        var_def (dict): A dictionary representing the defined variables
            attributes.
        provided_variable (:class:`stacker.variables.Variable`): The variable
            value provided to the blueprint.
        blueprint_name (str): The name of the blueprint that the variable is
            being applied to.

    Returns:
        object: The resolved variable value, could be any python object.

    Raises:
        MissingVariable: Raised when a variable with no default is not
            provided a value.
        UnresolvedVariable: Raised when the provided variable is not already
            resolved.
        ValueError: Raised when the value is not the right type and cannot be
            cast as the correct type. Raised by
            :func:`stacker.blueprints.base.validate_variable_type`
        ValidatorError: Raised when a validator raises an exception. Wraps the
            original exception.
    """

    try:
        var_type = var_def["type"]
    except KeyError:
        raise VariableTypeRequired(blueprint_name, var_name)

    if provided_variable:
        if not provided_variable.resolved:
            raise UnresolvedVariable(blueprint_name, provided_variable)

        value = provided_variable.value
    else:
        # Variable value not provided, try using the default, if it exists
        # in the definition
        try:
            value = var_def["default"]
        except KeyError:
            raise MissingVariable(blueprint_name, var_name)

    # If no validator, return the value as is, otherwise apply validator
    validator = var_def.get("validator", lambda v: v)
    try:
        value = validator(value)
    except Exception as exc:
        raise ValidatorError(var_name, validator.__name__, value, exc)

    # Ensure that the resulting value is the correct type
    value = validate_variable_type(var_name, var_type, value)

    allowed_values = var_def.get("allowed_values")
    if not validate_allowed_values(allowed_values, value):
        message = (
            "Invalid value passed to '%s' in blueprint: %s. Got: '%s', "
            "expected one of %s"
        ) % (var_name, blueprint_name, value, allowed_values)
        raise ValueError(message)

    return value
Resolve a provided variable value against the variable definition.

    Args:
        var_name (str): The name of the defined variable on a blueprint.
        var_def (dict): A dictionary representing the defined variables
            attributes.
        provided_variable (:class:`stacker.variables.Variable`): The variable
            value provided to the blueprint.
        blueprint_name (str): The name of the blueprint that the variable is
            being applied to.

    Returns:
        object: The resolved variable value, could be any python object.

    Raises:
        MissingVariable: Raised when a variable with no default is not
            provided a value.
        UnresolvedVariable: Raised when the provided variable is not already
            resolved.
        ValueError: Raised when the value is not the right type and cannot be
            cast as the correct type. Raised by
            :func:`stacker.blueprints.base.validate_variable_type`
        ValidatorError: Raised when a validator raises an exception. Wraps the
            original exception.
    
Resolve a provided variable value against the variable definition.
Resolve a provided variable value against the variable definition .
def resolve_variable(var_name, var_def, provided_variable, blueprint_name):
    try:
        var_type = var_def["type"]
    except KeyError:
        raise VariableTypeRequired(blueprint_name, var_name)
    if provided_variable:
        if not provided_variable.resolved:
            raise UnresolvedVariable(blueprint_name, provided_variable)
        value = provided_variable.value
    else:
        try:
            value = var_def["default"]
        except KeyError:
            raise MissingVariable(blueprint_name, var_name)
    validator = var_def.get("validator", lambda v: v)
    try:
        value = validator(value)
    except Exception as exc:
        raise ValidatorError(var_name, validator.__name__, value, exc)
    value = validate_variable_type(var_name, var_type, value)
    allowed_values = var_def.get("allowed_values")
    if not validate_allowed_values(allowed_values, value):
        message = (
            "Invalid value passed to '%s' in blueprint: %s. Got: '%s', "
            "expected one of %s"
        ) % (var_name, blueprint_name, value, allowed_values)
        raise ValueError(message)
    return value
def resolve_variable ( var_name , var_def , provided_variable , blueprint_name ) : try : var_type = var_def [ "type" ] except KeyError : raise VariableTypeRequired ( blueprint_name , var_name ) if provided_variable : if not provided_variable . resolved : raise UnresolvedVariable ( blueprint_name , provided_variable ) value = provided_variable . value else : try : value = var_def [ "default" ] except KeyError : raise MissingVariable ( blueprint_name , var_name ) validator = var_def . get ( "validator" , lambda v : v ) try : value = validator ( value ) except Exception as exc : raise ValidatorError ( var_name , validator . __name__ , value , exc ) value = validate_variable_type ( var_name , var_type , value ) allowed_values = var_def . get ( "allowed_values" ) if not validate_allowed_values ( allowed_values , value ) : message = ( "Invalid value passed to '%s' in blueprint: %s. Got: '%s', " "expected one of %s" ) % ( var_name , blueprint_name , value , allowed_values ) raise ValueError ( message ) return value
Resolve a provided variable value against the variable definition.
Resolve a provided variable value against the variable definition .
"""Resolve a provided variable value against the variable definition.

    Args:
        var_name (str): The name of the defined variable on a blueprint.
        var_def (dict): A dictionary representing the defined variables
            attributes.
        provided_variable (:class:`stacker.variables.Variable`): The variable
            value provided to the blueprint.
        blueprint_name (str): The name of the blueprint that the variable is
            being applied to.

    Returns:
        object: The resolved variable value, could be any python object.

    Raises:
        MissingVariable: Raised when a variable with no default is not
            provided a value.
        UnresolvedVariable: Raised when the provided variable is not already
            resolved.
        ValueError: Raised when the value is not the right type and cannot be
            cast as the correct type. Raised by
            :func:`stacker.blueprints.base.validate_variable_type`
        ValidatorError: Raised when a validator raises an exception. Wraps the
            original exception.
    """ # Variable value not provided, try using the default, if it exists # in the definition # If no validator, return the value as is, otherwise apply validator # Ensure that the resulting value is the correct type
The resolved variable value, could be any python object.
The resolved variable value could be any python object .
object
Raised when a variable with no default is not
provided a value.
Raised when a variable with no default is not provided a value .
MissingVariable
Raised when the provided variable is not already
resolved.
Raised when the provided variable is not already resolved .
UnresolvedVariable
Raised when the value is not the right type and cannot be
cast as the correct type. Raised by
:func:`stacker.blueprints.base.validate_variable_type`
Raised when the value is not the right type and cannot be cast as the correct type . Raised by : func : ` stacker . blueprints . base . validate_variable_type `
ValueError
Raised when a validator raises an exception. Wraps the
original exception.
Raised when a validator raises an exception . Wraps the original exception .
ValidatorError
var_name
The name of the defined variable on a blueprint.
The name of the defined variable on a blueprint .
var_def
A dictionary representing the defined variables
attributes.
A dictionary representing the defined variables attributes .
provided_variable
blueprint_name
The name of the blueprint that the variable is
being applied to.
The name of the blueprint that the variable is being applied to .
provided_variable (
`stacker.variables.Variable`): The variable
value provided to the blueprint.
` stacker . variables . Variable ` ) : The variable value provided to the blueprint .