Skip to content

Commit 419c566

Browse files
author
Jacob Shandling
committed
wire up linux DE summary to aggregate endpoint
1 parent 8efc7cf commit 419c566

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

server/fleet/mdm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ type MDMDiskEncryptionSummary struct {
310310
RemovingEnforcement MDMPlatformsCounts `db:"removing_enforcement" json:"removing_enforcement"`
311311
}
312312

313-
// MDMProfilesSummary reports the number of hosts being managed with MDM configuration
314-
// profiles. Each host may be counted in only one of four mutually-exclusive categories:
313+
// MDMProfilesSummary reports the number of hosts being managed with configuration
314+
// profiles and/or disk encryption. Each host may be counted in only one of four mutually-exclusive categories:
315315
// Failed, Pending, Verifying, or Verified.
316316
type MDMProfilesSummary struct {
317317
// Verified includes each host where Fleet has verified the installation of all of the

server/fleet/service.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,12 @@ type Service interface {
10591059
// Returns empty status if the host is not a supported Linux host
10601060
LinuxHostDiskEncryptionStatus(ctx context.Context, host Host) (HostMDMDiskEncryption, error)
10611061

1062+
// GetLinuxDiskEncryptionSummary summarizes the current state of disk encryption for
1063+
// supported Linux hosts in the specified team (or, if no team is specified, each host that is not assigned to any team).
1064+
1065+
// TODO - custom return type, or just use relevant fields?
1066+
GetLinuxDiskEncryptionSummary(ctx context.Context, teamId *uint) (*MDMLinuxDiskEncryptionSummary, error)
1067+
10621068
///////////////////////////////////////////////////////////////////////////////
10631069
// Common MDM
10641070

server/service/linux_mdm.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package service
33
import (
44
"context"
55

6+
"github.com/fleetdm/fleet/v4/server/contexts/ctxerr"
67
"github.com/fleetdm/fleet/v4/server/fleet"
78
)
89

@@ -42,3 +43,20 @@ func (svc *Service) LinuxHostDiskEncryptionStatus(ctx context.Context, host flee
4243
Status: &verified,
4344
}, nil
4445
}
46+
47+
func (svc *Service) GetLinuxDiskEncryptionSummary(ctx context.Context, teamId *uint) (*fleet.MDMLinuxDiskEncryptionSummary, error) {
48+
if err := svc.authz.Authorize(ctx, fleet.MDMConfigProfileAuthz{TeamID: teamId}, fleet.ActionRead); err != nil {
49+
return nil, ctxerr.Wrap(ctx, err)
50+
}
51+
52+
if svc.config.Server.PrivateKey == "" {
53+
return nil, ctxerr.New(ctx, "Missing required private key. Learn how to configure the private key here: https://fleetdm.com/learn-more-about/fleet-server-private-key")
54+
}
55+
56+
ps, err := svc.ds.GetLinuxDiskEncryptionSummary(ctx, teamId)
57+
if err != nil {
58+
return nil, ctxerr.Wrap(ctx, err)
59+
}
60+
61+
return &ps, nil
62+
}

server/service/mdm.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,8 @@ func (svc *Service) GetMDMDiskEncryptionSummary(ctx context.Context, teamID *uin
907907
}
908908

909909
////////////////////////////////////////////////////////////////////////////////
910-
// GET /mdm/profiles/summary
910+
// GET /mdm/profiles/summary (deprecated)
911+
// GET /configuration_profiles/summary
911912
////////////////////////////////////////////////////////////////////////////////
912913

913914
type getMDMProfilesSummaryRequest struct {
@@ -935,10 +936,15 @@ func getMDMProfilesSummaryEndpoint(ctx context.Context, request interface{}, svc
935936
return &getMDMProfilesSummaryResponse{Err: err}, nil
936937
}
937938

938-
res.Verified = as.Verified + ws.Verified
939+
lx, err := svc.GetLinuxDiskEncryptionSummary(ctx, req.TeamID)
940+
if err != nil {
941+
return &getMDMProfilesSummaryResponse{Err: err}, nil
942+
}
943+
944+
res.Verified = as.Verified + ws.Verified + lx.Verified
939945
res.Verifying = as.Verifying + ws.Verifying
940-
res.Failed = as.Failed + ws.Failed
941-
res.Pending = as.Pending + ws.Pending
946+
res.Failed = as.Failed + ws.Failed + lx.Failed
947+
res.Pending = as.Pending + ws.Pending + lx.ActionRequired
942948

943949
return &res, nil
944950
}

0 commit comments

Comments
 (0)