mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 19:44:21 +00:00
3549a8b64e
* move mgmt pkg * begin package restructure * rename auth package to authz * begin start api * move auth * move admin * fix merge * configs and interceptors * interceptor * revert generate-grpc.sh * some cleanups * console * move console * fix tests and merging * js linting * merge * merging and configs * change k8s base to current ports * fixes * cleanup * regenerate proto * remove unnecessary whitespace * missing param * go mod tidy * fix merging * move login pkg * cleanup * move api pkgs again * fix pkg naming * fix generate-static.sh for login * update workflow * fixes * logging * remove duplicate * comment for optional gateway interfaces * regenerate protos * fix proto imports for grpc web * protos * grpc web generate * grpc web generate * fix changes * add translation interceptor * fix merging * regenerate mgmt proto
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/caos/logging"
|
|
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
|
"golang.org/x/text/language"
|
|
"google.golang.org/grpc"
|
|
|
|
"github.com/caos/zitadel/internal/api/authz"
|
|
"github.com/caos/zitadel/internal/api/grpc/server/middleware"
|
|
"github.com/caos/zitadel/internal/api/http"
|
|
)
|
|
|
|
const (
|
|
defaultGrpcPort = "80"
|
|
)
|
|
|
|
type Server interface {
|
|
Gateway
|
|
RegisterServer(*grpc.Server)
|
|
AppName() string
|
|
MethodPrefix() string
|
|
AuthMethods() authz.MethodMapping
|
|
}
|
|
|
|
func CreateServer(verifier *authz.TokenVerifier, authConfig authz.Config, lang language.Tag) *grpc.Server {
|
|
return grpc.NewServer(
|
|
middleware.TracingStatsServer(http.Healthz, http.Readiness, http.Validation),
|
|
grpc.UnaryInterceptor(
|
|
grpc_middleware.ChainUnaryServer(
|
|
middleware.ErrorHandler(lang),
|
|
middleware.TranslationHandler(lang),
|
|
grpc_middleware.ChainUnaryServer(
|
|
middleware.AuthorizationInterceptor(verifier, authConfig),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
}
|
|
|
|
func Serve(ctx context.Context, server *grpc.Server, port string) {
|
|
go func() {
|
|
<-ctx.Done()
|
|
server.GracefulStop()
|
|
}()
|
|
|
|
go func() {
|
|
listener := http.CreateListener(port)
|
|
err := server.Serve(listener)
|
|
logging.Log("SERVE-Ga3e94").OnError(err).Panic("grpc server serve failed")
|
|
}()
|
|
logging.LogWithFields("SERVE-bZ44QM", "port", port).Info("grpc server is listening")
|
|
}
|
|
|
|
func grpcPort(port string) string {
|
|
if port == "" {
|
|
return defaultGrpcPort
|
|
}
|
|
return port
|
|
}
|