Skip to content

Commit

Permalink
Updated with globals refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz00 committed May 19, 2024
1 parent 0b10a70 commit a1076dc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
13 changes: 3 additions & 10 deletions bin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@
FONT_BOLD_PATH,
)

# Define paths
BASE_DIR = globals.BIN_DIR
ROOT_DIR = globals.ROOT_DIR
FONTS_DIR = globals.FONT_DIR
ENV_PATH = globals.ENV_PATH

# Load .env
load_dotenv(dotenv_path=ENV_PATH)
load_dotenv(dotenv_path=globals.ENV_PATH)

# Set environment variables
jamf_url = os.getenv("URL")
Expand Down Expand Up @@ -116,16 +110,15 @@ def update_env(token: AnyStr, expires_in: int) -> None:
:type expires_in: int
"""
try:
dotenv_path = os.path.join(ROOT_DIR, ".env")
expiration_time = datetime.utcnow() + timedelta(seconds=expires_in)

# Small buffer to account for time sync issues
buffer = 5 * 60
expiration_timestamp = (expiration_time - timedelta(seconds=buffer)).timestamp()

set_key(dotenv_path=dotenv_path, key_to_set="TOKEN", value_to_set=token)
set_key(dotenv_path=globals.ENV_PATH, key_to_set="TOKEN", value_to_set=token)
set_key(
dotenv_path=dotenv_path,
dotenv_path=globals.ENV_PATH,
key_to_set="TOKEN_EXPIRATION",
value_to_set=str(expiration_timestamp),
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_update_env(mock_set_key):
expires_in = 3600
utils.update_env(token=token, expires_in=expires_in)

dotenv_path = os.path.join(utils.ROOT_DIR, ".env")
dotenv_path = globals.ENV_PATH

expected_calls = [
call(
Expand Down

0 comments on commit a1076dc

Please # to comment.