Skip to content

Commit

Permalink
Creates only one adapter on startup based on flags
Browse files Browse the repository at this point in the history
When the server is starting up, an adapter is created based on command
line flags. Removed the adapter creation related API from protobuf. The
adapter is shared by all enforcers.

Change-Id: I2d399973c19caf31183078f36f400dfc2d3272b7
Signed-off-by: Loïc Collignon <loic.collignon@iot.bzh>
  • Loading branch information
Loïc Collignon committed Aug 19, 2019
1 parent db12762 commit 5b17273
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 286 deletions.
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,29 @@ import (

func main() {
var port int
var driverName string
var connectionString string
var dbSpecified bool
flag.IntVar(&port, "port", 50051, "listening port")
flag.StringVar(&driverName, "driver", "postgres", "adapter's driver (can be 'file', 'mysql', 'postgres' or 'mssql')")
flag.StringVar(&connectionString, "connstr", "", "adapter's connection string or file path if driver is 'file'")
flag.BoolVar(&dbSpecified, "dbspecified", false, "indicates whether the db is specified or not in the connstr")
flag.Parse()

if port < 1 || port > 65535 {
panic(fmt.Sprintf("invalid port number: %d", port))
}

if connectionString == "" {
panic("a connection string should be provided")
}

lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer()
pb.RegisterCasbinServer(s, server.NewServer())
pb.RegisterCasbinServer(s, server.NewServer(driverName, connectionString, dbSpecified))
// Register reflection service on gRPC server.
reflection.Register(s)
log.Println("Listening on", port)
Expand Down

0 comments on commit 5b17273

Please sign in to comment.