Compare commits

...

18 Commits

Author SHA1 Message Date
eb1e8a9cb0 consul registration update 2024-07-21 21:11:34 +02:00
2c797164e0 consul registration update 2024-07-21 21:00:49 +02:00
7725e5dd65 debug fix 2024-07-20 20:12:29 +02:00
07c0cd6f2e debug fix 2024-07-20 19:59:12 +02:00
d29bd0810b debug fix 2024-07-20 19:55:33 +02:00
b62c0e5a8c debug fix 2024-07-20 19:03:21 +02:00
a9eb0d0732 debug fix 2024-07-20 18:19:56 +02:00
92b84685c9 routing fix 2024-07-20 17:30:37 +02:00
cd6e62e3bc debug fix 2024-07-20 16:17:13 +02:00
7cf2d91fd8 debug fix 2024-07-20 16:15:20 +02:00
936982731d debug fix 2024-07-20 16:11:06 +02:00
33759c87db debug fix 2024-07-20 15:56:59 +02:00
974f82e9be debug fix 2024-07-20 15:53:05 +02:00
d7dc75c18f debug fix 2024-07-20 15:45:49 +02:00
c62c63249c debug fix 2024-07-20 14:44:45 +02:00
6c290eb66b tls fix 2024-07-20 14:43:47 +02:00
31ce7fc48e tls fix 2024-07-20 14:42:16 +02:00
99957861dc fix ssl support 2024-07-20 14:24:38 +02:00

View File

@@ -17,6 +17,7 @@ type Service struct {
appID string
domain string
pathPrefix string
tls bool
port int
ttl time.Duration
client *consul.Client
@@ -24,8 +25,8 @@ type Service struct {
connect *connect.Service
kv *consul.KV
hcTicker *time.Ticker
ttlTicker *time.Ticker
// hcTicker *time.Ticker
// ttlTicker *time.Ticker
}
var ErrServiceUnavailable = fmt.Errorf("Service is unavailable")
@@ -37,6 +38,7 @@ func NewService(servAddr, id, name, useDomainOverIp, addr, domain, pathPrefix st
s.appID = id
s.domain = domain
s.pathPrefix = pathPrefix
s.tls = true // FIXME add arg
s.port = appPort
s.ttl = time.Second * 10
@@ -68,12 +70,11 @@ func (s *Service) GetID() string {
}
func (s *Service) GetFullAddr() string {
isTLS := s.port == 443
proto := "http"
if isTLS {
if s.tls {
proto = "https"
}
return fmt.Sprintf("%s://%s:%d/", proto, s.Address, s.port)
return fmt.Sprintf("%s://%s:%d/", proto, s.domain, s.port)
}
func (s *Service) Register() error {
@@ -84,11 +85,13 @@ func (s *Service) Register() error {
Address: s.Address,
Port: s.port,
Tags: s.getTags(),
// Connect: &consul.AgentServiceConnect{Native: true},
Connect: &consul.AgentServiceConnect{Native: true},
// Proxy: &consul.AgentServiceConnectProxyConfig{
// DestinationServiceName: s.Name,
// },
Check: &consul.AgentServiceCheck{
// Interval: "5s",
// Timeout: "1s",
TTL: s.ttl.String(),
Status: "passing",
DeregisterCriticalServiceAfter: "10s",
@@ -141,11 +144,10 @@ func (s *Service) Connect() (*connect.Service, error) {
// })
svc, err := connect.NewService(s.Name, s.client)
s.connect = svc
cnf := svc.ServerTLSConfig()
fmt.Printf("CONNECT SERVER:: %s CONFIG:: %v\n", s.Name, cnf)
for k, c := range cnf.Certificates {
fmt.Printf("CONNECT CERT %d: %v", k, c)
}
fmt.Printf("CONNECT SERVER:: %s CERTS:: %v\n", s.Name, svc.ServerTLSConfig())
// for k, c := range cnf.Certificates {
// fmt.Printf("CONNECT CERT %d: %v", k, c)
// }
return svc, err
}
@@ -158,7 +160,7 @@ func (s *Service) healthCheck() (bool, error) {
alive := func() bool {
client := &http.Client{}
healthUrl := fmt.Sprintf("%s%s?name=%s", s.GetFullAddr(), "health", s.Name)
fmt.Printf("HealthCheck URL: %s%s?name=%s", s.GetFullAddr(), "health", s.Name)
// fmt.Printf("HealthCheck URL: %s%s?name=%s", s.GetFullAddr(), "health", s.Name)
req, err := http.NewRequest(http.MethodGet, healthUrl, nil)
if err != nil {
return false
@@ -202,21 +204,20 @@ func (s *Service) getTags() []string {
"traefik.http.middlewares.requestid_" + s.Name + ".plugin.requestid.headerName=X-Request-ID",
// "treafik.http.middlewares.retryif_" + s.Name + ".plugin.retryif.attempts=3",
// "treafik.http.middlewares.retryif_" + s.Name + ".plugin.retryif.statusCode=503",
"traefik.http.routers." + s.Name + ".rule=PathPrefix(`" + s.pathPrefix + "`)",
// "traefik.http.routers." + s.Name + ".rule=Host(`" + s.domain + "`)",
"traefik.http.routers." + s.Name + ".rule=Host(`" + s.domain + "`) && PathPrefix(`" + s.pathPrefix + "`)",
"traefik.http.routers." + s.Name + ".entryPoints=https",
// "traefik.http.routers." + s.Name + ".tls=true",
"traefik.http.routers." + s.Name + ".tls=true",
"traefik.http.routers." + s.Name + ".service=" + s.Name,
// "traefik.http.routers." + s.Name + ".middlewares=auth_" + s.Name + ",stripprefix_" + s.Name,
"traefik.http.routers." + s.Name + ".middlewares=auth_" + s.Name + ",stripprefix_" + s.Name + ",requestid_" + s.Name + "",
"traefik.http.services." + s.Name + ".loadbalancer.server.scheme=https",
"traefik.http.services." + s.Name + ".loadbalancer.server.port=" + strconv.Itoa(s.port),
"traefik.http.services." + s.Name + ".loadbalancer.passhostheader=true",
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.interval=1s",
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.interval=5s",
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.timeout=1s",
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.path=/health",
"traefik.tls.certificates.certfile=/certs/client.cert",
"traefik.tls.certificates.keyfile=/certs/client.key",
"traefik.tls.certificates.certfile=certs/client.crt",
"traefik.tls.certificates.keyfile=certs/client.key",
}
return tags