-
Notifications
You must be signed in to change notification settings - Fork 26
/
authorizer.go
60 lines (51 loc) · 1.58 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
56
57
58
59
60
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 authorizer service instance, responsible for managing
// the authorizer API, user directory instance 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, err := edgeServer.NewEdgeServer(
e.Configuration.Directory.EdgeConfig,
&e.Configuration.API.GRPC.Certs,
addr[0],
port,
e.Logger,
)
if err != nil {
return errors.Wrap(err, "failed to create edge directory server")
}
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
}