mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-28 15:29:09 +01:00
add support for GetNameServerGroups in sqlite
Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
This commit is contained in:
@@ -7,15 +7,11 @@ import (
|
|||||||
"net/netip"
|
"net/netip"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/management/server/types"
|
|
||||||
"github.com/netbirdio/netbird/shared/management/networkmap/nmdata"
|
"github.com/netbirdio/netbird/shared/management/networkmap/nmdata"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetNameServerGroups(t *testing.T) {
|
func TestGetNameServerGroups(t *testing.T) {
|
||||||
if engine == string(types.SqliteStoreEngine) {
|
|
||||||
t.Skip()
|
|
||||||
}
|
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
|
|
||||||
execQuery(t, ctx,
|
execQuery(t, ctx,
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -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) {
|
func (s *SqliteStoreConn) GetRoutes(ctx context.Context, accountId string) ([]nmdata.Route, error) {
|
||||||
return nil, nil
|
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) {
|
func (s *SqliteStoreConn) GetNetworkResources(ctx context.Context, accountId string) ([]nmdata.NetworkResource, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,3 +179,17 @@ func CollectRowsForSqlite[T any](rows *sql.Rows) ([]T, error) {
|
|||||||
|
|
||||||
return toret, nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user