reorganize profile service (#347)

Moved all the endpoints into the profile package.
Defined a Store interface which includes all the used BoltDB methods.
Moved the BoltDB implementation into a subpackage.
This commit is contained in:
Victor Vrantchan
2017-12-09 16:50:10 -05:00
committed by GitHub
parent ce6e18f18d
commit 83ea8491aa
27 changed files with 487 additions and 265 deletions

View File

@@ -13,18 +13,16 @@ import (
"strings"
"github.com/go-kit/kit/log"
httptransport "github.com/go-kit/kit/transport/http"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
"github.com/micromdm/micromdm/platform/api/server/apply"
"github.com/micromdm/micromdm/platform/blueprint"
"github.com/micromdm/micromdm/platform/profile"
)
type applyCommand struct {
config *ServerConfig
applysvc apply.Service
config *ServerConfig
*remoteServices
}
func (cmd *applyCommand) setup() error {
@@ -34,11 +32,11 @@ func (cmd *applyCommand) setup() error {
}
cmd.config = cfg
logger := log.NewLogfmtLogger(os.Stderr)
applysvc, err := apply.NewClient(cfg.ServerURL, logger, cfg.APIToken, httptransport.SetClient(skipVerifyHTTPClient(cmd.config.SkipVerify)))
remote, err := setupClient(logger)
if err != nil {
return err
}
cmd.applysvc = applysvc
cmd.remoteServices = remote
return nil
}
@@ -256,7 +254,7 @@ func (cmd *applyCommand) applyProfile(args []string) error {
}
ctx := context.Background()
err = cmd.applysvc.ApplyProfile(ctx, &p)
err = cmd.profilesvc.ApplyProfile(ctx, &p)
if err != nil {
return err
}

View File

@@ -13,16 +13,16 @@ import (
"crypto/x509"
"github.com/go-kit/kit/log"
httptransport "github.com/go-kit/kit/transport/http"
"github.com/pkg/errors"
"github.com/micromdm/micromdm/pkg/crypto"
"github.com/micromdm/micromdm/platform/api/server/list"
"github.com/micromdm/micromdm/platform/profile"
)
type getCommand struct {
config *ServerConfig
list list.Service
*remoteServices
}
func (cmd *getCommand) setup() error {
@@ -32,11 +32,12 @@ func (cmd *getCommand) setup() error {
}
cmd.config = cfg
logger := log.NewLogfmtLogger(os.Stderr)
listsvc, err := list.NewClient(cfg.ServerURL, logger, cfg.APIToken, httptransport.SetClient(skipVerifyHTTPClient(cmd.config.SkipVerify)))
remote, err := setupClient(logger)
if err != nil {
return err
}
cmd.list = listsvc
cmd.remoteServices = remote
return nil
}
@@ -304,7 +305,7 @@ func (cmd *getCommand) getProfiles(args []string) error {
}
ctx := context.Background()
profiles, err := cmd.list.GetProfiles(ctx, list.GetProfilesOption{Identifier: *flIdentifier})
profiles, err := cmd.profilesvc.GetProfiles(ctx, profile.GetProfilesOption{Identifier: *flIdentifier})
if err != nil {
return err
}

View File

@@ -6,15 +6,11 @@ import (
"strings"
"github.com/go-kit/kit/log"
httptransport "github.com/go-kit/kit/transport/http"
"github.com/micromdm/micromdm/platform/api/server/remove"
)
type removeCommand struct {
config *ServerConfig
remove remove.Service
*remoteServices
}
func (cmd *removeCommand) setup() error {
@@ -24,11 +20,11 @@ func (cmd *removeCommand) setup() error {
}
cmd.config = cfg
logger := log.NewLogfmtLogger(os.Stderr)
rmsvc, err := remove.NewClient(cfg.ServerURL, logger, cfg.APIToken, httptransport.SetClient(skipVerifyHTTPClient(cmd.config.SkipVerify)))
remote, err := setupClient(logger)
if err != nil {
return err
}
cmd.remove = rmsvc
cmd.remoteServices = remote
return nil
}

View File

@@ -18,7 +18,7 @@ func (cmd *removeCommand) removeProfiles(args []string) error {
}
ctx := context.Background()
err := cmd.remove.RemoveProfiles(ctx, strings.Split(*flIdentifier, ","))
err := cmd.profilesvc.RemoveProfiles(ctx, strings.Split(*flIdentifier, ","))
if err != nil {
return err
}

59
cmd/mdmctl/setup.go Normal file
View File

@@ -0,0 +1,59 @@
package main
import (
"github.com/go-kit/kit/log"
httptransport "github.com/go-kit/kit/transport/http"
"github.com/micromdm/micromdm/platform/api/server/apply"
"github.com/micromdm/micromdm/platform/api/server/list"
"github.com/micromdm/micromdm/platform/api/server/remove"
"github.com/micromdm/micromdm/platform/profile"
)
type remoteServices struct {
profilesvc profile.Service
applysvc apply.Service
list list.Service
remove remove.Service
}
func setupClient(logger log.Logger) (*remoteServices, error) {
cfg, err := LoadServerConfig()
if err != nil {
return nil, err
}
applysvc, err := apply.NewClient(
cfg.ServerURL, logger, cfg.APIToken,
httptransport.SetClient(skipVerifyHTTPClient(cfg.SkipVerify)))
if err != nil {
return nil, err
}
profilesvc, err := profile.NewHTTPClient(
cfg.ServerURL, cfg.APIToken, logger,
httptransport.SetClient(skipVerifyHTTPClient(cfg.SkipVerify)))
if err != nil {
return nil, err
}
listsvc, err := list.NewClient(
cfg.ServerURL, logger, cfg.APIToken,
httptransport.SetClient(skipVerifyHTTPClient(cfg.SkipVerify)))
if err != nil {
return nil, err
}
rmsvc, err := remove.NewClient(
cfg.ServerURL, logger, cfg.APIToken,
httptransport.SetClient(skipVerifyHTTPClient(cfg.SkipVerify)))
if err != nil {
return nil, err
}
return &remoteServices{
profilesvc: profilesvc,
applysvc: applysvc,
list: listsvc,
remove: rmsvc,
}, nil
}