How to use the schematics.types.DictType function in schematics

To help you get started, we’ve selected a few schematics 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 / config / __init__.py View on Github external
template_path = StringType(serialize_when_none=False)

    description = StringType(serialize_when_none=False)

    requires = ListType(StringType, serialize_when_none=False)

    required_by = ListType(StringType, serialize_when_none=False)

    locked = BooleanType(default=False)

    enabled = BooleanType(default=True)

    protected = BooleanType(default=False)

    variables = DictType(AnyType, serialize_when_none=False)

    parameters = DictType(AnyType, serialize_when_none=False)

    tags = DictType(StringType, serialize_when_none=False)

    stack_policy_path = StringType(serialize_when_none=False)

    in_progress_behavior = StringType(serialize_when_none=False)

    def validate_class_path(self, data, value):
        if value and data["template_path"]:
            raise ValidationError(
                "template_path cannot be present when "
                "class_path is provided.")
        self.validate_stack_source(data)
github onicagroup / runway / runway / embedded / stacker / config / __init__.py View on Github external
requires = ListType(StringType, serialize_when_none=False)

    required_by = ListType(StringType, serialize_when_none=False)

    locked = BooleanType(default=False)

    enabled = BooleanType(default=True)

    protected = BooleanType(default=False)

    variables = DictType(AnyType, serialize_when_none=False)

    parameters = DictType(AnyType, serialize_when_none=False)

    tags = DictType(StringType, serialize_when_none=False)

    stack_policy_path = StringType(serialize_when_none=False)

    in_progress_behavior = StringType(serialize_when_none=False)

    def validate_class_path(self, data, value):
        if value and data["template_path"]:
            raise ValidationError(
                "template_path cannot be present when "
                "class_path is provided.")
        self.validate_stack_source(data)

    def validate_template_path(self, data, value):
        if value and data["class_path"]:
            raise ValidationError(
                "class_path cannot be present when "
github onicagroup / runway / runway / embedded / stacker / config / __init__.py View on Github external
description = StringType(serialize_when_none=False)

    requires = ListType(StringType, serialize_when_none=False)

    required_by = ListType(StringType, serialize_when_none=False)

    locked = BooleanType(default=False)

    enabled = BooleanType(default=True)

    protected = BooleanType(default=False)

    variables = DictType(AnyType, serialize_when_none=False)

    parameters = DictType(AnyType, serialize_when_none=False)

    tags = DictType(StringType, serialize_when_none=False)

    stack_policy_path = StringType(serialize_when_none=False)

    in_progress_behavior = StringType(serialize_when_none=False)

    def validate_class_path(self, data, value):
        if value and data["template_path"]:
            raise ValidationError(
                "template_path cannot be present when "
                "class_path is provided.")
        self.validate_stack_source(data)

    def validate_template_path(self, data, value):
        if value and data["class_path"]:
github cloudtools / stacker / stacker / config / __init__.py View on Github external
sys_path = StringType(serialize_when_none=False)

    package_sources = ModelType(PackageSources, serialize_when_none=False)

    service_role = StringType(serialize_when_none=False)

    pre_build = ListType(ModelType(Hook), serialize_when_none=False)

    post_build = ListType(ModelType(Hook), serialize_when_none=False)

    pre_destroy = ListType(ModelType(Hook), serialize_when_none=False)

    post_destroy = ListType(ModelType(Hook), serialize_when_none=False)

    tags = DictType(StringType, serialize_when_none=False)

    template_indent = StringType(serialize_when_none=False)

    mappings = DictType(
        DictType(DictType(StringType)), serialize_when_none=False)

    lookups = DictType(StringType, serialize_when_none=False)

    targets = ListType(
        ModelType(Target), serialize_when_none=False)

    stacks = ListType(
        ModelType(Stack), default=[])

    log_formats = DictType(StringType, serialize_when_none=False)
github binderclip / code-snippets-python / packages / schematics_snippets / schematics_dict_type.py View on Github external
# coding: utf-8
from schematics.models import Model
from schematics.types import DictType, StringType, ModelType


# dict of string
# dict of model


class A(Model):
    s = StringType()


class B(Model):
    sd = DictType(StringType)
    md = DictType(ModelType(A))


def main():
    b = B()
    b.sd = {
        "e": "ee",
        "f": "ff"
    }
    b.md = {
        "g": A({"s": "ss"})
    }
    print(b.serialize())


if __name__ == '__main__':
    main()
github onicagroup / runway / runway / cfngin / config / __init__.py View on Github external
``cfngin_cache_dir``, support will be retained until the release
            of version 2.0.0 at the earliest.
        stacks (ListType): Stacks to be processed.
        sys_path (StringType): Relative or absolute path to use as the work
            directory.
        tags (DictType): Tags to apply to all resources.
        targets (ListType): Stag grouping.
        template_indent (StringType): Spaces to use per-indent level when
            outputing a template to json.

    """

    cfngin_bucket = StringType(serialize_when_none=False)
    cfngin_bucket_region = StringType(serialize_when_none=False)
    cfngin_cache_dir = StringType(serialize_when_none=False)
    log_formats = DictType(StringType, serialize_when_none=False)
    lookups = DictType(StringType, serialize_when_none=False)
    mappings = DictType(
        DictType(DictType(StringType)), serialize_when_none=False)
    namespace = StringType(required=True)
    namespace_delimiter = StringType(serialize_when_none=False)
    package_sources = ModelType(PackageSources, serialize_when_none=False)
    persistent_graph_key = StringType(serialize_when_none=False)
    post_build = ListType(ModelType(Hook), serialize_when_none=False)
    post_destroy = ListType(ModelType(Hook), serialize_when_none=False)
    pre_build = ListType(ModelType(Hook), serialize_when_none=False)
    pre_destroy = ListType(ModelType(Hook), serialize_when_none=False)
    service_role = StringType(serialize_when_none=False)
    stacker_bucket = StringType(serialize_when_none=False)
    stacker_bucket_region = StringType(serialize_when_none=False)
    stacker_cache_dir = StringType(serialize_when_none=False)
    stacks = ListType(
github onicagroup / runway / runway / cfngin / config / __init__.py View on Github external
sys_path (StringType): Relative or absolute path to use as the work
            directory.
        tags (DictType): Tags to apply to all resources.
        targets (ListType): Stag grouping.
        template_indent (StringType): Spaces to use per-indent level when
            outputing a template to json.

    """

    cfngin_bucket = StringType(serialize_when_none=False)
    cfngin_bucket_region = StringType(serialize_when_none=False)
    cfngin_cache_dir = StringType(serialize_when_none=False)
    log_formats = DictType(StringType, serialize_when_none=False)
    lookups = DictType(StringType, serialize_when_none=False)
    mappings = DictType(
        DictType(DictType(StringType)), serialize_when_none=False)
    namespace = StringType(required=True)
    namespace_delimiter = StringType(serialize_when_none=False)
    package_sources = ModelType(PackageSources, serialize_when_none=False)
    persistent_graph_key = StringType(serialize_when_none=False)
    post_build = ListType(ModelType(Hook), serialize_when_none=False)
    post_destroy = ListType(ModelType(Hook), serialize_when_none=False)
    pre_build = ListType(ModelType(Hook), serialize_when_none=False)
    pre_destroy = ListType(ModelType(Hook), serialize_when_none=False)
    service_role = StringType(serialize_when_none=False)
    stacker_bucket = StringType(serialize_when_none=False)
    stacker_bucket_region = StringType(serialize_when_none=False)
    stacker_cache_dir = StringType(serialize_when_none=False)
    stacks = ListType(
        ModelType(Stack), default=[])
    sys_path = StringType(serialize_when_none=False)
    tags = DictType(StringType, serialize_when_none=False)
github cloudtools / stacker / stacker / config / __init__.py View on Github external
pre_build = ListType(ModelType(Hook), serialize_when_none=False)

    post_build = ListType(ModelType(Hook), serialize_when_none=False)

    pre_destroy = ListType(ModelType(Hook), serialize_when_none=False)

    post_destroy = ListType(ModelType(Hook), serialize_when_none=False)

    tags = DictType(StringType, serialize_when_none=False)

    template_indent = StringType(serialize_when_none=False)

    mappings = DictType(
        DictType(DictType(StringType)), serialize_when_none=False)

    lookups = DictType(StringType, serialize_when_none=False)

    targets = ListType(
        ModelType(Target), serialize_when_none=False)

    stacks = ListType(
        ModelType(Stack), default=[])

    log_formats = DictType(StringType, serialize_when_none=False)

    def _remove_excess_keys(self, data):
        excess_keys = set(data.keys())
        excess_keys -= self._schema.valid_input_keys
        if not excess_keys:
            return data

        logger.debug('Removing excess keys from config input: %s',
github onicagroup / runway / runway / embedded / stacker / config / __init__.py View on Github external
git = ListType(ModelType(GitPackageSource))

    s3 = ListType(ModelType(S3PackageSource))


class Hook(Model):
    path = StringType(required=True)

    required = BooleanType(default=True)

    enabled = BooleanType(default=True)

    data_key = StringType(serialize_when_none=False)

    args = DictType(AnyType)


class Target(Model):
    name = StringType(required=True)

    requires = ListType(StringType, serialize_when_none=False)

    required_by = ListType(StringType, serialize_when_none=False)


class Stack(Model):
    name = StringType(required=True)

    stack_name = StringType(serialize_when_none=False)

    region = StringType(serialize_when_none=False)
github iterait / shepherd / shepherd / config.py View on Github external
return strip_url_scheme(self.url)


class LoggingConfig(Model):
    level: str = StringType(default="info")

    @property
    def log_level(self):
        return getattr(logging, self.level.upper())


class ShepherdConfig(Model):
    data_root: str = StringType(required=True)
    storage: StorageConfig = ModelType(StorageConfig, required=True)
    logging: LoggingConfig = ModelType(LoggingConfig, required=False, default=LoggingConfig(dict(level='info')))
    sheep: Dict[str, Dict[str, Any]] = DictType(DictType(BaseType), required=True)
    registry: Optional[RegistryConfig] = ModelType(RegistryConfig, required=False)


def load_shepherd_config(config_stream) -> ShepherdConfig:
    # regex pattern for compiling ENV variables
    regex_no_brackets = re.compile(r'([^$]*)\$([A-Z_][A-Z_0-9]*)')
    regex_brackets = re.compile(r'([^$]*)\${([A-Z_][A-Z_0-9]*)}')
    ruamel.yaml.add_implicit_resolver('!env', regex_no_brackets)
    ruamel.yaml.add_implicit_resolver('!env', regex_brackets)

    # define constructor for recognizing environment variables
    def env_constructor(loader, node):
        value = loader.construct_scalar(node)

        def replace_env_vars(matchobj):
            env_name = matchobj.group(2)