Documentation
¶
Overview ¶
Package distro provides distribution-specific definitions and caching rules for apt-proxy. This package contains constants, types, and configurations for supported Linux distributions (Ubuntu, Debian, CentOS, Alpine).
Package distro provides distribution configuration loading from external files ¶
Package distro provides distribution registry for dynamic distribution management
Index ¶
- Constants
- Variables
- func DistributionName(distType int) string
- func GenerateAliasFromURL(url string) string
- func GetHostPatternMap() map[*regexp.Regexp][]Rule
- func ReloadDistributionsConfig(configPath string, disableBuiltins bool)
- type AliasTemplateData
- type CacheRuleConfig
- type DistributionConfig
- type DistributionsConfig
- type Loader
- type MirrorListConfig
- type RegisteredDistribution
- type Registry
- func (r *Registry) Clear()
- func (r *Registry) GetAll() map[string]*RegisteredDistribution
- func (r *Registry) GetByID(id string) (*RegisteredDistribution, bool)
- func (r *Registry) GetByType(distType int) (*RegisteredDistribution, bool)
- func (r *Registry) LoadFromConfig(config *DistributionConfig) error
- func (r *Registry) Register(dist *RegisteredDistribution) error
- func (r *Registry) Unregister(id string) error
- type Rule
- type URLTemplateData
- type UrlWithAlias
Constants ¶
const ( LINUX_ALL_DISTROS string = "all" LINUX_DISTROS_UBUNTU string = "ubuntu" LINUX_DISTROS_UBUNTU_PORTS string = "ubuntu-ports" LINUX_DISTROS_DEBIAN string = "debian" LINUX_DISTROS_CENTOS string = "centos" LINUX_DISTROS_ALPINE string = "alpine" )
Distribution name constants
const ( TYPE_LINUX_ALL_DISTROS int = 0 TYPE_LINUX_DISTROS_UBUNTU int = 1 TYPE_LINUX_DISTROS_UBUNTU_PORTS int = 2 TYPE_LINUX_DISTROS_DEBIAN int = 3 TYPE_LINUX_DISTROS_CENTOS int = 4 TYPE_LINUX_DISTROS_ALPINE int = 5 )
Distribution type constants
const ( UBUNTU_PORTS_GEO_MIRROR_API = "http://mirrors.ubuntu.com/mirrors.txt" UBUNTU_PORTS_BENCHMARK_URL = "dists/noble/InRelease/Release" )
const ( UBUNTU_GEO_MIRROR_API = "http://mirrors.ubuntu.com/mirrors.txt" UBUNTU_BENCHMARK_URL = "dists/noble/main/binary-amd64/Release" )
const ALPINE_BENCHMARK_URL = "MIRRORS.txt"
const CENTOS_BENCHMARK_URL = "TIME"
const (
DEBIAN_BENCHMARK_URL = "dists/bullseye/main/binary-amd64/Release"
)
Variables ¶
var ALPINE_CUSTOM_MIRRORS = []string{}
var ALPINE_DEFAULT_CACHE_RULES = []Rule{ {Pattern: regexp.MustCompile(`APKINDEX.tar.gz$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_ALPINE}, {Pattern: regexp.MustCompile(`tar.gz$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_ALPINE}, {Pattern: regexp.MustCompile(`apk$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_ALPINE}, {Pattern: regexp.MustCompile(`.*`), CacheControl: `max-age=100000`, Rewrite: true, OS: TYPE_LINUX_DISTROS_ALPINE}, }
var ALPINE_HOST_PATTERN = regexp.MustCompile(`/alpine/(.+)$`)
var ALPINE_OFFICIAL_MIRRORS = []string{
"mirrors.tuna.tsinghua.edu.cn/alpine/",
"mirrors.ustc.edu.cn/alpine/",
"mirrors.nju.edu.cn/alpine/",
"mirrors.sjtug.sjtu.edu.cn/alpine/",
"mirrors.aliyun.com/alpine/",
}
https://mirrors.alpinelinux.org/ 2022.11.19 Sites that contain protocol headers, restrict access to resources using that protocol
var BUILDIN_ALPINE_MIRRORS = GenerateBuildInList(ALPINE_OFFICIAL_MIRRORS, ALPINE_CUSTOM_MIRRORS)
var BUILDIN_CENTOS_MIRRORS = GenerateBuildInList(CENTOS_OFFICIAL_MIRRORS, CENTOS_CUSTOM_MIRRORS)
var BUILDIN_DEBIAN_MIRRORS = GenerateBuildInList(DEBIAN_OFFICIAL_MIRRORS, DEBIAN_CUSTOM_MIRRORS)
var BUILDIN_UBUNTU_MIRRORS = GenerateBuildInList(UBUNTU_OFFICIAL_MIRRORS, UBUNTU_CUSTOM_MIRRORS)
var BUILDIN_UBUNTU_PORTS_MIRRORS = GenerateBuildInList(UBUNTU_PORTS_OFFICIAL_MIRRORS, UBUNTU_PORTS_CUSTOM_MIRRORS)
var CENTOS_CUSTOM_MIRRORS = []string{
"mirrors.aliyun.com/centos/",
}
var CENTOS_DEFAULT_CACHE_RULES = []Rule{ {Pattern: regexp.MustCompile(`repomd.xml$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_CENTOS}, {Pattern: regexp.MustCompile(`filelist.gz$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_CENTOS}, {Pattern: regexp.MustCompile(`dir_sizes$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_CENTOS}, {Pattern: regexp.MustCompile(`TIME$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_CENTOS}, {Pattern: regexp.MustCompile(`timestamp.txt$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_CENTOS}, {Pattern: regexp.MustCompile(`.*`), CacheControl: `max-age=100000`, Rewrite: true, OS: TYPE_LINUX_DISTROS_CENTOS}, }
var CENTOS_HOST_PATTERN = regexp.MustCompile(`/centos/(.+)$`)
var CENTOS_OFFICIAL_MIRRORS = []string{
"mirrors.bfsu.edu.cn/centos/",
"mirrors.cqu.edu.cn/CentOS/",
"http://mirrors.neusoft.edu.cn/centos/",
"mirrors.nju.edu.cn/centos/",
"mirrors.huaweicloud.com/centos/",
"mirror.lzu.edu.cn/centos/",
"http://mirrors.njupt.edu.cn/centos/",
"mirrors.163.com/centos/",
"mirrors.bupt.edu.cn/centos/",
"ftp.sjtu.edu.cn/centos/",
"mirrors.tuna.tsinghua.edu.cn/centos/",
"mirrors.ustc.edu.cn/centos/",
}
https://www.centos.org/download/mirrors/ 2022.11.19 Sites that contain protocol headers, restrict access to resources using that protocol
var DEBIAN_CUSTOM_MIRRORS = []string{
"repo.huaweicloud.com/debian/",
"mirrors.cloud.tencent.com/debian/",
"mirrors.hit.edu.cn/debian/",
"mirrors.aliyun.com/debian/",
"mirror.lzu.edu.cn/debian/",
"mirror.nju.edu.cn/debian/",
}
var DEBIAN_DEFAULT_CACHE_RULES = []Rule{ {Pattern: regexp.MustCompile(`deb$`), CacheControl: `max-age=100000`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, {Pattern: regexp.MustCompile(`udeb$`), CacheControl: `max-age=100000`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, {Pattern: regexp.MustCompile(`InRelease$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, {Pattern: regexp.MustCompile(`DiffIndex$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, {Pattern: regexp.MustCompile(`PackagesIndex$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, {Pattern: regexp.MustCompile(`Packages\.(bz2|gz|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, {Pattern: regexp.MustCompile(`SourcesIndex$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, {Pattern: regexp.MustCompile(`Sources\.(bz2|gz|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, {Pattern: regexp.MustCompile(`Release(\.gpg)?$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, {Pattern: regexp.MustCompile(`Translation-(en|fr)\.(gz|bz2|bzip2|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, {Pattern: regexp.MustCompile(`/by-hash/`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, }
var DEBIAN_HOST_PATTERN = regexp.MustCompile(`/debian(-security)?/(.+)$`)
var DEBIAN_OFFICIAL_MIRRORS = []string{
"http://ftp.cn.debian.org/debian/",
"mirror.bjtu.edu.cn/debian/",
"mirrors.163.com/debian/",
"mirrors.bfsu.edu.cn/debian/",
"mirrors.huaweicloud.com/debian/",
"http://mirrors.neusoft.edu.cn/debian/",
"mirrors.tuna.tsinghua.edu.cn/debian/",
"mirrors.ustc.edu.cn/debian/",
}
https://www.debian.org/mirror/list 2022.11.19 Sites that contain protocol headers, restrict access to resources using that protocol
var UBUNTU_CUSTOM_MIRRORS = []string{
"mirrors.163.com/ubuntu/",
}
var UBUNTU_DEFAULT_CACHE_RULES = []Rule{ {Pattern: regexp.MustCompile(`deb$`), CacheControl: `max-age=100000`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, {Pattern: regexp.MustCompile(`udeb$`), CacheControl: `max-age=100000`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, {Pattern: regexp.MustCompile(`InRelease$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, {Pattern: regexp.MustCompile(`DiffIndex$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, {Pattern: regexp.MustCompile(`PackagesIndex$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, {Pattern: regexp.MustCompile(`Packages\.(bz2|gz|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, {Pattern: regexp.MustCompile(`SourcesIndex$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, {Pattern: regexp.MustCompile(`Sources\.(bz2|gz|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, {Pattern: regexp.MustCompile(`Release(\.gpg)?$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, {Pattern: regexp.MustCompile(`Translation-(en|fr)\.(gz|bz2|bzip2|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, {Pattern: regexp.MustCompile(`\/by-hash\/`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, }
var UBUNTU_HOST_PATTERN = regexp.MustCompile(`/ubuntu/(.+)$`)
var UBUNTU_OFFICIAL_MIRRORS = []string{
"mirrors.cn99.com/ubuntu/",
"mirrors.tuna.tsinghua.edu.cn/ubuntu/",
"mirrors.cnnic.cn/ubuntu/",
"mirror.bjtu.edu.cn/ubuntu/",
"mirrors.cqu.edu.cn/ubuntu/",
"http://mirrors.skyshe.cn/ubuntu/",
"mirrors.yun-idc.com/ubuntu/",
"http://mirror.dlut.edu.cn/ubuntu/",
"mirrors.xjtu.edu.cn/ubuntu/",
"mirrors.huaweicloud.com/repository/ubuntu/",
"mirrors.bupt.edu.cn/ubuntu/",
"mirrors.hit.edu.cn/ubuntu/",
"http://mirrors.sohu.com/ubuntu/",
"mirror.nju.edu.cn/ubuntu/",
"mirrors.bfsu.edu.cn/ubuntu/",
"mirror.lzu.edu.cn/ubuntu/",
"mirrors.aliyun.com/ubuntu/",
"ftp.sjtu.edu.cn/ubuntu/",
"mirrors.njupt.edu.cn/ubuntu/",
"mirrors.cloud.tencent.com/ubuntu/",
"http://mirrors.dgut.edu.cn/ubuntu/",
"mirrors.ustc.edu.cn/ubuntu/",
"mirrors.sdu.edu.cn/ubuntu/",
"http://cn.archive.ubuntu.com/ubuntu/",
}
http://mirrors.ubuntu.com/mirrors.txt 2022.11.19 Sites that contain protocol headers, restrict access to resources using that protocol
var UBUNTU_PORTS_CUSTOM_MIRRORS = []string{
"mirrors.163.com/ubuntu-ports/",
}
var UBUNTU_PORTS_DEFAULT_CACHE_RULES = []Rule{ {Pattern: regexp.MustCompile(`deb$`), CacheControl: `max-age=100000`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU_PORTS}, {Pattern: regexp.MustCompile(`udeb$`), CacheControl: `max-age=100000`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU_PORTS}, {Pattern: regexp.MustCompile(`InRelease$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU_PORTS}, {Pattern: regexp.MustCompile(`DiffIndex$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU_PORTS}, {Pattern: regexp.MustCompile(`PackagesIndex$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU_PORTS}, {Pattern: regexp.MustCompile(`Packages\.(bz2|gz|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU_PORTS}, {Pattern: regexp.MustCompile(`SourcesIndex$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU_PORTS}, {Pattern: regexp.MustCompile(`Sources\.(bz2|gz|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU_PORTS}, {Pattern: regexp.MustCompile(`Release(\.gpg)?$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU_PORTS}, {Pattern: regexp.MustCompile(`Translation-(en|fr)\.(gz|bz2|bzip2|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU_PORTS}, {Pattern: regexp.MustCompile(`\/by-hash\/`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU_PORTS}, }
var UBUNTU_PORTS_HOST_PATTERN = regexp.MustCompile(`/ubuntu-ports/(.+)$`)
var UBUNTU_PORTS_OFFICIAL_MIRRORS = []string{
"mirrors.cn99.com/ubuntu-ports/",
"mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/",
"mirrors.cnnic.cn/ubuntu-ports/",
"mirror.bjtu.edu.cn/ubuntu-ports/",
"mirrors.cqu.edu.cn/ubuntu-ports/",
"http://mirrors.skyshe.cn/ubuntu-ports/",
"mirrors.yun-idc.com/ubuntu-ports/",
"http://mirror.dlut.edu.cn/ubuntu-ports/",
"mirrors.xjtu.edu.cn/ubuntu-ports/",
"mirrors.huaweicloud.com/repository/ubuntu-ports/",
"mirrors.bupt.edu.cn/ubuntu-ports/",
"mirrors.hit.edu.cn/ubuntu-ports/",
"http://mirrors.sohu.com/ubuntu-ports/",
"mirror.nju.edu.cn/ubuntu-ports/",
"mirrors.bfsu.edu.cn/ubuntu-ports/",
"mirror.lzu.edu.cn/ubuntu-ports/",
"mirrors.aliyun.com/ubuntu-ports/",
"ftp.sjtu.edu.cn/ubuntu-ports/",
"mirrors.njupt.edu.cn/ubuntu-ports/",
"mirrors.cloud.tencent.com/ubuntu-ports/",
"http://mirrors.dgut.edu.cn/ubuntu-ports/",
"mirrors.ustc.edu.cn/ubuntu-ports/",
"mirrors.sdu.edu.cn/ubuntu-ports/",
"http://cn.archive.ubuntu.com/ubuntu-ports/",
}
http://mirrors.ubuntu.com/mirrors.txt 2022.11.19 Sites that contain protocol headers, restrict access to resources using that protocol
Functions ¶
func DistributionName ¶
DistributionName returns the distribution ID string for the given type. Returns empty string for unknown types. Checks registry for dynamic distros.
func GenerateAliasFromURL ¶
GenerateAliasFromURL generates an alias from a URL
func GetHostPatternMap ¶
GetHostPatternMap returns a map from URL pattern regex to cache rules for all registered distributions. Used by the proxy to match requests and apply rules.
func ReloadDistributionsConfig ¶
ReloadDistributionsConfig resets the global registry, optionally registers built-in distributions, then loads and applies distributions from the given config file path. When disableBuiltins is true, only distributions from configPath are registered. When configPath is empty, Load() still tries default paths (./config/distributions.yaml, ./distributions.yaml, /etc/apt-proxy/distributions.yaml, etc.). Safe to call at startup and on SIGHUP/API reload.
Types ¶
type AliasTemplateData ¶
type AliasTemplateData struct {
Alias string
}
AliasTemplateData holds data for alias template execution
type CacheRuleConfig ¶
type CacheRuleConfig struct {
Pattern string `yaml:"pattern"`
CacheControl string `yaml:"cache_control"`
Rewrite bool `yaml:"rewrite"`
}
CacheRuleConfig represents a cache rule configuration
type DistributionConfig ¶
type DistributionConfig struct {
ID string `yaml:"id"`
Name string `yaml:"name"`
Type int `yaml:"type"`
URLPattern string `yaml:"url_pattern"`
BenchmarkURL string `yaml:"benchmark_url"`
GeoMirrorAPI string `yaml:"geo_mirror_api,omitempty"`
CacheRules []CacheRuleConfig `yaml:"cache_rules"`
Mirrors MirrorListConfig `yaml:"mirrors"`
Aliases map[string]string `yaml:"aliases,omitempty"`
}
DistributionConfig represents a distribution configuration loaded from YAML
type DistributionsConfig ¶
type DistributionsConfig struct {
Distributions []DistributionConfig `yaml:"distributions"`
}
DistributionsConfig represents the root configuration structure
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader handles loading distribution configurations
func (*Loader) GetConfig ¶
func (l *Loader) GetConfig() *DistributionsConfig
GetConfig returns the loaded configuration
func (*Loader) Load ¶
func (l *Loader) Load() (*DistributionsConfig, error)
Load loads distribution configurations from the configured file
func (*Loader) Reload ¶
func (l *Loader) Reload() (*DistributionsConfig, error)
Reload reloads the configuration from file
type MirrorListConfig ¶
type MirrorListConfig struct {
Official []string `yaml:"official"`
Custom []string `yaml:"custom"`
}
MirrorListConfig represents mirror list configuration
type RegisteredDistribution ¶
type RegisteredDistribution struct {
ID string
Name string
Type int
URLPattern *regexp.Regexp
BenchmarkURL string
GeoMirrorAPI string
CacheRules []Rule
Mirrors []UrlWithAlias
Aliases map[string]string
}
RegisteredDistribution represents a registered distribution with its configuration
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages distribution registrations
func GetRegistry ¶
func GetRegistry() *Registry
GetRegistry returns the global distribution registry
func (*Registry) Clear ¶
func (r *Registry) Clear()
Clear removes all distributions from the registry
func (*Registry) GetAll ¶
func (r *Registry) GetAll() map[string]*RegisteredDistribution
GetAll returns all registered distributions
func (*Registry) GetByID ¶
func (r *Registry) GetByID(id string) (*RegisteredDistribution, bool)
GetByID returns a distribution by its ID
func (*Registry) GetByType ¶
func (r *Registry) GetByType(distType int) (*RegisteredDistribution, bool)
GetByType returns a distribution by its type
func (*Registry) LoadFromConfig ¶
func (r *Registry) LoadFromConfig(config *DistributionConfig) error
LoadFromConfig loads distributions from a DistributionConfig and registers them
func (*Registry) Register ¶
func (r *Registry) Register(dist *RegisteredDistribution) error
Register registers a distribution in the registry
func (*Registry) Unregister ¶
Unregister removes a distribution from the registry
type URLTemplateData ¶
type URLTemplateData struct {
URL string
}
URLTemplateData holds data for URL template execution
type UrlWithAlias ¶
type UrlWithAlias struct {
URL string
Alias string
Http bool
Https bool
Official bool
Bandwidth int64
}
UrlWithAlias represents a mirror URL with its alias and metadata
func GenerateBuildInList ¶
func GenerateBuildInList(officialList []string, customList []string) (mirrors []UrlWithAlias)
GenerateBuildInList generates a list of mirror URLs with aliases
func GenerateBuildInMirorItem ¶
func GenerateBuildInMirorItem(url string, official bool) UrlWithAlias
GenerateBuildInMirorItem creates a UrlWithAlias from a URL