mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-07 21:54:54 +08:00
added netmaker check on checkin
This commit is contained in:
parent
eb1b79f898
commit
23df004620
2 changed files with 16 additions and 3 deletions
|
@ -68,7 +68,7 @@ func Insert(key string, value string, tableName string) error {
|
|||
}
|
||||
|
||||
func InsertPeer(key string, value string) error {
|
||||
if key != "" && value != "" {
|
||||
if key != "" && value != "" && isJSONString(value) {
|
||||
_, err := Database.WriteOne("INSERT OR REPLACE INTO " + PEERS_TABLE_NAME + " (key, value) VALUES ('" + key + "', '" + value + "')")
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -9,7 +9,8 @@ import (
|
|||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"strings"
|
||||
"encoding/base64"
|
||||
"github.com/gravitl/netmaker/database"
|
||||
"github.com/gravitl/netmaker/functions"
|
||||
"github.com/gravitl/netmaker/models"
|
||||
|
@ -201,7 +202,19 @@ func GetPeers(networkName string) (map[string]string, error) {
|
|||
return nil, err
|
||||
}
|
||||
for _, peer := range device.Peers {
|
||||
peers[peer.PublicKey.String()] = peer.Endpoint.String()
|
||||
if isBase64(peer.PublicKey.String()) && checkEndpoint(peer.Endpoint.String()) {
|
||||
peers[peer.PublicKey.String()] = peer.Endpoint.String()
|
||||
}
|
||||
}
|
||||
return peers, nil
|
||||
}
|
||||
|
||||
func checkEndpoint(endpoint string) bool {
|
||||
endpointarr := strings.Split(endpoint,":")
|
||||
return net.ParseIP(endpointarr[0]) == nil
|
||||
}
|
||||
|
||||
func isBase64(s string) bool {
|
||||
_, err := base64.StdEncoding.DecodeString(s)
|
||||
return err == nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue