Repository navigation
Find the key from .env or modapi login; clearer doctor output - #11
Merged
Merged
Conversation
… doctor - With no --secret-key, MODAPI_SECRET_KEY or `modapi configure` key, API commands now use the MODAPI_SECRET_KEY that `modapi init` wrote to the env file in the current directory, or the organization key from MODAPI_ORGANIZATION_KEY / `modapi login`. projects and channels try the organization key first. Before, they sent an empty "Bearer" and the API answered malformed_api_key. - With no key at all, the command stops before the request (exit 3) and says to run `modapi init` or `modapi login`. - doctor groups its checks into problems, warnings and passed, shows each fix as "Fix: <command>", ends with "1 problem, 2 warnings." and no longer prints a generic error block below that in a terminal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Bug: in a project set up with
modapi init, commands such asmodapi projects listormodapi wordlist listfailed with401 malformed_api_key. They looked for a key only in--secret-key,MODAPI_SECRET_KEYand themodapi configurekeychain or config, and found none, so they sentAuthorization: Bearerwith nothing after it.doctorpassed anyway, because it also reads the project's env file.Key fallback (
internal/custom/fallbackkey.go, wired incustom.Registeraround the root'sPersistentPreRunE)--secret-key,MODAPI_SECRET_KEY, ormodapi configure.MODAPI_SECRET_KEYfrom the env file in the current directory (.env.local,.env, …, asdoctorfinds it), then the organization key (MODAPI_ORGANIZATION_KEY, then themodapi loginsession).projectsandchannelstry the organization key first, because the management API needs one.modapi init,modapi login, or set the key.--dry-runstill works without a key.MODAPI_SECRET_KEY, which the generated client reads, so no generated file changes.doctor output (terminal only;
-o jsonand agent mode are unchanged)--colorandNO_COLOR.Error (runtime_error) … CLI_RUNTIMEblock below.Tests:
.envkey is used; an explicit key wins;projects listuses the organization key; with no key, no request is sent and the command exits 3.doctorhuman output, with nothing on stderr.go test ./...passes.Release: this is hand-written code only, so the generator won't bump the version by itself. It ships with the next CLI release.
modapi link(next PR, needs moderation-api/api#454) will come with that release.🤖 Generated with Claude Code