Add query description and resolution to the list of policies in hosts (#2584)
* Add query description and resolution to the list of policies in hosts * Add docs * Fix get host tests
This commit is contained in:
@@ -936,7 +936,9 @@ func (d *Datastore) ListPoliciesForHost(ctx context.Context, hid uint) (packs []
|
||||
WHEN pm.passes = 1 THEN 'pass'
|
||||
WHEN pm.passes = 0 THEN 'fail'
|
||||
ELSE ''
|
||||
END AS response
|
||||
END AS response,
|
||||
q.description,
|
||||
p.resolution
|
||||
FROM (
|
||||
SELECT * FROM policy_membership_history WHERE id IN (
|
||||
SELECT max(id) AS id FROM policy_membership_history WHERE host_id=? GROUP BY host_id, policy_id
|
||||
|
||||
@@ -267,7 +267,7 @@ func testPolicyQueriesForHost(t *testing.T, ds *Datastore) {
|
||||
Saved: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
gp, err := ds.NewGlobalPolicy(context.Background(), q.ID, "")
|
||||
gp, err := ds.NewGlobalPolicy(context.Background(), q.ID, "some gp resolution")
|
||||
require.NoError(t, err)
|
||||
|
||||
q2, err := ds.NewQuery(context.Background(), &fleet.Query{
|
||||
@@ -277,7 +277,7 @@ func testPolicyQueriesForHost(t *testing.T, ds *Datastore) {
|
||||
Saved: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
tp, err := ds.NewTeamPolicy(context.Background(), team1.ID, q2.ID, "")
|
||||
tp, err := ds.NewTeamPolicy(context.Background(), team1.ID, q2.ID, "some other gp resolution")
|
||||
require.NoError(t, err)
|
||||
|
||||
queries, err := ds.PolicyQueriesForHost(context.Background(), host1)
|
||||
@@ -308,6 +308,9 @@ func testPolicyQueriesForHost(t *testing.T, ds *Datastore) {
|
||||
policies, err = ds.ListPoliciesForHost(context.Background(), host2.ID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, policies, 1)
|
||||
|
||||
assert.Equal(t, "query1 desc", policies[0].QueryDescription)
|
||||
assert.Equal(t, "some gp resolution", policies[0].Resolution)
|
||||
}
|
||||
|
||||
func testTeamPolicyTransfer(t *testing.T, ds *Datastore) {
|
||||
|
||||
@@ -21,10 +21,12 @@ const (
|
||||
)
|
||||
|
||||
type HostPolicy struct {
|
||||
ID uint `json:"id" db:"id"`
|
||||
QueryID uint `json:"query_id" db:"query_id"`
|
||||
QueryName string `json:"query_name" db:"query_name"`
|
||||
Response string `json:"response" db:"response"`
|
||||
ID uint `json:"id" db:"id"`
|
||||
QueryID uint `json:"query_id" db:"query_id"`
|
||||
QueryName string `json:"query_name" db:"query_name"`
|
||||
QueryDescription string `json:"query_description" db:"description"`
|
||||
Response string `json:"response" db:"response"`
|
||||
Resolution string `json:"resolution" db:"resolution"`
|
||||
}
|
||||
|
||||
type PolicySpec struct {
|
||||
|
||||
Reference in New Issue
Block a user