mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-23 23:29:08 +02:00
add an posture-check-id to public-id index
Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
This commit is contained in:
@@ -31,7 +31,7 @@ type NetworkMapDBStore interface {
|
|||||||
GetNetwork(ctx context.Context, accountId string) (nmdata.Network, error)
|
GetNetwork(ctx context.Context, accountId string) (nmdata.Network, error)
|
||||||
GetAppliedZoneCandidates(ctx context.Context, accountId string) ([]networkmap.AppliedZoneCandidate, error)
|
GetAppliedZoneCandidates(ctx context.Context, accountId string) ([]networkmap.AppliedZoneCandidate, error)
|
||||||
GetAccountSettings(ctx context.Context, accountId string) (nmdata.AccountSettingsInfo, error)
|
GetAccountSettings(ctx context.Context, accountId string) (nmdata.AccountSettingsInfo, error)
|
||||||
GetPostureChecks(ctx context.Context, accountId string) ([]nmdata.PostureChecks, error)
|
GetPostureChecks(ctx context.Context, accountId string) ([]nmdata.PostureChecks, map[string]string, error)
|
||||||
GetNetworkMapData(ctx context.Context, accountId string) (*networkmap.NetworkMapData, error)
|
GetNetworkMapData(ctx context.Context, accountId string) (*networkmap.NetworkMapData, error)
|
||||||
GetAllowedUsers(ctx context.Context, accountId string) (map[string]struct{}, map[string][]string, error)
|
GetAllowedUsers(ctx context.Context, accountId string) (map[string]struct{}, map[string][]string, error)
|
||||||
GetDnsSettings(ctx context.Context, accountId string) (nmdata.DNSSettings, error)
|
GetDnsSettings(ctx context.Context, accountId string) (nmdata.DNSSettings, error)
|
||||||
|
|||||||
@@ -241,8 +241,9 @@ func TestGetPostureChecks(t *testing.T) {
|
|||||||
// err = loadSQL(ctx, s.pool, initDb)
|
// err = loadSQL(ctx, s.pool, initDb)
|
||||||
//assert.NoError(t, err)
|
//assert.NoError(t, err)
|
||||||
|
|
||||||
checks, err := s.GetPostureChecks(ctx, "cdfcks2t2r9s73a58us0") //"ckd7ee2fic3c73dtendg")
|
checks, idx, err := s.GetPostureChecks(ctx, "cdfcks2t2r9s73a58us0") //"ckd7ee2fic3c73dtendg")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
assert.NotEmpty(t, idx)
|
||||||
|
|
||||||
fmt.Print(checks)
|
fmt.Print(checks)
|
||||||
// assert.Contains(t,
|
// assert.Contains(t,
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func (pg *PgStore) GetNetworkMapData(ctx context.Context, accountId string) (*ne
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return rollbackAndReturnError(ctx, tx, err)
|
return rollbackAndReturnError(ctx, tx, err)
|
||||||
}
|
}
|
||||||
postureChecks, err := GetPostureChecksViaPgxConnection(ctx, tx.Conn(), accountId)
|
postureChecks, postureCheckXIDToPublicID, err := GetPostureChecksViaPgxConnection(ctx, tx.Conn(), accountId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return rollbackAndReturnError(ctx, tx, err)
|
return rollbackAndReturnError(ctx, tx, err)
|
||||||
}
|
}
|
||||||
@@ -112,23 +112,24 @@ func (pg *PgStore) GetNetworkMapData(ctx context.Context, accountId string) (*ne
|
|||||||
}
|
}
|
||||||
|
|
||||||
toret := networkmap.NetworkMapData{
|
toret := networkmap.NetworkMapData{
|
||||||
AccountSettings: &acctSettings,
|
AccountSettings: &acctSettings,
|
||||||
DNSSettings: &dnsSettings,
|
DNSSettings: &dnsSettings,
|
||||||
Network: &network,
|
Network: &network,
|
||||||
Peers: toMap(peers, func(p nmdata.Peer) string { return p.ID }),
|
Peers: toMap(peers, func(p nmdata.Peer) string { return p.ID }),
|
||||||
Groups: toMap(groups, func(g nmdata.Group) string { return g.PublicID }),
|
Groups: toMap(groups, func(g nmdata.Group) string { return g.PublicID }),
|
||||||
Policies: toSliceOfPtrs(policies),
|
Policies: toSliceOfPtrs(policies),
|
||||||
ResourcePolicies: resourcePolicies,
|
ResourcePolicies: resourcePolicies,
|
||||||
Routes: toSliceOfPtrs(routes),
|
Routes: toSliceOfPtrs(routes),
|
||||||
Routers: routers,
|
Routers: routers,
|
||||||
NameServerGroups: toSliceOfPtrs(nsGroups),
|
NameServerGroups: toSliceOfPtrs(nsGroups),
|
||||||
NetworkResources: toSliceOfPtrs(networkResources),
|
NetworkResources: toSliceOfPtrs(networkResources),
|
||||||
PostureChecks: toMap(postureChecks, func(pc nmdata.PostureChecks) string { return pc.ID }),
|
PostureChecks: toMap(postureChecks, func(pc nmdata.PostureChecks) string { return pc.ID }),
|
||||||
AllowedUserIDs: allowedUserIds,
|
AllowedUserIDs: allowedUserIds,
|
||||||
GroupIDToUserIDs: groupsToUserIds,
|
GroupIDToUserIDs: groupsToUserIds,
|
||||||
NetworkXIDToPublicID: networkXIDToPublicID, // TODO (dmitri) maybe we can switch to public ids everywhere?
|
NetworkXIDToPublicID: networkXIDToPublicID, // TODO (dmitri) maybe we can switch to public ids everywhere?
|
||||||
AppliedZoneCandidates: dnsZones,
|
AppliedZoneCandidates: dnsZones,
|
||||||
PrivateServiceCandidates: buildPrivateServiceCandidates(services, domains, proxyPeers),
|
PrivateServiceCandidates: buildPrivateServiceCandidates(services, domains, proxyPeers),
|
||||||
|
PostureCheckXIDToPublicID: postureCheckXIDToPublicID,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &toret, nil
|
return &toret, nil
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package networkmap_pgsql
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
@@ -12,45 +13,48 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
GetPostureChecksQuery = `
|
GetPostureChecksQuery = `
|
||||||
select public_id as id, checks
|
select id, public_id, checks
|
||||||
from posture_checks
|
from posture_checks
|
||||||
where account_id=$1
|
where account_id=$1
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
|
|
||||||
func (pg *PgStore) GetPostureChecks(ctx context.Context, accountId string) ([]nmdata.PostureChecks, error) {
|
func (pg *PgStore) GetPostureChecks(ctx context.Context, accountId string) ([]nmdata.PostureChecks, map[string]string, error) {
|
||||||
c, err := pg.Pool.Acquire(ctx)
|
c, err := pg.Pool.Acquire(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
return GetPostureChecksViaPgxConnection(ctx, c.Conn(), accountId)
|
return GetPostureChecksViaPgxConnection(ctx, c.Conn(), accountId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPostureChecksViaPgxConnection(ctx context.Context, con *pgx.Conn, accountId string) ([]nmdata.PostureChecks, error) {
|
func GetPostureChecksViaPgxConnection(ctx context.Context, con *pgx.Conn, accountId string) ([]nmdata.PostureChecks, map[string]string, error) {
|
||||||
rows, err := con.Query(ctx, GetPostureChecksQuery, accountId)
|
rows, err := con.Query(ctx, GetPostureChecksQuery, accountId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
checks, err := pgx.CollectRows(rows, pgx.RowToStructByName[posturechecks])
|
checks, err := pgx.CollectRows(rows, pgx.RowToStructByName[posturechecks])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
toret := make([]nmdata.PostureChecks, 0, len(checks))
|
toret := make([]nmdata.PostureChecks, 0, len(checks))
|
||||||
|
idToPublicIDIdx := make(map[string]string)
|
||||||
for _, c := range checks {
|
for _, c := range checks {
|
||||||
checks := nmdata.PostureChecks{}
|
checks := nmdata.PostureChecks{}
|
||||||
err := networkmapdb.FromSqlTypesToSharedTypes(reflect.ValueOf(&c), reflect.ValueOf(&checks))
|
err := networkmapdb.FromSqlTypesToSharedTypes(reflect.ValueOf(&c), reflect.ValueOf(&checks))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
toret = append(toret, checks)
|
toret = append(toret, checks)
|
||||||
|
idToPublicIDIdx[checks.ID] = c.PublicID.String
|
||||||
}
|
}
|
||||||
|
|
||||||
return toret, nil
|
return toret, idToPublicIDIdx, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type posturechecks struct {
|
type posturechecks struct {
|
||||||
ID string
|
ID string
|
||||||
Checks json.RawMessage
|
PublicID sql.NullString `nmap:"skip"`
|
||||||
|
Checks json.RawMessage
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user