runway.cfngin.lookups.handlers.split module
Split lookup.
- class runway.cfngin.lookups.handlers.split.SplitLookup[source]
Bases:
runway.lookups.handlers.base.LookupHandler
Split lookup.
- TYPE_NAME: Final[typing_extensions.Literal[split]] = 'split'
Name that the Lookup is registered as.
- __init__()
- __new__(**kwargs)
- classmethod dependencies(_LookupHandler__lookup_query: VariableValue) Set[str]
Calculate any dependencies required to perform this lookup.
Note that lookup_query may not be (completely) resolved at this time.
- classmethod format_results(value: Any, get: Optional[str] = None, load: Optional[str] = None, transform: Optional[typing_extensions.Literal[bool, str]] = None, **kwargs: Any) Any
Format results to be returned by a lookup.
- Parameters
value – Data collected by the Lookup.
get – Nested value to get from a dictionary like object.
load – Parser to use to parse a formatted string before the
get
andtransform
method.transform – Convert the final value to a different data type before returning it.
- Raises
TypeError – If
get
is provided but the value value is not a dictionary like object.
Runs the following actions in order:
load()
ifload
is provided.runway.util.MutableMap.find()
ordict.get()
depending on the data type ifget
is provided.Convert null value string to
NoneType
object. This includes string values of “None” and “null”. This conversion is case insensitive.transform()
iftransform
is provided.
- classmethod handle(value: str, **_: Any) List[str] [source]
Split the supplied string on the given delimiter, providing a list.
- Parameters
value – Parameter(s) given to this lookup.
Format of value:
<delimiter>::<value>
Example
Subnets: ${split ,::subnet-1,subnet-2,subnet-3}
Would result in the variable Subnets getting a list consisting of:
["subnet-1", "subnet-2", "subnet-3"]
This is particularly useful when getting an output from another stack that contains a list. For example, the standard vpc blueprint outputs the list of Subnets it creates as a pair of Outputs (
PublicSubnets
,PrivateSubnets
) that are comma separated, so you could use this in your config:Subnets: ${split ,::${output vpc.PrivateSubnets}}
- classmethod load(value: Any, parser: Optional[str] = None, **kwargs: Any) Any
Load a formatted string or object into a python data type.
First action taken in
format_results()
. If a lookup needs to handling loading data to process it before it entersformat_results()
, is should useargs.pop('load')
to prevent the data from being loaded twice.- Parameters
value – What is being loaded.
parser – Name of the parser to use.
- Returns
The loaded value.
- classmethod parse(value: str) Tuple[str, Dict[str, str]]
Parse the value passed to a lookup in a standardized way.
- Parameters
value – The raw value passed to a lookup.
- Returns
The lookup query and a dict of arguments
- classmethod transform(value: Any, *, to_type: Optional[typing_extensions.Literal[bool, str]] = 'str', **kwargs: Any) Any
Transform the result of a lookup into another datatype.
Last action taken in
format_results()
. If a lookup needs to handling transforming the data in a way that the base class can’t support it should overwrite this method of the base class to register different transform methods.- Parameters
value – What is to be transformed.
to_type – The type the value will be transformed into.
- Returns
The transformed value.