mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-19 20:32:35 +02:00
small refactor and fixes
This commit is contained in:
parent
cebc0c5405
commit
5d5c623f09
12 changed files with 46 additions and 52 deletions
|
@ -2,12 +2,12 @@
|
|||
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
|
||||
version: 0.1
|
||||
cli:
|
||||
version: 1.22.6
|
||||
version: 1.22.8
|
||||
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
|
||||
plugins:
|
||||
sources:
|
||||
- id: trunk
|
||||
ref: v1.6.3
|
||||
ref: v1.6.5
|
||||
uri: https://github.com/trunk-io/plugins
|
||||
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
|
||||
runtimes:
|
||||
|
@ -21,18 +21,18 @@ lint:
|
|||
- markdownlint
|
||||
- yamllint
|
||||
enabled:
|
||||
- hadolint@2.12.0
|
||||
- actionlint@1.7.3
|
||||
- checkov@3.2.257
|
||||
- hadolint@2.12.1-beta
|
||||
- actionlint@1.7.4
|
||||
- checkov@3.2.324
|
||||
- git-diff-check
|
||||
- gofmt@1.20.4
|
||||
- golangci-lint@1.61.0
|
||||
- osv-scanner@1.9.0
|
||||
- oxipng@9.1.2
|
||||
- prettier@3.3.3
|
||||
- golangci-lint@1.62.2
|
||||
- osv-scanner@1.9.1
|
||||
- oxipng@9.1.3
|
||||
- prettier@3.4.1
|
||||
- shellcheck@0.10.0
|
||||
- shfmt@3.6.0
|
||||
- trufflehog@3.82.7
|
||||
- trufflehog@3.84.1
|
||||
actions:
|
||||
disabled:
|
||||
- trunk-announce
|
||||
|
|
|
@ -204,15 +204,14 @@ func (p *Provider) registerACME() error {
|
|||
p.user.Registration = reg
|
||||
logger.Info().Msg("reused acme registration from private key")
|
||||
return nil
|
||||
} else {
|
||||
reg, err := p.client.Registration.Register(registration.RegisterOptions{TermsOfServiceAgreed: true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.user.Registration = reg
|
||||
logger.Info().Interface("reg", reg).Msg("acme registered")
|
||||
}
|
||||
|
||||
reg, err := p.client.Registration.Register(registration.RegisterOptions{TermsOfServiceAgreed: true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.user.Registration = reg
|
||||
logger.Info().Interface("reg", reg).Msg("acme registered")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/sha512"
|
||||
"encoding/base64"
|
||||
|
||||
|
@ -14,14 +13,6 @@ func HashPassword(pwd string) []byte {
|
|||
return h.Sum(nil)
|
||||
}
|
||||
|
||||
func generateJWTKey(size int) string {
|
||||
bytes := make([]byte, size)
|
||||
if _, err := rand.Read(bytes); err != nil {
|
||||
log.Panic().Err(err).Msg("failed to generate jwt key")
|
||||
}
|
||||
return base64.StdEncoding.EncodeToString(bytes)
|
||||
}
|
||||
|
||||
func decodeJWTKey(key string) []byte {
|
||||
if key == "" {
|
||||
return nil
|
||||
|
|
|
@ -8,12 +8,11 @@ import (
|
|||
|
||||
func Inspect(dockerHost string, containerID string) (*Container, error) {
|
||||
client, err := ConnectClient(dockerHost)
|
||||
defer client.Close()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer client.Close()
|
||||
return client.Inspect(containerID)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package homepage
|
||||
|
||||
// PredefinedCategories by alias or docker image name
|
||||
// PredefinedCategories by alias or docker image name.
|
||||
var PredefinedCategories = map[string]string{
|
||||
"sonarr": "Torrenting",
|
||||
"radarr": "Torrenting",
|
||||
|
|
|
@ -10,8 +10,8 @@ type (
|
|||
Icon string `json:"icon" yaml:"icon"`
|
||||
URL string `json:"url" yaml:"url"` // alias + domain
|
||||
Category string `json:"category" yaml:"category"`
|
||||
Description string `json:"description" yaml:"description"`
|
||||
WidgetConfig map[string]any `json:"widget_config" yaml:",flow"`
|
||||
Description string `json:"description" yaml:"description" aliases:"desc"`
|
||||
WidgetConfig map[string]any `json:"widget_config" yaml:",flow" aliases:"widget"`
|
||||
|
||||
SourceType string `json:"source_type" yaml:"-"`
|
||||
AltURL string `json:"alt_url" yaml:"-"` // original proxy target
|
||||
|
|
|
@ -218,7 +218,9 @@ func (lb *LoadBalancer) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
|||
if r.Header.Get(common.HeaderCheckRedirect) != "" {
|
||||
// wake all servers
|
||||
for _, srv := range srvs {
|
||||
srv.TryWake()
|
||||
if err := srv.TryWake(); err != nil {
|
||||
lb.l.Warn().Err(err).Str("server", srv.Name).Msg("failed to wake server")
|
||||
}
|
||||
}
|
||||
}
|
||||
lb.impl.ServeHTTP(srvs, rw, r)
|
||||
|
|
|
@ -109,7 +109,7 @@ func fetchUpdateCFIPRange(endpoint string, cfCIDRs []*types.CIDR) error {
|
|||
return fmt.Errorf("cloudflare responeded an invalid CIDR: %s", line)
|
||||
}
|
||||
|
||||
cfCIDRs = append(cfCIDRs, (*types.CIDR)(cidr))
|
||||
cfCIDRs = append(cfCIDRs, cidr)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -40,7 +40,10 @@ func jsonIfTemplateNotUsed(fl validator.FieldLevel) bool {
|
|||
}
|
||||
|
||||
func init() {
|
||||
utils.Validator().RegisterValidation("jsonIfTemplateNotUsed", jsonIfTemplateNotUsed)
|
||||
err := utils.Validator().RegisterValidation("jsonIfTemplateNotUsed", jsonIfTemplateNotUsed)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Name implements Provider.
|
||||
|
@ -52,9 +55,8 @@ func (webhook *Webhook) Name() string {
|
|||
func (webhook *Webhook) Method() string {
|
||||
if webhook.Meth != "" {
|
||||
return webhook.Meth
|
||||
} else {
|
||||
return http.MethodPost
|
||||
}
|
||||
return http.MethodPost
|
||||
}
|
||||
|
||||
// URL implements Provider.
|
||||
|
@ -71,17 +73,16 @@ func (webhook *Webhook) Token() string {
|
|||
func (webhook *Webhook) MIMEType() string {
|
||||
if webhook.MIMETyp != "" {
|
||||
return webhook.MIMETyp
|
||||
} else {
|
||||
return "application/json"
|
||||
}
|
||||
return "application/json"
|
||||
}
|
||||
|
||||
func (Webhook *Webhook) ColorMode() string {
|
||||
switch Webhook.Template {
|
||||
func (webhook *Webhook) ColorMode() string {
|
||||
switch webhook.Template {
|
||||
case "discord":
|
||||
return "dec"
|
||||
default:
|
||||
return Webhook.ColorM
|
||||
return webhook.ColorM
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,7 +120,7 @@ func (webhook *Webhook) MakeBody(logMsg *LogMessage) (io.Reader, error) {
|
|||
plTempl := strings.NewReplacer(
|
||||
"$title", string(title),
|
||||
"$message", string(message),
|
||||
"$fields", string(fields),
|
||||
"$fields", fields,
|
||||
"$color", color,
|
||||
)
|
||||
var pl string
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/yusing/go-proxy/internal/common"
|
||||
"github.com/yusing/go-proxy/internal/docker"
|
||||
D "github.com/yusing/go-proxy/internal/docker"
|
||||
E "github.com/yusing/go-proxy/internal/error"
|
||||
"github.com/yusing/go-proxy/internal/route"
|
||||
|
@ -17,9 +16,7 @@ import (
|
|||
. "github.com/yusing/go-proxy/internal/utils/testing"
|
||||
)
|
||||
|
||||
var (
|
||||
dummyNames = []string{"/a"}
|
||||
)
|
||||
var dummyNames = []string{"/a"}
|
||||
|
||||
func makeEntries(cont *types.Container, dockerHost ...string) route.RawEntries {
|
||||
var p DockerProvider
|
||||
|
@ -29,7 +26,7 @@ func makeEntries(cont *types.Container, dockerHost ...string) route.RawEntries {
|
|||
} else {
|
||||
host = client.DefaultDockerHost
|
||||
}
|
||||
entries := E.Must(p.entriesFromContainerLabels(docker.FromDocker(cont, host)))
|
||||
entries := E.Must(p.entriesFromContainerLabels(D.FromDocker(cont, host)))
|
||||
entries.RangeAll(func(k string, v *route.RawEntry) {
|
||||
v.Finalize()
|
||||
})
|
||||
|
@ -269,7 +266,9 @@ func TestPrivateIPLocalhost(t *testing.T) {
|
|||
"network": {
|
||||
IPAddress: "172.17.0.123",
|
||||
},
|
||||
}}}
|
||||
},
|
||||
},
|
||||
}
|
||||
raw, ok := makeEntries(c).Load("a")
|
||||
ExpectTrue(t, ok)
|
||||
ExpectEqual(t, raw.Container.PrivateIP, "172.17.0.123")
|
||||
|
@ -286,7 +285,8 @@ func TestPrivateIPRemote(t *testing.T) {
|
|||
IPAddress: "172.17.0.123",
|
||||
},
|
||||
},
|
||||
}}
|
||||
},
|
||||
}
|
||||
raw, ok := makeEntries(c, "tcp://1.2.3.4:2375").Load("a")
|
||||
ExpectTrue(t, ok)
|
||||
ExpectEqual(t, raw.Container.PrivateIP, "")
|
||||
|
|
|
@ -40,8 +40,10 @@ const (
|
|||
)
|
||||
|
||||
// function alias.
|
||||
var NewRoutes = F.NewMap[Routes]
|
||||
var NewProxyEntries = types.NewProxyEntries
|
||||
var (
|
||||
NewRoutes = F.NewMap[Routes]
|
||||
NewProxyEntries = types.NewProxyEntries
|
||||
)
|
||||
|
||||
func (rt *Route) Container() *docker.Container {
|
||||
if rt.Entry.Container == nil {
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
)
|
||||
|
||||
type HealthCheckConfig struct {
|
||||
Disable bool `json:"disable,omitempty" yaml:"disable"`
|
||||
Disable bool `json:"disable,omitempty" yaml:"disable" aliases:"disabled"`
|
||||
Path string `json:"path,omitempty" yaml:"path"`
|
||||
UseGet bool `json:"use_get,omitempty" yaml:"use_get"`
|
||||
Interval time.Duration `json:"interval" yaml:"interval"`
|
||||
|
|
Loading…
Add table
Reference in a new issue