Skip to content

Commit

Permalink
fix regression where COLD_PW can no longer be passed with env vars co…
Browse files Browse the repository at this point in the history
…ntaining hyphen
  • Loading branch information
mjurbanski-reef committed Sep 14, 2024
1 parent 7d6bcad commit 68e1d96
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion bittensor/keyfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import json
import stat
import getpass
import warnings

import bittensor
from bittensor.errors import KeyFileError
from typing import Optional
Expand Down Expand Up @@ -282,7 +284,19 @@ def get_coldkey_password_from_environment(coldkey_name: str) -> Optional[str]:
for env_name, env_value in os.environ.items()
if (normalized_env_name := env_name.upper()).startswith("BT_COLD_PW_")
}
return envs.get(f"BT_COLD_PW_{coldkey_name.replace('-', '_').upper()}")
pass_ = envs.get(f"BT_COLD_PW_{coldkey_name.upper()}")
if "-" in coldkey_name:
if pass_ is None:
return envs.get(f"BT_COLD_PW_{coldkey_name.replace('-', '_').upper()}")
else:
warnings.warn(
"Cold key name contains a hyphen. "
"Please use an underscore instead in enviornment variable name. "
"In future versions all environment variables with hypens will be ignored.",
DeprecationWarning,
)
return pass_
return pass_


def decrypt_keyfile_data(
Expand Down
2 changes: 2 additions & 0 deletions tests/unit_tests/test_keyfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,12 @@ def test_get_coldkey_password_from_environment(monkeypatch):
"WALLET": "password",
"my_wallet": "password2",
"my-wallet": "password2",
"my-wallet3": "password3",
}

monkeypatch.setenv("bt_cold_pw_wallet", password_by_wallet["WALLET"])
monkeypatch.setenv("BT_COLD_PW_My_Wallet", password_by_wallet["my_wallet"])
monkeypatch.setenv("BT_COLD_PW_My-Wallet3", password_by_wallet["my-wallet3"])

for wallet, password in password_by_wallet.items():
assert get_coldkey_password_from_environment(wallet) == password
Expand Down

0 comments on commit 68e1d96

Please sign in to comment.