Skip to content

Commit

Permalink
Get secrets, then delete environment variables that are in secrets co…
Browse files Browse the repository at this point in the history
  • Loading branch information
thorfi committed Nov 13, 2023
1 parent de8fd07 commit 438331b
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions ecs_composex/ecs/ecs_family/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,22 +513,26 @@ def set_add_region_when_external(self):

def sort_env_vars_alphabetically(self):
for service in self.services:
environment = getattr(service.container_definition, "Environment")
if not environment:
pass
original = [_env for _env in environment if isinstance(_env, Environment)]
sorted_env = sorted(original, key=lambda x: x.Name)
for _env in environment:
if not isinstance(_env, Environment):
sorted_env.append(_env)
setattr(service.container_definition, "Environment", sorted_env)
secrets = getattr(service.container_definition, "Secrets")
original_secrets = [_env for _env in secrets if isinstance(_env, Secret)]
sorted_secrets = sorted(original_secrets, key=lambda x: x.Name)
for _secret in secrets:
if not isinstance(_secret, Secret):
sorted_secrets.append(_secret)
setattr(service.container_definition, "Secrets", sorted_secrets)
if secrets:
original_secrets = [_env for _env in secrets if isinstance(_env, Secret)]
sorted_secrets = sorted(original_secrets, key=lambda x: x.Name)
for _secret in secrets:
if not isinstance(_secret, Secret):
sorted_secrets.append(_secret)
setattr(service.container_definition, "Secrets", sorted_secrets)
secret_names = frozenset(x.Name for x in sorted_secrets)
else:
secret_names = frozenset()
environment = getattr(service.container_definition, "Environment")
if environment:
remove_secrets = [_env for _env in environment if _env.Name not in secret_names]
original = [_env for _env in remove_secrets if isinstance(_env, Environment)]
sorted_env = sorted(original, key=lambda x: x.Name)
for _env in environment:
if not isinstance(_env, Environment):
sorted_env.append(_env)
setattr(service.container_definition, "Environment", sorted_env)

def set_services_to_services_dependencies(self):
"""
Expand Down

0 comments on commit 438331b

Please sign in to comment.