lockdown

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheStats

type CacheStats struct {
	Hits      int64
	Misses    int64
	Evictions int64
}

CacheStats summarizes cache activity counters.

type RepoAccessCache

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

RepoAccessCache caches repository metadata related to lockdown checks so that multiple tools can reuse the same access information safely across goroutines. In HTTP mode each request must construct its own instance so viewer-scoped lookups run under the requesting user's credentials.

func NewRepoAccessCache

func NewRepoAccessCache(client *githubv4.Client, restClient *github.Client, opts ...RepoAccessOption) *RepoAccessCache

NewRepoAccessCache creates a RepoAccessCache bound to the supplied clients.

func (*RepoAccessCache) IsSafeContent

func (c *RepoAccessCache) IsSafeContent(ctx context.Context, username, owner, repo string) (bool, error)

IsSafeContent determines if the specified user can safely access the requested repository content. Safe access applies when any of the following is true: - the content was created by a trusted bot; - the author currently has push access to the repository; - the repository is private; - the content was created by the viewer.

type RepoAccessInfo

type RepoAccessInfo struct {
	IsPrivate     bool
	HasPushAccess bool
}

RepoAccessInfo captures repository metadata needed for lockdown decisions.

type RepoAccessOption

type RepoAccessOption func(*RepoAccessCache)

RepoAccessOption configures RepoAccessCache at construction time.

func WithCacheName

func WithCacheName(name string) RepoAccessOption

WithCacheName overrides the cache table name used for storing entries. Use this to isolate cache entries between tenants or in tests.

cache2go never reclaims a named table, so names must come from a bounded, known set; never derive one from request data. Use WithIdentity instead to isolate per request identity.

func WithIdentity

func WithIdentity(identity string) RepoAccessOption

WithIdentity scopes cache entries to a single request identity, typically an auth token, so a decision computed under one caller's credentials is never served to another. Equal identities share a warm cache; an empty one is a no-op.

Scoping lives in the entry key rather than the table so per-identity state stays bounded and is reclaimed by ordinary idle-TTL cleanup. The identity is hashed so it never appears verbatim in a key.

func WithLogger

func WithLogger(logger *slog.Logger) RepoAccessOption

WithLogger sets the logger used for cache diagnostics.

func WithTTL

func WithTTL(ttl time.Duration) RepoAccessOption

WithTTL overrides the default TTL applied to cache entries. A non-positive duration disables expiration.

Jump to

Keyboard shortcuts

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