3
0
corteza/cmd/compose/main.go
Denis Arh 2a4054c9bc Implement permission provisioning and watchers
Remove rule reset from roles cli command
Add generic "provision" command for each binary and (re)set perm. rules
Permission rules are now separated and part of AccessControl service

Facility for watchers was added.
2019-05-10 09:49:07 +02:00

70 lines
1.6 KiB
Go

package main
import (
"os"
context "github.com/SentimensRG/ctx"
"github.com/SentimensRG/ctx/sigctx"
_ "github.com/joho/godotenv/autoload"
"github.com/namsral/flag"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
compose "github.com/crusttech/crust/compose"
"github.com/crusttech/crust/internal/logger"
"github.com/crusttech/crust/internal/subscription"
system "github.com/crusttech/crust/system"
)
func main() {
// Initialize default logger
logger.Init(zapcore.DebugLevel)
log := logger.Default().Named("compose")
// New signal-bond context that we will use and
// will get terminated (Done()) on SIGINT or SIGTERM
ctx := context.AsContext(sigctx.New())
// Bind default logger to context
ctx = logger.ContextWithValue(ctx, log)
compose.Flags("compose")
system.Flags("system")
subscription.Flags()
flag.Parse()
if err := system.Init(ctx); err != nil {
log.Fatal("failed to initialize system", zap.Error(err))
}
if err := compose.Init(ctx); err != nil {
log.Fatal("failed to initialize compose", zap.Error(err))
}
var command string
if len(os.Args) > 1 {
command = os.Args[1]
}
switch command {
case "help":
flag.PrintDefaults()
case "provision":
if err := compose.Provision(ctx); err != nil {
println("Failed to provision compose: ", err.Error())
os.Exit(1)
}
default:
// Checks subscription, will os.Exit(1) if there is an error
// Disabled for now, system service is the only one that validates subscription
// ctx = subscription.Monitor(ctx)
compose.StartWatchers(ctx)
if err := compose.StartRestAPI(ctx); err != nil {
log.Fatal("failed to start compose REST API", zap.Error(err))
}
}
}