mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-11 12:15:34 +08:00
Stub new method for application datastore
Handle command failures more gracefully than continuously retrying. Failures are not logged Add table for certificates.
This commit is contained in:
@@ -44,6 +44,10 @@ func NewDB(driver, conn string, logger kitlog.Logger) (Datastore, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (store pgStore) New(src string, a *Application) (string, error) {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
func (store pgStore) GetApplicationsByDeviceUUID(deviceUUID string) (*[]Application, error) {
|
func (store pgStore) GetApplicationsByDeviceUUID(deviceUUID string) (*[]Application, error) {
|
||||||
apps := []Application{}
|
apps := []Application{}
|
||||||
query := `SELECT * FROM applications
|
query := `SELECT * FROM applications
|
||||||
|
|||||||
@@ -55,6 +55,20 @@ func makeConnectEndpoint(svc Service) endpoint.Endpoint {
|
|||||||
return mdmConnectResponse{}, nil
|
return mdmConnectResponse{}, nil
|
||||||
}
|
}
|
||||||
return mdmConnectResponse{payload: next}, nil
|
return mdmConnectResponse{payload: next}, nil
|
||||||
|
case "Error":
|
||||||
|
total, err := svc.FailCommand(ctx, req.Response)
|
||||||
|
if err != nil {
|
||||||
|
return mdmConnectResponse{Err: err}, nil
|
||||||
|
}
|
||||||
|
// TODO: Deal with command failures
|
||||||
|
if total != 0 {
|
||||||
|
next, _, err := svc.NextCommand(ctx, req.Response)
|
||||||
|
if err != nil {
|
||||||
|
return mdmConnectResponse{Err: err}, nil
|
||||||
|
}
|
||||||
|
return mdmConnectResponse{payload: next}, nil
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return mdmConnectResponse{Err: errInvalidMessageType}, nil
|
return mdmConnectResponse{Err: errInvalidMessageType}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
type Service interface {
|
type Service interface {
|
||||||
Acknowledge(ctx context.Context, req mdm.Response) (int, error)
|
Acknowledge(ctx context.Context, req mdm.Response) (int, error)
|
||||||
NextCommand(ctx context.Context, req mdm.Response) ([]byte, int, error)
|
NextCommand(ctx context.Context, req mdm.Response) ([]byte, int, error)
|
||||||
|
FailCommand(ctx context.Context, req mdm.Response) (int, error)
|
||||||
|
|
||||||
RegisterAckHandler(requestType string, handler func(req mdm.Response, datastores map[string]interface{}) error, datastores map[string]interface{})
|
RegisterAckHandler(requestType string, handler func(req mdm.Response, datastores map[string]interface{}) error, datastores map[string]interface{})
|
||||||
FindAckHandler(requestType string) (func(req mdm.Response) error, bool)
|
FindAckHandler(requestType string) (func(req mdm.Response) error, bool)
|
||||||
@@ -66,6 +67,10 @@ func (svc service) NextCommand(ctx context.Context, req mdm.Response) ([]byte, i
|
|||||||
return svc.commands.NextCommand(req.UDID)
|
return svc.commands.NextCommand(req.UDID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (svc service) FailCommand(ctx context.Context, req mdm.Response) (int, error) {
|
||||||
|
return svc.commands.DeleteCommand(req.UDID, req.CommandUUID)
|
||||||
|
}
|
||||||
|
|
||||||
func (svc service) checkRequeue(deviceUDID string) (int, error) {
|
func (svc service) checkRequeue(deviceUDID string) (int, error) {
|
||||||
existing, err := svc.devices.GetDeviceByUDID(deviceUDID, []string{"awaiting_configuration"}...)
|
existing, err := svc.devices.GetDeviceByUDID(deviceUDID, []string{"awaiting_configuration"}...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -85,6 +90,7 @@ func (svc service) checkRequeue(deviceUDID string) (int, error) {
|
|||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register a handler function for a given RequestType, include datastore dependencies as a map.
|
||||||
func (svc service) RegisterAckHandler(requestType string, handler func(req mdm.Response, datastores map[string]interface{}) error, datastores map[string]interface{}) {
|
func (svc service) RegisterAckHandler(requestType string, handler func(req mdm.Response, datastores map[string]interface{}) error, datastores map[string]interface{}) {
|
||||||
datastoreInjectedHandler := func(req mdm.Response) error {
|
datastoreInjectedHandler := func(req mdm.Response) error {
|
||||||
return handler(req, datastores)
|
return handler(req, datastores)
|
||||||
@@ -92,7 +98,7 @@ func (svc service) RegisterAckHandler(requestType string, handler func(req mdm.R
|
|||||||
svc.handlers = append(svc.handlers, ackHandler{requestType, datastoreInjectedHandler})
|
svc.handlers = append(svc.handlers, ackHandler{requestType, datastoreInjectedHandler})
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not found, second return variable is false
|
// Find a handler function which is registered to deal with the RequestType
|
||||||
func (svc service) FindAckHandler(requestType string) (func(req mdm.Response) error, bool) {
|
func (svc service) FindAckHandler(requestType string) (func(req mdm.Response) error, bool) {
|
||||||
for _, h := range svc.handlers {
|
for _, h := range svc.handlers {
|
||||||
if h.requestType == requestType {
|
if h.requestType == requestType {
|
||||||
@@ -103,6 +109,7 @@ func (svc service) FindAckHandler(requestType string) (func(req mdm.Response) er
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Execute any registered handler function which matches the given RequestType
|
||||||
func (svc service) ExecAckHandler(requestType string, req mdm.Response) error {
|
func (svc service) ExecAckHandler(requestType string, req mdm.Response) error {
|
||||||
handler, found := svc.FindAckHandler(requestType)
|
handler, found := svc.FindAckHandler(requestType)
|
||||||
if !found {
|
if !found {
|
||||||
|
|||||||
1
migrations/201607110002_certificates_down.sql
Normal file
1
migrations/201607110002_certificates_down.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS certificates;
|
||||||
9
migrations/201607110002_certificates_up.sql
Normal file
9
migrations/201607110002_certificates_up.sql
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS certificates (
|
||||||
|
certificate_uuid uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
common_name text NOT NULL,
|
||||||
|
data BYTEA NOT NULL,
|
||||||
|
is_identity BOOL DEFAULT false
|
||||||
|
)
|
||||||
|
|
||||||
Reference in New Issue
Block a user