Documentation
¶
Overview ¶
Package gitaccess supplies repository authentication to Git without putting credentials in project metadata, command arguments, or Git configuration.
Index ¶
- Constants
- Variables
- func AuthenticationRequired(err error) bool
- func Helper(args []string, input io.Reader, output io.Writer) error
- func PublicRemoteURL(raw string) string
- func Redact(text string, auth Auth) string
- func RemoteURL(ctx context.Context, directory string, push bool) (string, error)
- func Repository(raw string) (string, error)
- func SSHHelper(args []string, input io.Reader, output, diagnostic io.Writer) error
- type Auth
- type Connection
- type Lease
- type Result
- type Service
- func (s *Service) Close()
- func (s *Service) ConfigureRepository(ctx context.Context, directory, repo string, c *Connection) error
- func (s *Service) EffectiveConnection(explicit *Connection, repo string) *Connection
- func (s *Service) Forget(id string) error
- func (s *Service) Prepare(ctx context.Context, repo string, c *Connection, supplied *Auth) (*Lease, error)
- func (s *Service) PrepareLocal(ctx context.Context, repo string, c *Connection, supplied *Auth) (*Lease, error)
- func (s *Service) Resolve(c *Connection, supplied *Auth) (Auth, error)
- func (s *Service) RestoreDefault(c *Connection) error
- func (s *Service) Run(ctx context.Context, directory, action string, c *Connection, supplied *Auth) (Result, error)
- func (s *Service) Save(c Connection, auth *Auth) error
- func (s *Service) SetDefault(c *Connection, auth *Auth) error
- func (s *Service) State() State
- type State
Constants ¶
const Version = 1
Variables ¶
var ErrCredential = errors.New("GitHub authentication is unavailable")
Functions ¶
func AuthenticationRequired ¶
AuthenticationRequired recognizes GitHub credential failures, including those emitted by commit hooks. Network failures and repository errors stay distinct.
func Helper ¶
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 ¶
PublicRemoteURL is metadata only. Native repositories may already contain credentials in their remote; never return those through a state response.
func RemoteURL ¶
RemoteURL asks Git to resolve insteadOf/pushInsteadOf rewrites before a credential is granted. Multiple push destinations require explicit setup.
func Repository ¶
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.
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 Service ¶
type Service struct {
// contains filtered or unexported fields
}
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 ¶
Forget removes the saved secret and invalidates its live helper leases. Project references remain visible so another account is never silently substituted.
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) 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) 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
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.