2022-12-05 16:35:45 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
|
|
)
|
|
|
|
|
|
|
|
type getAppleMDMResponse struct {
|
|
|
|
*fleet.AppleMDM
|
|
|
|
Err error `json:"error,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r getAppleMDMResponse) error() error { return r.Err }
|
|
|
|
|
2022-12-27 14:26:59 +00:00
|
|
|
func getAppleMDMEndpoint(ctx context.Context, request interface{}, svc fleet.Service) (errorer, error) {
|
2022-12-05 16:35:45 +00:00
|
|
|
appleMDM, err := svc.GetAppleMDM(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return getAppleMDMResponse{Err: err}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return getAppleMDMResponse{AppleMDM: appleMDM}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc *Service) GetAppleMDM(ctx context.Context) (*fleet.AppleMDM, error) {
|
|
|
|
if err := svc.authz.Authorize(ctx, &fleet.AppleMDM{}, fleet.ActionRead); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there is no apple mdm config, fail with a 404
|
|
|
|
if !svc.config.MDM.IsAppleAPNsSet() {
|
|
|
|
return nil, notFoundError{}
|
|
|
|
}
|
|
|
|
|
|
|
|
apns, _, _, err := svc.config.MDM.AppleAPNs()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
appleMDM := &fleet.AppleMDM{
|
|
|
|
CommonName: apns.Leaf.Subject.CommonName,
|
|
|
|
Issuer: apns.Leaf.Issuer.CommonName,
|
|
|
|
RenewDate: apns.Leaf.NotAfter,
|
|
|
|
}
|
|
|
|
if apns.Leaf.SerialNumber != nil {
|
|
|
|
appleMDM.SerialNumber = apns.Leaf.SerialNumber.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
return appleMDM, nil
|
|
|
|
}
|
2022-12-12 20:45:53 +00:00
|
|
|
|
|
|
|
type getAppleBMResponse struct {
|
|
|
|
*fleet.AppleBM
|
|
|
|
Err error `json:"error,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r getAppleBMResponse) error() error { return r.Err }
|
|
|
|
|
2022-12-27 14:26:59 +00:00
|
|
|
func getAppleBMEndpoint(ctx context.Context, request interface{}, svc fleet.Service) (errorer, error) {
|
2022-12-12 20:45:53 +00:00
|
|
|
appleBM, err := svc.GetAppleBM(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return getAppleBMResponse{Err: err}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return getAppleBMResponse{AppleBM: appleBM}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc *Service) GetAppleBM(ctx context.Context) (*fleet.AppleBM, error) {
|
|
|
|
// skipauth: No authorization check needed due to implementation returning
|
|
|
|
// only license error.
|
|
|
|
svc.authz.SkipAuthorization(ctx)
|
|
|
|
|
|
|
|
return nil, fleet.ErrMissingLicense
|
|
|
|
}
|