Non plural packages (#25)

* Stub new method for application datastore
Handle command failures more gracefully than continuously retrying. Failures are not logged
Add table for certificates.

(cherry picked from commit 9f580a6)

* Remove methods with signature NewDatastore() from datastores and injection of the logger instance into each datastore because groob is a doodoo head :)
Move NewDatastore methods into unit tests
Reinstate NewDB test
Create certificates package including a Certificate type and a datastore.
Began working on a method ackCertificateList in the connect service.
Boilerplate for management service test.
Renamed some tables in certificates migration, hopefully nobody notices.
Applications response handler should be omitted from this branch.

(cherry picked from commit 8bc2fc7)

* Add device uuid to certificate, as there will never be a normalised form of the certificate data.
Change statments to reflect table change from certificates to devices_certificates
Add the CertificateList request type to the connect service's Acknowledge method
Add certificates datastore to the management service, and add endpoints and request/responses for retrieving certificates by device uuid to the management endpoujnt.
Kludge. commits regarding app service will be amended.
(cherry picked from commit c723c80)

* Don't forget the endpoint definition for certificates!

(cherry picked from commit 4e5fc1f)

* Use byte field for certificate data.

(cherry picked from commit 66d5036)

* Fix empty import in certificates

(cherry picked from commit b6d4dca)

* Add table for certificates.

(cherry picked from commit 06bc231)

* Renamed some tables in certificates migration, hopefully nobody notices.
Rebase develop onto master

(cherry picked from commit 775484d)

* Certificate list responses are saved via replacing the entire certificate list on a per device basis. This is because neither the common name nor the data could be used as a unique constraint in the certificates table.
Few small changes to imports/style.

(cherry picked from commit e0a63e1)

* Properly rollback if certificate insert fails for any certificate in a response.

(cherry picked from commit 99e1ea1)

* Fix several incorrect statements and struct tags which were preventing the certificates management endpoint from listing certs.
Certificate listing is working without a base64 encoded representation of each certificate.

(cherry picked from commit 685dfef)

* Add commands index to command datastore.
Add simple test for commands index
Add commands index endpoint

(cherry picked from commit 4e2a2a2)

* Add handler for GET /mdm/commands

(cherry picked from commit ae71b8f)

* Added Find() method to commands datastore so that the request that matches a response can be retrieved by the connect service.
Added Find() method to command service

(cherry picked from commit ebceb28)

* Fix globally scoped vars in command datastore test suite

* groob prefers inline definition of struct members.

* Uppercase CommandUuid

* Add ackCertificateList to connect service, accidentally omitted from installed_certificate_list PR #14
Make push endpoint conform to Errorer interface.
Wrap error return in management service.
Add missing certsDB in main.go, should have been part of installed_certificate_list PR #14

* Fix erraneous comma in mdmEnrollResponse

* Rename certificates to certficiate
Rename applications to application
This commit is contained in:
mosen
2016-10-07 12:35:06 +11:00
committed by GitHub
parent 66dc2beb7f
commit bfdbc77a3a
14 changed files with 36 additions and 36 deletions

View File

@@ -1,4 +1,4 @@
package applications
package application
import "database/sql"

View File

@@ -1,4 +1,4 @@
package applications
package application
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package applications
package application
import (
"database/sql"

View File

@@ -1,4 +1,4 @@
package applications
package application
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package certificates
package certificate
type Certificate struct {
UUID string `db:"certificate_uuid" json:"uuid"`

View File

@@ -1,4 +1,4 @@
package certificates
package certificate
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package certificates
package certificate
import (
"database/sql"

View File

@@ -1,4 +1,4 @@
package certificates
package certificate
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package certificates
package certificate
import (
"testing"

View File

@@ -5,8 +5,8 @@ import (
"encoding/json"
"fmt"
"github.com/micromdm/mdm"
apps "github.com/micromdm/micromdm/applications"
"github.com/micromdm/micromdm/certificates"
"github.com/micromdm/micromdm/application"
"github.com/micromdm/micromdm/certificate"
"github.com/micromdm/micromdm/command"
"github.com/micromdm/micromdm/device"
"github.com/pkg/errors"
@@ -22,7 +22,7 @@ type Service interface {
}
// NewService creates a mdm service
func NewService(devices device.Datastore, apps apps.Datastore, certs certificates.Datastore, cs command.Service) Service {
func NewService(devices device.Datastore, apps application.Datastore, certs certificate.Datastore, cs command.Service) Service {
return &service{
commands: cs,
devices: devices,
@@ -33,9 +33,9 @@ func NewService(devices device.Datastore, apps apps.Datastore, certs certificate
type service struct {
devices device.Datastore
apps apps.Datastore
apps application.Datastore
commands command.Service
certs certificates.Datastore
certs certificate.Datastore
}
// Acknowledge a response from a device.
@@ -157,7 +157,7 @@ func (svc service) ackInstalledApplicationList(req mdm.Response) error {
return fmt.Errorf("clearing applications for device: %s", err)
}
var requestApps []apps.DeviceApplication = make([]apps.DeviceApplication, len(req.InstalledApplicationList))
var requestApps []application.DeviceApplication = make([]application.DeviceApplication, len(req.InstalledApplicationList))
// Update or insert application records that do not exist, returning the UUID so that it can be inserted for
// the device sending the response.
for i, reqApp := range req.InstalledApplicationList {
@@ -171,7 +171,7 @@ func (svc service) ackInstalledApplicationList(req mdm.Response) error {
dynamicSize := sql.NullInt64{}
dynamicSize.Scan(reqApp.DynamicSize)
newApp := apps.DeviceApplication{
newApp := application.DeviceApplication{
DeviceUUID: dev.UUID,
Name: reqApp.Name,
Identifier: identifier,
@@ -203,9 +203,9 @@ func (svc service) ackCertificateList(req mdm.Response) error {
return errors.Wrap(err, "getting a device record by udid")
}
var certs []certificates.Certificate = []certificates.Certificate{}
var certs []certificate.Certificate = []certificate.Certificate{}
for _, cert := range req.CertificateList {
newCert := certificates.Certificate{
newCert := certificate.Certificate{
CommonName: cert.CommonName,
IsIdentity: cert.IsIdentity,
Data: cert.Data,

View File

@@ -14,8 +14,8 @@ import (
"github.com/RobotsAndPencils/buford/push"
"github.com/go-kit/kit/log"
"github.com/micromdm/dep"
"github.com/micromdm/micromdm/applications"
"github.com/micromdm/micromdm/certificates"
"github.com/micromdm/micromdm/application"
mdmCert "github.com/micromdm/micromdm/certificate"
"github.com/micromdm/micromdm/checkin"
"github.com/micromdm/micromdm/command"
"github.com/micromdm/micromdm/connect"
@@ -189,7 +189,7 @@ func main() {
os.Exit(1)
}
appsDB, err := applications.NewDB(
appsDB, err := application.NewDB(
"postgres",
*flPGconn,
logger,
@@ -199,7 +199,7 @@ func main() {
os.Exit(1)
}
certsDB, err := certificates.NewDB(
certsDB, err := mdmCert.NewDB(
"postgres",
*flPGconn,
logger,

View File

@@ -3,7 +3,7 @@ package management
import (
"encoding/json"
"github.com/go-kit/kit/endpoint"
"github.com/micromdm/micromdm/certificates"
"github.com/micromdm/micromdm/certificate"
"golang.org/x/net/context"
"net/http"
)
@@ -13,8 +13,8 @@ type listCertificatesRequest struct {
}
type listCertificatesResponse struct {
certificates []certificates.Certificate `json:"certificates,omitempty"`
Err error `json:"error,omitempty"`
certificates []certificate.Certificate `json:"certificates,omitempty"`
Err error `json:"error,omitempty"`
}
func (r listCertificatesResponse) error() error { return r.Err }

View File

@@ -2,7 +2,7 @@ package management
import (
"github.com/go-kit/kit/endpoint"
"github.com/micromdm/micromdm/applications"
"github.com/micromdm/micromdm/application"
"golang.org/x/net/context"
)
@@ -11,7 +11,7 @@ type installedAppsRequest struct {
}
type installedAppsResponse struct {
applications []applications.Application
applications []application.Application
Err error `json:"error,omitempty"`
}

View File

@@ -5,8 +5,8 @@ import (
"github.com/RobotsAndPencils/buford/payload"
"github.com/RobotsAndPencils/buford/push"
"github.com/micromdm/dep"
"github.com/micromdm/micromdm/applications"
"github.com/micromdm/micromdm/certificates"
"github.com/micromdm/micromdm/application"
"github.com/micromdm/micromdm/certificate"
"github.com/micromdm/micromdm/device"
"github.com/micromdm/micromdm/workflow"
"github.com/pkg/errors"
@@ -31,10 +31,10 @@ type Service interface {
Device(uuid string) (*device.Device, error)
// Installed Applications
InstalledApps(deviceUUID string) ([]applications.Application, error)
InstalledApps(deviceUUID string) ([]application.Application, error)
// Installed Certificates
Certificates(deviceUUID string) ([]certificates.Certificate, error)
Certificates(deviceUUID string) ([]certificate.Certificate, error)
// AssignWorkflow assigns a workflow to a device
AssignWorkflow(deviceUUID, workflowUUID string) error
@@ -48,7 +48,7 @@ type Service interface {
}
// NewService creates a management service
func NewService(ds device.Datastore, ws workflow.Datastore, dc dep.Client, ps *push.Service, as applications.Datastore, cs certificates.Datastore) Service {
func NewService(ds device.Datastore, ws workflow.Datastore, dc dep.Client, ps *push.Service, as application.Datastore, cs certificate.Datastore) Service {
return &service{
devices: ds,
depClient: dc,
@@ -64,8 +64,8 @@ type service struct {
devices device.Datastore
workflows workflow.Datastore
pushsvc *push.Service
applications applications.Datastore
certificates certificates.Datastore
applications application.Datastore
certificates certificate.Datastore
}
func (svc service) Push(deviceUDID string) (string, error) {
@@ -172,7 +172,7 @@ func (svc service) AssignWorkflow(deviceUUID, workflowUUID string) error {
return svc.devices.Save("assignWorkflow", dev)
}
func (svc service) InstalledApps(deviceUUID string) ([]applications.Application, error) {
func (svc service) InstalledApps(deviceUUID string) ([]application.Application, error) {
apps, err := svc.applications.GetApplicationsByDeviceUUID(deviceUUID)
if err != nil {
return nil, errors.Wrap(err, "management: installed apps")
@@ -181,7 +181,7 @@ func (svc service) InstalledApps(deviceUUID string) ([]applications.Application,
return apps, nil
}
func (svc service) Certificates(deviceUUID string) ([]certificates.Certificate, error) {
func (svc service) Certificates(deviceUUID string) ([]certificate.Certificate, error) {
certs, err := svc.certificates.GetCertificatesByDeviceUUID(deviceUUID)
if err != nil {
return nil, errors.Wrap(err, "management: certificates")