Skip to content

feat(cli): token env vars for CI/CD auth#1876

Draft
dawsontoth wants to merge 2 commits into
mainfrom
claude/harper-cli-tokens-cicd-9803d5
Draft

feat(cli): token env vars for CI/CD auth#1876
dawsontoth wants to merge 2 commits into
mainfrom
claude/harper-cli-tokens-cicd-9803d5

Conversation

@dawsontoth

Copy link
Copy Markdown
Contributor

Summary

Two small additions that give a clean local-login → CI/CD path so Harper credentials don't have to live in the wild:

  1. harper login can emit a copy-paste CI/CD credential block. After a successful interactive login it asks (default No): "Print environment variables so CI/CD can deploy without your password?" On yes it prints the target and the long-lived refresh token, ready to paste into GitHub Actions (or other) repository secrets:

    # Harper CI/CD credentials
    HARPER_CLI_TARGET=https://my-instance:9925/
    HARPER_CLI_REFRESH_TOKEN=eyJ...
    

    The prompt is skipped when stdin isn't a TTY (e.g. a scripted/CI login driven by HARPER_CLI_PASSWORD), so it never blocks or dumps tokens into non-interactive output.

  2. The CLI's Bearer-token path reads tokens from env vars. harper deploy and other remote operations now honor HARPER_CLI_OPERATION_TOKEN / HARPER_CLI_REFRESH_TOKEN (with CLI_TARGET_* aliases), so a runner can authenticate without a stored password or a prior harper login.

Behavior

  • Precedence: explicit username → Basic (unchanged); else env-var tokens (override the credentials file); else ~/.harperdb/credentials.json (unchanged).
  • Refresh-token-only works: if no operation token is supplied (or it's expired), the CLI mints a fresh one from the refresh token — so CI needs only HARPER_CLI_TARGET + HARPER_CLI_REFRESH_TOKEN as durable secrets.
  • No file writes for env tokens: a token refreshed from env vars is used in-memory only; file-based credentials still persist their refreshed token exactly as before.

Tests

  • New unit coverage in unitTests/bin/login.test.js (opt-in prints target + refresh token only; decline prints nothing) and unitTests/bin/cliOperations.test.js (env token overrides file creds; refresh-token-only minting; expired-token refresh without persisting; CLI_TARGET_* alias).
  • Full bin login/cliOperations suites pass; oxlint clean.

Follow-up

  • Companion docs PR in HarperFast/documentation (new env vars + a GitHub Actions example) — not included here.

🤖 Generated with Claude Code

`harper login` now offers a copy-paste CI/CD credential block (target +
long-lived refresh token) after an interactive login, and the CLI's
Bearer-token path reads HARPER_CLI_OPERATION_TOKEN / HARPER_CLI_REFRESH_TOKEN
(with CLI_TARGET_* aliases) so `harper deploy` and other remote operations can
authenticate in CI without a stored password or a prior `harper login`.

Env-var tokens take precedence over ~/.harperdb/credentials.json and are used
in-memory only (never persisted). A refresh token alone is sufficient: when no
operation token is supplied (or it's expired), the CLI mints a fresh one from
the refresh token on each run — the single durable secret CI needs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for environment-variable-based bearer token authentication in the CLI, which is particularly useful for CI/CD environments. It allows the CLI to use HARPER_CLI_OPERATION_TOKEN and HARPER_CLI_REFRESH_TOKEN (and their aliases) to authenticate, bypassing or overriding the local credentials file. Additionally, the interactive login flow now prompts users to print these environment variables for easy setup in CI/CD pipelines. Unit tests have been added to verify these authentication flows and the environment variable output. I have no feedback to provide as there are no review comments to assess.

@claude

claude Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Reviewed; no blockers found.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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