Skip to content

Commit

Permalink
Move func into a utils file
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgianaElena committed Oct 17, 2023
1 parent 99b42e7 commit 902ea9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
21 changes: 1 addition & 20 deletions deployer/infra_components/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import tempfile
from contextlib import contextmanager

from deployer.utils.env_vars_management import unset_env_vars
from deployer.utils.file_acquisition import (
HELM_CHARTS_DIR,
get_decrypted_file,
Expand All @@ -14,26 +15,6 @@
from .hub import Hub


@contextmanager
def unset_env_vars(vars):
"""
Temporarily unset env vars in vars if they exist
"""
orig_values = {}
for e in vars:
if e in os.environ:
orig_values[e] = os.environ[e]
# Clear values from os.environ if they are present!
del os.environ[e]

try:
yield
finally:
for e in orig_values:
# Put values back into os.environ when contextmanager returns
os.environ[e] = orig_values[e]


class Cluster:
"""
A single k8s cluster we can deploy to
Expand Down
22 changes: 22 additions & 0 deletions deployer/utils/env_vars_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os
from contextlib import contextmanager


@contextmanager
def unset_env_vars(vars):
"""
Temporarily unset env vars in vars if they exist
"""
orig_values = {}
for e in vars:
if e in os.environ:
orig_values[e] = os.environ[e]
# Clear values from os.environ if they are present!
del os.environ[e]

try:
yield
finally:
for e in orig_values:
# Put values back into os.environ when contextmanager returns
os.environ[e] = orig_values[e]

0 comments on commit 902ea9c

Please sign in to comment.