veyron/examples/{tunnel,rockpaperscissors}: Use the library to generate ACL
authorizers instead of using custom flags.
Change-Id: I2eb0bfb40678429278ba2af163a408372f743e4e
diff --git a/examples/rockpaperscissors/rpsbot/main.go b/examples/rockpaperscissors/rpsbot/main.go
index 38ea9f6..012d36b 100644
--- a/examples/rockpaperscissors/rpsbot/main.go
+++ b/examples/rockpaperscissors/rpsbot/main.go
@@ -10,15 +10,14 @@
"fmt"
"math/rand"
"os"
- "strings"
"time"
rps "veyron/examples/rockpaperscissors"
"veyron/examples/rockpaperscissors/impl"
"veyron/lib/signals"
+ sflag "veyron/security/flag"
"veyron2/ipc"
"veyron2/rt"
- "veyron2/security"
"veyron2/vlog"
)
@@ -26,19 +25,8 @@
// TODO(rthellend): Remove the address and protocol flags when the config manager is working.
protocol = flag.String("protocol", "tcp", "network to listen on. For example, set to 'veyron' and set --address to the endpoint/name of a proxy to have this service proxied.")
address = flag.String("address", ":0", "address to listen on")
-
- users = flag.String("users", "", "A comma-separated list of principal patterns allowed to use this service.")
)
-func authorizer() security.Authorizer {
- ACL := make(security.ACL)
- principals := strings.Split(*users, ",")
- for _, p := range principals {
- ACL[security.PrincipalPattern(p)] = security.LabelSet(security.AdminLabel)
- }
- return security.NewACLAuthorizer(ACL)
-}
-
func main() {
r := rt.Init()
defer r.Shutdown()
@@ -51,7 +39,7 @@
rand.Seed(time.Now().UTC().UnixNano())
rpsService := impl.NewRPS(r.MountTable())
- if err := server.Register("", ipc.SoloDispatcher(rps.NewServerRockPaperScissors(rpsService), authorizer())); err != nil {
+ if err := server.Register("", ipc.SoloDispatcher(rps.NewServerRockPaperScissors(rpsService), sflag.NewAuthorizerOrDie())); err != nil {
vlog.Fatalf("Register failed: %v", err)
}
ep, err := server.Listen(*protocol, *address)
diff --git a/examples/rockpaperscissors/rpsscorekeeper/main.go b/examples/rockpaperscissors/rpsscorekeeper/main.go
index a76b8cf..38ca2a7 100644
--- a/examples/rockpaperscissors/rpsscorekeeper/main.go
+++ b/examples/rockpaperscissors/rpsscorekeeper/main.go
@@ -7,14 +7,13 @@
"flag"
"fmt"
"os"
- "strings"
rps "veyron/examples/rockpaperscissors"
"veyron/examples/rockpaperscissors/common"
+ sflag "veyron/security/flag"
"veyron2/ipc"
"veyron2/rt"
- "veyron2/security"
"veyron2/vlog"
)
@@ -22,8 +21,6 @@
// TODO(rthellend): Remove the address and protocol flags when the config manager is working.
protocol = flag.String("protocol", "tcp", "network to listen on. For example, set to 'veyron' and set --address to the endpoint/name of a proxy to have this service proxied.")
address = flag.String("address", ":0", "address to listen on")
-
- users = flag.String("users", "", "A comma-separated list of principal patterns allowed to use this service.")
)
type impl struct {
@@ -36,15 +33,6 @@
return nil
}
-func authorizer() security.Authorizer {
- ACL := make(security.ACL)
- principals := strings.Split(*users, ",")
- for _, p := range principals {
- ACL[security.PrincipalPattern(p)] = security.LabelSet(security.AdminLabel)
- }
- return security.NewACLAuthorizer(ACL)
-}
-
func main() {
r := rt.Init()
defer r.Shutdown()
@@ -57,7 +45,7 @@
ch := make(chan rps.ScoreCard)
rpsService := &impl{ch}
- if err := server.Register("", ipc.SoloDispatcher(rps.NewServerScoreKeeper(rpsService), authorizer())); err != nil {
+ if err := server.Register("", ipc.SoloDispatcher(rps.NewServerScoreKeeper(rpsService), sflag.NewAuthorizerOrDie())); err != nil {
vlog.Fatalf("Register failed: %v", err)
}
ep, err := server.Listen(*protocol, *address)
diff --git a/examples/tunnel/tunneld/main.go b/examples/tunnel/tunneld/main.go
index 283b227..33291a7 100644
--- a/examples/tunnel/tunneld/main.go
+++ b/examples/tunnel/tunneld/main.go
@@ -6,14 +6,13 @@
"fmt"
"net"
"os"
- "strings"
"veyron/examples/tunnel"
"veyron/examples/tunnel/tunneld/impl"
"veyron/lib/signals"
+ sflag "veyron/security/flag"
"veyron2/ipc"
"veyron2/rt"
- "veyron2/security"
"veyron2/vlog"
)
@@ -21,8 +20,6 @@
// TODO(rthellend): Remove the address and protocol flags when the config manager is working.
protocol = flag.String("protocol", "tcp", "network to listen on. For example, set to 'veyron' and set --address to the endpoint/name of a proxy to have this tunnel service proxied.")
address = flag.String("address", ":0", "address to listen on")
-
- users = flag.String("users", "", "A comma-separated list of principal patterns allowed to use this service.")
)
// firstHardwareAddrInUse returns the hwaddr of the first network interface
@@ -42,15 +39,6 @@
return "", errors.New("No usable network interfaces")
}
-func authorizer() security.Authorizer {
- ACL := make(security.ACL)
- principals := strings.Split(*users, ",")
- for _, p := range principals {
- ACL[security.PrincipalPattern(p)] = security.LabelSet(security.AdminLabel)
- }
- return security.NewACLAuthorizer(ACL)
-}
-
func main() {
r := rt.Init()
defer r.Shutdown()
@@ -60,7 +48,7 @@
}
defer server.Stop()
- if err := server.Register("", ipc.SoloDispatcher(tunnel.NewServerTunnel(&impl.T{}), authorizer())); err != nil {
+ if err := server.Register("", ipc.SoloDispatcher(tunnel.NewServerTunnel(&impl.T{}), sflag.NewAuthorizerOrDie())); err != nil {
vlog.Fatalf("Register failed: %v", err)
}
ep, err := server.Listen(*protocol, *address)