feat: send gateway dns and private address (#3378)

This commit is contained in:
Aceix 2025-03-18 09:26:29 +00:00 committed by GitHub
parent 3d765f9cf1
commit 39d812f137
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 0 deletions

View file

@ -44,6 +44,8 @@ type UserRemoteGws struct {
AllowedEndpoints []string `json:"allowed_endpoints"`
NetworkAddresses []string `json:"network_addresses"`
Status NodeStatus `json:"status"`
DnsAddress string `json:"dns_address"`
Addresses string `json:"addresses"`
}
// UserRAGs - struct for user access gws

View file

@ -21,6 +21,7 @@ import (
"github.com/gravitl/netmaker/pro/email"
proLogic "github.com/gravitl/netmaker/pro/logic"
"github.com/gravitl/netmaker/servercfg"
"github.com/gravitl/netmaker/utils"
"golang.org/x/exp/slog"
)
@ -1074,6 +1075,8 @@ func getRemoteAccessGatewayConf(w http.ResponseWriter, r *http.Request) {
Metadata: node.Metadata,
AllowedEndpoints: getAllowedRagEndpoints(&node, host),
NetworkAddresses: []string{network.AddressRange, network.AddressRange6},
DnsAddress: node.IngressDNS,
Addresses: utils.NoEmptyStringToCsv(node.Address.String(), node.Address6.String()),
}
slog.Debug("returned user gw config", "user", user.UserName, "gws", userGw)
@ -1165,6 +1168,8 @@ func getUserRemoteAccessGwsV1(w http.ResponseWriter, r *http.Request) {
AllowedEndpoints: getAllowedRagEndpoints(&node, host),
NetworkAddresses: []string{network.AddressRange, network.AddressRange6},
Status: node.Status,
DnsAddress: node.IngressDNS,
Addresses: utils.NoEmptyStringToCsv(node.Address.String(), node.Address6.String()),
})
userGws[node.Network] = gws
delete(userGwNodes, node.ID.String())
@ -1207,6 +1212,8 @@ func getUserRemoteAccessGwsV1(w http.ResponseWriter, r *http.Request) {
AllowedEndpoints: getAllowedRagEndpoints(&node, host),
NetworkAddresses: []string{network.AddressRange, network.AddressRange6},
Status: node.Status,
DnsAddress: node.IngressDNS,
Addresses: utils.NoEmptyStringToCsv(node.Address.String(), node.Address6.String()),
})
userGws[node.Network] = gws
}

View file

@ -3,6 +3,7 @@ package utils
import (
"log/slog"
"runtime"
"strings"
"time"
)
@ -59,3 +60,18 @@ func TraceCaller() {
slog.Debug("Called from function: %s\n", "func-name", funcName)
slog.Debug("File: %s, Line: %d\n", "file", file, "line-no", line)
}
// NoEmptyStringToCsv takes a bunch of strings, filters out empty ones and returns a csv version of the string
func NoEmptyStringToCsv(strs ...string) string {
var sb strings.Builder
for _, str := range strs {
trimmedStr := strings.TrimSpace(str)
if trimmedStr != "" && trimmedStr != "<nil>" {
if sb.Len() > 0 {
sb.WriteString(", ")
}
sb.WriteString(str)
}
}
return sb.String()
}