mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 01:18:42 +00:00
feat: soft delete for mdm assets
This commit is contained in:
parent
f4f247ef06
commit
c3e8427b13
5 changed files with 58 additions and 0 deletions
|
|
@ -4169,3 +4169,25 @@ WHERE
|
|||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (ds *Datastore) DeleteMDMConfigAssetsByName(ctx context.Context, assetNames []fleet.MDMAssetName) error {
|
||||
stmt := `
|
||||
UPDATE
|
||||
mdm_config_assets
|
||||
SET
|
||||
deleted_at = CURRENT_TIMESTAMP(),
|
||||
deletion_uuid = ?
|
||||
WHERE
|
||||
name IN (?) AND deletion_uuid = ''
|
||||
`
|
||||
|
||||
deletionUUID := uuid.New().String()
|
||||
|
||||
stmt, args, err := sqlx.In(stmt, deletionUUID, assetNames)
|
||||
if err != nil {
|
||||
return ctxerr.Wrap(ctx, err, "sqlx.In DeleteMDMConfigAssetsByName")
|
||||
}
|
||||
|
||||
_, err = ds.writer(ctx).ExecContext(ctx, stmt, args...)
|
||||
return ctxerr.Wrap(ctx, err, "deleting mdm config assets")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1255,6 +1255,9 @@ type Datastore interface {
|
|||
// GetMDMConfigAssetsByName returns the requested config assets.
|
||||
GetMDMConfigAssetsByName(ctx context.Context, assetNames []MDMAssetName) ([]MDMConfigAsset, error)
|
||||
|
||||
// DeleteMDMConfigAssetsByName soft deletes the given MDM config assets.
|
||||
DeleteMDMConfigAssetsByName(ctx context.Context, assetNames []MDMAssetName) error
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Microsoft MDM
|
||||
|
||||
|
|
|
|||
|
|
@ -695,6 +695,7 @@ type Service interface {
|
|||
GetMDMAppleCSR(ctx context.Context) ([]byte, error)
|
||||
|
||||
UploadMDMAppleAPNSCert(ctx context.Context, cert io.ReadSeeker) error
|
||||
DeleteMDMAppleAPNSCert(ctx context.Context) error
|
||||
|
||||
// GetHostDEPAssignment retrieves the host DEP assignment for the specified host.
|
||||
GetHostDEPAssignment(ctx context.Context, host *Host) (*HostDEPAssignment, error)
|
||||
|
|
|
|||
|
|
@ -714,6 +714,7 @@ func attachFleetAPIRoutes(r *mux.Router, svc fleet.Service, config config.FleetC
|
|||
|
||||
ue.GET("/api/_version_/fleet/mdm/apple/request_csr", getMDMAppleCSREndpoint, getMDMAppleCSRRequest{})
|
||||
ue.POST("/api/_version_/fleet/mdm/apple/apns_certificate", uploadMDMAppleAPNSCertEndpoint, uploadMDMAppleAPNSCertRequest{})
|
||||
ue.DELETE("/api/_version_/fleet/mdm/apple/apns_certificate", deleteMDMAppleAPNSCertEndpoint, deleteMDMAppleAPNSCertRequest{})
|
||||
|
||||
// Deprecated: GET /mdm/apple_bm is now deprecated, replaced by the
|
||||
// GET /abm endpoint.
|
||||
|
|
|
|||
|
|
@ -2296,3 +2296,34 @@ func (svc *Service) UploadMDMAppleAPNSCert(ctx context.Context, cert io.ReadSeek
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
type deleteMDMAppleAPNSCertRequest struct{}
|
||||
|
||||
type deleteMDMAppleAPNSCertResponse struct {
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r deleteMDMAppleAPNSCertResponse) error() error {
|
||||
return r.Err
|
||||
}
|
||||
|
||||
func deleteMDMAppleAPNSCertEndpoint(ctx context.Context, request interface{}, svc fleet.Service) (errorer, error) {
|
||||
if err := svc.DeleteMDMAppleAPNSCert(ctx); err != nil {
|
||||
return &deleteMDMAppleAPNSCertResponse{Err: err}, nil
|
||||
}
|
||||
|
||||
return &deleteMDMAppleAPNSCertResponse{}, nil
|
||||
}
|
||||
|
||||
func (svc *Service) DeleteMDMAppleAPNSCert(ctx context.Context) error {
|
||||
if err := svc.authz.Authorize(ctx, &fleet.AppleCSR{}, fleet.ActionWrite); err != nil {
|
||||
return ctxerr.Wrap(ctx, err)
|
||||
}
|
||||
|
||||
return ctxerr.Wrap(ctx, svc.ds.DeleteMDMConfigAssetsByName(ctx, []fleet.MDMAssetName{
|
||||
fleet.MDMAssetAPNSCert,
|
||||
fleet.MDMAssetAPNSKey,
|
||||
fleet.MDMAssetCACert,
|
||||
fleet.MDMAssetCAKey,
|
||||
}), "deleting apple mdm assets")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue