Skip to content

feat(gpg-key): add gpg-key list and add #482

Closed

Description

@q-horde

What to build

  • New command group gpg-key in internal/copiacmd/root.go.
  • gpg-key list (alias ls): GET /user/gpg_keys, all pages. Columns EMAIL (the key's emails joined with , ), KEY ID, PUBLIC KEY (cut on a terminal), ADDED, EXPIRES (Never or a date on a terminal, RFC3339 without one). --json id,key_id,primary_key_id,emails,public_key,created_at,expires_at,verified,can_sign. No keys: no GPG keys present in the Copia account.
  • gpg-key add [<key-file>] [-s/--signature <file>] (decision G1): POST /user/gpg_keys with armored_public_key and, with --signature, armored_signature (a detached armored signature over the token of GET /user/gpg_key_token). The key file and the signature file may not both be -. Success: GPG key added to your account.
  • Gitea's 422 for a duplicate key ID becomes gh's the key already exists in your account, exit 1. Content without -----BEGIN gets gh's armored-format hint with copia-cli. Gitea's 404 for a key without a verified email is shown with a hint to sign the token with --signature (the token is printed as Gitea gives it: it is no secret and expires in minutes). gh's -t/--title is left out (Gitea keys have no title).
  • The help and docs/parity.md show the signature route: copia-cli api user/gpg_key_token | gpg -a --detach-sig > sig.asc, then copia-cli gpg-key add key.asc --signature sig.asc.
  • Key fixture: the GPG part. gpg from the runner with a temporary GNUPGHOME, user ID it-run-<time>-<suffix>, added with the signature route. The stale sweep reads a key's user ID from its public_key with gpg --show-keys and deletes only keys whose user ID has that form; unit tests of that user ID guard without a build tag. CLAUDE.md names the GPG part of the key fixture rule.

Follow gh's flags and messages as gh prints them without a terminal (upstream cli/cli) within the copia-cli conventions: a package per subcommand under pkg/cmd/<group>/<sub>/, raw net/http through cmdutil.NewHTTPClient(), -R/--repo and --host as today, success lines on stdout also without a terminal, warnings on stderr, --json/--jq/--template on every list with the API's snake_case field names, no interactive prompts (every delete and remove requires --yes), table-driven unit tests with httpmock and iostreams.Test(). A key file argument - (or no argument with stdin not a terminal) reads stdin. Gitea's error messages are shown as Gitea words them, with the HTTP status. copia-cli never prints or logs a key file's content in an error.

Stop rule (R6): if the first integration run shows a key route answering 404 (feature disabled) or a 403 naming a missing token scope (write:user), stop with the evidence (status code and Gitea's message, never a key, login or token) and set the slice blocked for the Lead, who brings the choice to the owner. The scope does not change silently.

This slice gets a security review.

Files: pkg/cmd/gpgkey/gpgkey.go, pkg/cmd/gpgkey/list/, pkg/cmd/gpgkey/add/, internal/copiacmd/root.go, test/integration/gpgkey_test.go, test/integration/keys_test.go, test/integration/keys_unit_test.go, CLAUDE.md, CHANGELOG.md, docs/parity.md, docs/site/manual/.

Acceptance criteria

  • Unit tests cover list, --json, add with and without --signature, stdin, both files -, a duplicate key, content that is not armored and a key without a verified email.
  • Unit tests cover the sweep's user ID guard for GPG keys.
  • Integration test: generate a key with gpg, sign the token, add it with --signature, gpg-key list shows it verified (byte-count helpers); the test never reads the account's email.
  • horde-dev run go test ./... and horde-dev run golangci-lint run ./... pass.
  • horde-dev run go run script/gen-docs.go leaves no diff (the generated manual under docs/site/manual is committed).
  • CHANGELOG.md has an entry under Unreleased (Added); docs/parity.md has the slice's rows, its section text and the counts at the bottom updated.
  • Codecov codecov/patch (80%) and codecov/project are green.
  • The PR's integration job is green against live Copia. The integration test follows the no-logging guard of test/workflows: no t.Log/t.Logf, output checked only through the byte-count helpers of test/integration/helpers_test.go, testify calls with literal messages only; no key, title, login or email in a passing test's output. Deploy keys and collaborators live in the run repository; user SSH and GPG keys come from the key fixture of slice 1 (generated in the test, title or user ID it-run-<base36 time>-<suffix>), never a fixed key or repository. Each test generates its own key: Gitea refuses one key as both a user key and a deploy key.

Blocked by

#47 (every slice of this epic changes CHANGELOG.md, docs/parity.md and the generated manual, so they run as one chain). Branch from epic/481-keys-and-access; the PR goes into it.

Part of the keys and access epic planned in the Horde (epic epic/481-keys-and-access, slice 3 of 8).

Activity

  1. q-horde commented on Nov 16, 2026

    @q-horde
    ContributorAuthor

    Fixed in epic/481-keys-and-access by 6c7c503 (PR #488).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions