mirror of
https://github.com/yusing/godoxy.git
synced 2025-07-21 11:54:03 +02:00
(non-breaking) rebrand changed environment variables
This commit is contained in:
parent
cf1ecbc826
commit
99e43fe340
4 changed files with 43 additions and 38 deletions
|
@ -17,6 +17,9 @@ runtimes:
|
||||||
- go@1.23.2
|
- go@1.23.2
|
||||||
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
|
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
|
||||||
lint:
|
lint:
|
||||||
|
disabled:
|
||||||
|
- markdownlint
|
||||||
|
- yamllint
|
||||||
enabled:
|
enabled:
|
||||||
- hadolint@2.12.0
|
- hadolint@2.12.0
|
||||||
- actionlint@1.7.3
|
- actionlint@1.7.3
|
||||||
|
@ -24,14 +27,12 @@ lint:
|
||||||
- git-diff-check
|
- git-diff-check
|
||||||
- gofmt@1.20.4
|
- gofmt@1.20.4
|
||||||
- golangci-lint@1.61.0
|
- golangci-lint@1.61.0
|
||||||
- markdownlint@0.42.0
|
|
||||||
- osv-scanner@1.9.0
|
- osv-scanner@1.9.0
|
||||||
- oxipng@9.1.2
|
- oxipng@9.1.2
|
||||||
- prettier@3.3.3
|
- prettier@3.3.3
|
||||||
- shellcheck@0.10.0
|
- shellcheck@0.10.0
|
||||||
- shfmt@3.6.0
|
- shfmt@3.6.0
|
||||||
- trufflehog@3.82.7
|
- trufflehog@3.82.7
|
||||||
- yamllint@1.35.1
|
|
||||||
actions:
|
actions:
|
||||||
disabled:
|
disabled:
|
||||||
- trunk-announce
|
- trunk-announce
|
||||||
|
|
|
@ -12,31 +12,33 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
NoSchemaValidation = GetEnvBool("GOPROXY_NO_SCHEMA_VALIDATION", true)
|
prefixes = []string{"GODOXY_", "GOPROXY_", ""}
|
||||||
IsTest = GetEnvBool("GOPROXY_TEST", false) || strings.HasSuffix(os.Args[0], ".test")
|
|
||||||
IsDebug = GetEnvBool("GOPROXY_DEBUG", IsTest)
|
NoSchemaValidation = GetEnvBool("NO_SCHEMA_VALIDATION", true)
|
||||||
IsDebugSkipAuth = GetEnvBool("GOPROXY_DEBUG_SKIP_AUTH", false)
|
IsTest = GetEnvBool("TEST", false) || strings.HasSuffix(os.Args[0], ".test")
|
||||||
IsTrace = GetEnvBool("GOPROXY_TRACE", false) && IsDebug
|
IsDebug = GetEnvBool("DEBUG", IsTest)
|
||||||
|
IsDebugSkipAuth = GetEnvBool("DEBUG_SKIP_AUTH", false)
|
||||||
|
IsTrace = GetEnvBool("TRACE", false) && IsDebug
|
||||||
|
|
||||||
ProxyHTTPAddr,
|
ProxyHTTPAddr,
|
||||||
ProxyHTTPHost,
|
ProxyHTTPHost,
|
||||||
ProxyHTTPPort,
|
ProxyHTTPPort,
|
||||||
ProxyHTTPURL = GetAddrEnv("GOPROXY_HTTP_ADDR", ":80", "http")
|
ProxyHTTPURL = GetAddrEnv("HTTP_ADDR", ":80", "http")
|
||||||
|
|
||||||
ProxyHTTPSAddr,
|
ProxyHTTPSAddr,
|
||||||
ProxyHTTPSHost,
|
ProxyHTTPSHost,
|
||||||
ProxyHTTPSPort,
|
ProxyHTTPSPort,
|
||||||
ProxyHTTPSURL = GetAddrEnv("GOPROXY_HTTPS_ADDR", ":443", "https")
|
ProxyHTTPSURL = GetAddrEnv("HTTPS_ADDR", ":443", "https")
|
||||||
|
|
||||||
APIHTTPAddr,
|
APIHTTPAddr,
|
||||||
APIHTTPHost,
|
APIHTTPHost,
|
||||||
APIHTTPPort,
|
APIHTTPPort,
|
||||||
APIHTTPURL = GetAddrEnv("GOPROXY_API_ADDR", "127.0.0.1:8888", "http")
|
APIHTTPURL = GetAddrEnv("API_ADDR", "127.0.0.1:8888", "http")
|
||||||
|
|
||||||
APIJWTSecret = decodeJWTKey(GetEnv("GOPROXY_API_JWT_SECRET", ""))
|
APIJWTSecret = decodeJWTKey(GetEnvString("API_JWT_SECRET", ""))
|
||||||
APIJWTTokenTTL = GetDurationEnv("GOPROXY_API_JWT_TOKEN_TTL", time.Hour)
|
APIJWTTokenTTL = GetDurationEnv("API_JWT_TOKEN_TTL", time.Hour)
|
||||||
APIUser = GetEnv("GOPROXY_API_USER", "admin")
|
APIUser = GetEnvString("API_USER", "admin")
|
||||||
APIPasswordHash = HashPassword(GetEnv("GOPROXY_API_PASSWORD", "password"))
|
APIPasswordHash = HashPassword(GetEnvString("API_PASSWORD", "password"))
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -45,28 +47,38 @@ func init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetEnvBool(key string, defaultValue bool) bool {
|
func GetEnv[T any](key string, defaultValue T, parser func(string) (T, error)) T {
|
||||||
value, ok := os.LookupEnv(key)
|
var value string
|
||||||
|
var ok bool
|
||||||
|
for _, prefix := range prefixes {
|
||||||
|
value, ok = os.LookupEnv(prefix + key)
|
||||||
|
if ok && value != "" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
if !ok || value == "" {
|
if !ok || value == "" {
|
||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
b, err := strconv.ParseBool(value)
|
parsed, err := parser(value)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
log.Fatal().Msgf("env %s: invalid boolean value: %s", key, value)
|
return parsed
|
||||||
}
|
}
|
||||||
return b
|
log.Fatal().Err(err).Msgf("env %s: invalid %T value: %s", key, parsed, value)
|
||||||
|
return defaultValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetEnv(key, defaultValue string) string {
|
func GetEnvString(key string, defaultValue string) string {
|
||||||
value, ok := os.LookupEnv(key)
|
return GetEnv(key, defaultValue, func(s string) (string, error) {
|
||||||
if !ok || value == "" {
|
return s, nil
|
||||||
value = defaultValue
|
})
|
||||||
}
|
}
|
||||||
return value
|
|
||||||
|
func GetEnvBool(key string, defaultValue bool) bool {
|
||||||
|
return GetEnv(key, defaultValue, strconv.ParseBool)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAddrEnv(key, defaultValue, scheme string) (addr, host, port, fullURL string) {
|
func GetAddrEnv(key, defaultValue, scheme string) (addr, host, port, fullURL string) {
|
||||||
addr = GetEnv(key, defaultValue)
|
addr = GetEnvString(key, defaultValue)
|
||||||
host, port, err := net.SplitHostPort(addr)
|
host, port, err := net.SplitHostPort(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Msgf("env %s: invalid address: %s", key, addr)
|
log.Fatal().Msgf("env %s: invalid address: %s", key, addr)
|
||||||
|
@ -79,13 +91,5 @@ func GetAddrEnv(key, defaultValue, scheme string) (addr, host, port, fullURL str
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDurationEnv(key string, defaultValue time.Duration) time.Duration {
|
func GetDurationEnv(key string, defaultValue time.Duration) time.Duration {
|
||||||
value, ok := os.LookupEnv(key)
|
return GetEnv(key, defaultValue, time.ParseDuration)
|
||||||
if !ok || value == "" {
|
|
||||||
return defaultValue
|
|
||||||
}
|
|
||||||
d, err := time.ParseDuration(value)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Msgf("env %s: invalid duration value: %s", key, value)
|
|
||||||
}
|
|
||||||
return d
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ var (
|
||||||
|
|
||||||
func DockerProviderImpl(name, dockerHost string, explicitOnly bool) (ProviderImpl, error) {
|
func DockerProviderImpl(name, dockerHost string, explicitOnly bool) (ProviderImpl, error) {
|
||||||
if dockerHost == common.DockerHostFromEnv {
|
if dockerHost == common.DockerHostFromEnv {
|
||||||
dockerHost = common.GetEnv("DOCKER_HOST", client.DefaultDockerHost)
|
dockerHost = common.GetEnvString("DOCKER_HOST", client.DefaultDockerHost)
|
||||||
}
|
}
|
||||||
return &DockerProvider{
|
return &DockerProvider{
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
branch = common.GetEnv("GOPROXY_BRANCH", "v0.7")
|
branch = common.GetEnvString("BRANCH", "v0.7")
|
||||||
baseURL = "https://github.com/yusing/go-proxy/raw/" + branch
|
baseURL = "https://github.com/yusing/go-proxy/raw/" + branch
|
||||||
requiredConfigs = []Config{
|
requiredConfigs = []Config{
|
||||||
{common.ConfigBasePath, true, false, ""},
|
{common.ConfigBasePath, true, false, ""},
|
||||||
|
|
Loading…
Add table
Reference in a new issue