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")
def load_changeset_from_ssm(env_name: str) -> Optional[Changeset]:
    content = ssm.get_parameter_if_exists(name=f"/orbit/{env_name}/changeset")
    if content is None:
        return None
    return cast(
        Changeset,
        Changeset.Schema().load(data=content,
                                many=False,
                                partial=False,
                                unknown="RAISE"))