Skip to content

Commit

Permalink
don't write token if everything is already good
Browse files Browse the repository at this point in the history
  • Loading branch information
ceesem committed Oct 24, 2024
1 parent 80056fe commit 6f3c2fb
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions caveclient/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,21 @@ def write_token(token, filepath, key, overwrite=True, ignore_readonly=False):
else:
secrets = {}

secrets[key] = token

secret_dir = os.path.dirname(filepath)
if not os.path.exists(secret_dir):
full_dir = os.path.expanduser(secret_dir)
os.makedirs(full_dir)

if not os.access(secret_dir, os.W_OK) and ignore_readonly:
if secrets.get(key) == token:
return
else:
with open(filepath, "w") as f:
json.dump(secrets, f)
secrets[key] = token

secret_dir = os.path.dirname(filepath)
if not os.path.exists(secret_dir):
full_dir = os.path.expanduser(secret_dir)
os.makedirs(full_dir)

if not os.access(secret_dir, os.W_OK) and ignore_readonly:
return
else:
with open(filepath, "w") as f:
json.dump(secrets, f)


def server_token_filename(server_address):
Expand Down

0 comments on commit 6f3c2fb

Please sign in to comment.