gitaccess

package
v0.1.54 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitaccess supplies repository authentication to Git without putting credentials in project metadata, command arguments, or Git configuration.

Index

Constants

View Source
const Version = 1

Variables

View Source
var ErrCredential = errors.New("GitHub authentication is unavailable")

Functions

func AuthenticationRequired

func AuthenticationRequired(err error) bool

AuthenticationRequired recognizes GitHub credential failures, including those emitted by commit hooks. Network failures and repository errors stay distinct.

func Helper

func Helper(args []string, input io.Reader, output io.Writer) error

Helper runs in a short-lived mindwired subprocess spawned by Git. The original PAT never appears in its arguments or environment. Git's store/erase callbacks cannot persist, replace, or remove the app-owned credential.

func PublicRemoteURL

func PublicRemoteURL(raw string) string

PublicRemoteURL is metadata only. Native repositories may already contain credentials in their remote; never return those through a state response.

func Redact

func Redact(text string, auth Auth) string

func RemoteURL

func RemoteURL(ctx context.Context, directory string, push bool) (string, error)

RemoteURL asks Git to resolve insteadOf/pushInsteadOf rewrites before a credential is granted. Multiple push destinations require explicit setup.

func Repository

func Repository(raw string) (string, error)

Repository accepts only an exact GitHub host and a single owner/repository. The returned identity is independent of HTTPS versus SSH and a .git suffix.

func SSHHelper

func SSHHelper(args []string, input io.Reader, output, diagnostic io.Writer) error

SSHHelper holds the private key in an ephemeral SSH agent. Only its public identity is written to disk, so even SIGKILL cannot leave a private key behind.

Types

type Auth

type Auth struct {
	ConnectionID string `json:"connectionId,omitempty"`
	Kind         string `json:"kind,omitempty"`
	Username     string `json:"username,omitempty"`
	Token        string `json:"token,omitempty"`
	PrivateKey   string `json:"privateKey,omitempty"`
	ExpiresAt    string `json:"expiresAt,omitempty"`
	ReadOnly     bool   `json:"readOnly,omitempty"`
}

Auth is write-only. Run credentials are retained only for the operation's lifetime. Only an explicit workspace connection can persist credentials.

func (Auth) Validate

func (a Auth) Validate(c Connection) error

type Connection

type Connection struct {
	ID       string `json:"id"`
	Login    string `json:"login"`
	Mode     string `json:"mode"`     // token, oblienApp, sshKey, ghCli, native
	Lifetime string `json:"lifetime"` // run or workspace
}

Connection is a non-secret reference. A nil project connection inherits the workspace default; native explicitly uses the server's existing Git setup.

func (Connection) CheckRepository

func (c Connection) CheckRepository(repo string) (string, error)

CheckRepository validates both the host and the transport before configuring a helper. Selecting an SSH key never silently rewrites an existing remote.

func (Connection) Validate

func (c Connection) Validate() error

type Lease

type Lease struct {
	Environment map[string]string
	Auth        Auth // for redacting operation output; never serialize a Lease
	Close       func()
}

type Result

type Result struct {
	Output string `json:"output"`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(directory string) (*Service, error)

func (*Service) Close

func (s *Service) Close()

func (*Service) ConfigureRepository

func (s *Service) ConfigureRepository(ctx context.Context, directory, repo string, c *Connection) error

ConfigureRepository installs only an app-owned include. It never changes a user's global Git configuration or embeds a credential in origin/config.

func (*Service) EffectiveConnection

func (s *Service) EffectiveConnection(explicit *Connection, repo string) *Connection

EffectiveConnection applies a workspace GitHub default only to GitHub repositories. Other hosts retain their server authentication. Explicit project bindings remain visible and will report a mismatched remote instead of falling back to another account.

func (*Service) Forget

func (s *Service) Forget(id string) error

Forget removes the saved secret and invalidates its live helper leases. Project references remain visible so another account is never silently substituted.

func (*Service) Prepare

func (s *Service) Prepare(ctx context.Context, repo string, c *Connection, supplied *Auth) (*Lease, error)

func (*Service) PrepareLocal

func (s *Service) PrepareLocal(ctx context.Context, repo string, c *Connection, supplied *Auth) (*Lease, error)

PrepareLocal lets a plain commit finish without GitHub access. If a hook needs credentials, it uses the selected account's scoped lease. Missing access denies that lookup rather than falling back to another native account.

func (*Service) Resolve

func (s *Service) Resolve(c *Connection, supplied *Auth) (Auth, error)

func (*Service) RestoreDefault

func (s *Service) RestoreDefault(c *Connection) error

RestoreDefault restores a previously validated reference after configuration fails. A revoked credential must not prevent rolling metadata back.

func (*Service) Run

func (s *Service) Run(ctx context.Context, directory, action string, c *Connection, supplied *Auth) (Result, error)

func (*Service) Save

func (s *Service) Save(c Connection, auth *Auth) error

Save only writes a credential when the selected lifetime explicitly allows it. An absent auth preserves an existing saved credential (for a second device).

func (*Service) SetDefault

func (s *Service) SetDefault(c *Connection, auth *Auth) error

func (*Service) State

func (s *Service) State() State

type State

type State struct {
	Default             *Connection  `json:"default,omitempty"`
	StoredConnectionIDs []string     `json:"storedConnectionIds"`
	StoredConnections   []Connection `json:"storedConnections"`
	ActiveOperations    int          `json:"activeOperations"`
}

State is safe for API responses and caches. It never contains credentials.

Jump to

Keyboard shortcuts

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