mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-05 13:09:07 +02:00
moved test for RecordTypeAndRdata into the parent package
Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
This commit is contained in:
@@ -2,7 +2,6 @@ package networkmapdb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
|
||||||
|
|
||||||
"golang.org/x/exp/maps"
|
"golang.org/x/exp/maps"
|
||||||
|
|
||||||
@@ -12,13 +11,6 @@ import (
|
|||||||
"github.com/netbirdio/netbird/shared/management/networkmap/nmdata"
|
"github.com/netbirdio/netbird/shared/management/networkmap/nmdata"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
NMAP_STRUCT_TAG = "nmap"
|
|
||||||
NMAP_SKIP = "skip"
|
|
||||||
NMAP_MAP_TO = "map_to"
|
|
||||||
NMAP_JSON = "json"
|
|
||||||
)
|
|
||||||
|
|
||||||
type NetworkMapDBStore interface { //nolint:revive // established name across the codebase
|
type NetworkMapDBStore interface { //nolint:revive // established name across the codebase
|
||||||
GetNetworkMapData(ctx context.Context, accountId string) (*networkmap.NetworkMapData, error)
|
GetNetworkMapData(ctx context.Context, accountId string) (*networkmap.NetworkMapData, error)
|
||||||
}
|
}
|
||||||
@@ -43,19 +35,6 @@ type NetworkMapDBStoreConn interface { //nolint:revive // established name acros
|
|||||||
GetProxyTargetedDomainResourceIDs(ctx context.Context, accountId string) (map[string]struct{}, error)
|
GetProxyTargetedDomainResourceIDs(ctx context.Context, accountId string) (map[string]struct{}, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Domain struct {
|
|
||||||
Domain sql.NullString
|
|
||||||
TargetCluster sql.NullString
|
|
||||||
}
|
|
||||||
|
|
||||||
type Service struct {
|
|
||||||
Enabled sql.NullBool
|
|
||||||
Private sql.NullBool
|
|
||||||
AccessGroups []string
|
|
||||||
ProxyCluster sql.NullString
|
|
||||||
Domain sql.NullString
|
|
||||||
}
|
|
||||||
|
|
||||||
type NetworkMapDBStoreImpl struct { //nolint:revive // established name across the codebase
|
type NetworkMapDBStoreImpl struct { //nolint:revive // established name across the codebase
|
||||||
store NetworkMapDBStore
|
store NetworkMapDBStore
|
||||||
integratedPeerValidator integrated_validator.IntegratedValidator
|
integratedPeerValidator integrated_validator.IntegratedValidator
|
||||||
|
|||||||
@@ -5,18 +5,14 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/miekg/dns"
|
|
||||||
networkmapdb "github.com/netbirdio/netbird/management/internals/network_map_db"
|
networkmapdb "github.com/netbirdio/netbird/management/internals/network_map_db"
|
||||||
"github.com/netbirdio/netbird/shared/management/networkmap"
|
"github.com/netbirdio/netbird/shared/management/networkmap"
|
||||||
"github.com/netbirdio/netbird/shared/management/networkmap/nmdata"
|
"github.com/netbirdio/netbird/shared/management/networkmap/nmdata"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrDnsUnsupportedRecordType = errors.New("unsupported record type")
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
GetAccountZonesQuery = `
|
GetAccountZonesQuery = `
|
||||||
select zones.id as id, domain, not enable_search_domain as search_domain_disabled, distribution_groups,
|
select zones.id as id, domain, not enable_search_domain as search_domain_disabled, distribution_groups,
|
||||||
@@ -63,9 +59,9 @@ func (pgc *PgStoreConn) GetAppliedZoneCandidates(ctx context.Context, accountId
|
|||||||
currentZoneId = z.Id
|
currentZoneId = z.Id
|
||||||
}
|
}
|
||||||
|
|
||||||
rtype, rdata, err := recordTypeAndRdata(z.RecordType.String, z.RecordRData.String)
|
rtype, rdata, err := networkmapdb.RecordTypeAndRdata(z.RecordType.String, z.RecordRData.String)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, ErrDnsUnsupportedRecordType) {
|
if errors.Is(err, networkmapdb.ErrDnsUnsupportedRecordType) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -95,19 +91,6 @@ type zone struct {
|
|||||||
RecordRData sql.NullString `nmap:"skip"`
|
RecordRData sql.NullString `nmap:"skip"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func recordTypeAndRdata(t, rdata string) (int, string, error) {
|
|
||||||
switch t {
|
|
||||||
case "A":
|
|
||||||
return int(dns.TypeA), rdata, nil
|
|
||||||
case "AAAA":
|
|
||||||
return int(dns.TypeAAAA), rdata, nil
|
|
||||||
case "CNAME":
|
|
||||||
return int(dns.TypeCNAME), dns.Fqdn(rdata), nil
|
|
||||||
default:
|
|
||||||
return 0, "", fmt.Errorf("record type: %s %w", t, ErrDnsUnsupportedRecordType)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func appliedZoneCandidateFromZone(z nmdata.CustomZone, distributionGroups []string) networkmap.AppliedZoneCandidate {
|
func appliedZoneCandidateFromZone(z nmdata.CustomZone, distributionGroups []string) networkmap.AppliedZoneCandidate {
|
||||||
return networkmap.AppliedZoneCandidate{
|
return networkmap.AppliedZoneCandidate{
|
||||||
DistributionGroups: distributionGroups,
|
DistributionGroups: distributionGroups,
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package networkmapdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/miekg/dns"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ErrDnsUnsupportedRecordType = errors.New("unsupported record type")
|
||||||
|
|
||||||
|
type Domain struct {
|
||||||
|
Domain sql.NullString
|
||||||
|
TargetCluster sql.NullString
|
||||||
|
}
|
||||||
|
|
||||||
|
type Service struct {
|
||||||
|
Enabled sql.NullBool
|
||||||
|
Private sql.NullBool
|
||||||
|
AccessGroups []string
|
||||||
|
ProxyCluster sql.NullString
|
||||||
|
Domain sql.NullString
|
||||||
|
}
|
||||||
|
|
||||||
|
func RecordTypeAndRdata(t, rdata string) (int, string, error) {
|
||||||
|
switch t {
|
||||||
|
case "A":
|
||||||
|
return int(dns.TypeA), rdata, nil
|
||||||
|
case "AAAA":
|
||||||
|
return int(dns.TypeAAAA), rdata, nil
|
||||||
|
case "CNAME":
|
||||||
|
return int(dns.TypeCNAME), dns.Fqdn(rdata), nil
|
||||||
|
default:
|
||||||
|
return 0, "", fmt.Errorf("record type: %s %w", t, ErrDnsUnsupportedRecordType)
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
package networkmap_pgsql
|
package networkmapdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@@ -23,7 +23,7 @@ func TestRecordTypeAndRdata(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.recordType, func(t *testing.T) {
|
t.Run(tt.recordType, func(t *testing.T) {
|
||||||
recordType, rdata, err := recordTypeAndRdata(tt.recordType, tt.rdata)
|
recordType, rdata, err := RecordTypeAndRdata(tt.recordType, tt.rdata)
|
||||||
|
|
||||||
if tt.expectedErr != nil {
|
if tt.expectedErr != nil {
|
||||||
assert.ErrorIs(t, err, ErrDnsUnsupportedRecordType)
|
assert.ErrorIs(t, err, ErrDnsUnsupportedRecordType)
|
||||||
@@ -10,6 +10,13 @@ import (
|
|||||||
"github.com/rs/xid"
|
"github.com/rs/xid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
NMAP_STRUCT_TAG = "nmap"
|
||||||
|
NMAP_SKIP = "skip"
|
||||||
|
NMAP_MAP_TO = "map_to"
|
||||||
|
NMAP_JSON = "json"
|
||||||
|
)
|
||||||
|
|
||||||
type fieldTag struct {
|
type fieldTag struct {
|
||||||
Key string
|
Key string
|
||||||
Value string
|
Value string
|
||||||
|
|||||||
Reference in New Issue
Block a user