fix(login): preserve runpodctl credentials in ~/.runpod/config.toml#333
Open
fix(login): preserve runpodctl credentials in ~/.runpod/config.toml#333
Conversation
flash login was clobbering the top-level apikey/apiurl values that runpodctl writes to ~/.runpod/config.toml, because it delegated to runpod-python's set_credentials() which opens the file in "w" mode. save_api_key() now does a line-based merge that updates only the [default].api_key field and preserves all other content. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates flash login credential persistence to avoid clobbering runpodctl’s top-level apikey/apiurl keys in ~/.runpod/config.toml by performing a targeted text merge that updates only [default].api_key.
Changes:
- Replace
runpod-python’sset_credentials(overwrite=True)usage with a line-based upsert that preserves unrelated TOML content. - Add unit tests covering mixed
runpodctl+[default]formats, missing[default], preserving other profiles, and fresh-file creation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/runpod_flash/core/credentials.py |
Implements _upsert_default_api_key() and updates save_api_key() to preserve non-flash TOML content. |
tests/unit/test_credentials.py |
Adds unit tests to validate config preservation behavior when saving API keys. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+27
to
+28
| _DEFAULT_HEADER_RE = re.compile(r"^\s*\[default\]\s*$") | ||
| _SECTION_HEADER_RE = re.compile(r"^\s*\[[^\]]+\]\s*$") |
Comment on lines
+79
to
+107
| def test_preserves_runpodctl_top_level_keys(self, isolate_credentials_file): | ||
| isolate_credentials_file.parent.mkdir(parents=True, exist_ok=True) | ||
| isolate_credentials_file.write_text( | ||
| "apikey = 'rpa_runpodctl_key'\n" | ||
| "apiurl = 'https://api.runpod.io/graphql'\n" | ||
| "\n" | ||
| "[default]\n" | ||
| 'api_key = "old-flash-key"\n' | ||
| ) | ||
| save_api_key("new-flash-key") | ||
| text = isolate_credentials_file.read_text() | ||
| assert "apikey = 'rpa_runpodctl_key'" in text | ||
| assert "apiurl = 'https://api.runpod.io/graphql'" in text | ||
| parsed = tomllib.loads(text) | ||
| assert parsed["apikey"] == "rpa_runpodctl_key" | ||
| assert parsed["apiurl"] == "https://api.runpod.io/graphql" | ||
| assert parsed["default"]["api_key"] == "new-flash-key" | ||
|
|
||
| def test_adds_default_section_when_missing(self, isolate_credentials_file): | ||
| isolate_credentials_file.parent.mkdir(parents=True, exist_ok=True) | ||
| isolate_credentials_file.write_text( | ||
| "apikey = 'rpa_runpodctl_key'\napiurl = 'https://api.runpod.io/graphql'\n" | ||
| ) | ||
| save_api_key("flash-key") | ||
| text = isolate_credentials_file.read_text() | ||
| parsed = tomllib.loads(text) | ||
| assert parsed["apikey"] == "rpa_runpodctl_key" | ||
| assert parsed["apiurl"] == "https://api.runpod.io/graphql" | ||
| assert parsed["default"]["api_key"] == "flash-key" |
Comment on lines
+123
to
+127
| insert_idx = default_end | ||
| while insert_idx > default_start + 1 and lines[insert_idx - 1].strip() == "": | ||
| insert_idx -= 1 | ||
| lines.insert(insert_idx, new_line + "\n") | ||
| return "".join(lines) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
flash loginwas clobbering the top-levelapikey/apiurlvalues thatrunpodctlwrites to~/.runpod/config.toml. The cause:save_api_key()delegated torunpod-python'sset_credentials(overwrite=True), which opens the file in"w"mode and rewrites it with only a[default]section.save_api_key()now does a line-based merge that updates only the[default].api_keyfield and preserves everything else — runpodctl's top-level keys, other profile sections, and any unrelated fields within[default].Test plan
[default]when missing, preserving other profile sections, fresh-file creationtest_credentials.pyandtest_login.pystill pass (26/26)[default]withoutapi_key, blank lines between sections)🤖 Generated with Claude Code