Documentation
¶
Index ¶
- Constants
- func DefaultCacheDir() string
- func HostInCluster(host, cluster string) bool
- func ModifyCache(cacheDir string, fn func(ClusterCache) error) error
- func ModifyClusterCores(cacheDir string, fn func(ClusterCoresCache) error) error
- func ParseReplicas(header string) []string
- func SaveCache(cacheDir string, cache ClusterCache) error
- type ClusterCache
- func (c ClusterCache) GetClusterNodes(cluster string) ([]string, bool)
- func (c ClusterCache) GetRepoNodes(cluster, repoPath string) ([]string, bool)
- func (c ClusterCache) InvalidateCluster(cluster string)
- func (c ClusterCache) InvalidateRepo(cluster, repoPath string)
- func (c ClusterCache) SetClusterNodes(cluster string, nodes []string, ttl time.Duration)
- func (c ClusterCache) SetRepoNodes(cluster, repoPath string, nodes []string, ttl time.Duration)
- type ClusterCoresCache
- type ClusterEntry
- type CoresEntry
- type RepoEntry
Constants ¶
const ( // ClusterCoresTTL bounds how long a cached cluster→core_urls mapping is // treated as fresh. Which control plane(s) front a data-plane cluster is // near-static infra — once a cluster is homed to a core it stays — so a // long TTL is fine. On expiry we re-fetch /.well-known and only fall back // to the stale entry if that fetch fails. ClusterCoresTTL = 24 * time.Hour )
const ( // DefaultTTL is the cache TTL for replica sets discovered via info/refs. DefaultTTL = 24 * time.Hour )
Variables ¶
This section is empty.
Functions ¶
func DefaultCacheDir ¶
func DefaultCacheDir() string
DefaultCacheDir returns ~/.cache/entire, respecting XDG_CACHE_HOME.
func HostInCluster ¶
HostInCluster reports whether host equals the cluster's entry domain or is a subdomain of it. Both values are compared by hostname only — any port is stripped from either side before comparison. Used to scope sensitive-header preservation across redirects and the replica trust boundary: an in-cluster hop is safe to carry Authorization, anything else must be treated as a new trust boundary.
The subdomain (wildcard) match is only honored when the cluster host is strictly more specific than its own public suffix — see clusterAllowsSubdomains. Without that floor a cluster host of "io" or "co.uk" (a bare eTLD) would make every subdomain of an entire TLD "in cluster", so a relinquished or misconfigured subdomain anywhere under that suffix could inherit credential-carry trust.
func ModifyCache ¶
func ModifyCache(cacheDir string, fn func(ClusterCache) error) error
ModifyCache atomically applies fn to the node cache under a single exclusive flock — load, mutate, and write all happen with the lock held. Use this for any read-modify-write sequence; LoadCache followed by SaveCache releases the lock between them and races concurrent writers (e.g. two parallel clone/fetch/push processes updating nodes.json), losing each other's entries.
func ModifyClusterCores ¶
func ModifyClusterCores(cacheDir string, fn func(ClusterCoresCache) error) error
ModifyClusterCores atomically applies fn to the cluster→cores cache under a single exclusive flock.
func ParseReplicas ¶
ParseReplicas parses the X-Entire-Replicas header value into a list of replica URIs. The header is a comma-separated list of URIs; surrounding whitespace on each entry is trimmed and empty entries are skipped. An empty or missing header yields a nil slice.
func SaveCache ¶
func SaveCache(cacheDir string, cache ClusterCache) error
SaveCache writes the cache to disk atomically under an exclusive flock.
Types ¶
type ClusterCache ¶
type ClusterCache map[string]*ClusterEntry
ClusterCache is the top-level cache structure, keyed by cluster host.
func LoadCache ¶
func LoadCache(cacheDir string) (ClusterCache, error)
LoadCache reads the node cache from disk. Returns an empty cache if the file does not exist. This is an unlocked read — fine for read-only callers; use ModifyCache for read-modify-write sequences.
func (ClusterCache) GetClusterNodes ¶
func (c ClusterCache) GetClusterNodes(cluster string) ([]string, bool)
GetClusterNodes returns the cached cluster nodes. The second return value indicates whether the cache entry is fresh (not expired).
func (ClusterCache) GetRepoNodes ¶
func (c ClusterCache) GetRepoNodes(cluster, repoPath string) ([]string, bool)
GetRepoNodes returns cached hosting nodes for a repo. The second return value indicates freshness.
func (ClusterCache) InvalidateCluster ¶
func (c ClusterCache) InvalidateCluster(cluster string)
InvalidateCluster removes all cached data for a cluster.
func (ClusterCache) InvalidateRepo ¶
func (c ClusterCache) InvalidateRepo(cluster, repoPath string)
InvalidateRepo removes the cached repo entry.
func (ClusterCache) SetClusterNodes ¶
func (c ClusterCache) SetClusterNodes(cluster string, nodes []string, ttl time.Duration)
SetClusterNodes stores cluster nodes with the given TTL.
func (ClusterCache) SetRepoNodes ¶
func (c ClusterCache) SetRepoNodes(cluster, repoPath string, nodes []string, ttl time.Duration)
SetRepoNodes caches hosting nodes for a specific repo.
type ClusterCoresCache ¶
type ClusterCoresCache map[string]*CoresEntry
ClusterCoresCache maps a cluster host to the control-plane core URLs that front it, memoizing /.well-known/entire-cluster.json so routine git ops don't re-fetch it every time. It stores only the objective cluster→core fact — never which local account to authenticate as. The account is chosen fresh on every operation from the user's contexts, so a multi-account user is never silently pinned to one identity.
Cache file: cluster_cores.json in the cache dir (alongside nodes.json). Safe to delete by hand to force re-discovery.
func LoadClusterCores ¶
func LoadClusterCores(cacheDir string) (ClusterCoresCache, error)
LoadClusterCores reads the cluster→cores cache. A missing or corrupt file yields an empty cache. Unlocked read; use ModifyClusterCores for a read-modify-write sequence.
func (ClusterCoresCache) Get ¶
func (c ClusterCoresCache) Get(cluster string) (urls []string, fresh, ok bool)
Get returns a cluster's cached core URLs, whether the entry is still fresh, and whether it exists at all. A present-but-stale entry returns (urls, false, true) so callers can attempt a re-fetch yet fall back to the stale URLs if that fetch fails.
func (ClusterCoresCache) Set ¶
func (c ClusterCoresCache) Set(cluster string, urls []string)
Set records a cluster's core URLs, stamping the fetch time to now. The slice is copied so later mutation by the caller can't corrupt the cache.
type ClusterEntry ¶
type ClusterEntry struct {
Nodes []string `json:"nodes"`
NodesExpiresAt time.Time `json:"nodes_expires_at"`
Repos map[string]*RepoEntry `json:"repos,omitempty"`
}
ClusterEntry holds cached data for a single cluster.
type CoresEntry ¶
type CoresEntry struct {
CoreURLs []string `json:"core_urls"`
FetchedAt time.Time `json:"fetched_at"`
}
CoresEntry is one cluster's cached core URLs plus when they were fetched. Freshness is fetched_at + ClusterCoresTTL, computed at read time so a TTL change re-interprets existing entries without a migration.