runway.cfngin.lookups.handlers.xref module

Handler for fetching outputs from fully qualified stacks.

class runway.cfngin.lookups.handlers.xref.XrefLookup[source]

Bases: runway.lookups.handlers.base.LookupHandler

Xref lookup.

TYPE_NAME: Final[Literal['xref']] = 'xref'

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[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 and transform 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:

  1. load() if load is provided.

  2. runway.util.MutableMap.find() or dict.get() depending on the data type if get is provided.

  3. Convert null value string to NoneType object. This includes string values of “None” and “null”. This conversion is case insensitive.

  4. transform() if transform is provided.

classmethod handle(value: str, provider: Provider, **_: Any) str[source]

Fetch an output from the designated, fully qualified stack.

The output handler supports fetching outputs from stacks created within a single config file. Sometimes it’s useful to fetch outputs from stacks created outside of the current config file. xref supports this by not using the runway.context.CfnginContext to expand the fqn of the stack.

Parameters
  • value – Parameter(s) given to this lookup. <stack_name>::<output_name>

  • provider – Provider instance.

Returns

Output from the specified stack.

Example

conf_value: ${xref fully-qualified-stack-name::SomeOutputName}
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 enters format_results(), is should use args.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[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.