mirror of
https://github.com/netbirdio/netbird.git
synced 2026-08-24 16:41:30 +02:00
fix linter comments
This commit is contained in:
@@ -23,7 +23,7 @@ const (
|
||||
NMAP_MAP_TO = "map_to"
|
||||
)
|
||||
|
||||
type NetworkMapDBStore interface {
|
||||
type NetworkMapDBStore interface { //nolint:revive // established name across the codebase
|
||||
GetGroups(ctx context.Context, accountId string) ([]nmdata.Group, map[string]map[string]any, error)
|
||||
GetPeers(ctx context.Context, accountId string) ([]nmdata.Peer, map[string][]*nmdata.Peer, error)
|
||||
GetPolicies(ctx context.Context, accountId string) ([]nmdata.Policy, map[string]map[string]any, map[string]map[string]any, error)
|
||||
@@ -40,7 +40,7 @@ type NetworkMapDBStore interface {
|
||||
GetDnsSettings(ctx context.Context, accountId string) (nmdata.DNSSettings, error)
|
||||
}
|
||||
|
||||
type NetworkMapDBStoreImpl struct {
|
||||
type NetworkMapDBStoreImpl struct { //nolint:revive // established name across the codebase
|
||||
store NetworkMapDBStore
|
||||
integratedPeerValidator integrated_validator.IntegratedValidator
|
||||
extraSettingsManager settings.Manager
|
||||
@@ -138,7 +138,9 @@ func FromSqlTypesToSharedTypes(src reflect.Value, dst reflect.Value) error {
|
||||
}
|
||||
case "json.RawMessage":
|
||||
s := srcField.Interface().(json.RawMessage)
|
||||
json.Unmarshal(s, dstField.Addr().Interface())
|
||||
if err := json.Unmarshal(s, dstField.Addr().Interface()); err != nil {
|
||||
return err
|
||||
}
|
||||
case "[]string":
|
||||
if srcField.IsNil() {
|
||||
return nil
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/netbirdio/netbird/shared/management/networkmap/nmdata"
|
||||
)
|
||||
|
||||
var DnsUnsupportedRecordTypeError = errors.New("unsupported record type")
|
||||
var ErrDnsUnsupportedRecordType = errors.New("unsupported record type")
|
||||
|
||||
const (
|
||||
GetAccountZonesQuery = `
|
||||
@@ -73,7 +73,7 @@ func GetAppliedZoneCandidatesViaPgxConnection(ctx context.Context, conn *pgx.Con
|
||||
|
||||
rtype, rdata, err := recordTypeAndRdata(z.RecordType.String, z.RecordRData.String)
|
||||
if err != nil {
|
||||
if errors.Is(err, DnsUnsupportedRecordTypeError) {
|
||||
if errors.Is(err, ErrDnsUnsupportedRecordType) {
|
||||
continue
|
||||
}
|
||||
return nil, err
|
||||
@@ -112,7 +112,7 @@ func recordTypeAndRdata(t, rdata string) (int, string, error) {
|
||||
case "CNAME":
|
||||
return int(dns.TypeCNAME), dns.Fqdn(rdata), nil
|
||||
default:
|
||||
return 0, "", fmt.Errorf("record type: %s %w", t, DnsUnsupportedRecordTypeError)
|
||||
return 0, "", fmt.Errorf("record type: %s %w", t, ErrDnsUnsupportedRecordType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestRecordTypeAndRdata(t *testing.T) {
|
||||
{recordType: "AAAA", expectedRecordType: 28, rdata: "test.com", expectedRdata: "test.com", expectedErr: nil},
|
||||
{recordType: "CNAME", expectedRecordType: 5, rdata: "test.com", expectedRdata: "test.com.", expectedErr: nil},
|
||||
{recordType: "CNAME", expectedRecordType: 5, rdata: "test.com.", expectedRdata: "test.com.", expectedErr: nil},
|
||||
{recordType: "TypeMX", expectedErr: DnsUnsupportedRecordTypeError},
|
||||
{recordType: "TypeMX", expectedErr: ErrDnsUnsupportedRecordType},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -26,7 +26,7 @@ func TestRecordTypeAndRdata(t *testing.T) {
|
||||
recordType, rdata, err := recordTypeAndRdata(tt.recordType, tt.rdata)
|
||||
|
||||
if tt.expectedErr != nil {
|
||||
assert.ErrorIs(t, err, DnsUnsupportedRecordTypeError)
|
||||
assert.ErrorIs(t, err, ErrDnsUnsupportedRecordType)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package networkmap_pgsql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -20,7 +19,7 @@ func TestGetGroups(t *testing.T) {
|
||||
// err = loadSQL(ctx, s.pool, initDb)
|
||||
//assert.NoError(t, err)
|
||||
|
||||
_, err = s.Pool.Query(ctx, "insert into groups (id, account_id, name, resources, public_id) VALUES('test-group-id-1','ck7bnf2t2r9s739pkug0','test-group-1', '[{\"ID\":\"cui7q2jl0ubs73d8qpi0\",\"Type\":\"host\"}]','public-id-1')")
|
||||
_, err = s.Pool.Exec(ctx, "insert into groups (id, account_id, name, resources, public_id) VALUES('test-group-id-1','ck7bnf2t2r9s739pkug0','test-group-1', '[{\"ID\":\"cui7q2jl0ubs73d8qpi0\",\"Type\":\"host\"}]','public-id-1')")
|
||||
assert.NoError(t, err)
|
||||
|
||||
groups, _, err := s.GetGroups(ctx, "ck7bnf2t2r9s739pkug0") //"ckd7ee2fic3c73dtendg")
|
||||
@@ -47,7 +46,7 @@ func TestGetPeers(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, clusterToPeerIdx)
|
||||
|
||||
fmt.Print(peers)
|
||||
t.Log(peers)
|
||||
// assert.Contains(t,
|
||||
// groups,
|
||||
// nmdata.Group{Name: "test-group-1", PublicID: "public-id-1", Resources: []nmdata.Resource{{ID: "cui7q2jl0ubs73d8qpi0", Type: "host"}}},
|
||||
@@ -71,7 +70,7 @@ func TestGetPolicies(t *testing.T) {
|
||||
assert.NotEmpty(t, idx1)
|
||||
assert.NotEmpty(t, idx2)
|
||||
|
||||
fmt.Print(peers)
|
||||
t.Log(peers)
|
||||
// assert.Contains(t,
|
||||
// groups,
|
||||
// nmdata.Group{Name: "test-group-1", PublicID: "public-id-1", Resources: []nmdata.Resource{{ID: "cui7q2jl0ubs73d8qpi0", Type: "host"}}},
|
||||
@@ -93,7 +92,7 @@ func TestGetRoutes(t *testing.T) {
|
||||
peers, err := s.GetRoutes(ctx, "csg5iabl0ubs7398nf1g") //"ckd7ee2fic3c73dtendg")
|
||||
assert.NoError(t, err)
|
||||
|
||||
fmt.Print(peers)
|
||||
t.Log(peers)
|
||||
// assert.Contains(t,
|
||||
// groups,
|
||||
// nmdata.Group{Name: "test-group-1", PublicID: "public-id-1", Resources: []nmdata.Resource{{ID: "cui7q2jl0ubs73d8qpi0", Type: "host"}}},
|
||||
@@ -115,7 +114,7 @@ func TestGetNSGroups(t *testing.T) {
|
||||
groups, err := s.GetNameServerGroups(ctx, "cl3h77qfic3c738mkja0") //"ckd7ee2fic3c73dtendg")
|
||||
assert.NoError(t, err)
|
||||
|
||||
fmt.Print(groups)
|
||||
t.Log(groups)
|
||||
// assert.Contains(t,
|
||||
// groups,
|
||||
// nmdata.Group{Name: "test-group-1", PublicID: "public-id-1", Resources: []nmdata.Resource{{ID: "cui7q2jl0ubs73d8qpi0", Type: "host"}}},
|
||||
@@ -137,7 +136,7 @@ func TestGetNetworkResources(t *testing.T) {
|
||||
res, err := s.GetNetworkResources(ctx, "cag86v2t2r9s73d0416g") //"ckd7ee2fic3c73dtendg")
|
||||
assert.NoError(t, err)
|
||||
|
||||
fmt.Print(res)
|
||||
t.Log(res)
|
||||
// assert.Contains(t,
|
||||
// groups,
|
||||
// nmdata.Group{Name: "test-group-1", PublicID: "public-id-1", Resources: []nmdata.Resource{{ID: "cui7q2jl0ubs73d8qpi0", Type: "host"}}},
|
||||
@@ -160,7 +159,7 @@ func TestGetNetworkRouters(t *testing.T) {
|
||||
res, err := GetNetworkRoutersViaPgxConnection(ctx, c.Conn(), "d29f99jl0ubs73cm8ce0") //"ckd7ee2fic3c73dtendg")
|
||||
assert.NoError(t, err)
|
||||
|
||||
fmt.Print(res)
|
||||
t.Log(res)
|
||||
// assert.Contains(t,
|
||||
// groups,
|
||||
// nmdata.Group{Name: "test-group-1", PublicID: "public-id-1", Resources: []nmdata.Resource{{ID: "cui7q2jl0ubs73d8qpi0", Type: "host"}}},
|
||||
@@ -182,7 +181,7 @@ func TestGetNetwork(t *testing.T) {
|
||||
n, err := s.GetNetwork(ctx, "d29f99jl0ubs73cm8ce0") //"ckd7ee2fic3c73dtendg")
|
||||
assert.NoError(t, err)
|
||||
|
||||
fmt.Print(n)
|
||||
t.Log(n)
|
||||
// assert.Contains(t,
|
||||
// groups,
|
||||
// nmdata.Group{Name: "test-group-1", PublicID: "public-id-1", Resources: []nmdata.Resource{{ID: "cui7q2jl0ubs73d8qpi0", Type: "host"}}},
|
||||
@@ -204,7 +203,7 @@ func TestGetAccountZones(t *testing.T) {
|
||||
zones, err := s.GetAppliedZoneCandidates(ctx, "d4g66rjl0ubs73b2q3b0") //"ckd7ee2fic3c73dtendg")
|
||||
assert.NoError(t, err)
|
||||
|
||||
fmt.Print(zones)
|
||||
t.Log(zones)
|
||||
// assert.Contains(t,
|
||||
// groups,
|
||||
// nmdata.Group{Name: "test-group-1", PublicID: "public-id-1", Resources: []nmdata.Resource{{ID: "cui7q2jl0ubs73d8qpi0", Type: "host"}}},
|
||||
@@ -245,7 +244,7 @@ func TestGetPostureChecks(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, idx)
|
||||
|
||||
fmt.Print(checks)
|
||||
t.Log(checks)
|
||||
// assert.Contains(t,
|
||||
// groups,
|
||||
// nmdata.Group{Name: "test-group-1", PublicID: "public-id-1", Resources: []nmdata.Resource{{ID: "cui7q2jl0ubs73d8qpi0", Type: "host"}}},
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/miekg/dns"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/netbirdio/netbird/shared/management/networkmap"
|
||||
"github.com/netbirdio/netbird/shared/management/networkmap/nmdata"
|
||||
)
|
||||
@@ -111,9 +113,8 @@ func (pg *PgStore) GetNetworkMapData(ctx context.Context, accountId string) (*ne
|
||||
}
|
||||
}
|
||||
|
||||
err = tx.Commit(ctx)
|
||||
if err != nil {
|
||||
// TODO log and ignore?
|
||||
if err = tx.Commit(ctx); err != nil {
|
||||
log.WithContext(ctx).Warnf("failed to commit network map read transaction: %v", err)
|
||||
}
|
||||
|
||||
toret := networkmap.NetworkMapData{
|
||||
@@ -143,7 +144,7 @@ func (pg *PgStore) GetNetworkMapData(ctx context.Context, accountId string) (*ne
|
||||
|
||||
func rollbackAndReturnError(ctx context.Context, tx pgx.Tx, err error) (*networkmap.NetworkMapData, error) {
|
||||
if errr := tx.Rollback(ctx); errr != nil {
|
||||
// TODO log and ignore?
|
||||
log.WithContext(ctx).Warnf("failed to rollback network map read transaction: %v", errr)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
defaultTTL = 300
|
||||
// privateServiceDNSRecordTTL is short so proxy-peer changes propagate quickly to clients.
|
||||
privateServiceDNSRecordTTL = 5
|
||||
DefaultPeerLoginExpiration = 24 * time.Hour
|
||||
|
||||
Reference in New Issue
Block a user