Skip to content

Commit

Permalink
Merge pull request #184 from croessner/features
Browse files Browse the repository at this point in the history
Features
  • Loading branch information
croessner authored Dec 6, 2024
2 parents 749911f + 143b813 commit d7f248b
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 172 deletions.
1 change: 1 addition & 0 deletions server/config/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (r *RelayDomainsSection) String() string {
type BackendServer struct {
Protocol string `mapstructure:"protocol"`
Host string `mapstructure:"host"`
DeepCheck bool `mapstructure:"deep_check"`
RequestURI string `mapstructure:"request_uri"`
TestUsername string `mapstructure:"test_username"`
TestPassword string `mapstructure:"test_password"`
Expand Down
50 changes: 0 additions & 50 deletions server/config/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,56 +116,6 @@ func (f *File) GetBackendServer(protocol string) *BackendServer {
return nil
}

// GetBackendServerIP is a method for the File struct which
// attempts to get the IP address of a backend server
// for a specified protocol. The method first calls
// GetBackendServer with the given protocol and checks
// if it returns a non-nil value. If the value is not nil,
// it retrieves the IP attribute of the backend server.
// If the returned value is nil, indicating that there is
// no backend server for the given protocol, the method
// returns an empty string.
//
// Parameters:
//
// protocol: A string that specifies the protocol for
// which the backend server's IP address
// is to be retrieved. This could be "http",
// "https", etc.
//
// Returns:
//
// A string representing the IP address of the backend
// server for the given protocol. If there is no backend
// server for the specified protocol, the method returns
// an empty string.
func (f *File) GetBackendServerIP(protocol string) string {
if f == nil {
return ""
}

if f.GetBackendServer(protocol) != nil {
return f.GetBackendServer(protocol).Host
}

return ""
}

// GetBackendServerPort checks the specific protocol's backend server in the File structure.
// If the server exists, it returns the port of the server.
// If the server does not exist, it returns 0.
func (f *File) GetBackendServerPort(protocol string) int {
if f == nil {
return 0
}

if f.GetBackendServer(protocol) != nil {
return f.GetBackendServer(protocol).Port
}

return 0
}

/*
* LDAP Config
*/
Expand Down
6 changes: 6 additions & 0 deletions server/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,9 @@ var (
var (
ErrInvalidRange = errors.New("invalid range")
)

// connection.

var (
ErrMissingTLS = errors.New("missing TLS connection")
)
3 changes: 3 additions & 0 deletions server/lualib/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ func CheckBackendConnection(monitor monitoring.Monitor) lua.LGFunction {
server.Port = getNumberFromTable(table, "port")
server.HAProxyV2 = getBoolFromTable(table, "haproxy_v2")
server.TLS = getBoolFromTable(table, "tls")
server.TLSSkipVerify = getBoolFromTable(table, "tls_skip_verify")
server.TestUsername = getStringFromTable(table, "test_username")
server.TestPassword = getStringFromTable(table, "test_password")
server.RequestURI = getStringFromTable(table, "request_uri")
server.DeepCheck = getBoolFromTable(table, "deep_check")

if err := monitor.CheckBackendConnection(server); err != nil {
L.Push(lua.LString(err.Error()))
Expand Down
55 changes: 8 additions & 47 deletions server/lualib/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,39 +276,9 @@ type Request struct {
*lualib.CommonRequest
}

// LuaBackendServer represents a server configuration for a Lua script backend.
type LuaBackendServer struct {
// Protocol specifies the communication protocol (e.g., HTTP, HTTPS) used by the server.
Protocol string

// Host specifies the hostname or IP address of the server used in the backend configuration.
Host string

// RequestURL represents the request URL path used by the Lua backend server.
RequestURL string

// TestUsername is a placeholder used for testing purposes, representing the username required for server authentication.
TestUsername string

// TestPassword is a placeholder used for testing purposes, representing the password required for server authentication.
TestPassword string

// Port represents the network port number used by the server for communication.
Port int

// HAProxyV2 indicates whether HAProxy version 2 protocol is enabled for the backend server configuration.
HAProxyV2 bool

// TLS indicates whether Transport Layer Security (TLS) should be enabled for the server connection.
TLS bool

// TLSSKipVerify indicates whether to skip verification of the server's TLS certificate.
TLSSKipVerify bool
}

// The userData constellation method:
func newLuaBackendServer(userData *lua.LUserData) *LuaBackendServer {
if v, ok := userData.Value.(*LuaBackendServer); ok {
func newLuaBackendServer(userData *lua.LUserData) *config.BackendServer {
if v, ok := userData.Value.(*config.BackendServer); ok {
return v
}

Expand All @@ -332,8 +302,8 @@ func indexMethod(L *lua.LState) int {
L.Push(lua.LString(server.Host))
case "port":
L.Push(lua.LNumber(server.Port))
case "request_url":
L.Push(lua.LString(server.RequestURL))
case "request_uri":
L.Push(lua.LString(server.RequestURI))
case "test_username":
L.Push(lua.LString(server.TestUsername))
case "test_password":
Expand All @@ -343,7 +313,9 @@ func indexMethod(L *lua.LState) int {
case "tls":
L.Push(lua.LBool(server.TLS))
case "tls_skip_verify":
L.Push(lua.LBool(server.TLSSKipVerify))
L.Push(lua.LBool(server.TLSSkipVerify))
case "deep_check":
L.Push(lua.LBool(server.DeepCheck))
default:
return 0 // The field does not exist
}
Expand All @@ -368,18 +340,7 @@ func getBackendServers(backendServers []*config.BackendServer) lua.LGFunction {

// Create an userdata and set its metatable
serverUserData := L.NewUserData()

serverUserData.Value = &LuaBackendServer{
Protocol: backendServer.Protocol,
Host: backendServer.Host,
RequestURL: backendServer.RequestURI,
TestUsername: backendServer.TestUsername,
TestPassword: backendServer.TestPassword,
Port: backendServer.Port,
HAProxyV2: backendServer.HAProxyV2,
TLS: backendServer.TLS,
TLSSKipVerify: backendServer.TLSSkipVerify,
}
serverUserData.Value = backendServer

L.SetMetatable(serverUserData, L.GetTypeMetatable(definitions.LuaBackendServerTypeName))

Expand Down
3 changes: 1 addition & 2 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,8 +851,7 @@ func startStatsLoop(ctx context.Context, ticker *time.Ticker) error {
// err: the error that has occurred
func logBackendServerError(server *config.BackendServer, err error) {
level.Error(log.Logger).Log(
definitions.LogKeyMsg, err,
definitions.LogKeyMsg, "Server down",
definitions.LogKeyMsg, fmt.Sprintf("Server down: %v", err),
definitions.LogKeyBackendServer, server,
)
}
Expand Down
Loading

0 comments on commit d7f248b

Please sign in to comment.