Skip to content

cmd/rocketclaw: let oai login set up ChatGPT on a fresh or AWS-stored config - #1552

Open
ucirello wants to merge 1 commit into
mainfrom
oai-login-setup
Open

ucirello wants to merge 1 commit into
mainfrom
oai-login-setup

Conversation

@ucirello

Copy link
Copy Markdown
Collaborator

Summary

rocketclaw oai login exists to switch a provider to ChatGPT sign-in, but it refused to run until the whole server configuration was valid. A fresh "openai": {} failed with openai.api_key is required when openai.auth is api_key, which is the very setting the command writes. When the provider lived only in the AWS secret, or there was no local config file, the command failed after you had already finished signing in in the browser. rocketclaw ts login was also blocked by settings it does not use, such as database_url.

What changes

  • oai login, oai list, and oai logout now check only that the provider exists. ts login checks only the web.tsnet settings. Missing server settings such as database_url no longer block them. rocketclaw run still checks the whole configuration as before.
  • A first-time setup no longer needs a hand-written auth. With "openai": {}, or with no openai entry at all, oai login signs in and writes "auth": "chatgpt". A named provider needs only an entry such as "providers": {"work": {}}.
  • With --aws-secrets-manager-arn, oai login writes only "auth": "chatgpt" for the provider into the local config file. It adds the provider's entry if needed and creates the file with mode 0600 when there is none. The secret is not changed.
  • If the AWS secret itself sets the provider's auth to anything other than chatgpt, the secret would win. In that case oai login stops before the sign-in starts and says to change the setting in the secret. If the secret already says chatgpt, the command saves only the credentials and does not touch the file.
  • A provider that is in neither the file nor the secret still fails before the sign-in, with unknown provider.
  • The "Restart RocketClaw" hint and oai list now show the provider's effective sign-in mode after the file and the secret are merged.
  • The config lock, the atomic replace, file-mode preservation, and the rollback when saving the credentials fails all still work. If the file was newly created, the rollback removes it. A named provider that is only in the file, and that someone removes from the file during the sign-in, is still refused with provider "…" is no longer configured, so the command does not bring it back.
  • The oai and ts help texts and the README now list --aws-secrets-manager-arn and describe the first-time setup and the AWS behaviour.

Verification

  • New tests in cmd/rocketclaw/oai_test.go:
    • TestRunOAILoginSetsUpChatGPT covers four cases: a fresh "openai": {}; a secret-only openai with no local file; a secret-only named provider with no local file; and a secret-only named provider missing from an existing file, whose other keys are kept. Each case checks the file contents, mode 0600, the saved credentials, and the restart hint. The fresh-config case fails on the old code with a configuration error.
    • TestRunOAILoginRejectsBeforeOAuth covers an unknown provider, with and without a secret, and a secret that sets api_key for the default or a named provider. It checks that no sign-in request was made, that the file is unchanged, and that no credentials were saved.
    • TestRunOAILoginLeavesConfigAloneWhenSecretUsesChatGPT checks that no file is created and the credentials are saved.
    • TestRunOAIListIgnoresServerOnlySettings checks that oai list works without database_url or web.tsnet.
  • TestTailnetLogin now runs ts login with a config that holds only web.tsnet. TestRunTS checks that ts login still rejects a bad web.tsnet.hostname.
  • Updated the existing saveOAILogin tests and the config tests that relied on config.Load running the server checks.
  • make -C internal/rocketclaw lint and make -C internal/rocketclaw test pass (coverage: 92.1%, above the required 91.8%).

… config

oai login, list and logout used to load the configuration with the
server's full checks, so a fresh "openai": {} failed with
"openai.api_key is required" before oai login could write the auth
setting it exists to write. ts login had the same problem with unrelated
settings such as database_url. config.Load now only reads the
configuration; rocketclaw run validates it in full, ts login checks only
web.tsnet, and the oai commands check only that the provider exists.

With --aws-secrets-manager-arn, oai login now writes only
"auth": "chatgpt" into the local config file, adding the provider's
entry and creating the file (mode 0600) when needed, so a provider kept
only in the secret can switch to ChatGPT. If the secret itself sets that
provider's auth to something else, the command stops before the sign-in
starts; if the secret already says chatgpt, it only saves the token. The
restart hint now follows the merged auth, and the help texts and README
list the flag.
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.

1 participant