@@ -43,8 +43,6 @@ import (
4343 "github.com/micromdm/micromdm/mdm/connect"
4444 "github.com/micromdm/micromdm/mdm/enroll"
4545 "github.com/micromdm/micromdm/pkg/crypto"
46- "github.com/micromdm/micromdm/platform/api/server/apply"
47- "github.com/micromdm/micromdm/platform/api/server/list"
4846 "github.com/micromdm/micromdm/platform/apns"
4947 "github.com/micromdm/micromdm/platform/appstore"
5048 appsbuiltin "github.com/micromdm/micromdm/platform/appstore/builtin"
@@ -53,6 +51,7 @@ import (
5351 "github.com/micromdm/micromdm/platform/command"
5452 "github.com/micromdm/micromdm/platform/config"
5553 configbuiltin "github.com/micromdm/micromdm/platform/config/builtin"
54+ depapi "github.com/micromdm/micromdm/platform/dep"
5655 "github.com/micromdm/micromdm/platform/device"
5756 devicebuiltin "github.com/micromdm/micromdm/platform/device/builtin"
5857 "github.com/micromdm/micromdm/platform/profile"
@@ -160,6 +159,7 @@ func serve(args []string) error {
160159 sm .setupCommandService ()
161160 sm .setupWebhooks ()
162161 sm .setupCommandQueue (logger )
162+ sm .setupDepClient ()
163163 sm .setupDEPSync ()
164164 if sm .err != nil {
165165 stdlog .Fatal (sm .err )
@@ -254,10 +254,7 @@ func serve(args []string) error {
254254 ConnectEndpoint : connectEndpoint ,
255255 }
256256
257- dc , err := sm .depClient ()
258- if err != nil {
259- stdlog .Fatalf ("creating DEP client: %s\n " , err )
260- }
257+ dc := sm .depClient
261258 appDB := & appsbuiltin.Repo {Path : * flRepoPath }
262259
263260 var profilesvc profile.Service
@@ -302,46 +299,11 @@ func serve(args []string) error {
302299 }
303300 deviceEndpoints := device .MakeServerEndpoints (devicesvc )
304301
305- var listsvc list .Service
302+ var depsvc depapi .Service
306303 {
307- l := & list.ListService {
308- DEPClient : dc ,
309- }
310- listsvc = l
311-
312- if err := l .WatchTokenUpdates (sm .pubclient ); err != nil {
313- stdlog .Fatal (err )
314- }
315- }
316- listEndpoints := list.Endpoints {
317- GetDEPAccountInfoEndpoint : list .MakeGetDEPAccountInfoEndpoint (listsvc ),
318- GetDEPProfileEndpoint : list .MakeGetDEPProfileEndpoint (listsvc ),
319- GetDEPDeviceEndpoint : list .MakeGetDEPDeviceDetailsEndpoint (listsvc ),
304+ depsvc = depapi .New (dc , sm .pubclient )
320305 }
321-
322- var applysvc apply.Service
323- {
324- l := & apply.ApplyService {
325- DEPClient : dc ,
326- }
327- applysvc = l
328- if err := l .WatchTokenUpdates (sm .pubclient ); err != nil {
329- stdlog .Fatal (err )
330- }
331- }
332-
333- var defineDEPProfileEndpoint endpoint.Endpoint
334- {
335- defineDEPProfileEndpoint = apply .MakeDefineDEPProfile (applysvc )
336- }
337-
338- applyEndpoints := apply.Endpoints {
339- DefineDEPProfileEndpoint : defineDEPProfileEndpoint ,
340- }
341-
342- applyAPIHandlers := apply .MakeHTTPHandlers (ctx , applyEndpoints , connectOpts ... )
343-
344- listAPIHandlers := list .MakeHTTPHandlers (ctx , listEndpoints , connectOpts ... )
306+ depEndpoints := depapi .MakeServerEndpoints (depsvc )
345307
346308 connectHandlers := connect .MakeHTTPHandlers (ctx , connectEndpoints , connectOpts ... )
347309
@@ -366,6 +328,7 @@ func serve(args []string) error {
366328 configHandler := config .MakeHTTPHandler (configEndpoints , logger )
367329 appsHandler := appstore .MakeHTTPHandler (appEndpoints , logger )
368330 deviceHandler := device .MakeHTTPHandler (deviceEndpoints , logger )
331+ depHandlers := depapi .MakeHTTPHandler (depEndpoints , logger )
369332
370333 // API commands. Only handled if the user provides an api key.
371334 if * flAPIKey != "" {
@@ -379,12 +342,11 @@ func serve(args []string) error {
379342 r .Handle ("/v1/dep-tokens" , apiAuthMiddleware (* flAPIKey , configHandler ))
380343 r .Handle ("/v1/dep-tokens" , apiAuthMiddleware (* flAPIKey , configHandler ))
381344 r .Handle ("/v1/config/certificate" , apiAuthMiddleware (* flAPIKey , configHandler ))
382- r .Handle ("/push/{udid}" , apiAuthMiddleware (* flAPIKey , pushHandlers .PushHandler ))
345+ r .Handle ("/v1/dep/devices" , apiAuthMiddleware (* flAPIKey , depHandlers ))
346+ r .Handle ("/v1/dep/account" , apiAuthMiddleware (* flAPIKey , depHandlers ))
347+ r .Handle ("/v1/dep/profiles" , apiAuthMiddleware (* flAPIKey , depHandlers ))
383348 r .Handle ("/v1/commands" , apiAuthMiddleware (* flAPIKey , commandHandlers .NewCommandHandler )).Methods ("POST" )
384- r .Handle ("/v1/dep/devices" , apiAuthMiddleware (* flAPIKey , listAPIHandlers .GetDEPDeviceDetailsHandler )).Methods ("GET" )
385- r .Handle ("/v1/dep/account" , apiAuthMiddleware (* flAPIKey , listAPIHandlers .GetDEPAccountInfoHandler )).Methods ("GET" )
386- r .Handle ("/v1/dep/profiles" , apiAuthMiddleware (* flAPIKey , listAPIHandlers .GetDEPProfileHandler )).Methods ("GET" )
387- r .Handle ("/v1/dep/profiles" , apiAuthMiddleware (* flAPIKey , applyAPIHandlers .DefineDEPProfileHandler )).Methods ("POST" )
349+ r .Handle ("/push/{udid}" , apiAuthMiddleware (* flAPIKey , pushHandlers .PushHandler ))
388350 }
389351
390352 if * flRepoPath != "" {
@@ -483,6 +445,7 @@ type server struct {
483445 configDB config.Store
484446 removeDB block.Store
485447 CommandWebhookURL string
448+ depClient dep.Client
486449
487450 // TODO: refactor enroll service and remove the need to reference
488451 // this on-disk cert. but it might be useful to keep the PEM
@@ -763,7 +726,7 @@ func (p staticTopicProvider) PushTopic() (string, error) {
763726 return p .topic , nil
764727}
765728
766- func (c * server ) depClient () (dep.Client , error ) {
729+ func (c * server ) setupDepClient () (dep.Client , error ) {
767730 if c .err != nil {
768731 return nil , c .err
769732 }
@@ -808,6 +771,8 @@ func (c *server) depClient() (dep.Client, error) {
808771 return nil , err
809772 }
810773
774+ c .depClient = client
775+
811776 return client , nil
812777}
813778
@@ -816,17 +781,13 @@ func (c *server) setupDEPSync() {
816781 return
817782 }
818783
819- client , err := c .depClient ()
820- if err != nil {
821- c .err = err
822- return
823- }
784+ client := c .depClient
824785 var opts []depsync.Option
825786 if client != nil {
826787 opts = append (opts , depsync .WithClient (client ))
827788 }
828789 _ , c .err = depsync .New (c .pubclient , c .db , opts ... )
829- if err != nil {
790+ if c . err != nil {
830791 return
831792 }
832793}
0 commit comments