mirror of
https://github.com/yusing/godoxy.git
synced 2026-02-20 01:17:43 +01:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb96a2a4f1 | ||
|
|
fdfb682e2a | ||
|
|
8d56c61826 | ||
|
|
d1fca7e987 | ||
|
|
95f88a6f3c | ||
|
|
c0e2cf63b5 | ||
|
|
6388d07f64 | ||
|
|
15e50322c9 | ||
|
|
3ad6e98a17 |
2
Makefile
2
Makefile
@@ -92,7 +92,7 @@ docker-build-test:
|
|||||||
|
|
||||||
go_ver := $(shell go version | cut -d' ' -f3 | cut -d'o' -f2)
|
go_ver := $(shell go version | cut -d' ' -f3 | cut -d'o' -f2)
|
||||||
files := $(shell find . -name go.mod -type f -or -name Dockerfile -type f)
|
files := $(shell find . -name go.mod -type f -or -name Dockerfile -type f)
|
||||||
gomod_paths := $(shell find . -name go.mod -type f | xargs dirname)
|
gomod_paths := $(shell find . -name go.mod -type f | grep -vE '^./internal/(go-oidc|go-proxmox|gopsutil)/' | xargs dirname)
|
||||||
|
|
||||||
update-go:
|
update-go:
|
||||||
for file in ${files}; do \
|
for file in ${files}; do \
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package agentapi
|
package agentapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -36,6 +37,9 @@ type VerifyNewAgentRequest struct {
|
|||||||
// @Failure 500 {object} ErrorResponse
|
// @Failure 500 {object} ErrorResponse
|
||||||
// @Router /agent/verify [post]
|
// @Router /agent/verify [post]
|
||||||
func Verify(c *gin.Context) {
|
func Verify(c *gin.Context) {
|
||||||
|
// avoid timeout waiting for response headers
|
||||||
|
c.Status(http.StatusContinue)
|
||||||
|
|
||||||
var request VerifyNewAgentRequest
|
var request VerifyNewAgentRequest
|
||||||
if err := c.ShouldBindJSON(&request); err != nil {
|
if err := c.ShouldBindJSON(&request); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, apitypes.Error("invalid request", err))
|
c.JSON(http.StatusBadRequest, apitypes.Error("invalid request", err))
|
||||||
@@ -60,7 +64,7 @@ func Verify(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nRoutesAdded, err := verifyNewAgent(request.Host, ca, client, request.ContainerRuntime)
|
nRoutesAdded, err := verifyNewAgent(c.Request.Context(), request.Host, ca, client, request.ContainerRuntime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, apitypes.Error("invalid request", err))
|
c.JSON(http.StatusBadRequest, apitypes.Error("invalid request", err))
|
||||||
return
|
return
|
||||||
@@ -82,7 +86,7 @@ func Verify(c *gin.Context) {
|
|||||||
|
|
||||||
var errAgentAlreadyExists = gperr.New("agent already exists")
|
var errAgentAlreadyExists = gperr.New("agent already exists")
|
||||||
|
|
||||||
func verifyNewAgent(host string, ca agent.PEMPair, client agent.PEMPair, containerRuntime agent.ContainerRuntime) (int, gperr.Error) {
|
func verifyNewAgent(ctx context.Context, host string, ca agent.PEMPair, client agent.PEMPair, containerRuntime agent.ContainerRuntime) (int, gperr.Error) {
|
||||||
var agentCfg agent.AgentConfig
|
var agentCfg agent.AgentConfig
|
||||||
agentCfg.Addr = host
|
agentCfg.Addr = host
|
||||||
agentCfg.Runtime = containerRuntime
|
agentCfg.Runtime = containerRuntime
|
||||||
@@ -99,7 +103,7 @@ func verifyNewAgent(host string, ca agent.PEMPair, client agent.PEMPair, contain
|
|||||||
return 0, errAgentAlreadyExists
|
return 0, errAgentAlreadyExists
|
||||||
}
|
}
|
||||||
|
|
||||||
err := agentCfg.InitWithCerts(cfgState.Context(), ca.Cert, client.Cert, client.Key)
|
err := agentCfg.InitWithCerts(ctx, ca.Cert, client.Cert, client.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, gperr.Wrap(err, "failed to initialize agent config")
|
return 0, gperr.Wrap(err, "failed to initialize agent config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,8 +222,9 @@ func (p *Provider) ObtainCertIfNotExistsAll() error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err := errs.Wait().Error()
|
||||||
p.rebuildSNIMatcher()
|
p.rebuildSNIMatcher()
|
||||||
return errs.Wait().Error()
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// obtainCertIfNotExists obtains a new certificate for this provider if it does not exist.
|
// obtainCertIfNotExists obtains a new certificate for this provider if it does not exist.
|
||||||
@@ -261,7 +262,10 @@ func (p *Provider) ObtainCertAll() error {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return errs.Wait().Error()
|
|
||||||
|
err := errs.Wait().Error()
|
||||||
|
p.rebuildSNIMatcher()
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObtainCert renews existing certificate or obtains a new certificate for this provider.
|
// ObtainCert renews existing certificate or obtains a new certificate for this provider.
|
||||||
|
|||||||
@@ -12,6 +12,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Stream(ctx context.Context, url *url.URL, timeout time.Duration) (types.HealthCheckResult, error) {
|
func Stream(ctx context.Context, url *url.URL, timeout time.Duration) (types.HealthCheckResult, error) {
|
||||||
|
if port := url.Port(); port == "" || port == "0" {
|
||||||
|
return types.HealthCheckResult{
|
||||||
|
Latency: 0,
|
||||||
|
Healthy: false,
|
||||||
|
Detail: "no port specified",
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
dialer := net.Dialer{
|
dialer := net.Dialer{
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
FallbackDelay: -1,
|
FallbackDelay: -1,
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ func (r *Route) validate() gperr.Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return error if route is localhost:<godoxy_port> but route is not agent
|
// return error if route is localhost:<godoxy_port> but route is not agent
|
||||||
if !r.IsAgent() {
|
if !r.IsAgent() && !r.ShouldExclude() {
|
||||||
switch r.Host {
|
switch r.Host {
|
||||||
case "localhost", "127.0.0.1":
|
case "localhost", "127.0.0.1":
|
||||||
switch r.Port.Proxy {
|
switch r.Port.Proxy {
|
||||||
@@ -749,6 +749,7 @@ const (
|
|||||||
ExcludedReasonNoPortSpecified
|
ExcludedReasonNoPortSpecified
|
||||||
ExcludedReasonBlacklisted
|
ExcludedReasonBlacklisted
|
||||||
ExcludedReasonBuildx
|
ExcludedReasonBuildx
|
||||||
|
ExcludedReasonYAMLAnchor
|
||||||
ExcludedReasonOld
|
ExcludedReasonOld
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -768,6 +769,8 @@ func (re ExcludedReason) String() string {
|
|||||||
return "Blacklisted (backend service or database)"
|
return "Blacklisted (backend service or database)"
|
||||||
case ExcludedReasonBuildx:
|
case ExcludedReasonBuildx:
|
||||||
return "Buildx"
|
return "Buildx"
|
||||||
|
case ExcludedReasonYAMLAnchor:
|
||||||
|
return "YAML anchor or reference"
|
||||||
case ExcludedReasonOld:
|
case ExcludedReasonOld:
|
||||||
return "Container renaming intermediate state"
|
return "Container renaming intermediate state"
|
||||||
default:
|
default:
|
||||||
@@ -802,6 +805,12 @@ func (r *Route) findExcludedReason() ExcludedReason {
|
|||||||
} else if r.IsZeroPort() && r.Scheme != route.SchemeFileServer {
|
} else if r.IsZeroPort() && r.Scheme != route.SchemeFileServer {
|
||||||
return ExcludedReasonNoPortSpecified
|
return ExcludedReasonNoPortSpecified
|
||||||
}
|
}
|
||||||
|
// this should happen on validation API only,
|
||||||
|
// those routes are removed before validation.
|
||||||
|
// see removeXPrefix in provider/file.go
|
||||||
|
if strings.HasPrefix(r.Alias, "x-") { // for YAML anchors and references
|
||||||
|
return ExcludedReasonYAMLAnchor
|
||||||
|
}
|
||||||
if strings.HasSuffix(r.Alias, "-old") {
|
if strings.HasSuffix(r.Alias, "-old") {
|
||||||
return ExcludedReasonOld
|
return ExcludedReasonOld
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,5 +49,7 @@ COPY --from=builder /app/run /app/run
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
LABEL proxy.#1.healthcheck.disable=true
|
||||||
|
|
||||||
ENV LISTEN_ADDR=0.0.0.0:2375
|
ENV LISTEN_ADDR=0.0.0.0:2375
|
||||||
CMD ["/app/run"]
|
CMD ["/app/run"]
|
||||||
Reference in New Issue
Block a user