-
Notifications
You must be signed in to change notification settings - Fork 26
/
console.go
82 lines (71 loc) · 2.22 KB
/
console.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package app
import (
"context"
"fmt"
"strings"
builder "github.com/aserto-dev/service-host"
"github.com/aserto-dev/topaz/pkg/app/ui"
"github.com/aserto-dev/topaz/pkg/cc/config"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
)
type ConsoleService struct{}
const (
consoleService = "console"
)
func NewConsole() ServiceTypes {
return &ConsoleService{}
}
func (e *ConsoleService) AvailableServices() []string {
return []string{"console"}
}
func (e *ConsoleService) GetGRPCRegistrations(services ...string) builder.GRPCRegistrations {
return func(server *grpc.Server) {
}
}
func (e *ConsoleService) GetGatewayRegistration(services ...string) builder.HandlerRegistrations {
return func(ctx context.Context, mux *runtime.ServeMux, grpcEndpoint string, opts []grpc.DialOption) error {
return nil
}
}
func (e *ConsoleService) Cleanups() []func() {
return nil
}
func (e *ConsoleService) PrepareConfig(cfg *config.Config) *ui.ConsoleCfg {
authorizerURL := ""
if serviceConfig, ok := cfg.APIConfig.Services[authorizerService]; ok {
authorizerURL = getGatewayAddress(serviceConfig)
}
readerURL := ""
if serviceConfig, ok := cfg.APIConfig.Services[readerService]; ok {
readerURL = getGatewayAddress(serviceConfig)
}
if readerURL == "" {
host := strings.Split(cfg.DirectoryResolver.Address, ":")[0]
readerURL = fmt.Sprintf("https://%s", host)
}
writerURL := ""
if serviceConfig, ok := cfg.APIConfig.Services[writerService]; ok {
writerURL = getGatewayAddress(serviceConfig)
}
modelURL := ""
if serviceConfig, ok := cfg.APIConfig.Services[modelService]; ok {
modelURL = getGatewayAddress(serviceConfig)
}
return &ui.ConsoleCfg{
AsertoDirectoryURL: readerURL,
DirectoryAPIKey: cfg.DirectoryResolver.APIKey,
DirectoryTenantID: cfg.DirectoryResolver.TenantID,
AuthorizerServiceURL: authorizerURL,
AsertoDirectoryReaderURL: &readerURL,
AsertoDirectoryWriterURL: &writerURL,
AsertoDirectoryModelURL: &modelURL,
}
}
func getGatewayAddress(serviceConfig *builder.API) string {
if serviceConfig.Gateway.HTTP {
return fmt.Sprintf("http://%s", serviceConfig.Gateway.ListenAddress)
} else {
return fmt.Sprintf("https://%s", serviceConfig.Gateway.ListenAddress)
}
}