Skip to content

Commit

Permalink
rewrite main to use the new kitsvc endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
groob committed Jul 8, 2016
1 parent 3dcd780 commit 6bff573
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 1,205 deletions.
50 changes: 35 additions & 15 deletions cmd/squirrel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import (
"os"
"path/filepath"

"github.com/micromdm/squirrel/munki/api"
"golang.org/x/net/context"

kitlog "github.com/go-kit/kit/log"

"github.com/micromdm/squirrel/munki/datastore"
"github.com/micromdm/squirrel/munki/server"
)

const usage = "usage: MUNKI_REPO_PATH= SQUIRREL_HTTP_LISTEN_PORT= ape -repo MUNKI_REPO_PATH -port SQUIRREL_HTTP_LISTEN_PORT"
Expand Down Expand Up @@ -54,29 +59,44 @@ func main() {
log.Fatal("Basic Authentication is used to issue JWT Tokens. You must enable JWT as well")
}

var opts api.ServerOptions
var repo datastore.Datastore
{
if *flJWT {
jwtOpt := api.JWTAuth(*flJWTSecret)
opts = append(opts, jwtOpt)
}
repo = &datastore.SimpleRepo{Path: *flRepo}

// add basic auth
if *flBasic {
opts = append(opts, api.BasicAuth())
}

var err error
var svc munkiserver.Service
{
svc, err = munkiserver.NewService(repo)
if err != nil {
log.Fatal(err)
}
}
repo := api.SimpleRepo(*flRepo)
opts = append(opts, repo)
apiHandler := api.NewServer(opts...)
http.Handle("/", apiHandler)

var logger kitlog.Logger
{
logger = kitlog.NewLogfmtLogger(os.Stderr)
logger = kitlog.NewContext(logger).With("ts", kitlog.DefaultTimestampUTC)
logger = kitlog.NewContext(logger).With("caller", kitlog.DefaultCaller)
}

ctx := context.Background()
var h http.Handler
{
h = munkiserver.ServiceHandler(ctx, svc, logger)
}

mux := http.NewServeMux()
mux.Handle("/api/v1/", h)
mux.Handle("/repo/", http.StripPrefix("/repo/", http.FileServer(http.Dir(*flRepo))))

port := fmt.Sprintf(":%v", *flPort)

if *flTLS {
log.Fatal(http.ListenAndServeTLS(port, *flTLSCert, *flTLSKey, nil))
log.Fatal(http.ListenAndServeTLS(port, *flTLSCert, *flTLSKey, mux))
} else {
log.Fatal(http.ListenAndServe(port, nil))
log.Fatal(http.ListenAndServe(port, mux))
}
}

Expand Down
197 changes: 0 additions & 197 deletions munki/api/api_test.go

This file was deleted.

106 changes: 0 additions & 106 deletions munki/api/auth.go

This file was deleted.

Loading

0 comments on commit 6bff573

Please sign in to comment.