mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
Remove skipLoadingExtras and includeCVEScores from GetHost and HostByIdentifier methods (#5874)
This commit is contained in:
parent
85c6ca0e5f
commit
b4ffec10db
15 changed files with 87 additions and 109 deletions
|
|
@ -1,17 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/fleetdm/fleet/v4/server/fleet"
|
||||
)
|
||||
|
||||
func (svc *Service) GetHost(ctx context.Context, id uint, includeCVEScores bool) (*fleet.HostDetail, error) {
|
||||
// reuse GetHost, but include cve scores in premium version
|
||||
return svc.Service.GetHost(ctx, id, true)
|
||||
}
|
||||
|
||||
func (svc *Service) HostByIdentifier(ctx context.Context, identifier string, includeCVEScores bool) (*fleet.HostDetail, error) {
|
||||
// reuse HostByIdentifier, but include cve scores in premium version
|
||||
return svc.Service.HostByIdentifier(ctx, identifier, true)
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ func testDeleteEntity(t *testing.T, ds *Datastore) {
|
|||
|
||||
require.NoError(t, ds.deleteEntity(context.Background(), hostsTable, host.ID))
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, host)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -315,7 +315,7 @@ func (ds *Datastore) DeleteHost(ctx context.Context, hid uint) error {
|
|||
})
|
||||
}
|
||||
|
||||
func (ds *Datastore) Host(ctx context.Context, id uint, skipLoadingExtras bool) (*fleet.Host, error) {
|
||||
func (ds *Datastore) Host(ctx context.Context, id uint) (*fleet.Host, error) {
|
||||
policiesColumns := `,
|
||||
coalesce(failing_policies.count, 0) as failing_policies_count,
|
||||
coalesce(failing_policies.count, 0) as total_issues_count`
|
||||
|
|
@ -324,11 +324,6 @@ func (ds *Datastore) Host(ctx context.Context, id uint, skipLoadingExtras bool)
|
|||
SELECT count(*) as count FROM policy_membership WHERE passes=0 AND host_id=?
|
||||
) failing_policies`
|
||||
args := []interface{}{id, id}
|
||||
if skipLoadingExtras {
|
||||
policiesColumns = ""
|
||||
policiesJoin = ""
|
||||
args = []interface{}{id}
|
||||
}
|
||||
sqlStatement := fmt.Sprintf(`
|
||||
SELECT
|
||||
h.*,
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ func testUpdateHost(t *testing.T, ds *Datastore, updateHostFunc func(context.Con
|
|||
err = updateHostFunc(context.Background(), host)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "bar.local", host.Hostname)
|
||||
|
|
@ -163,7 +163,7 @@ func testUpdateHost(t *testing.T, ds *Datastore, updateHostFunc func(context.Con
|
|||
err = ds.SaveHostAdditional(context.Background(), host.ID, &additionalJSON)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, host)
|
||||
require.NotNil(t, host.Additional)
|
||||
|
|
@ -172,7 +172,7 @@ func testUpdateHost(t *testing.T, ds *Datastore, updateHostFunc func(context.Con
|
|||
err = updateHostFunc(context.Background(), host)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, host)
|
||||
|
||||
|
|
@ -189,7 +189,7 @@ func testUpdateHost(t *testing.T, ds *Datastore, updateHostFunc func(context.Con
|
|||
require.NoError(t, err)
|
||||
require.Empty(t, newP.Hosts)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
assert.NotNil(t, err)
|
||||
assert.Nil(t, host)
|
||||
|
||||
|
|
@ -222,7 +222,7 @@ func testHostsDeleteWithSoftware(t *testing.T, ds *Datastore) {
|
|||
err = ds.DeleteHost(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
assert.NotNil(t, err)
|
||||
assert.Nil(t, host)
|
||||
}
|
||||
|
|
@ -330,7 +330,7 @@ func testSaveHostPackStatsDB(t *testing.T, ds *Datastore) {
|
|||
err = ds.SaveHostPackStats(context.Background(), host.ID, packStats)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, host.PackStats, 2)
|
||||
|
|
@ -425,7 +425,7 @@ func testHostsSavePackStatsOverwrites(t *testing.T, ds *Datastore) {
|
|||
err = ds.SaveHostPackStats(context.Background(), host.ID, packStats)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
sort.Slice(host.PackStats, func(i, j int) bool {
|
||||
|
|
@ -485,7 +485,7 @@ func testHostsSavePackStatsOverwrites(t *testing.T, ds *Datastore) {
|
|||
err = ds.SaveHostPackStats(context.Background(), host.ID, packStats)
|
||||
require.NoError(t, err)
|
||||
|
||||
gotHost, err := ds.Host(context.Background(), host.ID, false)
|
||||
gotHost, err := ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
sort.Slice(gotHost.PackStats, func(i, j int) bool {
|
||||
|
|
@ -576,7 +576,7 @@ func testHostsWithTeamPackStats(t *testing.T, ds *Datastore) {
|
|||
err = ds.SaveHostPackStats(context.Background(), host.ID, packStats)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, host.PackStats, 2)
|
||||
|
|
@ -619,7 +619,7 @@ func testHostsDelete(t *testing.T, ds *Datastore) {
|
|||
err = ds.DeleteHost(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -1252,7 +1252,7 @@ func testHostsMarkSeen(t *testing.T, ds *Datastore) {
|
|||
require.NoError(t, err)
|
||||
|
||||
{
|
||||
h1Verify, err := ds.Host(context.Background(), 1, false)
|
||||
h1Verify, err := ds.Host(context.Background(), 1)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, h1Verify)
|
||||
assert.WithinDuration(t, aDayAgo, h1Verify.SeenTime, time.Second)
|
||||
|
|
@ -1262,7 +1262,7 @@ func testHostsMarkSeen(t *testing.T, ds *Datastore) {
|
|||
require.NoError(t, err)
|
||||
|
||||
{
|
||||
h1Verify, err := ds.Host(context.Background(), 1, false)
|
||||
h1Verify, err := ds.Host(context.Background(), 1)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, h1Verify)
|
||||
assert.WithinDuration(t, anHourAgo, h1Verify.SeenTime, time.Second)
|
||||
|
|
@ -1304,12 +1304,12 @@ func testHostsMarkSeenMany(t *testing.T, ds *Datastore) {
|
|||
require.NoError(t, err)
|
||||
|
||||
{
|
||||
h1Verify, err := ds.Host(context.Background(), h1.ID, false)
|
||||
h1Verify, err := ds.Host(context.Background(), h1.ID)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, h1Verify)
|
||||
assert.WithinDuration(t, anHourAgo, h1Verify.SeenTime, time.Second)
|
||||
|
||||
h2Verify, err := ds.Host(context.Background(), h2.ID, false)
|
||||
h2Verify, err := ds.Host(context.Background(), h2.ID)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, h2Verify)
|
||||
assert.WithinDuration(t, aDayAgo, h2Verify.SeenTime, time.Second)
|
||||
|
|
@ -1319,12 +1319,12 @@ func testHostsMarkSeenMany(t *testing.T, ds *Datastore) {
|
|||
require.NoError(t, err)
|
||||
|
||||
{
|
||||
h1Verify, err := ds.Host(context.Background(), h1.ID, false)
|
||||
h1Verify, err := ds.Host(context.Background(), h1.ID)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, h1Verify)
|
||||
assert.WithinDuration(t, aSecondAgo, h1Verify.SeenTime, time.Second)
|
||||
|
||||
h2Verify, err := ds.Host(context.Background(), h2.ID, false)
|
||||
h2Verify, err := ds.Host(context.Background(), h2.ID)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, h2Verify)
|
||||
assert.WithinDuration(t, aSecondAgo, h2Verify.SeenTime, time.Second)
|
||||
|
|
@ -1364,18 +1364,18 @@ func testHostsCleanupIncoming(t *testing.T, ds *Datastore) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Both hosts should still exist because they are new
|
||||
_, err = ds.Host(context.Background(), h1.ID, false)
|
||||
_, err = ds.Host(context.Background(), h1.ID)
|
||||
require.NoError(t, err)
|
||||
_, err = ds.Host(context.Background(), h2.ID, false)
|
||||
_, err = ds.Host(context.Background(), h2.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ds.CleanupIncomingHosts(context.Background(), mockClock.Now().Add(6*time.Minute).UTC())
|
||||
require.NoError(t, err)
|
||||
|
||||
// Now only the host with details should exist
|
||||
_, err = ds.Host(context.Background(), h1.ID, false)
|
||||
_, err = ds.Host(context.Background(), h1.ID)
|
||||
assert.NotNil(t, err)
|
||||
_, err = ds.Host(context.Background(), h2.ID, false)
|
||||
_, err = ds.Host(context.Background(), h2.ID)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -1526,7 +1526,7 @@ func testHostsAdditional(t *testing.T, ds *Datastore) {
|
|||
assert.Nil(t, h.Additional)
|
||||
|
||||
// Additional not yet set
|
||||
h, err = ds.Host(context.Background(), h.ID, false)
|
||||
h, err = ds.Host(context.Background(), h.ID)
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, h.Additional)
|
||||
|
||||
|
|
@ -1540,7 +1540,7 @@ func testHostsAdditional(t *testing.T, ds *Datastore) {
|
|||
assert.Equal(t, "foobar.local", h.Hostname)
|
||||
assert.Nil(t, h.Additional)
|
||||
|
||||
h, err = ds.Host(context.Background(), h.ID, false)
|
||||
h, err = ds.Host(context.Background(), h.ID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, &additional, h.Additional)
|
||||
|
||||
|
|
@ -1556,7 +1556,7 @@ func testHostsAdditional(t *testing.T, ds *Datastore) {
|
|||
assert.Equal(t, "baz.local", h.Hostname)
|
||||
assert.Nil(t, h.Additional)
|
||||
|
||||
h, err = ds.Host(context.Background(), h.ID, false)
|
||||
h, err = ds.Host(context.Background(), h.ID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, &additional, h.Additional)
|
||||
|
||||
|
|
@ -1570,7 +1570,7 @@ func testHostsAdditional(t *testing.T, ds *Datastore) {
|
|||
assert.Equal(t, "baz.local", h.Hostname)
|
||||
assert.Nil(t, h.Additional)
|
||||
|
||||
h, err = ds.Host(context.Background(), h.ID, false)
|
||||
h, err = ds.Host(context.Background(), h.ID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, &additional, h.Additional)
|
||||
}
|
||||
|
|
@ -1625,7 +1625,7 @@ func testHostsAddToTeam(t *testing.T, ds *Datastore) {
|
|||
}
|
||||
|
||||
for i := 1; i <= 10; i++ {
|
||||
host, err := ds.Host(context.Background(), uint(i), false)
|
||||
host, err := ds.Host(context.Background(), uint(i))
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, host.TeamID)
|
||||
}
|
||||
|
|
@ -1634,7 +1634,7 @@ func testHostsAddToTeam(t *testing.T, ds *Datastore) {
|
|||
require.NoError(t, ds.AddHostsToTeam(context.Background(), &team2.ID, []uint{3, 4, 5}))
|
||||
|
||||
for i := 1; i <= 10; i++ {
|
||||
host, err := ds.Host(context.Background(), uint(i), false)
|
||||
host, err := ds.Host(context.Background(), uint(i))
|
||||
require.NoError(t, err)
|
||||
var expectedID *uint
|
||||
switch {
|
||||
|
|
@ -1650,7 +1650,7 @@ func testHostsAddToTeam(t *testing.T, ds *Datastore) {
|
|||
require.NoError(t, ds.AddHostsToTeam(context.Background(), &team1.ID, []uint{5, 6, 7, 8, 9, 10}))
|
||||
|
||||
for i := 1; i <= 10; i++ {
|
||||
host, err := ds.Host(context.Background(), uint(i), false)
|
||||
host, err := ds.Host(context.Background(), uint(i))
|
||||
require.NoError(t, err)
|
||||
var expectedID *uint
|
||||
switch {
|
||||
|
|
@ -1679,7 +1679,7 @@ func testHostsSaveUsers(t *testing.T, ds *Datastore) {
|
|||
err = ds.UpdateHost(context.Background(), host)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, host.Users, 0)
|
||||
|
||||
|
|
@ -1701,7 +1701,7 @@ func testHostsSaveUsers(t *testing.T, ds *Datastore) {
|
|||
err = ds.SaveHostUsers(context.Background(), host.ID, hostUsers)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, host.Users, 2)
|
||||
test.ElementsMatchSkipID(t, host.Users, []fleet.HostUser{u1, u2})
|
||||
|
|
@ -1711,7 +1711,7 @@ func testHostsSaveUsers(t *testing.T, ds *Datastore) {
|
|||
err = ds.SaveHostUsers(context.Background(), host.ID, hostUsers)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, host.Users, 1)
|
||||
assert.Equal(t, host.Users[0].Uid, u2.Uid)
|
||||
|
|
@ -1722,7 +1722,7 @@ func testHostsSaveUsers(t *testing.T, ds *Datastore) {
|
|||
err = ds.SaveHostUsers(context.Background(), host.ID, hostUsers)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, host.Users, 2)
|
||||
test.ElementsMatchSkipID(t, host.Users, []fleet.HostUser{u1, u2})
|
||||
|
|
@ -1746,7 +1746,7 @@ func testHostsSaveUsersWithoutUid(t *testing.T, ds *Datastore) {
|
|||
err = ds.UpdateHost(context.Background(), host)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, host.Users, 0)
|
||||
|
||||
|
|
@ -1767,7 +1767,7 @@ func testHostsSaveUsersWithoutUid(t *testing.T, ds *Datastore) {
|
|||
err = ds.SaveHostUsers(context.Background(), host.ID, hostUsers)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, host.Users, 2)
|
||||
test.ElementsMatchSkipID(t, host.Users, []fleet.HostUser{u1, u2})
|
||||
|
|
@ -1777,7 +1777,7 @@ func testHostsSaveUsersWithoutUid(t *testing.T, ds *Datastore) {
|
|||
err = ds.SaveHostUsers(context.Background(), host.ID, hostUsers)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, host.Users, 1)
|
||||
assert.Equal(t, host.Users[0].Uid, u2.Uid)
|
||||
|
|
@ -2046,13 +2046,13 @@ func testHostsReadsLessRows(t *testing.T, ds *Datastore) {
|
|||
require.NoError(t, ds.RecordPolicyQueryExecutions(context.Background(), h2, map[uint]*bool{p.ID: ptr.Bool(false)}, time.Now(), false))
|
||||
|
||||
prevRead := getReads(t, ds)
|
||||
h1WithExtras, err := ds.Host(context.Background(), h1.ID, false)
|
||||
h1WithExtras, err := ds.Host(context.Background(), h1.ID)
|
||||
require.NoError(t, err)
|
||||
newRead := getReads(t, ds)
|
||||
withExtraRowReads := newRead - prevRead
|
||||
|
||||
prevRead = getReads(t, ds)
|
||||
h1WithoutExtras, err := ds.Host(context.Background(), h1.ID, true)
|
||||
h1WithoutExtras, err := ds.Host(context.Background(), h1.ID)
|
||||
require.NoError(t, err)
|
||||
newRead = getReads(t, ds)
|
||||
withoutExtraRowReads := newRead - prevRead
|
||||
|
|
@ -2091,7 +2091,7 @@ func checkHostIssuesWithOpts(t *testing.T, ds *Datastore, hosts []*fleet.Host, f
|
|||
return
|
||||
}
|
||||
|
||||
hostById, err := ds.Host(context.Background(), hid, false)
|
||||
hostById, err := ds.Host(context.Background(), hid)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expected, hostById.HostIssues.FailingPoliciesCount)
|
||||
assert.Equal(t, expected, hostById.HostIssues.TotalIssuesCount)
|
||||
|
|
@ -2142,7 +2142,7 @@ func testHostsUpdateTonsOfUsers(t *testing.T, ds *Datastore) {
|
|||
defer wg.Done()
|
||||
|
||||
for {
|
||||
host1, err := ds.Host(context.Background(), host1.ID, false)
|
||||
host1, err := ds.Host(context.Background(), host1.ID)
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
return
|
||||
|
|
@ -2203,7 +2203,7 @@ func testHostsUpdateTonsOfUsers(t *testing.T, ds *Datastore) {
|
|||
defer wg.Done()
|
||||
|
||||
for {
|
||||
host2, err := ds.Host(context.Background(), host2.ID, false)
|
||||
host2, err := ds.Host(context.Background(), host2.ID)
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
return
|
||||
|
|
@ -2567,7 +2567,7 @@ func testHostsAllPackStats(t *testing.T, ds *Datastore) {
|
|||
userSQuery := test.NewScheduledQuery(t, ds, userPack.ID, userQuery.ID, 30, true, true, "time-scheduled-user")
|
||||
|
||||
// Even if the scheduled queries didn't run, we get their pack stats (with zero values).
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
packStats := host.PackStats
|
||||
require.Len(t, packStats, 3)
|
||||
|
|
@ -2667,7 +2667,7 @@ func testHostsAllPackStats(t *testing.T, ds *Datastore) {
|
|||
WallTime: 0,
|
||||
}}
|
||||
// Reload the host and set the scheduled queries stats.
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
hostPackStats := []fleet.PackStats{
|
||||
{PackID: globalPack.ID, PackName: globalPack.Name, QueryStats: globalPackSQueryStats},
|
||||
|
|
@ -2676,7 +2676,7 @@ func testHostsAllPackStats(t *testing.T, ds *Datastore) {
|
|||
err = ds.SaveHostPackStats(context.Background(), host.ID, hostPackStats)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
packStats = host.PackStats
|
||||
require.Len(t, packStats, 3)
|
||||
|
|
@ -2784,7 +2784,7 @@ func testHostsPackStatsMultipleHosts(t *testing.T, ds *Datastore) {
|
|||
globalStats: globalStatsHost2,
|
||||
},
|
||||
} {
|
||||
host, err := ds.Host(context.Background(), tc.hostID, false)
|
||||
host, err := ds.Host(context.Background(), tc.hostID)
|
||||
require.NoError(t, err)
|
||||
hostPackStats := []fleet.PackStats{
|
||||
{PackID: globalPack.ID, PackName: globalPack.Name, QueryStats: tc.globalStats},
|
||||
|
|
@ -2807,7 +2807,7 @@ func testHostsPackStatsMultipleHosts(t *testing.T, ds *Datastore) {
|
|||
expectedStats: globalStatsHost2,
|
||||
},
|
||||
} {
|
||||
host, err := ds.Host(context.Background(), tc.host.ID, false)
|
||||
host, err := ds.Host(context.Background(), tc.host.ID)
|
||||
require.NoError(t, err)
|
||||
packStats := host.PackStats
|
||||
require.Len(t, packStats, 1)
|
||||
|
|
@ -3011,7 +3011,7 @@ func testHostsPackStatsForPlatform(t *testing.T, ds *Datastore) {
|
|||
UserTime: 183,
|
||||
WallTime: 3,
|
||||
})
|
||||
host, err := ds.Host(context.Background(), host1.ID, false)
|
||||
host, err := ds.Host(context.Background(), host1.ID)
|
||||
require.NoError(t, err)
|
||||
hostPackStats := []fleet.PackStats{
|
||||
{PackID: globalPack.ID, PackName: globalPack.Name, QueryStats: stats},
|
||||
|
|
@ -3021,7 +3021,7 @@ func testHostsPackStatsForPlatform(t *testing.T, ds *Datastore) {
|
|||
|
||||
// host should only return scheduled query stats only for the scheduled queries
|
||||
// scheduled to run on "darwin".
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
packStats := host.PackStats
|
||||
require.Len(t, packStats, 1)
|
||||
|
|
@ -3036,7 +3036,7 @@ func testHostsPackStatsForPlatform(t *testing.T, ds *Datastore) {
|
|||
|
||||
// host2 should only return scheduled query stats only for the scheduled queries
|
||||
// scheduled to run on "linux"
|
||||
host2, err = ds.Host(context.Background(), host2.ID, false)
|
||||
host2, err = ds.Host(context.Background(), host2.ID)
|
||||
require.NoError(t, err)
|
||||
packStats2 := host2.PackStats
|
||||
require.Len(t, packStats2, 1)
|
||||
|
|
@ -3134,7 +3134,7 @@ func testHostsNoSeenTime(t *testing.T, ds *Datastore) {
|
|||
}
|
||||
removeHostSeenTimes(h1.ID)
|
||||
|
||||
h1, err = ds.Host(context.Background(), h1.ID, true)
|
||||
h1, err = ds.Host(context.Background(), h1.ID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, h1.CreatedAt, h1.SeenTime)
|
||||
|
||||
|
|
@ -3231,9 +3231,9 @@ func testHostsNoSeenTime(t *testing.T, ds *Datastore) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Reload hosts.
|
||||
h1, err = ds.Host(context.Background(), h1.ID, true)
|
||||
h1, err = ds.Host(context.Background(), h1.ID)
|
||||
require.NoError(t, err)
|
||||
h2, err = ds.Host(context.Background(), h2.ID, true)
|
||||
h2, err = ds.Host(context.Background(), h2.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Equal doesn't work, it looks like a time.Time scanned from
|
||||
|
|
@ -3331,7 +3331,7 @@ func testHostDeviceMapping(t *testing.T, ds *Datastore) {
|
|||
})
|
||||
|
||||
// device mapping is not included in basic method for host by id
|
||||
host, err := ds.Host(ctx, h.ID, false)
|
||||
host, err := ds.Host(ctx, h.ID)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, host.DeviceMapping)
|
||||
|
||||
|
|
@ -3813,7 +3813,7 @@ func testHostsSaveHostUsers(t *testing.T, ds *Datastore) {
|
|||
err = ds.SaveHostUsers(context.Background(), host.ID, users)
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, host.Users, 2)
|
||||
test.ElementsMatchSkipID(t, users, host.Users)
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ func testLabelsAddAllHosts(deferred bool, t *testing.T, db *Datastore) {
|
|||
}, baseTime, deferred)
|
||||
assert.Nil(t, err)
|
||||
|
||||
host, err = db.Host(context.Background(), host.ID, false)
|
||||
host, err = db.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
host.LabelUpdatedAt = baseTime
|
||||
|
||||
|
|
|
|||
|
|
@ -62,14 +62,14 @@ func TestDatastoreReplica(t *testing.T) {
|
|||
require.NotNil(t, host)
|
||||
|
||||
// trying to read it fails, not replicated yet
|
||||
_, err = ds.Host(context.Background(), host.ID, false)
|
||||
_, err = ds.Host(context.Background(), host.ID)
|
||||
require.Error(t, err)
|
||||
require.True(t, errors.Is(err, sql.ErrNoRows))
|
||||
|
||||
opts.RunReplication()
|
||||
|
||||
// now it can read it
|
||||
host2, err := ds.Host(context.Background(), host.ID, false)
|
||||
host2, err := ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, host.ID, host2.ID)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -547,7 +547,7 @@ func newTestHostWithPlatform(t *testing.T, ds *Datastore, hostname, platform str
|
|||
if teamID != nil {
|
||||
err := ds.AddHostsToTeam(context.Background(), teamID, []uint{host.ID})
|
||||
require.NoError(t, err)
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
return host
|
||||
|
|
@ -785,7 +785,7 @@ func testPolicyQueriesForHost(t *testing.T, ds *Datastore) {
|
|||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, ds.AddHostsToTeam(context.Background(), &team1.ID, []uint{host1.ID}))
|
||||
host1, err = ds.Host(context.Background(), host1.ID, false)
|
||||
host1, err = ds.Host(context.Background(), host1.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
host2, err := ds.NewHost(context.Background(), &fleet.Host{
|
||||
|
|
@ -942,7 +942,7 @@ func testTeamPolicyTransfer(t *testing.T, ds *Datastore) {
|
|||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, ds.AddHostsToTeam(context.Background(), &team1.ID, []uint{host1.ID}))
|
||||
host1, err = ds.Host(context.Background(), host1.ID, false)
|
||||
host1, err = ds.Host(context.Background(), host1.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
tq, err := ds.NewQuery(context.Background(), &fleet.Query{
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func TestUnicode(t *testing.T) {
|
|||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
host, err = ds.Host(context.Background(), host.ID, false)
|
||||
host, err = ds.Host(context.Background(), host.ID)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "🍌", host.Hostname)
|
||||
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ type Datastore interface {
|
|||
// NewHost is deprecated and will be removed. Hosts should always be enrolled via EnrollHost.
|
||||
NewHost(ctx context.Context, host *Host) (*Host, error)
|
||||
DeleteHost(ctx context.Context, hid uint) error
|
||||
Host(ctx context.Context, id uint, skipLoadingExtras bool) (*Host, error)
|
||||
Host(ctx context.Context, id uint) (*Host, error)
|
||||
ListHosts(ctx context.Context, filter TeamFilter, opt HostListOptions) ([]*Host, error)
|
||||
MarkHostsSeen(ctx context.Context, hostIDs []uint, t time.Time) error
|
||||
SearchHosts(ctx context.Context, filter TeamFilter, query string, omit ...uint) ([]*Host, error)
|
||||
|
|
|
|||
|
|
@ -239,12 +239,12 @@ type Service interface {
|
|||
AuthenticateDevice(ctx context.Context, authToken string) (host *Host, debug bool, err error)
|
||||
|
||||
ListHosts(ctx context.Context, opt HostListOptions) (hosts []*Host, err error)
|
||||
GetHost(ctx context.Context, id uint, includeCVEScores bool) (host *HostDetail, err error)
|
||||
GetHost(ctx context.Context, id uint) (host *HostDetail, err error)
|
||||
GetHostSummary(ctx context.Context, teamID *uint, platform *string) (summary *HostSummary, err error)
|
||||
DeleteHost(ctx context.Context, id uint) (err error)
|
||||
// HostByIdentifier returns one host matching the provided identifier. Possible matches can be on
|
||||
// osquery_host_identifier, node_key, UUID, or hostname.
|
||||
HostByIdentifier(ctx context.Context, identifier string, includeCVEScores bool) (*HostDetail, error)
|
||||
HostByIdentifier(ctx context.Context, identifier string) (*HostDetail, error)
|
||||
// RefetchHost requests a refetch of host details for the provided host.
|
||||
RefetchHost(ctx context.Context, id uint) (err error)
|
||||
// AddHostsToTeam adds hosts to an existing team, clearing their team settings if teamID is nil.
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ type NewHostFunc func(ctx context.Context, host *fleet.Host) (*fleet.Host, error
|
|||
|
||||
type DeleteHostFunc func(ctx context.Context, hid uint) error
|
||||
|
||||
type HostFunc func(ctx context.Context, id uint, skipLoadingExtras bool) (*fleet.Host, error)
|
||||
type HostFunc func(ctx context.Context, id uint) (*fleet.Host, error)
|
||||
|
||||
type ListHostsFunc func(ctx context.Context, filter fleet.TeamFilter, opt fleet.HostListOptions) ([]*fleet.Host, error)
|
||||
|
||||
|
|
@ -1314,9 +1314,9 @@ func (s *DataStore) DeleteHost(ctx context.Context, hid uint) error {
|
|||
return s.DeleteHostFunc(ctx, hid)
|
||||
}
|
||||
|
||||
func (s *DataStore) Host(ctx context.Context, id uint, skipLoadingExtras bool) (*fleet.Host, error) {
|
||||
func (s *DataStore) Host(ctx context.Context, id uint) (*fleet.Host, error) {
|
||||
s.HostFuncInvoked = true
|
||||
return s.HostFunc(ctx, id, skipLoadingExtras)
|
||||
return s.HostFunc(ctx, id)
|
||||
}
|
||||
|
||||
func (s *DataStore) ListHosts(ctx context.Context, filter fleet.TeamFilter, opt fleet.HostListOptions) ([]*fleet.Host, error) {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ func getDeviceHostEndpoint(ctx context.Context, request interface{}, svc fleet.S
|
|||
}
|
||||
|
||||
// must still load the full host details, as it returns more information
|
||||
hostDetails, err := svc.GetHost(ctx, host.ID, false)
|
||||
hostDetails, err := svc.GetHost(ctx, host.ID)
|
||||
if err != nil {
|
||||
return getDeviceHostResponse{Err: err}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ func (r getHostResponse) error() error { return r.Err }
|
|||
|
||||
func getHostEndpoint(ctx context.Context, request interface{}, svc fleet.Service) (interface{}, error) {
|
||||
req := request.(*getHostRequest)
|
||||
host, err := svc.GetHost(ctx, req.ID, false)
|
||||
host, err := svc.GetHost(ctx, req.ID)
|
||||
if err != nil {
|
||||
return getHostResponse{Err: err}, nil
|
||||
}
|
||||
|
|
@ -268,7 +268,7 @@ func getHostEndpoint(ctx context.Context, request interface{}, svc fleet.Service
|
|||
return getHostResponse{Host: resp}, nil
|
||||
}
|
||||
|
||||
func (svc *Service) GetHost(ctx context.Context, id uint, includeCVEScores bool) (*fleet.HostDetail, error) {
|
||||
func (svc *Service) GetHost(ctx context.Context, id uint) (*fleet.HostDetail, error) {
|
||||
alreadyAuthd := svc.authz.IsAuthenticatedWith(ctx, authz.AuthnDeviceToken)
|
||||
if !alreadyAuthd {
|
||||
// First ensure the user has access to list hosts, then check the specific
|
||||
|
|
@ -278,7 +278,7 @@ func (svc *Service) GetHost(ctx context.Context, id uint, includeCVEScores bool)
|
|||
}
|
||||
}
|
||||
|
||||
host, err := svc.ds.Host(ctx, id, includeCVEScores)
|
||||
host, err := svc.ds.Host(ctx, id)
|
||||
if err != nil {
|
||||
return nil, ctxerr.Wrap(ctx, err, "get host")
|
||||
}
|
||||
|
|
@ -393,7 +393,7 @@ type hostByIdentifierRequest struct {
|
|||
|
||||
func hostByIdentifierEndpoint(ctx context.Context, request interface{}, svc fleet.Service) (interface{}, error) {
|
||||
req := request.(*hostByIdentifierRequest)
|
||||
host, err := svc.HostByIdentifier(ctx, req.Identifier, false)
|
||||
host, err := svc.HostByIdentifier(ctx, req.Identifier)
|
||||
if err != nil {
|
||||
return getHostResponse{Err: err}, nil
|
||||
}
|
||||
|
|
@ -408,7 +408,7 @@ func hostByIdentifierEndpoint(ctx context.Context, request interface{}, svc flee
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (svc *Service) HostByIdentifier(ctx context.Context, identifier string, includeCVEScores bool) (*fleet.HostDetail, error) {
|
||||
func (svc *Service) HostByIdentifier(ctx context.Context, identifier string) (*fleet.HostDetail, error) {
|
||||
if err := svc.authz.Authorize(ctx, &fleet.Host{}, fleet.ActionList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ func TestHostAuth(t *testing.T) {
|
|||
}
|
||||
return globalHost, nil
|
||||
}
|
||||
ds.HostFunc = func(ctx context.Context, id uint, skipLoadingExtras bool) (*fleet.Host, error) {
|
||||
ds.HostFunc = func(ctx context.Context, id uint) (*fleet.Host, error) {
|
||||
if id == 1 {
|
||||
return teamHost, nil
|
||||
}
|
||||
|
|
@ -183,16 +183,16 @@ func TestHostAuth(t *testing.T) {
|
|||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctx := viewer.NewContext(context.Background(), viewer.Viewer{User: tt.user})
|
||||
|
||||
_, err := svc.GetHost(ctx, 1, false)
|
||||
_, err := svc.GetHost(ctx, 1)
|
||||
checkAuthErr(t, tt.shouldFailTeamRead, err)
|
||||
|
||||
_, err = svc.HostByIdentifier(ctx, "1", false)
|
||||
_, err = svc.HostByIdentifier(ctx, "1")
|
||||
checkAuthErr(t, tt.shouldFailTeamRead, err)
|
||||
|
||||
_, err = svc.GetHost(ctx, 2, false)
|
||||
_, err = svc.GetHost(ctx, 2)
|
||||
checkAuthErr(t, tt.shouldFailGlobalRead, err)
|
||||
|
||||
_, err = svc.HostByIdentifier(ctx, "2", false)
|
||||
_, err = svc.HostByIdentifier(ctx, "2")
|
||||
checkAuthErr(t, tt.shouldFailGlobalRead, err)
|
||||
|
||||
err = svc.DeleteHost(ctx, 1)
|
||||
|
|
|
|||
|
|
@ -689,11 +689,11 @@ func (s *integrationTestSuite) TestBulkDeleteHostsFromTeam() {
|
|||
resp := deleteHostsResponse{}
|
||||
s.DoJSON("POST", "/api/latest/fleet/hosts/delete", req, http.StatusOK, &resp)
|
||||
|
||||
_, err = s.ds.Host(context.Background(), hosts[0].ID, false)
|
||||
_, err = s.ds.Host(context.Background(), hosts[0].ID)
|
||||
require.Error(t, err)
|
||||
_, err = s.ds.Host(context.Background(), hosts[1].ID, false)
|
||||
_, err = s.ds.Host(context.Background(), hosts[1].ID)
|
||||
require.NoError(t, err)
|
||||
_, err = s.ds.Host(context.Background(), hosts[2].ID, false)
|
||||
_, err = s.ds.Host(context.Background(), hosts[2].ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = s.ds.DeleteHosts(context.Background(), []uint{hosts[1].ID, hosts[2].ID})
|
||||
|
|
@ -731,11 +731,11 @@ func (s *integrationTestSuite) TestBulkDeleteHostsInLabel() {
|
|||
resp := deleteHostsResponse{}
|
||||
s.DoJSON("POST", "/api/latest/fleet/hosts/delete", req, http.StatusOK, &resp)
|
||||
|
||||
_, err = s.ds.Host(context.Background(), hosts[0].ID, false)
|
||||
_, err = s.ds.Host(context.Background(), hosts[0].ID)
|
||||
require.NoError(t, err)
|
||||
_, err = s.ds.Host(context.Background(), hosts[1].ID, false)
|
||||
_, err = s.ds.Host(context.Background(), hosts[1].ID)
|
||||
require.Error(t, err)
|
||||
_, err = s.ds.Host(context.Background(), hosts[2].ID, false)
|
||||
_, err = s.ds.Host(context.Background(), hosts[2].ID)
|
||||
require.Error(t, err)
|
||||
|
||||
err = s.ds.DeleteHosts(context.Background(), []uint{hosts[0].ID})
|
||||
|
|
@ -753,11 +753,11 @@ func (s *integrationTestSuite) TestBulkDeleteHostByIDs() {
|
|||
resp := deleteHostsResponse{}
|
||||
s.DoJSON("POST", "/api/latest/fleet/hosts/delete", req, http.StatusOK, &resp)
|
||||
|
||||
_, err := s.ds.Host(context.Background(), hosts[0].ID, false)
|
||||
_, err := s.ds.Host(context.Background(), hosts[0].ID)
|
||||
require.Error(t, err)
|
||||
_, err = s.ds.Host(context.Background(), hosts[1].ID, false)
|
||||
_, err = s.ds.Host(context.Background(), hosts[1].ID)
|
||||
require.Error(t, err)
|
||||
_, err = s.ds.Host(context.Background(), hosts[2].ID, false)
|
||||
_, err = s.ds.Host(context.Background(), hosts[2].ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = s.ds.DeleteHosts(context.Background(), []uint{hosts[2].ID})
|
||||
|
|
|
|||
Loading…
Reference in a new issue