mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 04:52:35 +02:00
v0.5.0-rc5: added proxy.exclude label, refactored some code
This commit is contained in:
parent
83d1d027c6
commit
be7a766cb2
8 changed files with 31 additions and 24 deletions
|
@ -88,6 +88,7 @@
|
|||
| Label | Description | Default |
|
||||
| ----------------------- | -------------------------------------------------------- | ---------------- |
|
||||
| `proxy.aliases` | comma separated aliases for subdomain and label matching | `container_name` |
|
||||
| `proxy.exclude` | to be excluded from `go-proxy` | false |
|
||||
| `proxy.<alias>.<field>` | set field for specific alias | N/A |
|
||||
| `proxy.*.<field>` | set field for all aliases | N/A |
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ func (p *Provider) LoadCert() E.NestedError {
|
|||
p.tlsCert = &cert
|
||||
p.certExpiries = expiries
|
||||
|
||||
logger.Infof("next renewal in %v", time.Until(p.ShouldRenewOn()))
|
||||
logger.Infof("next renewal in %v", U.FormatDuration(time.Until(p.ShouldRenewOn())))
|
||||
return p.renewIfNeeded()
|
||||
}
|
||||
|
||||
|
|
|
@ -2,17 +2,13 @@ package common
|
|||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
U "github.com/yusing/go-proxy/utils"
|
||||
)
|
||||
|
||||
var NoSchemaValidation = getEnvBool("GOPROXY_NO_SCHEMA_VALIDATION")
|
||||
var IsDebug = getEnvBool("GOPROXY_DEBUG")
|
||||
|
||||
func getEnvBool(key string) bool {
|
||||
switch strings.ToLower(os.Getenv(key)) {
|
||||
case "1", "true", "yes", "on":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return U.ParseBool(os.Getenv(key))
|
||||
}
|
||||
|
|
|
@ -60,7 +60,6 @@ const NSProxy = "proxy"
|
|||
|
||||
var _ = func() int {
|
||||
RegisterNamespace(NSProxy, ValueParserMap{
|
||||
"aliases": commaSepParser,
|
||||
"path_patterns": yamlListParser,
|
||||
"set_headers": yamlStringMappingParser,
|
||||
"hide_headers": yamlListParser,
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
package provider
|
||||
|
||||
const wildcardAlias = "*"
|
|
@ -10,6 +10,7 @@ import (
|
|||
E "github.com/yusing/go-proxy/error"
|
||||
M "github.com/yusing/go-proxy/models"
|
||||
PT "github.com/yusing/go-proxy/proxy/fields"
|
||||
U "github.com/yusing/go-proxy/utils"
|
||||
W "github.com/yusing/go-proxy/watcher"
|
||||
)
|
||||
|
||||
|
@ -72,6 +73,12 @@ func (p *DockerProvider) getEntriesFromLabels(container *types.Container, client
|
|||
var mainAlias string
|
||||
var aliases PT.Aliases
|
||||
|
||||
if exclude, ok := container.Labels[D.NSProxy+".exclude"]; ok {
|
||||
if U.ParseBool(exclude) {
|
||||
return M.NewProxyEntries(), E.Nil()
|
||||
}
|
||||
}
|
||||
|
||||
// set mainAlias to docker compose service name if available
|
||||
if serviceName, ok := container.Labels["com.docker.compose.service"]; ok {
|
||||
mainAlias = serviceName
|
||||
|
@ -84,9 +91,9 @@ func (p *DockerProvider) getEntriesFromLabels(container *types.Container, client
|
|||
mainAlias = containerName
|
||||
}
|
||||
|
||||
if l, ok := container.Labels["proxy.aliases"]; ok {
|
||||
if l, ok := container.Labels[D.NSProxy+".aliases"]; ok {
|
||||
aliases = PT.NewAliases(l)
|
||||
delete(container.Labels, "proxy.aliases")
|
||||
delete(container.Labels, D.NSProxy+"proxy.aliases")
|
||||
} else {
|
||||
aliases = PT.NewAliases(mainAlias)
|
||||
}
|
||||
|
@ -157,3 +164,5 @@ func findFirstPort(c *types.Container) (string, E.NestedError) {
|
|||
}
|
||||
return "", E.Failure("findFirstPort")
|
||||
}
|
||||
|
||||
const wildcardAlias = "*"
|
||||
|
|
|
@ -20,16 +20,16 @@ func FormatDuration(d time.Duration) string {
|
|||
var parts []string
|
||||
|
||||
if days > 0 {
|
||||
parts = append(parts, fmt.Sprintf("%d Day%s", days, pluralize(days)))
|
||||
parts = append(parts, fmt.Sprintf("%d day%s", days, pluralize(days)))
|
||||
}
|
||||
if hours > 0 {
|
||||
parts = append(parts, fmt.Sprintf("%d Hour%s", hours, pluralize(hours)))
|
||||
parts = append(parts, fmt.Sprintf("%d hour%s", hours, pluralize(hours)))
|
||||
}
|
||||
if minutes > 0 {
|
||||
parts = append(parts, fmt.Sprintf("%d Minute%s", minutes, pluralize(minutes)))
|
||||
parts = append(parts, fmt.Sprintf("%d minute%s", minutes, pluralize(minutes)))
|
||||
}
|
||||
if seconds > 0 {
|
||||
parts = append(parts, fmt.Sprintf("%d Second%s", seconds, pluralize(seconds)))
|
||||
parts = append(parts, fmt.Sprintf("%d second%s", seconds, pluralize(seconds)))
|
||||
}
|
||||
|
||||
// Join the parts with appropriate connectors
|
||||
|
@ -42,6 +42,15 @@ func FormatDuration(d time.Duration) string {
|
|||
return strings.Join(parts[:len(parts)-1], ", ") + " and " + parts[len(parts)-1]
|
||||
}
|
||||
|
||||
func ParseBool(s string) bool {
|
||||
switch strings.ToLower(s) {
|
||||
case "1", "true", "yes", "on":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func pluralize(n int64) string {
|
||||
if n > 1 {
|
||||
return "s"
|
||||
|
|
|
@ -2,7 +2,6 @@ package utils
|
|||
|
||||
import (
|
||||
"github.com/santhosh-tekuri/jsonschema"
|
||||
"github.com/yusing/go-proxy/common"
|
||||
)
|
||||
|
||||
var schemaCompiler = func() *jsonschema.Compiler {
|
||||
|
@ -14,9 +13,6 @@ var schemaCompiler = func() *jsonschema.Compiler {
|
|||
var schemaStorage = make(map[string]*jsonschema.Schema)
|
||||
|
||||
func GetSchema(path string) *jsonschema.Schema {
|
||||
if common.NoSchemaValidation {
|
||||
panic("bug: GetSchema called when schema validation disabled")
|
||||
}
|
||||
if schema, ok := schemaStorage[path]; ok {
|
||||
return schema
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue