# Path: stacker_blueprints/kms.py
# class Key(Blueprint):
#     VARIABLES = {
#         "KeyAlias": {
#             "type": str,
#             "description": "The alias to give the key.",
#             "default": "",
#         },
#         "Properties": {
#             "type": dict,
#             "description": "A dictionary of KMS key attributes which should "
#                            "match the attributes for AWS::KMS::Key "
#                            "Cloudformation resource. Note: You should "
#                            "not supply a `KeyPolicy` attribute.",
#             "default": {},
#         },
#         "Attributes": {
#             "type": dict,
#             "description": "Deprecated. Use Properties instead.",
#             "default": {},
#         }
#     }
# 
#     def generate_key_policy(self):
#         return kms_key_policy()
# 
#     def create_template(self):
#         t = self.template
#         variables = self.get_variables()
# 
#         key_policy = self.generate_key_policy()
#         props = variables["Properties"]
# 
#         if variables["Attributes"]:
#             raise DeprecationWarning(
#                     "Attributes was deprecated, use Properties instead.")
# 
#         if "KeyPolicy" in props:
#             logger.warning("KeyPolicy provided, but not used. To write "
#                            "your own policy you need to subclass this "
#                            "blueprint and override `generate_key_policy`.")
#         props["KeyPolicy"] = key_policy
# 
#         key = t.add_resource(
#             kms.Key.from_dict("Key", props)
#         )
# 
#         key_arn = Join(
#             "",
#             [
#                 "arn:aws:kms:",
#                 Ref("AWS::Region"),
#                 ":",
#                 Ref("AWS::AccountId"),
#                 ":key/",
#                 Ref(key)
#             ]
#         )
# 
#         t.add_output(Output("KeyArn", Value=key_arn))
#         t.add_output(Output("KeyId", Value=Ref(key)))
# 
#         key_alias = variables["KeyAlias"]
#         if key_alias:
#             if not key_alias.startswith("alias/"):
#                 key_alias = "alias/%s" % key_alias
#             alias = t.add_resource(
#                 kms.Alias(
#                     "Alias",
#                     AliasName="%s" % key_alias,
#                     TargetKeyId=Ref(key)
#                 )
#             )
# 
#             t.add_output(Output("KeyAlias", Value=Ref(alias)))


from stacker.context import Context
from stacker.config import Config
from stacker.variables import Variable
from stacker_blueprints.kms import Key
from stacker.blueprints.testutil import BlueprintTestCase
            [
                Variable("KeyAlias", "alias/a-test-key"),
                Variable("Properties", {"Description": "a KMS test-key."}),
            ]
        )
        blueprint.create_template()
        self.assertRenderedBlueprint(blueprint)

    def test_kms_key_alias_not_in_keyalias(self):
        blueprint = Key('kms_key_b', self.ctx)
        blueprint.resolve_variables(
            [
                Variable("KeyAlias", "b-test-key"),
                Variable("Properties", {"Description": "b KMS test-key."}),
            ]
        )
        blueprint.create_template()
        self.assertRenderedBlueprint(blueprint)

    def test_kms_key_without_properties(self):
        blueprint = Key('kms_key_c', self.ctx)
        blueprint.resolve_variables(
            [
                Variable("KeyAlias", "alias/c-test-key"),
            ]
        )
        blueprint.create_template()
        self.assertRenderedBlueprint(blueprint)

    def test_kms_key_attributes_is_deprecated(self):

# Path: stacker_blueprints/kms.py
# class Key(Blueprint):
#     VARIABLES = {
#         "KeyAlias": {
#             "type": str,
#             "description": "The alias to give the key.",
#             "default": "",
#         },
#         "Properties": {
#             "type": dict,
#             "description": "A dictionary of KMS key attributes which should "
#                            "match the attributes for AWS::KMS::Key "
#                            "Cloudformation resource. Note: You should "
#                            "not supply a `KeyPolicy` attribute.",
#             "default": {},
#         },
#         "Attributes": {
#             "type": dict,
#             "description": "Deprecated. Use Properties instead.",
#             "default": {},
#         }
#     }
# 
#     def generate_key_policy(self):
#         return kms_key_policy()
# 
#     def create_template(self):
#         t = self.template
#         variables = self.get_variables()
# 
#         key_policy = self.generate_key_policy()
#         props = variables["Properties"]
# 
#         if variables["Attributes"]:
#             raise DeprecationWarning(
#                     "Attributes was deprecated, use Properties instead.")
# 
#         if "KeyPolicy" in props:
#             logger.warning("KeyPolicy provided, but not used. To write "
#                            "your own policy you need to subclass this "
#                            "blueprint and override `generate_key_policy`.")
#         props["KeyPolicy"] = key_policy
# 
#         key = t.add_resource(
#             kms.Key.from_dict("Key", props)
#         )
# 
#         key_arn = Join(
#             "",
#             [
#                 "arn:aws:kms:",
#                 Ref("AWS::Region"),
#                 ":",
#                 Ref("AWS::AccountId"),
#                 ":key/",
#                 Ref(key)
#             ]
#         )
# 
#         t.add_output(Output("KeyArn", Value=key_arn))
#         t.add_output(Output("KeyId", Value=Ref(key)))
# 
#         key_alias = variables["KeyAlias"]
#         if key_alias:
#             if not key_alias.startswith("alias/"):
#                 key_alias = "alias/%s" % key_alias
#             alias = t.add_resource(
#                 kms.Alias(
#                     "Alias",
#                     AliasName="%s" % key_alias,
#                     TargetKeyId=Ref(key)
#                 )
#             )
# 
#             t.add_output(Output("KeyAlias", Value=Ref(alias)))


# Path: tests/test_kms.py
from stacker.context import Context
from stacker.config import Config
from stacker.variables import Variable
from stacker_blueprints.kms import Key
from stacker.blueprints.testutil import BlueprintTestCase

            [
                Variable("KeyAlias", "alias/a-test-key"),
                Variable("Properties", {"Description": "a KMS test-key."}),
            ]
        )
        blueprint.create_template()
        self.assertRenderedBlueprint(blueprint)

    def test_kms_key_alias_not_in_keyalias(self):
        blueprint = Key('kms_key_b', self.ctx)
        blueprint.resolve_variables(
            [
                Variable("KeyAlias", "b-test-key"),
                Variable("Properties", {"Description": "b KMS test-key."}),
            ]
        )
        blueprint.create_template()
        self.assertRenderedBlueprint(blueprint)

    def test_kms_key_without_properties(self):
        blueprint = Key('kms_key_c', self.ctx)
        blueprint.resolve_variables(
            [
                Variable("KeyAlias", "alias/c-test-key"),
            ]
        )
        blueprint.create_template()
        self.assertRenderedBlueprint(blueprint)

    def test_kms_key_attributes_is_deprecated(self):

        blueprint = Key('kms_key_attributes_deprecated', self.ctx)