Skip to content

Commit

Permalink
fix: improve error handling and logging for token generator
Browse files Browse the repository at this point in the history
  • Loading branch information
echozio committed May 28, 2024
1 parent 944f130 commit 1ca3042
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion scripts/token-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ def getSecret(fullname):
return None

def updateSecret(secret):
proc = subprocess.run(
subprocess.run(
[
"kubectl",
"apply",
"-f",
"-",
],
input=json.dumps(secret).encode(),
check=True,
)

def generateTokenSet(service, globalHashSecret):
Expand Down Expand Up @@ -103,6 +104,7 @@ def __main__():
try:
globalHashSecret = b64decode(secret["data"].get("globalHashSecret"))
except:
log("No global hash secret found, generating one...")
globalHashSecret = secrets.token_urlsafe(SECRET_LENGTH)
secret["data"]["globalHashSecret"] = b64encode(globalHashSecret)

Expand All @@ -114,6 +116,7 @@ def __main__():
b64decode(secret["data"].get(f"{service}AuthTokens")),
globalHashSecret
)
log(f"Token for {service} is valid.")
except:
log(f"Generating token for {service}...")
secret["data"].update(generateTokenSet(service, globalHashSecret))
Expand Down

0 comments on commit 1ca3042

Please sign in to comment.