auth

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package auth defines the Authenticator interface and provides implementations for GitHub token validation and no-op (permissive) authentication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authenticator

type Authenticator interface {
	Authenticate(ctx context.Context, endpoint *config.Endpoint, username, password string, op Operation) (Result, error)
}

Authenticator validates credentials and checks authorisation for an endpoint.

Implementations must return Result{Authenticated: false} (not an error) when the provided credentials are invalid. Errors should only be returned for transient failures such as network errors or upstream service outages. The username parameter may be ignored by implementations where the token is self-authenticating (e.g., GitHub PATs).

type GitHub

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

GitHub authenticates users by validating their token against the GitHub API. Successful authentication results are cached to reduce API calls.

func NewGitHub

func NewGitHub(httpClient *http.Client, cacheTTL time.Duration, baseURL *url.URL) *GitHub

NewGitHub creates a GitHub authenticator. The httpClient is used for GitHub API calls; sharing a single client across endpoints allows connection pooling. If nil, http.DefaultClient is used. The cacheTTL controls how long successful auth results are cached; a zero value disables caching entirely. The baseURL overrides the GitHub API base URL for GitHub Enterprise deployments; pass nil to use the default (https://api.github.com/).

func (*GitHub) Authenticate

func (g *GitHub) Authenticate(ctx context.Context, endpoint *config.Endpoint, _ string, password string, op Operation) (Result, error)

Authenticate validates the user's GitHub token against the configured repository. The username from Basic Auth is not verified — GitHub tokens are self-authenticating, and Git LFS clients send it only as a hint.

func (*GitHub) Close

func (g *GitHub) Close() error

Close shuts down the background cache sweeper. It is safe to call multiple times or if the sweeper was never started.

type None

type None struct{}

None is an authenticator that permits all operations without credentials.

func (*None) Authenticate

func (n *None) Authenticate(_ context.Context, _ *config.Endpoint, username, _ string, _ Operation) (Result, error)

Authenticate always returns an authenticated and authorized result. The username from Basic Auth is preserved for lock ownership; if no username is provided, "anonymous" is used.

type Operation

type Operation string

Operation represents an LFS operation type (download or upload).

const (
	OperationDownload Operation = "download"
	OperationUpload   Operation = "upload"
)

Supported LFS operations.

type Result

type Result struct {
	// Authenticated indicates the user provided valid credentials.
	Authenticated bool
	// Authorized indicates the user has permission for the requested operation.
	Authorized bool
	// Username identifies the authenticated user (used for lock ownership).
	Username string
}

Result represents the outcome of an authentication attempt.

Jump to

Keyboard shortcuts

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