Skip to content

Commit

Permalink
Updating
Browse files Browse the repository at this point in the history
  • Loading branch information
jboucourt committed Aug 16, 2024
1 parent 3ce7d3a commit 7553fdf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions gestalt/vault.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import os
from datetime import datetime, timedelta, timezone
from queue import Queue
from threading import Thread, Event
from time import sleep
from typing import Any, Dict, List, Optional, Tuple, Union

import hvac # type: ignore
Expand Down Expand Up @@ -58,7 +56,6 @@ def __init__(

self.delay = delay
self.tries = tries
# self.kubernetes_ttl_renew: Optional[Thread] = None

@property
def vault_client(self) -> hvac.Client:
Expand Down Expand Up @@ -95,14 +92,14 @@ def connect(self) -> None:
)

if token is not None:
print("Kubernetes login successful")
kubes_token = (
"kubernetes",
token["data"]["id"],
token["data"]["ttl"],
token["data"]['expire_time'],
)
self.kubes_token = kubes_token
print(f"Token LookUp after K8s Login: {self.kubes_token}")
except hvac.exceptions.InvalidPath:
raise RuntimeError(
"Gestalt Error: Kubernetes auth couldn't be performed")
Expand Down Expand Up @@ -214,11 +211,8 @@ def scheme(self) -> str:
return self._scheme

def _validate_token_expiration(self) -> None:
# token_details = self.vault_client.auth.token.lookup_self()
print(f"Token Stored after K8s Login: {self.kubes_token}")
if self.kubes_token is not None:
expire_time = self.kubes_token[3]
print(f"ExpireTime: {expire_time}")
# Use isoparse to correctly parse the datetime string
expire_time = isoparse(expire_time)

Expand All @@ -233,11 +227,11 @@ def _validate_token_expiration(self) -> None:
delta_time = (expire_time - current_time).total_seconds() / 3600

if delta_time < EXPIRATION_THRESHOLD_HOURS:
print(f"Re-auth with vault")
print(f"Re-authenticating with vault")
self.connect()
else:
print(f"Token still valid for: {delta_time} days")
print(f"Token still valid for: {delta_time} hours")
else:
print(
f"Can't reconnect cause token: {self.kubes_token}, expire_time is None"
f"Can't reconnect, token information: {self.kubes_token}, not valid"
)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def readme():

setup(
name="gestalt-cfg",
version="3.4.2beta11",
version="3.4.2",
description="A sensible configuration library for Python",
long_description=readme(),
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 7553fdf

Please sign in to comment.