support for posture-checks

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
This commit is contained in:
Dmitri Dolguikh
2026-07-30 18:00:58 +02:00
parent 799f3a3c62
commit 4bf75fdc97
3 changed files with 71 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ type NetworkMapDBStore interface {
GetNetwork(ctx context.Context, accountId string) (nmdata.Network, error)
GetAccountZones(ctx context.Context, accountId string) ([]nmdata.CustomZone, error)
GetAccountSettings(ctx context.Context, accountId string) (nmdata.AccountSettingsInfo, error)
GetPostureChecks(ctx context.Context, accountId string) ([]nmdata.PostureChecks, error)
}
type NetworkMapDBStoreImpl struct {

View File

@@ -234,6 +234,28 @@ func TestGetAccountSetings(t *testing.T) {
}, settings)
}
func TestGetPostureChecks(t *testing.T) {
ctx := context.TODO()
s, err := NewPostgresqlStore(ctx, "postgresql://root:netbird@localhost:5432/netbird")
assert.NoError(t, err)
// err = loadSQL(ctx, s.pool, initDb)
//assert.NoError(t, err)
checks, err := s.GetPostureChecks(ctx, "cdfcks2t2r9s73a58us0") //"ckd7ee2fic3c73dtendg")
assert.NoError(t, err)
fmt.Print(checks)
// assert.Contains(t,
// groups,
// nmdata.Group{Name: "test-group-1", PublicID: "public-id-1", Resources: []nmdata.Resource{{ID: "cui7q2jl0ubs73d8qpi0", Type: "host"}}},
// )
// assert.Contains(t,
// groups,
// nmdata.Group{Name: "All", PublicID: "d9aejspvcsu517nkh4a0", Resources: []nmdata.Resource{{ID: "cui7olrl0ubs73d8qpe0", Type: "subnet"}, {ID: "cui7q2jl0ubs73d8qpi0", Type: "host"}}},
// )
}
func loadSQL(ctx context.Context, pool *pgxpool.Pool, initdb string) error {
queries := strings.Split(string(initdb), ";")

View File

@@ -0,0 +1,48 @@
package networkmap_pgsql
import (
"context"
"encoding/json"
"reflect"
"github.com/jackc/pgx/v5"
networkmapdb "github.com/netbirdio/netbird/management/internals/network_map_db"
"github.com/netbirdio/netbird/shared/management/networkmap/nmdata"
)
const (
GetPostureChecksQuery = `
select id, checks
from posture_checks
where account_id=$1
`
)
func (pg *PgStore) GetPostureChecks(ctx context.Context, accountId string) ([]nmdata.PostureChecks, error) {
rows, err := pg.pool.Query(ctx, GetPostureChecksQuery, accountId)
if err != nil {
return nil, err
}
checks, err := pgx.CollectRows(rows, pgx.RowToStructByName[posturechecks])
if err != nil {
return nil, err
}
toret := make([]nmdata.PostureChecks, 0, len(checks))
for _, c := range checks {
checks := nmdata.PostureChecks{}
err := networkmapdb.FromSqlTypesToSharedTypes(reflect.ValueOf(&c), reflect.ValueOf(&checks))
if err != nil {
return nil, err
}
toret = append(toret, checks)
}
return toret, nil
}
type posturechecks struct {
ID string
Checks json.RawMessage
}