Skip to content

Commit

Permalink
Add comments and truncate team identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmrod committed Nov 15, 2024
1 parent 0b099f5 commit c598e84
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion server/fleet/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,12 @@ type Datastore interface {
// UpdateHostSoftwareInstalledPaths looks at all software for 'hostID' and based on the contents of
// 'reported', either inserts or deletes the corresponding entries in the
// 'host_software_installed_paths' table. 'reported' is a set of
// 'software.ToUniqueStr()--installed_path' strings. 'mutationResults' contains the software inventory of
// 'installed_path\0team_identifier\0software.ToUniqueStr()h' strings. 'mutationResults' contains the software inventory of
// the host (pre-mutations) and the mutations performed after calling 'UpdateHostSoftware',
// it is used as DB optimization.
//
// TODO(lucas): We should amend UpdateHostSoftwareInstalledPaths to just accept raw information
// otherwise the caller has to assemble the reported set the same way in all places where it's used.
UpdateHostSoftwareInstalledPaths(ctx context.Context, hostID uint, reported map[string]struct{}, mutationResults *UpdateHostSoftwareDBResult) error

// UpdateHost updates a host.
Expand Down
9 changes: 8 additions & 1 deletion server/service/osquery_utils/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,14 @@ func directIngestSoftware(ctx context.Context, logger log.Logger, host *fleet.Ho
// NOTE: osquery is sometimes incorrectly returning the value "null" for some install paths.
// Thus, we explicitly ignore such value here.
strings.ToLower(installedPath) != "null" {
teamIdentifier := row["team_identifier"]
truncateString := func(str string, length int) string {
runes := []rune(str)
if len(runes) > length {
return string(runes[:length])
}
return str
}
teamIdentifier := truncateString(row["team_identifier"], fleet.SoftwareTeamIdentifierMaxLength)
key := fmt.Sprintf(
"%s%s%s%s%s",
installedPath, fleet.SoftwareFieldSeparator, teamIdentifier, fleet.SoftwareFieldSeparator, s.ToUniqueStr(),
Expand Down

0 comments on commit c598e84

Please sign in to comment.