Documentation
¶
Index ¶
- Constants
- func HostInCluster(host, cluster string) bool
- func ModifyAPICores(cacheDir string, fn func(ClusterCoresCache) error) error
- func ModifyCache(cacheDir string, fn func(ClusterCache) error) error
- func ModifyClusterCores(cacheDir string, fn func(ClusterCoresCache) error) error
- func ParseReplicas(header string) []string
- 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 host→trusted-issuer-URLs mapping // is treated as fresh, for both clusters and data APIs. Which login // server(s) front a resource is near-static infra — once homed 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 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 ModifyAPICores ¶ added in v0.7.6
func ModifyAPICores(cacheDir string, fn func(ClusterCoresCache) error) error
ModifyAPICores atomically applies fn to the api-host→trusted-issuer-URLs cache under a single exclusive flock.
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, so concurrent writers (e.g. two parallel clone/fetch/push processes updating nodes.json) can't lose 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.
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 LoadAPICores ¶ added in v0.7.6
func LoadAPICores(cacheDir string) (ClusterCoresCache, error)
LoadAPICores reads the api-host→trusted-issuer-URLs cache. Unlocked read; use ModifyAPICores for a read-modify-write sequence.
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) GetEntry ¶ added in v0.8.0
func (c ClusterCoresCache) GetEntry(cluster string) (entry *CoresEntry, fresh, ok bool)
GetEntry returns a cluster's cached cores entry, whether it is still fresh, and whether it exists at all. A present-but-stale entry returns (entry, false, true) so callers can attempt a re-fetch yet fall back to the stale entry if that fetch fails.
func (ClusterCoresCache) SetEntry ¶ added in v0.8.0
func (c ClusterCoresCache) SetEntry(cluster string, entry CoresEntry)
SetEntry records a full discovery result (cores plus the jurisdiction audience/core when advertised), 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"`
// JurisdictionAudience is the cluster's jurisdiction-token audience as
// advertised by its /.well-known/entire-cluster.json. Empty when the
// cluster does not accept jurisdiction access tokens (or predates
// the field) — git-remote-entire treats that as an error; other
// callers decide their own fallback.
JurisdictionAudience string `json:"jurisdiction_audience,omitempty"`
// JurisdictionCoreURL is the advertised core that mints for
// JurisdictionAudience — the cross-jurisdiction exchange endpoint.
JurisdictionCoreURL string `json:"jurisdiction_core_url,omitempty"`
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.