mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-09 15:09:08 +02:00
support for posture-checks
Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
This commit is contained in:
@@ -28,6 +28,7 @@ type NetworkMapDBStore interface {
|
|||||||
GetNetwork(ctx context.Context, accountId string) (nmdata.Network, error)
|
GetNetwork(ctx context.Context, accountId string) (nmdata.Network, error)
|
||||||
GetAccountZones(ctx context.Context, accountId string) ([]nmdata.CustomZone, error)
|
GetAccountZones(ctx context.Context, accountId string) ([]nmdata.CustomZone, 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
type NetworkMapDBStoreImpl struct {
|
type NetworkMapDBStoreImpl struct {
|
||||||
|
|||||||
@@ -234,6 +234,28 @@ func TestGetAccountSetings(t *testing.T) {
|
|||||||
}, settings)
|
}, 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 {
|
func loadSQL(ctx context.Context, pool *pgxpool.Pool, initdb string) error {
|
||||||
queries := strings.Split(string(initdb), ";")
|
queries := strings.Split(string(initdb), ";")
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user