forked from zitadel/zitadel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
79 lines (66 loc) · 2.07 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package management
import (
"context"
"time"
"google.golang.org/grpc"
"github.com/dennigogo/zitadel/internal/api/assets"
"github.com/dennigogo/zitadel/internal/api/authz"
"github.com/dennigogo/zitadel/internal/api/grpc/server"
"github.com/dennigogo/zitadel/internal/command"
"github.com/dennigogo/zitadel/internal/config/systemdefaults"
"github.com/dennigogo/zitadel/internal/crypto"
"github.com/dennigogo/zitadel/internal/query"
"github.com/dennigogo/zitadel/pkg/grpc/management"
)
const (
mgmtName = "Management-API"
)
var _ management.ManagementServiceServer = (*Server)(nil)
type Server struct {
management.UnimplementedManagementServiceServer
command *command.Commands
query *query.Queries
systemDefaults systemdefaults.SystemDefaults
assetAPIPrefix func(context.Context) string
passwordHashAlg crypto.HashAlgorithm
userCodeAlg crypto.EncryptionAlgorithm
externalSecure bool
auditLogRetention time.Duration
}
func CreateServer(
command *command.Commands,
query *query.Queries,
sd systemdefaults.SystemDefaults,
userCodeAlg crypto.EncryptionAlgorithm,
externalSecure bool,
auditLogRetention time.Duration,
) *Server {
return &Server{
command: command,
query: query,
systemDefaults: sd,
assetAPIPrefix: assets.AssetAPI(externalSecure),
passwordHashAlg: crypto.NewBCrypt(sd.SecretGenerators.PasswordSaltCost),
userCodeAlg: userCodeAlg,
externalSecure: externalSecure,
auditLogRetention: auditLogRetention,
}
}
func (s *Server) RegisterServer(grpcServer *grpc.Server) {
management.RegisterManagementServiceServer(grpcServer, s)
}
func (s *Server) AppName() string {
return mgmtName
}
func (s *Server) MethodPrefix() string {
return management.ManagementService_MethodPrefix
}
func (s *Server) AuthMethods() authz.MethodMapping {
return management.ManagementService_AuthMethods
}
func (s *Server) RegisterGateway() server.GatewayFunc {
return management.RegisterManagementServiceHandlerFromEndpoint
}
func (s *Server) GatewayPathPrefix() string {
return "/management/v1"
}