forked from micro/micro
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.go
executable file
·64 lines (55 loc) · 1.63 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package server
import (
pb "github.com/2637309949/micro/v3/proto/auth"
"github.com/2637309949/micro/v3/service"
"github.com/2637309949/micro/v3/service/auth"
"github.com/2637309949/micro/v3/service/auth/handler"
log "github.com/2637309949/micro/v3/service/logger"
"github.com/2637309949/micro/v3/service/store"
mustore "github.com/2637309949/micro/v3/service/store"
"github.com/2637309949/micro/v3/util/auth/token"
"github.com/2637309949/micro/v3/util/auth/token/jwt"
"github.com/urfave/cli/v2"
)
// Flags specific to the router
var Flags = []cli.Flag{
&cli.BoolFlag{
Name: "disable_admin",
EnvVars: []string{"MICRO_AUTH_DISABLE_ADMIN"},
Usage: "Prevent generation of default accounts in namespaces",
},
}
const (
name = "auth"
address = ":8010"
)
// Run the auth service
func Run(ctx *cli.Context) error {
srv := service.New(
service.Name(name),
service.Address(address),
)
// setup the handlers
ruleH := &handler.Rules{}
authH := &handler.Auth{
DisableAdmin: ctx.Bool("disable_admin"),
}
// setup the auth handler to use JWTs
authH.TokenProvider = jwt.NewTokenProvider(
token.WithPublicKey(auth.DefaultAuth.Options().PublicKey),
token.WithPrivateKey(auth.DefaultAuth.Options().PrivateKey),
)
// set the handlers store
mustore.DefaultStore.Init(store.Table("auth"))
authH.Init(auth.Store(mustore.DefaultStore))
ruleH.Init(auth.Store(mustore.DefaultStore))
// register handlers
pb.RegisterAuthHandler(srv.Server(), authH)
pb.RegisterRulesHandler(srv.Server(), ruleH)
pb.RegisterAccountsHandler(srv.Server(), authH)
// run service
if err := srv.Run(); err != nil {
log.Fatal(err)
}
return nil
}