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:
Mosen
2016-07-11 19:31:20 +10:00
parent 23df1261b5
commit 9f580a6ba2
5 changed files with 36 additions and 1 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -0,0 +1 @@
DROP TABLE IF EXISTS certificates;

View 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
)