fix(credentials): read runpodctl top-level apikey as fallback - #369
Draft
justinwlin wants to merge 1 commit into
Draft
fix(credentials): read runpodctl top-level apikey as fallback#369justinwlin wants to merge 1 commit into
justinwlin wants to merge 1 commit into
Conversation
get_api_key() only consulted runpod-python's [default] profile, so a config.toml written by runpodctl (top-level apikey/apiurl, no profile table) was read without error yet yielded no key, making flash report 'No RunPod API key found' despite a valid key sitting in the file. Add a file-based fallback: when the profile lookup finds no usable api_key, parse ~/.runpod/config.toml directly (tomllib) and return the top-level apikey. Precedence is unchanged: env var > [default].api_key > runpodctl top-level apikey. apiurl stays ignored. Fixes #363
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.
flash could not authenticate from a
~/.runpod/config.tomlwritten by runpodctl. runpodctl writes a top-levelapikeykey with no[default]profile table, butget_api_key()only consulted runpod-python's profile-basedget_credentials(), which returns no key in that case — so flash reported "No RunPod API key found" about a file it read without error that contained a valid key. This adds a file-based fallback: when the profile lookup finds no usableapi_key, flash parses the config file directly (viatomllib) and returns the top-levelapikey(apiurlstays ignored). Precedence is unchanged: env var >[default].api_key> runpodctl top-levelapikey.Fixes #363
Internal: CON-1228
What changed
src/runpod_flash/core/credentials.py:get_api_key()now falls back to a new_get_runpodctl_api_key()helper that parses the credential file withtomlliband returns the top-levelapikeywhen the[default]profile has no usable key. Missing file, malformed TOML, and blank/non-string keys all yieldNoneas before.tests/unit/test_credentials.py: new tests — runpodctl-format config (top-levelapikeyonly) yields the key;[default]profile takes precedence over the top-level key; blank top-levelapikeyis ignored; no credentials file still raisesRunpodAPIKeyErrorviavalidate_api_key().How verified
pytest tests/unit/test_credentials.py tests/unit/test_credential_migration.py— 33 passed.pyteston all credential/login/API-key-related unit files (7 files) — 104 passed.ruff checkandruff format --checkon both touched files — clean.mypyfull run: no net-new errors vsmain(261 pre-existing errors; the 2 attributed tocredentials.pyare pre-existing patterns —tomllibstub andAnyreturn — identical before and after).The write path (
save_api_key) already preserved runpodctl's top-level keys; this PR only fixes the read path.