support for GetNetworkXIDToPublicIdMap in sqlite

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
This commit is contained in:
Dmitri Dolguikh
2026-08-11 10:51:34 +02:00
parent 3da27221ac
commit fad568fdb0
4 changed files with 43 additions and 14 deletions

View File

@@ -2,9 +2,9 @@ package networkmap_pgsql
import (
"context"
"database/sql"
"github.com/jackc/pgx/v5"
networkmapdb "github.com/netbirdio/netbird/management/internals/network_map_db"
)
const (
@@ -14,16 +14,13 @@ const (
`
)
func (pgc *PgStoreConn) GetNetworks(ctx context.Context, accountId string) ([]network, error) {
func (pgc *PgStoreConn) GetNetworkXIDToPublicIdMap(ctx context.Context, accountId string) (map[string]string, error) {
rows, err := pgc.Conn.Query(ctx, GetNetworksQuery, accountId)
if err != nil {
return nil, err
}
return pgx.CollectRows(rows, pgx.RowToStructByName[network])
}
func (pgc *PgStoreConn) GetNetworkXIDToPublicIdMap(ctx context.Context, accountId string) (map[string]string, error) {
networks, err := pgc.GetNetworks(ctx, accountId)
networks, err := pgx.CollectRows(rows, pgx.RowToStructByName[networkmapdb.Network])
if err != nil {
return nil, err
}
@@ -37,8 +34,3 @@ func (pgc *PgStoreConn) GetNetworkXIDToPublicIdMap(ctx context.Context, accountI
return toret, nil
}
type network struct {
ID string
PublicID sql.NullString
}

View File

@@ -87,6 +87,11 @@ type AccountNetwork struct {
Serial sql.NullInt64
}
type Network struct {
ID string
PublicID sql.NullString
}
func RecordTypeAndRdata(t, rdata string) (int, string, error) {
switch t {
case "A":

View File

@@ -0,0 +1,35 @@
package networkmap_sqlite
import (
"context"
networkmapdb "github.com/netbirdio/netbird/management/internals/network_map_db"
)
const (
GetNetworksQuery = `
select id, public_id
from networks where account_id=?
`
)
func (sc *SqliteStoreConn) GetNetworkXIDToPublicIdMap(ctx context.Context, accountId string) (map[string]string, error) {
rows, err := sc.Conn.QueryContext(ctx, GetNetworksQuery, accountId)
if err != nil {
return nil, err
}
networks, err := CollectRowsForSqlite[networkmapdb.Network](rows)
if err != nil {
return nil, err
}
toret := make(map[string]string)
for _, n := range networks {
if n.PublicID.Valid {
toret[n.ID] = n.PublicID.String
}
}
return toret, nil
}

View File

@@ -135,9 +135,6 @@ func (s *SqliteStoreConn) GetPostureChecks(ctx context.Context, accountId string
func (s *SqliteStoreConn) GetAllowedUsers(ctx context.Context, accountId string) (map[string]struct{}, map[string][]string, error) {
return nil, nil, nil
}
func (s *SqliteStoreConn) GetNetworkXIDToPublicIdMap(ctx context.Context, accountId string) (map[string]string, error) {
return nil, nil
}
func (s *SqliteStoreConn) GetPrivateServices(ctx context.Context, accountId string) ([]networkmapdb.Service, error) {
return nil, nil
}