Beispiel #1
0
 def load_manifest_from_ssm(env_name: str, type: Type[T]) -> Optional[T]:
     if type is Manifest:
         context_parameter_name = f"/orbit/{env_name}/manifest"
         main = ssm.get_parameter_if_exists(name=context_parameter_name)
         if main is None:
             return None
         teams_parameters = ssm.list_parameters(
             prefix=f"/orbit/{env_name}/teams/")
         _logger.debug("teams_parameters (/orbit/%s/teams/): %s", env_name,
                       teams_parameters)
         teams = [
             ssm.get_parameter(name=p) for p in teams_parameters
             if p.endswith("/manifest")
         ]
         main["Teams"] = teams
         return cast(
             T,
             Manifest.Schema().load(data=main,
                                    many=False,
                                    partial=False,
                                    unknown=EXCLUDE))
     elif type is FoundationManifest:
         context_parameter_name = f"/orbit-f/{env_name}/manifest"
         main = ssm.get_parameter_if_exists(name=context_parameter_name)
         if main is None:
             return None
         return cast(
             T,
             FoundationManifest.Schema().load(data=main,
                                              many=False,
                                              partial=False,
                                              unknown=EXCLUDE))
     else:
         raise ValueError("Unknown 'manifest' Type")
 def load_context_from_ssm(env_name: str, type: Type[V]) -> V:
     if type is Context:
         context_parameter_name: str = f"/orbit/{env_name}/context"
         if ssm.does_parameter_exist(context_parameter_name):
             main = ssm.get_parameter(name=context_parameter_name)
         else:
             msg = f"SSM parameter {context_parameter_name} not found for env {env_name}"
             _logger.error(msg)
             raise Exception(msg)
         teams_parameters = ssm.list_parameters(
             prefix=f"/orbit/{env_name}/teams/")
         _logger.debug("teams_parameters: %s", teams_parameters)
         teams = [
             ssm.get_parameter_if_exists(name=p) for p in teams_parameters
             if p.endswith("/context")
         ]
         main["Teams"] = [t for t in teams if t]
         return cast(
             V,
             Context.Schema().load(data=main,
                                   many=False,
                                   partial=False,
                                   unknown="RAISE"))
     elif type is FoundationContext:
         context_parameter_name = f"/orbit-foundation/{env_name}/context"
         main = ssm.get_parameter(name=context_parameter_name)
         return cast(
             V,
             FoundationContext.Schema().load(data=main,
                                             many=False,
                                             partial=False,
                                             unknown="RAISE"))
     else:
         raise ValueError("Unknown 'context' Type")
Beispiel #3
0
def destroy_teams(env: str, debug: bool) -> None:
    with MessagesContext("Destroying", debug=debug) as msg_ctx:
        ssm.cleanup_changeset(env_name=env)

        if not ssm.list_parameters(prefix=f"/orbit/{env}/teams/"):
            msg_ctx.info(f"No {env} Teams found.")
            msg_ctx.progress(100)
            return

        context: "Context" = ContextSerDe.load_context_from_ssm(env_name=env,
                                                                type=Context)
        msg_ctx.info("Context loaded")
        msg_ctx.info(f"Teams: {','.join([t.name for t in context.teams])}")
        msg_ctx.progress(2)

        plugins.PLUGINS_REGISTRIES.load_plugins(
            context=context,
            msg_ctx=msg_ctx,
            plugin_changesets=[],
            teams_changeset=None,
        )
        msg_ctx.progress(4)

        if any(
                cfn.does_stack_exist(stack_name=t.stack_name)
                for t in context.teams):
            bundle_path = bundle.generate_bundle(command_name="destroy",
                                                 context=context)
            msg_ctx.progress(5)

            buildspec = codebuild.generate_spec(
                context=context,
                plugins=True,
                cmds_build=[f"orbit remote --command destroy_teams {env}"],
                changeset=None,
            )
            remote.run(
                command_name="destroy",
                context=context,
                bundle_path=bundle_path,
                buildspec=buildspec,
                codebuild_log_callback=msg_ctx.progress_bar_callback,
                timeout=45,
            )
        msg_ctx.progress(95)

        msg_ctx.info("Teams Destroyed")
        msg_ctx.progress(100)
def destroy_teams(env: str, debug: bool) -> None:
    with MessagesContext("Destroying", debug=debug) as msg_ctx:
        ssm.cleanup_changeset(env_name=env)

        if not ssm.list_parameters(prefix=f"/orbit/{env}/teams/"):
            msg_ctx.info(f"No {env} Teams found.")
            msg_ctx.progress(100)
            return

        msg_ctx.progress(15)
        context: "Context" = ContextSerDe.load_context_from_ssm(env_name=env,
                                                                type=Context)
        msg_ctx.info("Context loaded")
        msg_ctx.info(f"Teams: {','.join([t.name for t in context.teams])}")
        msg_ctx.progress(25)

        if any(
                cfn.does_stack_exist(stack_name=t.stack_name)
                for t in context.teams):
            destroy.destroy_teams(env_name=context.name)
        msg_ctx.progress(95)

        msg_ctx.info("Teams Destroyed")
        msg_ctx.progress(100)