Skip to content

fix(credentials): read runpodctl top-level apikey as fallback - #369

Draft
justinwlin wants to merge 1 commit into
mainfrom
fix/363-runpodctl-apikey-compat
Draft

fix(credentials): read runpodctl top-level apikey as fallback#369
justinwlin wants to merge 1 commit into
mainfrom
fix/363-runpodctl-apikey-compat

Conversation

@justinwlin

Copy link
Copy Markdown

flash could not authenticate from a ~/.runpod/config.toml written by runpodctl. runpodctl writes a top-level apikey key with no [default] profile table, but get_api_key() only consulted runpod-python's profile-based get_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 usable api_key, flash parses the config file directly (via tomllib) and returns the top-level apikey (apiurl stays ignored). Precedence is unchanged: env var > [default].api_key > runpodctl top-level apikey.

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 with tomllib and returns the top-level apikey when the [default] profile has no usable key. Missing file, malformed TOML, and blank/non-string keys all yield None as before.
  • tests/unit/test_credentials.py: new tests — runpodctl-format config (top-level apikey only) yields the key; [default] profile takes precedence over the top-level key; blank top-level apikey is ignored; no credentials file still raises RunpodAPIKeyError via validate_api_key().

How verified

  • pytest tests/unit/test_credentials.py tests/unit/test_credential_migration.py — 33 passed.
  • pytest on all credential/login/API-key-related unit files (7 files) — 104 passed.
  • ruff check and ruff format --check on both touched files — clean.
  • mypy full run: no net-new errors vs main (261 pre-existing errors; the 2 attributed to credentials.py are pre-existing patterns — tomllib stub and Any return — identical before and after).

The write path (save_api_key) already preserved runpodctl's top-level keys; this PR only fixes the read path.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flash cannot read a ~/.runpod/config.toml written by runpodctl; the error suggests exporting the key instead

1 participant