How to use the stacker.lookups.handlers.LookupHandler function in stacker

To help you get started, we’ve selected a few stacker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudtools / stacker / stacker / lookups / handlers / hook_data.py View on Github external
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

from . import LookupHandler


TYPE_NAME = "hook_data"


class HookDataLookup(LookupHandler):
    @classmethod
    def handle(cls, value, context, **kwargs):
        """Returns the value of a key for a given hook in hook_data.

        Format of value:

            ::
        """
        try:
            hook_name, key = value.split("::")
        except ValueError:
            raise ValueError("Invalid value for hook_data: %s. Must be in "
                             ":: format." % value)

        return context.hook_data[hook_name][key]
github cloudtools / stacker / stacker / lookups / handlers / rxref.py View on Github external
Example:

    conf_value: ${rxref
        some-relative-fully-qualified-stack-name::SomeOutputName}

"""
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from . import LookupHandler
from .output import deconstruct

TYPE_NAME = "rxref"


class RxrefLookup(LookupHandler):
    @classmethod
    def handle(cls, value, provider=None, context=None, **kwargs):
        """Fetch an output from the designated stack.

        Args:
            value (str): string with the following format:
                ::, ie. some-stack::SomeOutput
            provider (:class:`stacker.provider.base.BaseProvider`): subclass of
                the base provider
            context (:class:`stacker.context.Context`): stacker context

        Returns:
            str: output from the specified stack
        """

        if provider is None:
github cloudtools / stacker / stacker / lookups / handlers / output.py View on Github external
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

import re
from collections import namedtuple

from . import LookupHandler

TYPE_NAME = "output"

Output = namedtuple("Output", ("stack_name", "output_name"))


class OutputLookup(LookupHandler):
    @classmethod
    def handle(cls, value, context=None, **kwargs):
        """Fetch an output from the designated stack.

        Args:
            value (str): string with the following format:
                ::, ie. some-stack::SomeOutput
            context (:class:`stacker.context.Context`): stacker context

        Returns:
            str: output from the specified stack

        """

        if context is None:
            raise ValueError('Context is required')
github cloudtools / stacker / stacker / lookups / handlers / envvar.py View on Github external
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
import os

from . import LookupHandler
from ...util import read_value_from_path

TYPE_NAME = "envvar"


class EnvvarLookup(LookupHandler):
    @classmethod
    def handle(cls, value, **kwargs):
        """Retrieve an environment variable.

        For example:

            # In stacker we would reference the environment variable like this:
            conf_key: ${envvar ENV_VAR_NAME}

            You can optionally store the value in a file, ie:

            $ cat envvar_value.txt
            ENV_VAR_NAME

            and reference it within stacker (NOTE: the path should be relative
            to the stacker config file):
github cloudtools / stacker / stacker / lookups / handlers / kms.py View on Github external
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
import codecs
from stacker.session_cache import get_session

from . import LookupHandler
from ...util import read_value_from_path

TYPE_NAME = "kms"


class KmsLookup(LookupHandler):
    @classmethod
    def handle(cls, value, **kwargs):
        """Decrypt the specified value with a master key in KMS.

        kmssimple field types should be in the following format:

            [@]

        Note: The region is optional, and defaults to the environment's
        `AWS_DEFAULT_REGION` if not specified.

        For example:

            # We use the aws cli to get the encrypted value for the string
            # "PASSWORD" using the master key called "myStackerKey" in
            # us-east-1
github cloudtools / stacker / stacker / lookups / handlers / default.py View on Github external
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

from . import LookupHandler


TYPE_NAME = "default"


class DefaultLookup(LookupHandler):
    @classmethod
    def handle(cls, value, **kwargs):
        """Use a value from the environment or fall back to a default if the
           environment doesn't contain the variable.

        Format of value:

            ::

        For example:

            Groups: ${default app_security_groups::sg-12345,sg-67890}

        If `app_security_groups` is defined in the environment, its defined
        value will be returned. Otherwise, `sg-12345,sg-67890` will be the
        returned value.
github cloudtools / stacker / stacker / lookups / handlers / xref.py View on Github external
Example:

    conf_value: ${xref some-fully-qualified-stack-name::SomeOutputName}

"""
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from . import LookupHandler
from .output import deconstruct

TYPE_NAME = "xref"


class XrefLookup(LookupHandler):
    @classmethod
    def handle(cls, value, provider=None, **kwargs):
        """Fetch an output from the designated stack.

        Args:
            value (str): string with the following format:
                ::, ie. some-stack::SomeOutput
            provider (:class:`stacker.provider.base.BaseProvider`): subclass of
                the base provider

        Returns:
            str: output from the specified stack
        """

        if provider is None:
            raise ValueError('Provider is required')
github cloudtools / stacker / stacker / lookups / handlers / ami.py View on Github external
from . import LookupHandler
from ...util import read_value_from_path

TYPE_NAME = "ami"


class ImageNotFound(Exception):
    def __init__(self, search_string):
        self.search_string = search_string
        message = ("Unable to find ec2 image with search string: {}").format(
            search_string
        )
        super(ImageNotFound, self).__init__(message)


class AmiLookup(LookupHandler):
    @classmethod
    def handle(cls, value, provider, **kwargs):
        """Fetch the most recent AMI Id using a filter
    
        For example:
    
            ${ami [@]owners:self,account,amazon name_regex:serverX-[0-9]+ architecture:x64,i386}
    
            The above fetches the most recent AMI where owner is self
            account or amazon and the ami name matches the regex described,
            the architecture will be either x64 or i386
    
            You can also optionally specify the region in which to perform the
            AMI lookup.
    
            Valid arguments:
github cloudtools / stacker / stacker / lookups / handlers / file.py View on Github external
from collections import Mapping, Sequence

import yaml

from troposphere import GenericHelperFn, Base64

from . import LookupHandler
from ...util import read_value_from_path


TYPE_NAME = "file"

_PARAMETER_PATTERN = re.compile(r'{{([::|\w]+)}}')


class FileLookup(LookupHandler):
    @classmethod
    def handle(cls, value, **kwargs):
        """Translate a filename into the file contents.

        Fields should use the following format::

            :
github cloudtools / stacker / stacker / lookups / handlers / split.py View on Github external
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from . import LookupHandler
TYPE_NAME = "split"


class SplitLookup(LookupHandler):
    @classmethod
    def handle(cls, value, **kwargs):
        """Split the supplied string on the given delimiter, providing a list.

        Format of value:

            ::

        For 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"]