Skip to content

Commit 97f658c

Browse files
fix: regex for api key shell export
1 parent 8753e54 commit 97f658c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

codeflash/code_utils/shell_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
SHELL_RC_EXPORT_PATTERN = re.compile(r"^set CODEFLASH_API_KEY=(cf-.*)$", re.MULTILINE)
1616
SHELL_RC_EXPORT_PREFIX = "set CODEFLASH_API_KEY="
1717
else:
18-
SHELL_RC_EXPORT_PATTERN = re.compile(r'^(?!#)export CODEFLASH_API_KEY=[\'"]?(cf-[^\s"]+)[\'"]$', re.MULTILINE)
18+
SHELL_RC_EXPORT_PATTERN = re.compile(
19+
r'^(?!#)export CODEFLASH_API_KEY=(?:"|\')?(cf-[^\s"\']+)(?:"|\')?$', re.MULTILINE
20+
)
1921
SHELL_RC_EXPORT_PREFIX = "export CODEFLASH_API_KEY="
2022

2123

tests/test_shell_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ def test_valid_api_key(self):
6464
) as mock_file:
6565
self.assertEqual(read_api_key_from_shell_config(), None)
6666
mock_file.assert_called_once_with(self.test_rc_path, encoding="utf8")
67+
with patch(
68+
"builtins.open", mock_open(read_data=f'export CODEFLASH_API_KEY={self.api_key}\n')
69+
) as mock_file:
70+
self.assertEqual(read_api_key_from_shell_config(), self.api_key)
71+
mock_file.assert_called_once_with(self.test_rc_path, encoding="utf8")
72+
6773

6874
@patch("codeflash.code_utils.shell_utils.get_shell_rc_path")
6975
def test_no_api_key(self, mock_get_shell_rc_path):

0 commit comments

Comments
 (0)