add support for GetNameServerGroups in sqlite

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
This commit is contained in:
Dmitri Dolguikh
2026-08-10 17:53:34 +02:00
parent 78947c1611
commit 3834e67a51
4 changed files with 58 additions and 7 deletions

View File

@@ -7,15 +7,11 @@ import (
"net/netip"
"testing"
"github.com/netbirdio/netbird/management/server/types"
"github.com/netbirdio/netbird/shared/management/networkmap/nmdata"
"github.com/stretchr/testify/assert"
)
func TestGetNameServerGroups(t *testing.T) {
if engine == string(types.SqliteStoreEngine) {
t.Skip()
}
ctx := context.TODO()
execQuery(t, ctx,

View File

@@ -0,0 +1,44 @@
package networkmap_sqlite
import (
"context"
"database/sql"
networkmapdb "github.com/netbirdio/netbird/management/internals/network_map_db"
"github.com/netbirdio/netbird/shared/management/networkmap/nmdata"
)
const (
GetNameserversQuery = `
select id, public_id, name, description, name_servers, groups, "primary", domains, enabled, search_domains_enabled
from name_server_groups
where account_id=$1
`
)
func (sc *SqliteStoreConn) GetNameServerGroups(ctx context.Context, accountId string) ([]nmdata.NameServerGroup, error) {
rows, err := sc.Conn.QueryContext(ctx, GetNameserversQuery, accountId)
if err != nil {
return nil, err
}
nsgroups, err := networkmapdb.CollectRowsForSqlite[nameserverGroup](rows)
if err != nil {
return nil, err
}
return networkmapdb.ConvertAllToSharedTypes[nameserverGroup, nmdata.NameServerGroup](nsgroups)
}
type nameserverGroup struct {
ID string
PublicID sql.NullString
Name sql.NullString
Description sql.NullString
NameServers []byte `nmap:"json"`
Groups []byte `nmap:"json"`
Primary sql.NullBool
Domains []byte `nmap:"json"`
Enabled sql.NullBool
SearchDomainsEnabled sql.NullBool
}

View File

@@ -91,9 +91,6 @@ func (s *SqliteStoreConn) GetPolicies(ctx context.Context, accountId string) ([]
func (s *SqliteStoreConn) GetRoutes(ctx context.Context, accountId string) ([]nmdata.Route, error) {
return nil, nil
}
func (s *SqliteStoreConn) GetNameServerGroups(ctx context.Context, accountId string) ([]nmdata.NameServerGroup, error) {
return nil, nil
}
func (s *SqliteStoreConn) GetNetworkResources(ctx context.Context, accountId string) ([]nmdata.NetworkResource, error) {
return nil, nil
}

View File

@@ -179,3 +179,17 @@ func CollectRowsForSqlite[T any](rows *sql.Rows) ([]T, error) {
return toret, nil
}
func ConvertAllToSharedTypes[T any, T1 any](allsrc []T) ([]T1, error) {
toret := make([]T1, 0, len(allsrc))
for _, src := range allsrc {
var dst T1
err := FromSqlTypesToSharedTypes(
reflect.ValueOf(&src), reflect.ValueOf(&dst))
if err != nil {
return nil, err
}
toret = append(toret, dst)
}
return toret, nil
}