-
Notifications
You must be signed in to change notification settings - Fork 25
/
authorizer.go
55 lines (49 loc) · 1.49 KB
/
authorizer.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
package app
import (
"context"
"strconv"
"strings"
edgeServer "github.com/aserto-dev/go-edge-ds/pkg/server"
"github.com/aserto-dev/topaz/pkg/app/server"
"github.com/aserto-dev/topaz/pkg/cc/config"
"github.com/aserto-dev/topaz/resolvers"
"github.com/pkg/errors"
"github.com/rs/zerolog"
)
// Authorizer is an Aserto Edge Authorizer instance
// It's responsible with managing the Aserto Edge API, the User Directory
// and the OPA plugins
type Authorizer struct {
Context context.Context
Logger *zerolog.Logger
Configuration *config.Config
Server *server.Server
Resolver *resolvers.Resolvers
}
// Start starts all services required by the Engine
func (e *Authorizer) Start() error {
if (strings.Contains(e.Configuration.Directory.Remote.Addr, "localhost") || strings.Contains(e.Configuration.Directory.Remote.Addr, "0.0.0.0")) &&
e.Configuration.Directory.EdgeConfig.DBPath != "" {
addr := strings.Split(e.Configuration.Directory.Remote.Addr, ":")
if len(addr) != 2 {
return errors.Errorf("invalid remote address - should contain <host>:<port>")
}
port, err := strconv.Atoi(addr[1])
if err != nil {
return err
}
edge := edgeServer.NewEdgeServer(
e.Configuration.Directory.EdgeConfig,
&e.Configuration.API.GRPC.Certs,
addr[0],
port,
e.Logger,
)
e.Server.RegisterServer("edgeDirServer", edge.Start, edge.Stop)
}
err := e.Server.Start(e.Context)
if err != nil {
return errors.Wrap(err, "failed to start engine server")
}
return nil
}