2021-03-26 00:17:52 +08:00
|
|
|
package functions
|
|
|
|
|
|
|
|
import (
|
2021-07-14 11:08:10 +08:00
|
|
|
"encoding/json"
|
2021-04-25 06:03:26 +08:00
|
|
|
"strings"
|
2021-07-15 04:47:05 +08:00
|
|
|
|
2021-07-21 05:18:45 +08:00
|
|
|
"github.com/gravitl/netmaker/database"
|
2021-04-25 06:03:26 +08:00
|
|
|
"github.com/gravitl/netmaker/models"
|
2021-03-26 00:17:52 +08:00
|
|
|
)
|
|
|
|
|
2021-10-09 03:07:12 +08:00
|
|
|
// NameInDNSCharSet - name in dns char set
|
2021-04-27 11:39:15 +08:00
|
|
|
func NameInDNSCharSet(name string) bool {
|
|
|
|
|
2021-05-01 19:57:49 +08:00
|
|
|
charset := "abcdefghijklmnopqrstuvwxyz1234567890-."
|
2021-04-27 11:39:15 +08:00
|
|
|
|
2021-05-01 19:57:49 +08:00
|
|
|
for _, char := range name {
|
|
|
|
if !strings.Contains(charset, strings.ToLower(string(char))) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2021-04-27 11:39:15 +08:00
|
|
|
|
2021-10-09 03:07:12 +08:00
|
|
|
// NameInNodeCharSet - name in node char set
|
2021-04-25 06:03:26 +08:00
|
|
|
func NameInNodeCharSet(name string) bool {
|
2021-03-26 00:17:52 +08:00
|
|
|
|
2021-04-25 06:03:26 +08:00
|
|
|
charset := "abcdefghijklmnopqrstuvwxyz1234567890-"
|
2021-03-26 00:17:52 +08:00
|
|
|
|
2021-04-25 06:03:26 +08:00
|
|
|
for _, char := range name {
|
|
|
|
if !strings.Contains(charset, strings.ToLower(string(char))) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
2021-03-26 00:17:52 +08:00
|
|
|
}
|
|
|
|
|
2021-10-09 03:07:12 +08:00
|
|
|
// RemoveDeletedNode - remove deleted node
|
2021-08-10 10:31:01 +08:00
|
|
|
func RemoveDeletedNode(nodeid string) bool {
|
|
|
|
return database.DeleteRecord(database.DELETED_NODES_TABLE_NAME, nodeid) == nil
|
|
|
|
}
|
|
|
|
|
2021-10-09 03:07:12 +08:00
|
|
|
// GetAllExtClients - get all ext clients
|
2021-05-20 01:59:10 +08:00
|
|
|
func GetAllExtClients() ([]models.ExtClient, error) {
|
2021-07-15 04:47:05 +08:00
|
|
|
var extclients []models.ExtClient
|
2021-07-21 05:18:45 +08:00
|
|
|
collection, err := database.FetchRecords(database.EXT_CLIENT_TABLE_NAME)
|
|
|
|
|
2021-07-15 04:47:05 +08:00
|
|
|
if err != nil {
|
2021-07-21 05:18:45 +08:00
|
|
|
return extclients, err
|
2021-07-15 04:47:05 +08:00
|
|
|
}
|
2021-07-21 05:18:45 +08:00
|
|
|
|
|
|
|
for _, value := range collection {
|
|
|
|
var extclient models.ExtClient
|
|
|
|
err := json.Unmarshal([]byte(value), &extclient)
|
2021-07-15 04:47:05 +08:00
|
|
|
if err != nil {
|
|
|
|
return []models.ExtClient{}, err
|
|
|
|
}
|
|
|
|
// add node to our array
|
|
|
|
extclients = append(extclients, extclient)
|
|
|
|
}
|
2021-05-20 01:59:10 +08:00
|
|
|
|
2021-07-15 04:47:05 +08:00
|
|
|
return extclients, nil
|
|
|
|
}
|