fleet/server/service/osquery_utils/disk_encryption_helpers.go
Victor Lyuboslavsky 44c6aee5c7
Converted osquery_utils to slog (#39883)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #38889 

Plan was to convert `osquery_utils` package to slog. Picked up some
additional code that was related.

# Checklist for submitter

- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
  - Already have changes

## Testing

- [x] Added/updated automated tests
- [x] QA'd all new/changed functionality manually


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

# Release Notes

## Refactor
* Updated internal logging infrastructure to use improved system-level
logging utilities

## Tests
* Updated test suite to align with internal logging changes

---

**Note:** This release contains internal infrastructure improvements
with no user-facing changes or new features.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 15:43:59 -06:00

40 lines
997 B
Go

package osquery_utils
import (
"context"
"log/slog"
"github.com/fleetdm/fleet/v4/server/fleet"
)
// IsDiskEncryptionEnabledForHost checks if disk encryption is enabled for the
// host team or globally if the host is not assigned to a team.
func IsDiskEncryptionEnabledForHost(ctx context.Context, logger *slog.Logger, ds fleet.Datastore, host *fleet.Host) bool {
// team
if host.TeamID != nil {
teamMDM, err := ds.TeamMDMConfig(ctx, *host.TeamID)
if err != nil {
logger.DebugContext(ctx, "failed to get team MDM config for disk encryption check",
"host_id", host.ID,
"team_id", *host.TeamID,
"err", err,
)
return false
}
if teamMDM == nil {
return false
}
return teamMDM.EnableDiskEncryption
}
// global
appConfig, err := ds.AppConfig(ctx)
if err != nil {
logger.DebugContext(ctx, "failed to get app config for disk encryption check",
"host_id", host.ID,
"err", err,
)
return false
}
return appConfig.MDM.EnableDiskEncryption.Value
}