mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-14 13:44:37 +08:00
e086cee9f2
Signed-off-by: John Sahhar <john@gravitl.com>
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package functions
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
|
|
"github.com/gravitl/netmaker/database"
|
|
"github.com/gravitl/netmaker/models"
|
|
)
|
|
|
|
// NetworkExists - check if network exists
|
|
func NetworkExists(name string) (bool, error) {
|
|
|
|
var network string
|
|
var err error
|
|
if network, err = database.FetchRecord(database.NETWORKS_TABLE_NAME, name); err != nil {
|
|
return false, err
|
|
}
|
|
return len(network) > 0, nil
|
|
}
|
|
|
|
// NameInDNSCharSet - name in dns char set
|
|
func NameInDNSCharSet(name string) bool {
|
|
|
|
charset := "abcdefghijklmnopqrstuvwxyz1234567890-."
|
|
|
|
for _, char := range name {
|
|
if !strings.Contains(charset, strings.ToLower(string(char))) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
// NameInNodeCharSet - name in node char set
|
|
func NameInNodeCharSet(name string) bool {
|
|
|
|
charset := "abcdefghijklmnopqrstuvwxyz1234567890-"
|
|
|
|
for _, char := range name {
|
|
if !strings.Contains(charset, strings.ToLower(string(char))) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
// RemoveDeletedNode - remove deleted node
|
|
func RemoveDeletedNode(nodeid string) bool {
|
|
return database.DeleteRecord(database.DELETED_NODES_TABLE_NAME, nodeid) == nil
|
|
}
|
|
|
|
// GetAllExtClients - get all ext clients
|
|
func GetAllExtClients() ([]models.ExtClient, error) {
|
|
var extclients []models.ExtClient
|
|
collection, err := database.FetchRecords(database.EXT_CLIENT_TABLE_NAME)
|
|
|
|
if err != nil {
|
|
return extclients, err
|
|
}
|
|
|
|
for _, value := range collection {
|
|
var extclient models.ExtClient
|
|
err := json.Unmarshal([]byte(value), &extclient)
|
|
if err != nil {
|
|
return []models.ExtClient{}, err
|
|
}
|
|
// add node to our array
|
|
extclients = append(extclients, extclient)
|
|
}
|
|
|
|
return extclients, nil
|
|
}
|