fleet/ee/server/service/service.go
Ian Littman f1949ac2bf
Add VPP policy automation support to backend (#25154)
For #23529, #23530.

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files)
for more information.
- [x] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [x] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [x] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [x] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [x] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [x] Added/updated automated tests
- [x] A detailed QA plan exists on the associated ticket (if it isn't
there, work with the product group's QA engineer to add it)
- [x] Manual QA for all new/changed functionality
2025-01-13 15:53:24 -06:00

95 lines
3.5 KiB
Go

package service
import (
"fmt"
"github.com/WatchBeam/clock"
"github.com/fleetdm/fleet/v4/server/authz"
"github.com/fleetdm/fleet/v4/server/config"
"github.com/fleetdm/fleet/v4/server/fleet"
apple_mdm "github.com/fleetdm/fleet/v4/server/mdm/apple"
"github.com/fleetdm/fleet/v4/server/mdm/nanodep/storage"
"github.com/fleetdm/fleet/v4/server/sso"
kitlog "github.com/go-kit/log"
)
// Service wraps a free Service and implements additional premium functionality on top of it.
type Service struct {
fleet.Service
ds fleet.Datastore
logger kitlog.Logger
config config.FleetConfig
clock clock.Clock
authz *authz.Authorizer
depStorage storage.AllDEPStorage
mdmAppleCommander fleet.MDMAppleCommandIssuer
ssoSessionStore sso.SessionStore
depService *apple_mdm.DEPService
profileMatcher fleet.ProfileMatcher
softwareInstallStore fleet.SoftwareInstallerStore
bootstrapPackageStore fleet.MDMBootstrapPackageStore
distributedLock fleet.Lock
keyValueStore fleet.KeyValueStore
}
func NewService(
svc fleet.Service,
ds fleet.Datastore,
logger kitlog.Logger,
config config.FleetConfig,
mailService fleet.MailService,
c clock.Clock,
depStorage storage.AllDEPStorage,
mdmAppleCommander fleet.MDMAppleCommandIssuer,
sso sso.SessionStore,
profileMatcher fleet.ProfileMatcher,
softwareInstallStore fleet.SoftwareInstallerStore,
bootstrapPackageStore fleet.MDMBootstrapPackageStore,
distributedLock fleet.Lock,
keyValueStore fleet.KeyValueStore,
) (*Service, error) {
authorizer, err := authz.NewAuthorizer()
if err != nil {
return nil, fmt.Errorf("new authorizer: %w", err)
}
eeservice := &Service{
Service: svc,
ds: ds,
logger: logger,
config: config,
clock: c,
authz: authorizer,
depStorage: depStorage,
mdmAppleCommander: mdmAppleCommander,
ssoSessionStore: sso,
depService: apple_mdm.NewDEPService(ds, depStorage, logger),
profileMatcher: profileMatcher,
softwareInstallStore: softwareInstallStore,
bootstrapPackageStore: bootstrapPackageStore,
distributedLock: distributedLock,
keyValueStore: keyValueStore,
}
// Override methods that can't be easily overriden via
// embedding.
svc.SetEnterpriseOverrides(fleet.EnterpriseOverrides{
HostFeatures: eeservice.HostFeatures,
TeamByIDOrName: eeservice.teamByIDOrName,
UpdateTeamMDMDiskEncryption: eeservice.updateTeamMDMDiskEncryption,
MDMAppleEnableFileVaultAndEscrow: eeservice.MDMAppleEnableFileVaultAndEscrow,
MDMAppleDisableFileVaultAndEscrow: eeservice.MDMAppleDisableFileVaultAndEscrow,
DeleteMDMAppleSetupAssistant: eeservice.DeleteMDMAppleSetupAssistant,
MDMAppleSyncDEPProfiles: eeservice.mdmAppleSyncDEPProfiles,
DeleteMDMAppleBootstrapPackage: eeservice.DeleteMDMAppleBootstrapPackage,
MDMWindowsEnableOSUpdates: eeservice.mdmWindowsEnableOSUpdates,
MDMWindowsDisableOSUpdates: eeservice.mdmWindowsDisableOSUpdates,
MDMAppleEditedAppleOSUpdates: eeservice.mdmAppleEditedAppleOSUpdates,
SetupExperienceNextStep: eeservice.SetupExperienceNextStep,
GetVPPTokenIfCanInstallVPPApps: eeservice.GetVPPTokenIfCanInstallVPPApps,
InstallVPPAppPostValidation: eeservice.InstallVPPAppPostValidation,
})
return eeservice, nil
}