Repository navigation
feat(cli): use the credential site login saved for every site command - #28
Merged
Merged
Conversation
After `ptctl site login SITE`, every site command for that site works without a credential flag. `site login` keeps the TJUPT session cookie it issues, and now also saves an M-Team API key (typed hidden, or piped with --api-key-stdin) or a browser cookie (--cookie-stdin) once one status read accepts it. Status, account, search, detail, bonus catalog and review, metafile fetch, and bonus exchange submit read the saved file when no stdin flag is given; an explicit flag still wins. The saved file lives at ptctl/sessions/SITE.cookie or SITE.api-key under the user config directory, 0600 in a 0700 directory. It is refused without disclosure when it is a symlink or not a regular file, grants group or other access (outside Windows), changes while opened, or is not exactly one valid credential line. It is located after every other usage check and read where stdin would have been read, so the preflight order is unchanged. A saved credential never replaces an acknowledgement flag, and account and downloader passwords are never saved. `ptctl site logout SITE` deletes the saved files. Bonus exchange submit on a password-confirmed site (TJUPT) with the saved cookie asks for the account password with echo off before its timeout starts. Error messages that named a cookie or API-key path are reworded so the redactor no longer swallows their tail. Tests isolate HOME, XDG_CONFIG_HOME, and AppData so they never read real saved credentials; fixtures are synthetic canaries. 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.
Summary
After
ptctl site login SITE, every site command for that site now works without a credential flag. Signing in is meant to be done once, not repeated as--cookie-stdin/--api-key-stdinon every call.site login tjuptalready saved the session cookie it issues; commands now read it back implicitly.site login mteamnow asks for the API key with echo off and saves the API key once one status read accepts it. Before this change, M-Team had no way to save a credential.site login --cookie-stdin SITE/site login --api-key-stdin SITEsave a piped credential the same way, for agents. Nothing is saved, and an earlier file is kept, if the check fails.site metafile fetch, andsite bonus exchange submit.ptctl site logout SITEdeletes the saved files. It sends nothing to the site, so the session or key stays valid there until it expires or is revoked.Security model change (deliberate)
This change deliberately adds credential persistence and implicit read-back, which the project previously avoided:
ptctl/sessions/SITE.cookieorSITE.api-keyunderos.UserConfigDir(). It is plaintext, mode0600in a0700directory, and written through an owner-only temp file plus rename.\nor\r\n.bonus exchange submiton a password-confirmed site (TJUPT) asks for the account password with echo off, before the 45 s timeout starts, so typing it does not use up the review/submit time.--credential-bundle-stdin.TestMainisolatesHOME,XDG_CONFIG_HOMEandAppData, so tests never read real saved credentials. Fixtures are synthetic canaries.Public text changes (deliberate)
--cookie-stdin is required; credentials are never accepted in argv(and the API-key variant) is replaced byno saved session cookie|API key for site "SITE"; run 'ptctl site login SITE' first, or pipe one with --cookie-stdin|--api-key-stdin.[--cookie-stdin | --api-key-stdin]).site logouthas its own help.site.loginwith exactlysite_id,username,api_key_file,requests_attempted.TestSiteLoginReportsJSONWithoutTheCookie).site bonus exchange submit requires --acknowledge-bonus-exchange.:were partly swallowed bysecurity.Redact(for examplerefusing to replace … with a session cookie: [REDACTED]). They now use… because it is not a regular file, including the pre-existing--cookie-filemessage.Unchanged:
Out of scope
reconcile(--site-cookie-stdin,--site-ref) still takes its cookie from stdin only.site login --credential-bundle-stdinwithout--cookie-filestill writes the cookie to stdout and does not save it, for compatibility with existing agent pipelines.Testing
gofmt,go vet ./...,go test -race ./...,go build -trimpath ./cmd/ptctl.internal/cli/saved_credentials_test.go:HOME, connectivity only, with no download and no genDlToken:site login --api-key-stdin mteamsaved the key with one request (file0600, directory0700);site status mteamauthenticated.🤖 Generated with Claude Code