credential

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package credential implements a git credential helper for gitswitch.

gitswitch never stores tokens. It acts purely as a router: given a git credential request (protocol/host), it resolves which gitswitch profile applies to the current repo, then delegates to the gh CLI to fetch that account's token (`gh auth token --hostname <host> --user <ghUser>`). The token lives in gh's own secure storage; gitswitch only forwards it to git.

For any case it cannot serve (gh missing, no profile, account not authenticated for the host), the helper writes nothing and exits 0 so git falls through to the next helper in the chain (osxkeychain, gh, prompt).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(req Request, st *storage.Store, repoKey, repoDir string, w io.Writer) error

Get handles the `get`/`fill` operation: resolve the applicable profile, fetch its token via gh, and write a credential response to w. repoDir is the directory git invoked the helper from, used to read the repo's local identity. On any miss (no profile, gh unavailable, account not authed for host) it writes nothing so git falls through to the next helper. Always returns nil (exit 0).

func ResolveGHUser added in v0.3.0

func ResolveGHUser(st *storage.Store, repoKey, repoDir string) string

ResolveGHUser picks which profile's gh_user applies to repoDir/repoKey.

  1. If the repo or this terminal's session overrides the global identity, that wins outright — commits here are authored as that profile, so pushes must use its token.
  2. Otherwise determine the globally active profile.
  3. Ask history for a per-repo recommendation (pinned/learned identity for repoKey). history.Recommend returns ("",false) when the recommendation equals the active nickname, so the active profile is the natural fallback and the two branches converge on the same result.

Returns "" if no profile applies (callers then stay silent). Shared by the git credential helper (Get, below) and the `gh` CLI wrapper (cmd/gitswitch ghuser), so HTTPS pushes and bare `gh` commands always resolve identically.

Types

type Request

type Request struct {
	Protocol string
	Host     string // may include :port; use HostNoPort() for matching/queries
	Path     string
	Username string
}

Request is the parsed git credential protocol input.

func ParseRequest

func ParseRequest(r io.Reader) (Request, error)

ParseRequest reads key=value lines from r until a blank line or EOF. Unknown keys are ignored. Lines without '=' are skipped.

func (Request) HostNoPort

func (r Request) HostNoPort() string

HostNoPort returns Host with any trailing :port stripped (github.com:443 -> github.com). IPv6 hosts are left untouched.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL