diff --git a/applications/datastore.go b/applications/datastore.go index be517787..29a61d06 100644 --- a/applications/datastore.go +++ b/applications/datastore.go @@ -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) { apps := []Application{} query := `SELECT * FROM applications diff --git a/connect/endpoint.go b/connect/endpoint.go index 8f0d5c97..7530eaa0 100644 --- a/connect/endpoint.go +++ b/connect/endpoint.go @@ -55,6 +55,20 @@ func makeConnectEndpoint(svc Service) endpoint.Endpoint { return mdmConnectResponse{}, 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: return mdmConnectResponse{Err: errInvalidMessageType}, nil } diff --git a/connect/service.go b/connect/service.go index cd8d5eb1..c73f9a04 100644 --- a/connect/service.go +++ b/connect/service.go @@ -12,6 +12,7 @@ import ( type Service interface { Acknowledge(ctx context.Context, req mdm.Response) (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{}) 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) } +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) { existing, err := svc.devices.GetDeviceByUDID(deviceUDID, []string{"awaiting_configuration"}...) if err != nil { @@ -85,6 +90,7 @@ func (svc service) checkRequeue(deviceUDID string) (int, error) { 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{}) { datastoreInjectedHandler := func(req mdm.Response) error { 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}) } -// 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) { for _, h := range svc.handlers { if h.requestType == requestType { @@ -103,6 +109,7 @@ func (svc service) FindAckHandler(requestType string) (func(req mdm.Response) er return nil, false } +// Execute any registered handler function which matches the given RequestType func (svc service) ExecAckHandler(requestType string, req mdm.Response) error { handler, found := svc.FindAckHandler(requestType) if !found { diff --git a/migrations/201607110002_certificates_down.sql b/migrations/201607110002_certificates_down.sql new file mode 100644 index 00000000..4116a42f --- /dev/null +++ b/migrations/201607110002_certificates_down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS certificates; \ No newline at end of file diff --git a/migrations/201607110002_certificates_up.sql b/migrations/201607110002_certificates_up.sql new file mode 100644 index 00000000..0c73ee0a --- /dev/null +++ b/migrations/201607110002_certificates_up.sql @@ -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 +) +