{"modulePath":"github.com/bborbe/github-update-go-agent","version":"v0.26.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package githubauth\n\nPackage githubauth resolves the github-update-go agent's effective GitHub credential at startup. It mirrors the github-releaser agent's resolution order: GitHub App installation token, or startup error. Extracted into its own package so the resolution outcomes are unit-testable against an httptest IAT endpoint (the pattern lib/githubapp tests already use).\n\n## Variables\n\n```go\nvar ErrAppCredentialsRequired = stderrors.New(\n\t\"github-update-go auth: App credentials required\",\n)\n```\nErrAppCredentialsRequired is returned (wrapped) when no usable GitHub App credentials are configured at startup. Exposed as a sentinel so callers and tests can match it via errors.Is rather than string comparison.\n\n## Functions\n\n```go\nfunc Resolve(ctx context.Context, cfg Config) (string, error)\n```\nResolve returns the single effective GitHub token for the agent.\n\n  - App mode: mints an installation access token via lib/githubapp.MintIAT (preferring PEMKeyFile over PEMKey when both are set).\n  - None: returns a non-nil error naming the required App env vars.\n\nThe returned token is the bearer credential wired to the GitOps clone/push URLs, the gh CLI seam, and the Claude subprocess env. It is never logged in full (MintIAT logs only token\\_prefix).\n\nToken lifetime (known constraint): the App-mode IAT is minted ONCE at startup and is valid for ~1 hour (GitHub's max IAT lifetime); it is not refreshed during the run. A github-update-go task — clone, update, gate, push, draft PR — completes well under the IAT lifetime for typical repos.\n\n## Types\n\n```go\ntype AuthMode int\n```\nAuthMode classifies which credential type is active at pod startup.\n\n```go\nconst (\n\t// AuthModeNone means no usable App credential is configured; the caller\n\t// falls back to a raw GH_TOKEN (local cmd/run-task) or refuses to start.\n\tAuthModeNone AuthMode = iota\n\t// AuthModeGitHubApp means App credentials are present and an IAT will\n\t// be minted.\n\tAuthModeGitHubApp\n)\n```\n\n```go\nfunc ResolveAuthMode(appID, installationID int64, pemKeyFile, pemKey string) AuthMode\n```\nResolveAuthMode picks the credential type to use at startup.\n\n  - AppID\u003e0 AND InstallationID\u003e0 AND (PEMKeyFile set OR PEMKey set) → AuthModeGitHubApp\n  - else → AuthModeNone\n\n```go\ntype Config struct {\n\tAppID          int64\n\tInstallationID int64\n\tPEMKeyFile     string\n\tPEMKey         string\n\tBaseURL        string\n}\n```\nConfig carries the raw credential inputs read from env/flags. Either a PEM file path (PEMKeyFile) or PEM env content (PEMKey) may be supplied; PEMKeyFile is preferred when both are present. BaseURL overrides the GitHub API base (defaults to [https://api.github.com](https://api.github.com)); tests point it at an httptest server.\n\n```go\ntype Configurator interface {\n\tSetup(ctx context.Context) error\n}\n```\nConfigurator configures git credential helpers for GitHub at pod startup. The pod implementation invokes \\`gh auth setup-git\\`; the local-CLI noop returns nil without touching any config file.\n\n```go\nfunc NewGhAuthSetupGit(ghToken string) Configurator\n```\nNewGhAuthSetupGit returns a Configurator that invokes \\`gh auth setup-git\\` when ghToken is non-empty. When ghToken is empty the Setup call is a no-op.\n\nThe token is bound into the exec wrapper here so the gh subprocess receives GH\\_TOKEN in its env — without that, gh inherits the pod env (which has no token under GitHub App auth) and dies with \"You are not logged into any GitHub hosts\" even though the IAT was minted successfully.\n\n```go\nfunc NewNoopAuthSetup() Configurator\n```\nNewNoopAuthSetup returns a Configurator that always returns nil. Used by cmd/run-task so the developer's existing gh auth login continues to handle credentials; ~/.gitconfig is never mutated by the agent.\n\n","path":"github.com/bborbe/github-update-go-agent/pkg/githubauth","name":"githubauth","synopsis":"Package githubauth resolves the github-update-go agent's effective GitHub credential at startup.","isRedistributable":true}
