2020-03-24 09:14:39 +00:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
2020-04-07 11:23:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/api/auth"
|
2020-03-25 10:17:38 +00:00
|
|
|
grpc_util "github.com/caos/zitadel/internal/api/grpc"
|
2020-03-24 15:16:05 +00:00
|
|
|
"github.com/caos/zitadel/internal/api/grpc/server/middleware"
|
2020-06-05 05:50:04 +00:00
|
|
|
authz_repo "github.com/caos/zitadel/internal/authz/repository/eventsourcing"
|
2020-06-09 12:41:09 +00:00
|
|
|
"github.com/caos/zitadel/internal/config/systemdefaults"
|
2020-04-07 11:23:04 +00:00
|
|
|
mgmt_auth "github.com/caos/zitadel/internal/management/auth"
|
|
|
|
"github.com/caos/zitadel/internal/management/repository"
|
2020-03-24 10:20:45 +00:00
|
|
|
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
2020-03-24 09:14:39 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ ManagementServiceServer = (*Server)(nil)
|
|
|
|
|
|
|
|
type Server struct {
|
2020-06-09 12:41:09 +00:00
|
|
|
port string
|
|
|
|
project repository.ProjectRepository
|
|
|
|
policy repository.PolicyRepository
|
|
|
|
org repository.OrgRepository
|
|
|
|
user repository.UserRepository
|
|
|
|
usergrant repository.UserGrantRepository
|
|
|
|
iam repository.IamRepository
|
|
|
|
verifier *mgmt_auth.TokenVerifier
|
|
|
|
authZ auth.Config
|
|
|
|
systemDefaults systemdefaults.SystemDefaults
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-06-09 12:41:09 +00:00
|
|
|
func StartServer(conf grpc_util.ServerConfig, authZRepo *authz_repo.EsRepository, authZ auth.Config, sd systemdefaults.SystemDefaults, repo repository.Repository) *Server {
|
2020-03-24 09:14:39 +00:00
|
|
|
return &Server{
|
2020-06-09 12:41:09 +00:00
|
|
|
port: conf.Port,
|
|
|
|
project: repo,
|
|
|
|
policy: repo,
|
|
|
|
org: repo,
|
|
|
|
user: repo,
|
|
|
|
usergrant: repo,
|
|
|
|
iam: repo,
|
|
|
|
authZ: authZ,
|
|
|
|
verifier: mgmt_auth.Start(authZRepo),
|
|
|
|
systemDefaults: sd,
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) GRPCPort() string {
|
|
|
|
return s.port
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) GRPCServer() (*grpc.Server, error) {
|
2020-03-24 10:20:45 +00:00
|
|
|
gs := grpc.NewServer(
|
2020-03-24 15:16:05 +00:00
|
|
|
middleware.TracingStatsServer("/Healthz", "/Ready", "/Validate"),
|
2020-03-24 10:20:45 +00:00
|
|
|
grpc.UnaryInterceptor(
|
|
|
|
grpc_middleware.ChainUnaryServer(
|
2020-03-24 15:16:05 +00:00
|
|
|
middleware.ErrorHandler(),
|
2020-04-07 11:23:04 +00:00
|
|
|
ManagementService_Authorization_Interceptor(s.verifier, &s.authZ),
|
2020-03-24 10:20:45 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
2020-03-24 09:14:39 +00:00
|
|
|
RegisterManagementServiceServer(gs, s)
|
|
|
|
return gs, nil
|
|
|
|
}
|