Skip to content

Commit 600dc23

Browse files
authored
Get status of TLS from server service (#629)
* Add IsTLSEnabled function to server and add it to the API endpoint, getServers * Ignore error * Initialize variable and check for nil before returning * Initialize variable
1 parent 37fec61 commit 600dc23

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

api/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ func (a *API) GetServers(context.Context, *emptypb.Empty) (*structpb.Struct, err
289289
"status": uint(server.Status),
290290
"tickInterval": server.TickInterval.Nanoseconds(),
291291
"loadBalancer": map[string]any{"strategy": server.LoadbalancerStrategyName},
292+
"isTLSEnabled": server.IsTLSEnabled(),
292293
}
293294
}
294295

network/server.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const (
3434
Shutdown
3535
)
3636

37+
//nolint:interfacebloat
3738
type IServer interface {
3839
OnBoot() Action
3940
OnOpen(conn *ConnWrapper) ([]byte, Action)
@@ -44,7 +45,10 @@ type IServer interface {
4445
Run() *gerr.GatewayDError
4546
Shutdown()
4647
IsRunning() bool
48+
IsTLSEnabled() bool
4749
CountConnections() int
50+
GetProxyForConnection(conn *ConnWrapper) (IProxy, bool)
51+
RemoveConnectionFromMap(conn *ConnWrapper)
4852
}
4953

5054
type Server struct {
@@ -69,12 +73,13 @@ type Server struct {
6973
KeyFile string
7074
HandshakeTimeout time.Duration
7175

72-
listener net.Listener
73-
host string
74-
port int
75-
connections uint32
76-
running *atomic.Bool
77-
stopServer chan struct{}
76+
listener net.Listener
77+
host string
78+
port int
79+
connections uint32
80+
running *atomic.Bool
81+
isTLSEnabled *atomic.Bool
82+
stopServer chan struct{}
7883

7984
// loadbalancer
8085
loadbalancerStrategy LoadBalancerStrategy
@@ -543,6 +548,9 @@ func (s *Server) Run() *gerr.GatewayDError {
543548
return gerr.ErrCastFailed.Wrap(origErr)
544549
}
545550

551+
s.isTLSEnabled = &atomic.Bool{}
552+
s.running = &atomic.Bool{}
553+
546554
go func(server *Server) {
547555
<-server.stopServer
548556
server.OnShutdown()
@@ -582,6 +590,7 @@ func (s *Server) Run() *gerr.GatewayDError {
582590
return gerr.ErrGetTLSConfigFailed.Wrap(origErr)
583591
}
584592
s.Logger.Info().Msg("TLS is enabled")
593+
s.isTLSEnabled.Store(true)
585594
} else {
586595
s.Logger.Debug().Msg("TLS is disabled")
587596
}
@@ -767,6 +776,14 @@ func (s *Server) CountConnections() int {
767776
return int(s.connections)
768777
}
769778

779+
// IsTLSEnabled returns true if TLS is enabled.
780+
func (s *Server) IsTLSEnabled() bool {
781+
if s.isTLSEnabled == nil {
782+
return false
783+
}
784+
return s.isTLSEnabled.Load()
785+
}
786+
770787
// GetProxyForConnection returns the proxy associated with the given connection.
771788
func (s *Server) GetProxyForConnection(conn *ConnWrapper) (IProxy, bool) {
772789
proxy, exists := s.connectionToProxyMap.Load(conn)

0 commit comments

Comments
 (0)