Beispiel #1
0
    def netscaler_spec(self):
        class to_boolean(Spec):
            def setup(self, spec):
                self.spec = spec

            def normalise_either(self, meta, val):
                val = self.spec.normalise(meta, val)

                if type(val) is bool:
                    return val

                if val == 'False':
                    return False
                elif val == 'True':
                    return True
                raise BadConfiguration("Expected a boolean", got=val, meta=meta)

        return create_spec(netscaler_specs.NetScaler
            , host = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
            , dry_run = to_boolean(formatted(overridden("{bespin.dry_run}"), formatter=MergedOptionStringFormatter))

            , username = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
            , configuration_username = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))

            , password = delayed(required(formatted(string_spec(), formatter=MergedOptionStringFormatter)))
            , configuration_password = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))

            , verify_ssl = defaulted(boolean(), True)
            , nitro_api_version = defaulted(formatted(string_spec(), formatter=MergedOptionStringFormatter), "v1")
            , configuration = optional_spec(netscaler_specs.configuration_spec())
            , syncable_environments = optional_spec(listof(valid_environment_spec()))
            )
Beispiel #2
0
    def bespin_spec(self):
        """Spec for bespin options"""
        formatted_string = formatted(string_spec(), MergedOptionStringFormatter, expected_type=six.string_types)
        formatted_boolean = formatted(boolean(), MergedOptionStringFormatter, expected_type=bool)

        return create_spec(Bespin
            , validators.deprecated_key("region", "Please use ``environments.<env>.region``")

            , config = file_spec()
            , configuration = any_spec()

            , assume_role = optional_spec(string_spec())

            , dry_run = defaulted(boolean(), False)
            , flat = defaulted(boolean(), False)
            , environment = optional_spec(string_spec())

            , no_assume_role = defaulted(formatted_boolean, False)

            , chosen_task = defaulted(formatted_string, "list_tasks")
            , chosen_stack = defaulted(formatted_string, "")
            , chosen_artifact = defaulted(formatted_string, "")

            , extra_imports = listof(imports.import_spec())
            )
Beispiel #3
0
    def netscaler_spec(self):
        class to_boolean(Spec):
            def setup(self, spec):
                self.spec = spec

            def normalise_either(self, meta, val):
                val = self.spec.normalise(meta, val)

                if type(val) is bool:
                    return val

                if val == 'False':
                    return False
                elif val == 'True':
                    return True
                raise BadConfiguration("Expected a boolean", got=val, meta=meta)

        return create_spec(netscaler_specs.NetScaler
            , host = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
            , dry_run = to_boolean(formatted(overridden("{bespin.dry_run}"), formatter=MergedOptionStringFormatter))

            , username = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
            , configuration_username = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))

            , password = delayed(required(formatted(string_spec(), formatter=MergedOptionStringFormatter)))
            , configuration_password = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))

            , verify_ssl = defaulted(boolean(), True)
            , nitro_api_version = defaulted(formatted(string_spec(), formatter=MergedOptionStringFormatter), "v1")
            , configuration = optional_spec(netscaler_specs.configuration_spec())
            , syncable_environments = optional_spec(listof(valid_environment_spec()))
            )
Beispiel #4
0
    def bespin_spec(self):
        """Spec for bespin options"""
        formatted_string = formatted(string_spec(),
                                     MergedOptionStringFormatter,
                                     expected_type=six.string_types)
        formatted_boolean = formatted(boolean(),
                                      MergedOptionStringFormatter,
                                      expected_type=bool)

        return create_spec(Bespin,
                           validators.deprecated_key(
                               "region",
                               "Please use ``environments.<env>.region``"),
                           config=file_spec(),
                           configuration=any_spec(),
                           assume_role=optional_spec(string_spec()),
                           extra=defaulted(string_spec(), ""),
                           dry_run=defaulted(boolean(), False),
                           flat=defaulted(boolean(), False),
                           environment=optional_spec(string_spec()),
                           no_assume_role=defaulted(formatted_boolean, False),
                           chosen_task=defaulted(formatted_string,
                                                 "list_tasks"),
                           chosen_stack=defaulted(formatted_string, ""),
                           chosen_artifact=defaulted(formatted_string, ""),
                           extra_imports=listof(imports.import_spec()))
Beispiel #5
0
 def authentications_spec(self):
     """Spec for a group of authentication options"""
     return container_spec(authentication_objs.Authentication
           , dictof(string_spec(), set_options(
               reading = optional_spec(authentication_spec())
             , writing = optional_spec(authentication_spec())
             )
           )
         )
Beispiel #6
0
 def authentications_spec(self):
     """Spec for a group of authentication options"""
     return optional_spec(
         container_spec(
             authentication_objs.Authentication,
             dictof(
                 string_spec(),
                 set_options(reading=optional_spec(authentication_spec()),
                             writing=optional_spec(
                                 authentication_spec())))))
Beispiel #7
0
    def password_spec(self):
        formatted_string = formatted(string_spec(), formatter=MergedOptionStringFormatter)
        return create_spec(stack_objs.Password
            , name = formatted(overridden("{_key_name_1}"), formatter=MergedOptionStringFormatter)
            , bespin = formatted(overridden("{bespin}"), formatter=MergedOptionStringFormatter)

            , KMSMasterKey = required(formatted_string)
            , encryption_context = optional_spec(dictionary_spec())
            , grant_tokens = optional_spec(listof(formatted_string))
            , crypto_text = required(formatted_string)

            , vars = dictionary_spec()
            )
Beispiel #8
0
    def password_spec(self):
        formatted_string = formatted(string_spec(), formatter=MergedOptionStringFormatter)
        return create_spec(stack_objs.Password
            , name = formatted(overridden("{_key_name_1}"), formatter=MergedOptionStringFormatter)
            , bespin = formatted(overridden("{bespin}"), formatter=MergedOptionStringFormatter)

            , KMSMasterKey = required(formatted_string)
            , encryption_context = optional_spec(dictionary_spec())
            , grant_tokens = optional_spec(listof(formatted_string))
            , crypto_text = required(formatted_string)

            , vars = dictionary_spec()
            )
Beispiel #9
0
    def normalise_filled(self, meta, val):
        typ = formatted(overridden("{_key_name_1}"), formatter=MergedOptionStringFormatter).normalise(meta, val)
        name = formatted(overridden("{_key_name_0}"), formatter=MergedOptionStringFormatter).normalise(meta, val)
        special = {}
        kls = special.get(typ, GenericNetscalerConfig)

        formatted_string = formatted(string_spec(), formatter=MergedOptionStringFormatter)
        formatted_options = dictof(string_spec(), match_spec((six.string_types, formatted_string), fallback=any_spec()))

        options = dict(
              typ=overridden(typ)
            , name=overridden(name)
            , bindings=dictof(string_spec()
            , netscaler_binding_spec())
            , tags=listof(string_spec())
            , options=formatted_options
            , overrides=formatted_options
            , binding_options=formatted_options
            , environments=optional_spec(listof(valid_environment_spec()))
            )

        if typ == "sslcertkey":
            options["link"] = listof(string_spec())
        as_dict = set_options(**options).normalise(meta, val)
        return kls(**dict((name, as_dict[name]) for name in options))
Beispiel #10
0
    def normalise(self, meta, val):
        from harpoon.option_spec.harpoon_specs import HarpoonSpec
        if "content" in val or "context" in val:
            spec = sb.set_options(mtime=sb.optional_spec(sb.integer_spec()), dest=sb.required(sb.formatted(sb.string_spec(), formatter=MergedOptionStringFormatter)), content=sb.string_spec(), context=sb.optional_spec(HarpoonSpec().context_spec))
            result = spec.normalise(meta, val)
            if result["content"] != "" and result["context"] is not NotSpecified:
                raise BadOption("Please don't specify both context and content")

            mtime = result["mtime"]
            if mtime is NotSpecified:
                ctxt = type("Context", (object, ), {"use_git": True})()
                mtime = meta.everything["mtime"](ctxt)
            context_name = "{0}-{1}-mtime({2})".format(hashlib.md5(result['content'].encode('utf-8')).hexdigest(), result["dest"].replace("/", "-").replace(" ", "--"), mtime)
            extra_context = (result["content"], context_name)
            if result["context"] is not NotSpecified:
                context_name = "{0}.tar".format(context_name)
                extra_context = ({"context": result["context"]}, context_name)

            return Command(("ADD", "{0} {1}".format(context_name, result["dest"])), extra_context)
        else:
            spec = sb.set_options(
                  get=sb.required(sb.listof(sb.formatted(sb.string_spec(), formatter=MergedOptionStringFormatter)))
                , prefix = sb.defaulted(sb.string_spec(), "")
                )
            result = spec.normalise(meta, val)

            final = []
            for val in result["get"]:
                final.append(Command(("ADD", "{0} {1}/{2}".format(val, result["prefix"], val))))
            return final
Beispiel #11
0
    def normalise(self, meta, val):
        result = sb.create_spec(LambdaPostMethod
            , function = formatted_string()
            , location = formatted_string()
            , account = sb.optional_spec(formatted_string())
            , require_api_key = sb.defaulted(sb.boolean(), False)
            , mapping = sb.defaulted(mapping_spec(), Mapping("application/json", "$input.json('$')"))
            ).normalise(meta, val)

        function = result.function
        location = None

        if result.location is not NotSpecified and location is not None:
            raise BadSpecValue("Please don't specify a defined lambda function and location at the same time", meta=meta)

        if not isinstance(function, six.string_types):
            location = function.location
            function = function.name

        if location is None and result.location is NotSpecified:
            raise BadSpecValue("Location is a required key!", meta=meta)

        result.function = function
        result.location = location
        return result
Beispiel #12
0
    def confirm_deployment_spec(self):
        return create_spec(deployment_check.ConfirmDeployment
            , deploys_s3_path = optional_spec(listof(stack_specs.s3_address()))
            , zero_instances_is_ok = defaulted(boolean(), False)
            , auto_scaling_group_name = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))

            , url_checker = optional_spec(self.url_checker_spec)

            , sns_confirmation = optional_spec(create_spec(deployment_check.SNSConfirmation
                , validators.deprecated_key("auto_scaling_group_id", "Use ``confirm_deployment.auto_scaling_group_name``")
                , validators.deprecated_key("env", "Use ``stack.<stack>.env`` instead``")

                , timeout = defaulted(integer_spec(), 300)
                , version_message = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                , deployment_queue = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                ))
            )
Beispiel #13
0
    def confirm_deployment_spec(self):
        return create_spec(deployment_check.ConfirmDeployment
            , deploys_s3_path = optional_spec(listof(stack_specs.s3_address()))
            , zero_instances_is_ok = defaulted(boolean(), False)
            , auto_scaling_group_name = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))

            , url_checker = optional_spec(self.url_checker_spec)

            , sns_confirmation = optional_spec(create_spec(deployment_check.SNSConfirmation
                , validators.deprecated_key("auto_scaling_group_id", "Use ``confirm_deployment.auto_scaling_group_name``")
                , validators.deprecated_key("env", "Use ``stack.<stack>.env`` instead``")

                , timeout = defaulted(integer_spec(), 300)
                , version_message = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                , deployment_queue = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                ))
            )
Beispiel #14
0
class expiration_spec(statement_spec):
    args = lambda s, self_type, self_name: {
        "days":
        sb.optional_spec(sb.integer_spec()),
        "date":
        capitalized_only_spec(),
        (("sep", "_"), ("parts", ("expired", "object", "delete", "marker"))):
        sb.optional_spec(sb.boolean())
    }
    conflicting = [('days', 'date', 'expired_object_delete_marker')]
    validators = [
        validators.has_either([
            "days", "Days", "date", "Date", "expired_object_delete_marker",
            "ExpiredObjectDeleteMarker"
        ])
    ]
    final_kls = lambda s, *args, **kwargs: LifecycleExpirationConfig(
        *args, **kwargs)
Beispiel #15
0
class transition_spec(statement_spec):
    args = lambda s, self_type, self_name: {
        "days": sb.optional_spec(sb.integer_spec()),
        "date": capitalized_only_spec(),
        ("storage", "class"): sb.string_choice_spec(["GLACIER", "STANDARD_IA"])
    }
    required = ["storageclass"]
    conflicting = [('days', 'date')]
    validators = [validators.has_either(["days", "Days", "date", "Date"])]
    final_kls = lambda s, *args, **kwargs: LifecycleTransitionConfig(
        *args, **kwargs)
Beispiel #16
0
 def ultradns_site_spec(self, this):
     formatted_string = sb.formatted(sb.string_spec(), formatter=MergedOptionStringFormatter)
     return sb.create_spec(UltraDNSSite
         , name = sb.formatted(sb.overridden("{_key_name_1}"), formatter=MergedOptionStringFormatter)
         , ttl = sb.optional_spec(sb.integer_spec())
         , provider = sb.any_spec()
         , record_type = sb.required(formatted_string)
         , zone = sb.required(formatted_string)
         , domain = sb.required(formatted_string)
         , environments = sb.required(self.dns_environment_spec(this))
         )
Beispiel #17
0
 def ultradns_site_spec(self, this):
     formatted_string = sb.formatted(sb.string_spec(),
                                     formatter=MergedOptionStringFormatter)
     return sb.create_spec(
         UltraDNSSite,
         name=sb.formatted(sb.overridden("{_key_name_1}"),
                           formatter=MergedOptionStringFormatter),
         ttl=sb.optional_spec(sb.integer_spec()),
         provider=sb.any_spec(),
         record_type=sb.required(formatted_string),
         zone=sb.required(formatted_string),
         domain=sb.required(formatted_string),
         environments=sb.required(self.dns_environment_spec(this)))
Beispiel #18
0
    def normalise(self, meta, val):
        from harpoon.option_spec.harpoon_specs import HarpoonSpec
        formatted_string = sb.formatted(sb.string_spec(), formatter=MergedOptionStringFormatter)
        val = sb.apply_validators(meta, val, [validators.either_keys(["context"], ["content"], ["get"], ["formatted"])])

        if "get" in val:
            val = sb.create_spec(CommandAddExtra
                , get = sb.required(sb.listof(formatted_string))
                , prefix = sb.optional_spec(sb.string_spec())
                ).normalise(meta, val)

        if "context" in val:
            val = sb.create_spec(CommandContextAdd
                , dest = sb.required(formatted_string)
                , mtime = sb.optional_spec(sb.integer_spec())
                , context = sb.required(HarpoonSpec().context_spec)
                ).normalise(meta, val)

        if "formatted" in val:
            val = sb.create_spec(CommandContentAdd
                , dest = sb.required(formatted_string)
                , mtime = sb.optional_spec(sb.integer_spec())
                , content = sb.overridden(sb.NotSpecified)
                , formatted = sb.container_spec(CommandContentAddString, formatted_string)
                ).normalise(meta, val)

        if "content" in val:
            val = sb.create_spec(CommandContentAdd
                , dest = sb.required(formatted_string)
                , mtime = sb.optional_spec(sb.integer_spec())
                , content = sb.match_spec(
                      (six.string_types, sb.container_spec(CommandContentAddString, sb.string_spec()))
                    , fallback = complex_ADD_from_image_spec()
                    )
                ).normalise(meta, val)

        return list(val.commands(meta))
Beispiel #19
0
    def harpoon_spec(self):
        """Spec for harpoon options"""
        formatted_string = formatted(string_spec(),
                                     MergedOptionStringFormatter,
                                     expected_type=six.string_types)
        formatted_boolean = formatted(boolean(),
                                      MergedOptionStringFormatter,
                                      expected_type=bool)

        return create_spec(
            Harpoon,
            config=optional_spec(file_spec()),
            tag=optional_spec(string_spec()),
            extra=defaulted(formatted_string, ""),
            debug=defaulted(boolean(), False),
            addons=dictof(string_spec(), listof(string_spec())),
            artifact=optional_spec(formatted_string),
            extra_files=listof(string_spec()),
            chosen_task=defaulted(formatted_string, "list_tasks"),
            chosen_image=defaulted(formatted_string, ""),
            flat=defaulted(formatted_boolean, False),
            no_cleanup=defaulted(formatted_boolean, False),
            interactive=defaulted(formatted_boolean, True),
            silent_build=defaulted(formatted_boolean, False),
            keep_replaced=defaulted(formatted_boolean, False),
            ignore_missing=defaulted(formatted_boolean, False),
            no_intervention=defaulted(formatted_boolean, False),
            intervene_afterwards=defaulted(formatted_boolean, False),
            do_push=defaulted(formatted_boolean, False),
            only_pushable=defaulted(formatted_boolean, False),
            docker_context=any_spec(),
            docker_context_maker=any_spec(),
            stdout=defaulted(any_spec(), sys.stdout),
            tty_stdin=defaulted(any_spec(), None),
            tty_stdout=defaulted(any_spec(), lambda: sys.stdout),
            tty_stderr=defaulted(any_spec(), lambda: sys.stderr))
Beispiel #20
0
    def harpoon_spec(self):
        """Spec for harpoon options"""
        formatted_string = formatted(string_spec(), MergedOptionStringFormatter, expected_type=six.string_types)
        formatted_boolean = formatted(boolean(), MergedOptionStringFormatter, expected_type=bool)

        return create_spec(Harpoon
            , config = optional_spec(file_spec())

            , tag = optional_spec(string_spec())
            , extra = defaulted(formatted_string, "")
            , debug = defaulted(boolean(), False)
            , addons = dictof(string_spec(), listof(string_spec()))
            , artifact = optional_spec(formatted_string)
            , extra_files = listof(string_spec())
            , chosen_task = defaulted(formatted_string, "list_tasks")
            , chosen_image = defaulted(formatted_string, "")

            , flat = defaulted(formatted_boolean, False)
            , no_cleanup = defaulted(formatted_boolean, False)
            , interactive = defaulted(formatted_boolean, True)
            , silent_build = defaulted(formatted_boolean, False)
            , keep_replaced = defaulted(formatted_boolean, False)
            , ignore_missing = defaulted(formatted_boolean, False)
            , no_intervention = defaulted(formatted_boolean, False)
            , intervene_afterwards = defaulted(formatted_boolean, False)

            , do_push = defaulted(formatted_boolean, False)
            , only_pushable = defaulted(formatted_boolean, False)
            , docker_context = any_spec()
            , docker_context_maker = any_spec()

            , stdout = defaulted(any_spec(), sys.stdout)
            , tty_stdin = defaulted(any_spec(), None)
            , tty_stdout = defaulted(any_spec(), lambda: sys.stdout)
            , tty_stderr = defaulted(any_spec(), lambda: sys.stderr)
            )
Beispiel #21
0
    def normalise(self, meta, val):
        result = sb.create_spec(
            LambdaMethod,
            http_method=sb.overridden(self.method),
            resource_name=sb.overridden(self.resource_name),
            function=formatted_string(),
            location=formatted_string(),
            account=sb.optional_spec(formatted_string()),
            require_api_key=sb.defaulted(sb.boolean(), False),
            request_mapping=sb.defaulted(mapping_spec(),
                                         Mapping("application/json", "")),
            mapping=sb.defaulted(
                mapping_spec(), Mapping("application/json",
                                        "$input.json('$')")),
            sample_event=sb.or_spec(formatted_dictionary(), sb.string_spec()),
            desired_output_for_test=sb.or_spec(formatted_dictionary(),
                                               sb.string_spec())).normalise(
                                                   meta, val)

        for key in ('sample_event', 'desired_output_for_test'):
            if isinstance(result[key], six.string_types):
                v = result[key]
                if v.startswith("{") and v.endswith("}"):
                    v = sb.formatted(
                        sb.string_spec(),
                        formatter=MergedOptionStringFormatter).normalise(
                            meta.at(key), v)
                    result[key] = v

        function = result.function
        location = None

        if result.location is not NotSpecified and location is not None:
            raise BadSpecValue(
                "Please don't specify a defined lambda function and location at the same time",
                meta=meta)

        if not isinstance(function, six.string_types):
            location = function.location
            function = function.name

        if location is None and result.location is NotSpecified:
            raise BadSpecValue("Location is a required key!", meta=meta)

        result.function = function
        result.location = location
        return result
Beispiel #22
0
    def normalise(self, meta, val):
        from harpoon.option_spec.harpoon_specs import HarpoonSpec
        formatted_string = sb.formatted(sb.string_spec(), formatter=MergedOptionStringFormatter)
        val = sb.apply_validators(meta, val, [validators.either_keys(["context"], ["content"], ["get"], ["formatted"])])

        if "get" in val:
            val = sb.create_spec(CommandAddExtra
                , get = sb.required(sb.listof(formatted_string))
                , prefix = sb.optional_spec(sb.string_spec())
                ).normalise(meta, val)

        if "context" in val:
            val = sb.create_spec(CommandContextAdd
                , validators.deprecated_key("mtime", "Since docker 1.8, timestamps no longer invalidate the docker layer cache")

                , dest = sb.required(formatted_string)
                , context = sb.required(HarpoonSpec().context_spec)
                ).normalise(meta, val)

        if "formatted" in val:
            val = sb.create_spec(CommandContentAdd
                , validators.deprecated_key("mtime", "Since docker 1.8, timestamps no longer invalidate the docker layer cache")

                , dest = sb.required(formatted_string)
                , content = sb.overridden(sb.NotSpecified)
                , formatted = sb.container_spec(CommandContentAddString, formatted_string)
                ).normalise(meta, val)

        if "content" in val:
            val = sb.create_spec(CommandContentAdd
                , validators.deprecated_key("mtime", "Since docker 1.8, timestamps no longer invalidate the docker layer cache")

                , dest = sb.required(formatted_string)
                , content = sb.match_spec(
                      (six.string_types, sb.container_spec(CommandContentAddString, sb.string_spec()))
                    , fallback = complex_ADD_from_image_spec()
                    )
                ).normalise(meta, val)

        return list(val.commands(meta))
Beispiel #23
0
    def wait_condition_spec(self):
        """Spec for a wait_condition block"""
        from harpoon.option_spec import image_objs
        formatted_string = formatted(string_spec(), formatter=MergedOptionStringFormatter)
        return create_spec(image_objs.WaitCondition
            , harpoon = formatted(overridden("{harpoon}"), formatter=MergedOptionStringFormatter)
            , timeout = defaulted(integer_spec(), 300)
            , wait_between_attempts = defaulted(float_spec(), 5)

            , greps = optional_spec(dictof(formatted_string, formatted_string))
            , command = optional_spec(listof(formatted_string))
            , port_open = optional_spec(listof(integer_spec()))
            , file_value = optional_spec(dictof(formatted_string, formatted_string))
            , curl_result = optional_spec(dictof(formatted_string, formatted_string))
            , file_exists = optional_spec(listof(formatted_string))
            )
Beispiel #24
0
    def normalise(self, meta, val):
        from harpoon.option_spec.harpoon_specs import HarpoonSpec
        formatted_string = sb.formatted(sb.string_spec(), formatter=MergedOptionStringFormatter)

        if "from" not in val:
            raise BadSpecValue("Specifying [COPY, {options}] must contain 'from' in the options", meta=meta)

        if type(val["from"]) is int:
            val["from_image"] = val["from"]
        else:
            img, conf = complex_from_image_spec().normalise(meta.at("from"), val["from"])
            val["from_image"] = conf
            val["image"] = img

        val = sb.create_spec(CommandCopyExtra
            , from_image = sb.any_spec()
            , path = sb.required(sb.string_spec())
            , to = sb.required(sb.string_spec())
            , image = sb.optional_spec(sb.any_spec())
            ).normalise(meta, val)

        return list(val.commands(meta))
Beispiel #25
0
    def normalise(self, meta, val):
        result = sb.create_spec(LambdaMethod
            , http_method = sb.overridden(self.method)
            , resource_name = sb.overridden(self.resource_name)

            , function = formatted_string()
            , location = formatted_string()
            , account = sb.optional_spec(formatted_string())
            , require_api_key = sb.defaulted(sb.boolean(), False)
            , request_mapping = sb.defaulted(mapping_spec(), Mapping("application/json", ""))
            , mapping = sb.defaulted(mapping_spec(), Mapping("application/json", "$input.json('$')"))
            , sample_event = sb.or_spec(formatted_dictionary(), sb.string_spec())
            , desired_output_for_test = sb.or_spec(formatted_dictionary(), sb.string_spec())
            ).normalise(meta, val)

        for key in ('sample_event', 'desired_output_for_test'):
            if isinstance(result[key], six.string_types):
                v = result[key]
                if v.startswith("{") and v.endswith("}"):
                    v = sb.formatted(sb.string_spec(), formatter=MergedOptionStringFormatter).normalise(meta.at(key), v)
                    result[key] = v

        function = result.function
        location = None

        if result.location is not NotSpecified and location is not None:
            raise BadSpecValue("Please don't specify a defined lambda function and location at the same time", meta=meta)

        if not isinstance(function, six.string_types):
            location = function.location
            function = function.name

        if location is None and result.location is NotSpecified:
            raise BadSpecValue("Location is a required key!", meta=meta)

        result.function = function
        result.location = location
        return result
Beispiel #26
0
 def wait_condition_spec(self):
     """Spec for a wait_condition block"""
     from harpoon.option_spec import image_objs
     formatted_string = formatted(string_spec(),
                                  formatter=MergedOptionStringFormatter)
     return create_spec(
         image_objs.WaitCondition,
         harpoon=formatted(overridden("{harpoon}"),
                           formatter=MergedOptionStringFormatter),
         timeout=defaulted(integer_spec(), 300),
         wait_between_attempts=defaulted(float_spec(), 5),
         greps=optional_spec(dictof(formatted_string, formatted_string)),
         command=optional_spec(listof(formatted_string)),
         port_open=optional_spec(listof(integer_spec())),
         file_value=optional_spec(dictof(formatted_string,
                                         formatted_string)),
         curl_result=optional_spec(
             dictof(formatted_string, formatted_string)),
         file_exists=optional_spec(listof(formatted_string)))
Beispiel #27
0
        val = sb.dictionary_spec().normalise(meta, val)
        if 'plain' in val and 'kms' in val:
            raise BadSpecValue("Please only specify plain or kms", got=list(val.keys()), meta=meta)

        if 'plain' not in val and 'kms' not in val:
            raise BadSpecValue("Please specify plain or kms", got=list(val.keys()), meta=meta)

        if 'kms' in val and ('location' not in val or 'kms_data_key' not in val):
            raise BadSpecValue("Please specify location and kms_data_key if you specify kms", got=list(val.keys()), meta=meta)

        return val

secret_spec = lambda: sb.create_spec(Secret
    , valid_secret()

    , plain = sb.optional_spec(formatted_string())
    , kms = sb.optional_spec(formatted_string())
    , location = sb.optional_spec(formatted_string())
    , kms_data_key = sb.optional_spec(formatted_string())
    )

class certificate_spec(Spec):
    def normalise(self, meta, val):
        if isinstance(val, six.string_types):
            val = formatted_string().normalise(meta, val)

        return sb.create_spec(Certificate
            , name = sb.required(formatted_string())
            , body = sb.required(secret_spec())
            , key = sb.required(secret_spec())
            , chain = sb.required(secret_spec())
Beispiel #28
0
                               meta=meta)

        if 'kms' in val and ('location' not in val
                             or 'kms_data_key' not in val):
            raise BadSpecValue(
                "Please specify location and kms_data_key if you specify kms",
                got=list(val.keys()),
                meta=meta)

        return val


secret_spec = lambda: sb.create_spec(
    Secret,
    valid_secret(),
    plain=sb.optional_spec(formatted_string()),
    kms=sb.optional_spec(formatted_string()),
    location=sb.optional_spec(formatted_string()),
    kms_data_key=sb.optional_spec(formatted_string()))


class certificate_spec(Spec):
    def normalise(self, meta, val):
        if isinstance(val, six.string_types):
            val = formatted_string().normalise(meta, val)

        return sb.create_spec(Certificate,
                              name=sb.required(formatted_string()),
                              body=sb.required(secret_spec()),
                              key=sb.required(secret_spec()),
                              chain=sb.required(secret_spec())).normalise(
Beispiel #29
0
    def image_spec(self):
        """Spec for each image"""
        from harpoon.option_spec import image_specs as specs
        from harpoon.option_spec import image_objs

        return create_spec(
            image_objs.Image
            # Change the context options
            ,
            validators.deprecated_key("exclude_context", "Use ``context.exclude``"),
            validators.deprecated_key("use_git_timestamps", "Use ``context.use_git_timestamps``"),
            validators.deprecated_key("respect_gitignore", "Use ``context.use_gitignore``"),
            validators.deprecated_key("parent_dir", "Use ``context.parent_dir``"),
            validators.deprecated_key("recursive", "Use ``persistence``")
            # Changed how volumes_from works
            ,
            validators.deprecated_key("volumes_from", "Use ``volumes.share_with``")
            # Deprecated link
            ,
            validators.deprecated_key("link", "Use ``links``")
            # Harpoon options
            ,
            harpoon=any_spec()
            # default the name to the key of the image
            ,
            name=formatted(defaulted(string_spec(), "{_key_name_1}"), formatter=MergedOptionStringFormatter),
            key_name=formatted(overridden("{_key_name_1}"), formatter=MergedOptionStringFormatter),
            image_name=optional_spec(string_spec()),
            image_index=defaulted(string_spec(), ""),
            container_name=optional_spec(string_spec()),
            image_name_prefix=defaulted(string_spec(), ""),
            user=defaulted(string_spec(), None),
            mtime=defaulted(any_spec(), time.time()),
            configuration=any_spec(),
            vars=dictionary_spec(),
            deleteable_image=defaulted(boolean(), False)
            # The spec itself
            ,
            bash=delayed(optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))),
            command=delayed(optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))),
            commands=required(container_spec(Commands, listof(command_spec()))),
            squash_after=optional_spec(or_spec(boolean(), container_spec(Commands, listof(command_spec())))),
            squash_before_push=optional_spec(or_spec(boolean(), container_spec(Commands, listof(command_spec())))),
            persistence=optional_spec(
                create_spec(
                    image_objs.Persistence,
                    validators.deprecated_key("persist", "Use ``folders``"),
                    action=required(formatted(string_spec(), formatter=MergedOptionStringFormatter)),
                    folders=required(listof(formatted(string_spec(), formatter=MergedOptionStringFormatter))),
                    cmd=optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter)),
                    shell=defaulted(formatted(string_spec(), formatter=MergedOptionStringFormatter), "/bin/bash"),
                    image_name=delayed(
                        many_format(
                            overridden("images.{_key_name_2}.image_name"), formatter=MergedOptionStringFormatter
                        )
                    ),
                )
            ),
            links=listof(specs.link_spec(), expect=image_objs.Link),
            context=self.context_spec,
            wait_condition=optional_spec(self.wait_condition_spec),
            lxc_conf=defaulted(filename_spec(), None),
            volumes=create_spec(
                image_objs.Volumes,
                mount=listof(specs.mount_spec(), expect=image_objs.Mount),
                share_with=listof(
                    formatted(string_spec(), MergedOptionStringFormatter, expected_type=image_objs.Image)
                ),
            ),
            dependency_options=dictof(
                specs.image_name_spec(),
                create_spec(
                    image_objs.DependencyOptions,
                    attached=defaulted(boolean(), False),
                    wait_condition=optional_spec(self.wait_condition_spec),
                ),
            ),
            env=listof(specs.env_spec(), expect=image_objs.Environment),
            ports=listof(specs.port_spec(), expect=image_objs.Port),
            ulimits=defaulted(listof(dictionary_spec()), None),
            log_config=defaulted(listof(dictionary_spec()), None),
            security_opt=defaulted(listof(string_spec()), None),
            read_only_rootfs=defaulted(boolean(), False),
            other_options=create_spec(
                other_options,
                start=dictionary_spec(),
                build=dictionary_spec(),
                create=dictionary_spec(),
                host_config=dictionary_spec(),
            ),
            network=create_spec(
                image_objs.Network,
                dns=defaulted(listof(string_spec()), None),
                mode=defaulted(string_spec(), None),
                hostname=defaulted(string_spec(), None),
                domainname=defaulted(string_spec(), None),
                disabled=defaulted(boolean(), False),
                dns_search=defaulted(listof(string_spec()), None),
                extra_hosts=listof(string_spec()),
                network_mode=defaulted(string_spec(), None),
                publish_all_ports=defaulted(boolean(), False),
            ),
            cpu=create_spec(
                image_objs.Cpu,
                cap_add=defaulted(boolean(), None),
                cpuset=defaulted(listof(string_spec()), None),
                cap_drop=defaulted(boolean(), None),
                mem_limit=defaulted(integer_spec(), 0),
                cpu_shares=defaulted(integer_spec(), None),
                memswap_limit=defaulted(integer_spec(), 0),
            ),
            devices=defaulted(listof(dictionary_spec()), None),
            privileged=defaulted(boolean(), False),
            restart_policy=defaulted(string_spec(), None),
        )
Beispiel #30
0
    add_into_tar=sb.listof(artifact_path_spec()))

params_json_spec = lambda: sb.listof(
    sb.set_options(ParameterKey=sb.required(sb.any_spec()),
                   ParameterValue=sb.required(sb.any_spec())))

params_yaml_spec = lambda: sb.dictof(
    sb.string_spec(),
    sb.formatted(sb.string_or_int_as_string_spec(),
                 formatter=MergedOptionStringFormatter))

stack_json_spec = lambda: sb.set_options(Resources=sb.required(
    sb.dictof(
        sb.string_spec(),
        sb.set_options(Type=sb.required(sb.string_spec()),
                       Properties=sb.optional_spec(sb.dictionary_spec())))),
                                         Parameters=sb.optional_spec(
                                             sb.dictof(sb.string_spec(),
                                                       sb.dictionary_spec())),
                                         Outputs=sb.optional_spec(
                                             sb.dictof(sb.string_spec(),
                                                       sb.dictionary_spec())))


class policy_set_options(sb.set_options):
    """
    Strip ``NotSpecified`` values from normalised dictionary
    and ensure only one of the 'Not' options are specified
    """
    def normalise_filled(self, meta, val):
        result = super(policy_set_options, self).normalise_filled(meta, val)
Beispiel #31
0
    def stack_spec(self):
        """Spec for each stack"""
        return create_spec(stack_objs.Stack
            , validators.deprecated_key("url_checker", "Use ``confirm_deployment.url_checker1``")
            , validators.deprecated_key("deploys_s3_path", "Use ``confirm_deployment.deploys_s3_path``")
            , validators.deprecated_key("sns_confirmation", "Use ``confirm_deployment.sns_confirmation``")
            , validators.deprecated_key("autoscaling_group_id", "Use ``auto_scaling_group_name``")
            , validators.deprecated_key("instance_count_limit", "Use ``scaling_options.instance_count_limit``")

            , bespin = any_spec()

            , name = formatted(defaulted(string_spec(), "{_key_name_1}"), formatter=MergedOptionStringFormatter)
            , key_name = formatted(overridden("{_key_name_1}"), formatter=MergedOptionStringFormatter)
            , stack_name = formatted(defaulted(string_spec(), "{_key_name_1}"), formatter=MergedOptionStringFormatter)
            , environment = formatted(overridden("{environment}"), formatter=MergedOptionStringFormatter)

            , env = listof(stack_specs.env_spec(), expect=stack_objs.Environment)
            , build_env = listof(stack_specs.env_spec(), expect=stack_objs.Environment)
            , stack_name_env = listof(stack_specs.env_spec(), expect=stack_objs.Environment)

            , tags = dictionary_spec()

            , stack_json = valid_stack_json(default="{config_root}/{_key_name_1}.json")

            , params_json = valid_params_json(default="{config_root}/{environment}/{_key_name_1}-params.json")
            , params_yaml = valid_params_yaml(default="{config_root}/{environment}/{_key_name_1}-params.yaml")

            , build_first = listof(formatted(string_spec(), formatter=MergedOptionStringFormatter))
            , build_after = listof(formatted(string_spec(), formatter=MergedOptionStringFormatter))
            , build_timeout = defaulted(integer_spec(), 1200)
            , ignore_deps = defaulted(boolean(), False)

            , vars = dictof(string_spec(), stack_specs.var_spec(), nested=True)

            , skip_update_if_equivalent = listof(stack_specs.skipper_spec())

            , suspend_actions = defaulted(boolean(), False)
            , auto_scaling_group_name = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))

            , artifact_retention_after_deployment = defaulted(boolean(), False)

            , command = optional_spec(string_spec())

            , netscaler = optional_spec(self.netscaler_spec)

            , dns = optional_spec(stack_specs.dns_spec(create_spec(stack_objs.DNS
                , vars = dictof(string_spec(), formatted(string_spec(), formatter=MergedOptionStringFormatter), nested=True)
                , providers = dictof(string_spec(), stack_specs.dns_provider_spec())
                , sites = delayed(dictof(string_spec(), stack_specs.dns_site_spec()))
                )))

            , scaling_options = create_spec(ScalingOptions
                , highest_min = defaulted(integer_spec(), 2)
                , instance_count_limit = defaulted(integer_spec(), 10)
                )

            , artifacts = container_spec(artifact_objs.ArtifactCollection, dictof(string_spec(), create_spec(artifact_objs.Artifact
                , not_created_here = defaulted(boolean(), False)
                , compression_type = string_choice_spec(["gz", "xz"])
                , history_length = integer_spec()
                , cleanup_prefix = optional_spec(string_spec())
                , upload_to = formatted(string_spec(), formatter=MergedOptionStringFormatter)
                , commands = listof(stack_specs.artifact_command_spec(), expect=artifact_objs.ArtifactCommand)
                , paths = listof(stack_specs.artifact_path_spec(), expect=artifact_objs.ArtifactPath)
                , files = listof(create_spec(artifact_objs.ArtifactFile, validators.has_either(["content", "task"])
                    , content = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                    , task = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                    , path = formatted(string_spec(), formatter=MergedOptionStringFormatter)
                    , task_runner = formatted(always_same_spec("{task_runner}"), formatter=MergedOptionStringFormatter)
                    ))
                )))

            , newrelic = optional_spec(create_spec(stack_objs.NewRelic
                , api_key = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                , account_id = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                , application_id = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))

                , env = listof(stack_specs.env_spec(), expect=stack_objs.Environment)
                , deployed_version = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                ))

            , downtimer_options = optional_spec(dictof(valid_string_spec(valid_alerting_system())
                , create_spec(stack_objs.DowntimerOptions
                    , hosts = listof(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                    )
                ))

            , alerting_systems = optional_spec(dictof(string_spec(), self.alerting_system_spec))

            , ssh = optional_spec(create_spec(stack_objs.SSH
                , validators.deprecated_key("autoscaling_group_id", "Use ``auto_scaling_group_name``")

                , user = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                , bastion = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                , bastion_user = required(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                , bastion_key_location = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                , instance_key_location = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))

                , address = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                , instance = optional_spec(listof(formatted(string_spec(), formatter=MergedOptionStringFormatter)))
                , auto_scaling_group_name = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))

                , bastion_key_path = formatted(defaulted(string_spec(), "{config_root}/{environment}/bastion_ssh_key.pem"), formatter=MergedOptionStringFormatter)
                , instance_key_path = formatted(defaulted(string_spec(), "{config_root}/{environment}/ssh_key.pem"), formatter=MergedOptionStringFormatter)

                , storage_type = formatted(defaulted(string_choice_spec(["url", "rattic"]), "url"), formatter=MergedOptionStringFormatter)
                , storage_host = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))
                ))

            , confirm_deployment = optional_spec(self.confirm_deployment_spec)
            )
Beispiel #32
0
        val = sb.dictionary_spec().normalise(meta, val)
        if 'plain' in val and 'kms' in val:
            raise BadSpecValue("Please only specify plain or kms", got=list(val.keys()), meta=meta)

        if 'plain' not in val and 'kms' not in val:
            raise BadSpecValue("Please specify plain or kms", got=list(val.keys()), meta=meta)

        if 'kms' in val and ('location' not in val or 'kms_data_key' not in val):
            raise BadSpecValue("Please specify location and kms_data_key if you specify kms", got=list(val.keys()), meta=meta)

        return val

secret_spec = lambda: sb.create_spec(Secret
    , valid_secret()

    , plain = sb.optional_spec(formatted_string())
    , kms = sb.optional_spec(formatted_string())
    , location = sb.optional_spec(formatted_string())
    , kms_data_key = sb.optional_spec(formatted_string())
    )

class certificate_spec(Spec):
    def normalise(self, meta, val):
        if isinstance(val, six.string_types):
            val = formatted_string().normalise(meta, val)

        return sb.create_spec(Certificate
            , name = sb.required(formatted_string())
            , body = sb.required(secret_spec())
            , key = sb.required(secret_spec())
            , chain = sb.required(secret_spec())
Beispiel #33
0
    def image_spec(self):
        """Spec for each image"""
        from harpoon.option_spec import image_specs as specs
        from harpoon.option_spec import image_objs
        return create_spec(
            image_objs.Image
            # Change the context options
            ,
            validators.deprecated_key("exclude_context",
                                      "Use ``context.exclude``"),
            validators.deprecated_key("use_git_timestamps",
                                      "Use ``context.use_git_timestamps``"),
            validators.deprecated_key("respect_gitignore",
                                      "Use ``context.use_gitignore``"),
            validators.deprecated_key("parent_dir",
                                      "Use ``context.parent_dir``")

            # Changed how volumes_from works
            ,
            validators.deprecated_key("volumes_from",
                                      "Use ``volumes.share_with``")

            # Deprecated link
            ,
            validators.deprecated_key("link", "Use ``links``")

            # Harpoon options
            ,
            harpoon=any_spec()

            # default the name to the key of the image
            ,
            name=formatted(defaulted(string_spec(), "{_key_name_1}"),
                           formatter=MergedOptionStringFormatter),
            key_name=formatted(overridden("{_key_name_1}"),
                               formatter=MergedOptionStringFormatter),
            image_name=optional_spec(string_spec()),
            image_index=defaulted(string_spec(), ""),
            container_name=optional_spec(string_spec()),
            image_name_prefix=defaulted(string_spec(), ""),
            user=defaulted(string_spec(), None),
            mtime=defaulted(any_spec(), time.time()),
            configuration=any_spec(),
            vars=dictionary_spec(),
            deleteable_image=defaulted(boolean(), False)

            # The spec itself
            ,
            bash=delayed(
                optional_spec(
                    formatted(string_spec(),
                              formatter=MergedOptionStringFormatter))),
            command=delayed(
                optional_spec(
                    formatted(string_spec(),
                              formatter=MergedOptionStringFormatter))),
            commands=required(container_spec(Commands,
                                             listof(command_spec()))),
            squash_after=optional_spec(
                or_spec(boolean(),
                        container_spec(Commands, listof(command_spec())))),
            squash_before_push=optional_spec(
                or_spec(boolean(),
                        container_spec(Commands, listof(command_spec())))),
            recursive=optional_spec(
                create_spec(
                    image_objs.Recursive,
                    action=required(
                        formatted(string_spec(),
                                  formatter=MergedOptionStringFormatter)),
                    persist=required(
                        listof(
                            formatted(string_spec(),
                                      formatter=MergedOptionStringFormatter))),
                    image_name=delayed(
                        many_format(
                            overridden("images.{_key_name_2}.image_name"),
                            formatter=MergedOptionStringFormatter)))),
            links=listof(specs.link_spec(), expect=image_objs.Link),
            context=self.context_spec,
            wait_condition=optional_spec(self.wait_condition_spec),
            lxc_conf=defaulted(filename_spec(), None),
            volumes=create_spec(image_objs.Volumes,
                                mount=listof(specs.mount_spec(),
                                             expect=image_objs.Mount),
                                share_with=listof(
                                    formatted(
                                        string_spec(),
                                        MergedOptionStringFormatter,
                                        expected_type=image_objs.Image))),
            dependency_options=dictof(
                specs.image_name_spec(),
                create_spec(image_objs.DependencyOptions,
                            attached=defaulted(boolean(), False),
                            wait_condition=optional_spec(
                                self.wait_condition_spec))),
            env=listof(specs.env_spec(), expect=image_objs.Environment),
            ports=listof(specs.port_spec(), expect=image_objs.Port),
            ulimits=defaulted(listof(dictionary_spec()), None),
            log_config=defaulted(listof(dictionary_spec()), None),
            security_opt=defaulted(listof(string_spec()), None),
            read_only_rootfs=defaulted(boolean(), False),
            other_options=create_spec(other_options,
                                      start=dictionary_spec(),
                                      build=dictionary_spec(),
                                      create=dictionary_spec(),
                                      host_config=dictionary_spec()),
            network=create_spec(image_objs.Network,
                                dns=defaulted(listof(string_spec()), None),
                                mode=defaulted(string_spec(), None),
                                hostname=defaulted(string_spec(), None),
                                domainname=defaulted(string_spec(), None),
                                disabled=defaulted(boolean(), False),
                                dns_search=defaulted(listof(string_spec()),
                                                     None),
                                extra_hosts=listof(string_spec()),
                                network_mode=defaulted(string_spec(), None),
                                publish_all_ports=defaulted(boolean(), False)),
            cpu=create_spec(image_objs.Cpu,
                            cap_add=defaulted(boolean(), None),
                            cpuset=defaulted(listof(string_spec()), None),
                            cap_drop=defaulted(boolean(), None),
                            mem_limit=defaulted(integer_spec(), 0),
                            cpu_shares=defaulted(integer_spec(), None),
                            memswap_limit=defaulted(integer_spec(), 0)),
            devices=defaulted(listof(dictionary_spec()), None),
            privileged=defaulted(boolean(), False),
            restart_policy=defaulted(string_spec(), None))
Beispiel #34
0
import time
import nose
import mock
import sys
import os

if sys.version_info[0] == 2 and sys.version_info[1] == 6:
    # This can be removed when we can use latest Httpretty again
    def mock_s3_deprecated(func):
        def wrapped(*args):
            raise nose.SkipTest("No moto support for python2.6 atm")
        return wrapped
else:
    from moto import mock_s3

optional_any = lambda: sb.optional_spec(sb.any_spec())
artifact_spec = sb.create_spec(Artifact
    , compression_type = optional_any()
    , history_length = optional_any()
    , upload_to = optional_any()
    , paths = optional_any()
    , files = optional_any()
    , commands = optional_any()
    )

describe BespinCase, "ArtifactCollection":
    describe "clean_old_artifacts":
        @mock_s3
        it "does nothing if dry_run is True":
            s3 = S3()
            environment = {}
Beispiel #35
0
import nose
import boto
import mock
import sys
import os

if sys.version_info[0] == 2 and sys.version_info[1] == 6:
    # This can be removed when we can use latest Httpretty again
    def mock_s3(func):
        def wrapped(*args):
            raise nose.SkipTest("No moto support for python2.6 atm")
        return wrapped
else:
    from moto import mock_s3

optional_any = lambda: sb.optional_spec(sb.any_spec())
artifact_spec = sb.create_spec(Artifact
    , compression_type = optional_any()
    , history_length = optional_any()
    , upload_to = optional_any()
    , paths = optional_any()
    , files = optional_any()
    , commands = optional_any()
    )

describe BespinCase, "ArtifactCollection":
    describe "clean_old_artifacts":
        @mock_s3
        it "does nothing if dry_run is True":
            s3 = S3()
            conn = s3.conn = boto.connect_s3()
Beispiel #36
0
 def stack_spec(self):
     """Spec for each stack"""
     return create_spec(
         stack_objs.Stack,
         validators.deprecated_key(
             "url_checker", "Use ``confirm_deployment.url_checker1``"),
         validators.deprecated_key(
             "deploys_s3_path",
             "Use ``confirm_deployment.deploys_s3_path``"),
         validators.deprecated_key(
             "sns_confirmation",
             "Use ``confirm_deployment.sns_confirmation``"),
         validators.deprecated_key("autoscaling_group_id",
                                   "Use ``auto_scaling_group_name``"),
         validators.deprecated_key(
             "instance_count_limit",
             "Use ``scaling_options.instance_count_limit``"),
         bespin=any_spec(),
         name=formatted(defaulted(string_spec(), "{_key_name_1}"),
                        formatter=MergedOptionStringFormatter),
         key_name=formatted(overridden("{_key_name_1}"),
                            formatter=MergedOptionStringFormatter),
         stack_name=formatted(defaulted(string_spec(), "{_key_name_1}"),
                              formatter=MergedOptionStringFormatter),
         environment=formatted(overridden("{environment}"),
                               formatter=MergedOptionStringFormatter),
         env=listof(stack_specs.env_spec(),
                    expect=stack_objs.EnvironmentVariable),
         build_env=listof(stack_specs.env_spec(),
                          expect=stack_objs.EnvironmentVariable),
         stack_name_env=listof(stack_specs.env_spec(),
                               expect=stack_objs.EnvironmentVariable),
         tags=self.tags_spec,
         termination_protection=defaulted(boolean(), False),
         stack_json=valid_stack_json(
             default="{config_root}/{_key_name_1}.json"),
         stack_yaml=valid_stack_yaml(
             default="{config_root}/{_key_name_1}.yaml"),
         params_json=valid_params_json(
             default="{config_root}/{environment}/{_key_name_1}-params.json"
         ),
         params_yaml=valid_params_yaml(
             default="{config_root}/{environment}/{_key_name_1}-params.yaml"
         ),
         stack_policy=valid_policy_json(
             default="{config_root}/{_key_name_1}-policy.json"),
         role_name=formatted(string_spec(),
                             formatter=MergedOptionStringFormatter),
         build_first=listof(
             formatted(string_spec(),
                       formatter=MergedOptionStringFormatter)),
         build_after=listof(
             formatted(string_spec(),
                       formatter=MergedOptionStringFormatter)),
         build_timeout=defaulted(integer_spec(), 1200),
         ignore_deps=defaulted(boolean(), False),
         vars=delayed(
             dictof(string_spec(), stack_specs.var_spec(), nested=True)),
         skip_update_if_equivalent=listof(stack_specs.skipper_spec()),
         suspend_actions=defaulted(boolean(), False),
         auto_scaling_group_name=optional_spec(
             formatted(string_spec(),
                       formatter=MergedOptionStringFormatter)),
         artifact_retention_after_deployment=defaulted(boolean(), False),
         command=optional_spec(string_spec()),
         netscaler=optional_spec(self.netscaler_spec),
         notify_stackdriver=defaulted(boolean(), False),
         stackdriver=optional_spec(
             create_spec(
                 stack_objs.Stackdriver,
                 api_key=required(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 deployment_version=defaulted(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter),
                     "<version>"))),
         dns=optional_spec(
             stack_specs.dns_spec(
                 create_spec(
                     stack_objs.DNS,
                     vars=dictof(
                         string_spec(),
                         formatted(string_spec(),
                                   formatter=MergedOptionStringFormatter),
                         nested=True),
                     providers=dictof(string_spec(),
                                      stack_specs.dns_provider_spec()),
                     sites=delayed(
                         dictof(string_spec(),
                                stack_specs.dns_site_spec()))))),
         scaling_options=create_spec(
             ScalingOptions,
             highest_min=defaulted(integer_spec(), 2),
             instance_count_limit=defaulted(integer_spec(), 10)),
         artifacts=container_spec(
             artifact_objs.ArtifactCollection,
             dictof(
                 string_spec(),
                 create_spec(
                     artifact_objs.Artifact,
                     not_created_here=defaulted(boolean(), False),
                     compression_type=string_choice_spec(["gz", "xz"]),
                     history_length=integer_spec(),
                     cleanup_prefix=optional_spec(string_spec()),
                     upload_to=formatted(
                         string_spec(),
                         formatter=MergedOptionStringFormatter),
                     commands=listof(stack_specs.artifact_command_spec(),
                                     expect=artifact_objs.ArtifactCommand),
                     paths=listof(stack_specs.artifact_path_spec(),
                                  expect=artifact_objs.ArtifactPath),
                     files=listof(
                         create_spec(
                             artifact_objs.ArtifactFile,
                             validators.has_either(["content", "task"]),
                             content=optional_spec(
                                 formatted(
                                     string_spec(),
                                     formatter=MergedOptionStringFormatter)
                             ),
                             task=optional_spec(
                                 formatted(
                                     string_spec(),
                                     formatter=MergedOptionStringFormatter)
                             ),
                             path=formatted(
                                 string_spec(),
                                 formatter=MergedOptionStringFormatter),
                             task_runner=formatted(
                                 always_same_spec("{task_runner}"),
                                 formatter=MergedOptionStringFormatter)))))
         ),
         newrelic=optional_spec(
             create_spec(
                 stack_objs.NewRelic,
                 api_key=required(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 account_id=required(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 application_id=required(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 env=listof(stack_specs.env_spec(),
                            expect=stack_objs.EnvironmentVariable),
                 deployed_version=required(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)))),
         downtimer_options=optional_spec(
             dictof(
                 valid_string_spec(valid_alerting_system()),
                 create_spec(
                     stack_objs.DowntimerOptions,
                     hosts=listof(
                         formatted(
                             string_spec(),
                             formatter=MergedOptionStringFormatter))))),
         alerting_systems=optional_spec(
             dictof(string_spec(), self.alerting_system_spec)),
         ssh=optional_spec(
             create_spec(
                 stack_objs.SSH,
                 validators.deprecated_key(
                     "autoscaling_group_id",
                     "Use ``auto_scaling_group_name``"),
                 user=required(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 bastion=optional_spec(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 bastion_user=required(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 bastion_key_location=optional_spec(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 instance_key_location=optional_spec(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 address=optional_spec(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 instance=optional_spec(
                     listof(
                         formatted(string_spec(),
                                   formatter=MergedOptionStringFormatter))),
                 auto_scaling_group_name=optional_spec(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)),
                 bastion_key_path=formatted(
                     defaulted(
                         string_spec(),
                         "{config_root}/{environment}/bastion_ssh_key.pem"),
                     formatter=MergedOptionStringFormatter),
                 instance_key_path=formatted(
                     defaulted(string_spec(),
                               "{config_root}/{environment}/ssh_key.pem"),
                     formatter=MergedOptionStringFormatter),
                 storage_type=formatted(
                     defaulted(string_choice_spec(["url", "rattic"]),
                               "url"),
                     formatter=MergedOptionStringFormatter),
                 storage_host=optional_spec(
                     formatted(string_spec(),
                               formatter=MergedOptionStringFormatter)))),
         confirm_deployment=optional_spec(self.confirm_deployment_spec))
Beispiel #37
0
    def image_spec(self):
        """Spec for each image"""
        from harpoon.option_spec import image_specs as specs
        from harpoon.option_spec import image_objs
        class persistence_shell_spec(Spec):
            """Make the persistence shell default to the shell on the image"""
            def normalise(self, meta, val):
                shell = defaulted(string_spec(), "/bin/bash").normalise(meta, meta.everything[["images", meta.key_names()["_key_name_2"]]].get("shell", NotSpecified))
                shell = defaulted(formatted(string_spec(), formatter=MergedOptionStringFormatter), shell).normalise(meta, val)
                return shell

        return create_spec(image_objs.Image
            , validators.deprecated_key("persistence", "The persistence feature has been removed")
            , validators.deprecated_key("squash_after", "The squash feature has been removed")
            , validators.deprecated_key("squash_before_push", "The squash feature has been removed")

            # Changed how volumes_from works
            , validators.deprecated_key("volumes_from", "Use ``volumes.share_with``")

            # Deprecated link
            , validators.deprecated_key("link", "Use ``links``")

            # Harpoon options
            , harpoon = any_spec()

            # default the name to the key of the image
            , tag = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))
            , name = formatted(defaulted(string_spec(), "{_key_name_1}"), formatter=MergedOptionStringFormatter)
            , key_name = formatted(overridden("{_key_name_1}"), formatter=MergedOptionStringFormatter)
            , image_name = optional_spec(string_spec())
            , image_index = formatted(defaulted(string_spec(), ""), formatter=MergedOptionStringFormatter)
            , container_name = optional_spec(string_spec())
            , image_name_prefix = defaulted(string_spec(), "")

            , no_tty_option = defaulted(formatted(boolean(), formatter=MergedOptionStringFormatter), False)

            , user = defaulted(string_spec(), None)
            , configuration = any_spec()

            , vars = dictionary_spec()
            , assume_role = optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter))
            , deleteable_image = defaulted(boolean(), False)

            , authentication = self.authentications_spec

            # The spec itself
            , shell = defaulted(formatted(string_spec(), formatter=MergedOptionStringFormatter), "/bin/bash")
            , bash = delayed(optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter)))
            , command = delayed(optional_spec(formatted(string_spec(), formatter=MergedOptionStringFormatter)))
            , commands = required(container_spec(Commands, listof(command_spec())))
            , cache_from = delayed(or_spec(boolean(), listof(formatted(string_spec(), formatter=MergedOptionStringFormatter))))
            , cleanup_intermediate_images = defaulted(boolean(), True)

            , links = listof(specs.link_spec(), expect=image_objs.Link)

            , context = self.context_spec
            , wait_condition = optional_spec(self.wait_condition_spec)

            , lxc_conf = defaulted(filename_spec(), None)

            , volumes = create_spec(image_objs.Volumes
                , mount = listof(specs.mount_spec(), expect=image_objs.Mount)
                , share_with = listof(formatted(string_spec(), MergedOptionStringFormatter, expected_type=image_objs.Image))
                )

            , dependency_options = dictof(specs.image_name_spec()
                , create_spec(image_objs.DependencyOptions
                  , attached = defaulted(boolean(), False)
                  , wait_condition = optional_spec(self.wait_condition_spec)
                  )
                )

            , env = listof(specs.env_spec(), expect=image_objs.Environment)
            , ports = listof(specs.port_spec(), expect=image_objs.Port)
            , ulimits = defaulted(listof(dictionary_spec()), None)
            , log_config = defaulted(listof(dictionary_spec()), None)
            , security_opt = defaulted(listof(string_spec()), None)
            , read_only_rootfs = defaulted(boolean(), False)

            , other_options = create_spec(other_options
                , start = dictionary_spec()
                , build = dictionary_spec()
                , create = dictionary_spec()
                , host_config = dictionary_spec()
                )

            , network = create_spec(image_objs.Network
                , dns = defaulted(listof(string_spec()), None)
                , mode = defaulted(string_spec(), None)
                , hostname = defaulted(string_spec(), None)
                , domainname = defaulted(string_spec(), None)
                , disabled = defaulted(boolean(), False)
                , dns_search = defaulted(listof(string_spec()), None)
                , extra_hosts = listof(string_spec())
                , network_mode = defaulted(string_spec(), None)
                , publish_all_ports = defaulted(boolean(), False)
                )

            , cpu = create_spec(image_objs.Cpu
                , cap_add = defaulted(listof(string_spec()), None)
                , cpuset_cpus = defaulted(string_spec(), None)
                , cpuset_mems = defaulted(string_spec(), None)
                , cap_drop = defaulted(listof(string_spec()), None)
                , mem_limit = defaulted(integer_spec(), 0)
                , cpu_shares = defaulted(integer_spec(), None)
                , memswap_limit = defaulted(integer_spec(), 0)
                )

            , devices = defaulted(listof(dictionary_spec()), None)
            , privileged = defaulted(boolean(), False)
            , restart_policy = defaulted(string_spec(), None)
            )
Beispiel #38
0
            , name = sb.formatted(sb.overridden("{_key_name_1}"), formatter=MergedOptionStringFormatter)
            , provider_type = sb.required(sb.string_spec())
            , username = sb.required(formatted_string)
            , password = sb.required(formatted_string)
            )

formatted_string = sb.formatted(sb.string_spec(), formatter=MergedOptionStringFormatter)

artifact_command_spec = lambda : sb.create_spec(ArtifactCommand
    , copy = sb.listof(artifact_path_spec())
    , modify = sb.dictof(sb.string_spec(), sb.set_options(append=sb.listof(formatted_string)))
    , command = sb.listof(formatted_string)
    , timeout = sb.defaulted(sb.integer_spec(), 600)
    , temp_dir = sb.defaulted(formatted_string, None)
    , add_into_tar = sb.listof(artifact_path_spec())
    )

params_json_spec = lambda: sb.listof(sb.set_options(
      ParameterKey = sb.required(sb.any_spec())
    , ParameterValue = sb.required(sb.any_spec())
    ))

params_yaml_spec = lambda: sb.dictionary_spec()

stack_json_spec = lambda: sb.set_options(
      Resources = sb.required(sb.dictof(sb.string_spec(), sb.set_options(Type=sb.required(sb.string_spec()), Properties=sb.optional_spec(sb.dictionary_spec()))))
    , Parameters = sb.optional_spec(sb.dictof(sb.string_spec(), sb.dictionary_spec()))
    , Outputs = sb.optional_spec(sb.dictof(sb.string_spec(), sb.dictionary_spec()))
    )