mirror of
https://github.com/zitadel/zitadel.git
synced 2025-07-15 23:28:36 +00:00

# Which Problems Are Solved The current maintained gRPC server in combination with a REST (grpc) gateway is getting harder and harder to maintain. Additionally, there have been and still are issues with supporting / displaying `oneOf`s correctly. We therefore decided to exchange the server implementation to connectRPC, which apart from supporting connect as protocol, also also "standard" gRCP clients as well as HTTP/1.1 / rest like clients, e.g. curl directly call the server without any additional gateway. # How the Problems Are Solved - All v2 services are moved to connectRPC implementation. (v1 services are still served as pure grpc servers) - All gRPC server interceptors were migrated / copied to a corresponding connectRPC interceptor. - API.ListGrpcServices and API. ListGrpcMethods were changed to include the connect services and endpoints. - gRPC server reflection was changed to a `StaticReflector` using the `ListGrpcServices` list. - The `grpc.Server` interfaces was split into different combinations to be able to handle the different cases (grpc server and prefixed gateway, connect server with grpc gateway, connect server only, ...) - Docs of services serving connectRPC only with no additional gateway (instance, webkey, project, app, org v2 beta) are changed to expose that - since the plugin is not yet available on buf, we download it using `postinstall` hook of the docs # Additional Changes - WebKey service is added as v2 service (in addition to the current v2beta) # Additional Context closes #9483 --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
170 lines
7.1 KiB
Go
170 lines
7.1 KiB
Go
package settings
|
|
|
|
import (
|
|
"context"
|
|
|
|
"connectrpc.com/connect"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
object "github.com/zitadel/zitadel/internal/api/grpc/object/v2beta"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/i18n"
|
|
"github.com/zitadel/zitadel/internal/query"
|
|
object_pb "github.com/zitadel/zitadel/pkg/grpc/object/v2beta"
|
|
settings "github.com/zitadel/zitadel/pkg/grpc/settings/v2beta"
|
|
)
|
|
|
|
func (s *Server) GetLoginSettings(ctx context.Context, req *connect.Request[settings.GetLoginSettingsRequest]) (*connect.Response[settings.GetLoginSettingsResponse], error) {
|
|
current, err := s.query.LoginPolicyByID(ctx, true, object.ResourceOwnerFromReq(ctx, req.Msg.GetCtx()), false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return connect.NewResponse(&settings.GetLoginSettingsResponse{
|
|
Settings: loginSettingsToPb(current),
|
|
Details: &object_pb.Details{
|
|
Sequence: current.Sequence,
|
|
CreationDate: timestamppb.New(current.CreationDate),
|
|
ChangeDate: timestamppb.New(current.ChangeDate),
|
|
ResourceOwner: current.OrgID,
|
|
},
|
|
}), nil
|
|
}
|
|
|
|
func (s *Server) GetPasswordComplexitySettings(ctx context.Context, req *connect.Request[settings.GetPasswordComplexitySettingsRequest]) (*connect.Response[settings.GetPasswordComplexitySettingsResponse], error) {
|
|
current, err := s.query.PasswordComplexityPolicyByOrg(ctx, true, object.ResourceOwnerFromReq(ctx, req.Msg.GetCtx()), false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return connect.NewResponse(&settings.GetPasswordComplexitySettingsResponse{
|
|
Settings: passwordComplexitySettingsToPb(current),
|
|
Details: &object_pb.Details{
|
|
Sequence: current.Sequence,
|
|
CreationDate: timestamppb.New(current.CreationDate),
|
|
ChangeDate: timestamppb.New(current.ChangeDate),
|
|
ResourceOwner: current.ResourceOwner,
|
|
},
|
|
}), nil
|
|
}
|
|
|
|
func (s *Server) GetPasswordExpirySettings(ctx context.Context, req *connect.Request[settings.GetPasswordExpirySettingsRequest]) (*connect.Response[settings.GetPasswordExpirySettingsResponse], error) {
|
|
current, err := s.query.PasswordAgePolicyByOrg(ctx, true, object.ResourceOwnerFromReq(ctx, req.Msg.GetCtx()), false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return connect.NewResponse(&settings.GetPasswordExpirySettingsResponse{
|
|
Settings: passwordExpirySettingsToPb(current),
|
|
Details: &object_pb.Details{
|
|
Sequence: current.Sequence,
|
|
CreationDate: timestamppb.New(current.CreationDate),
|
|
ChangeDate: timestamppb.New(current.ChangeDate),
|
|
ResourceOwner: current.ResourceOwner,
|
|
},
|
|
}), nil
|
|
}
|
|
|
|
func (s *Server) GetBrandingSettings(ctx context.Context, req *connect.Request[settings.GetBrandingSettingsRequest]) (*connect.Response[settings.GetBrandingSettingsResponse], error) {
|
|
current, err := s.query.ActiveLabelPolicyByOrg(ctx, object.ResourceOwnerFromReq(ctx, req.Msg.GetCtx()), false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return connect.NewResponse(&settings.GetBrandingSettingsResponse{
|
|
Settings: brandingSettingsToPb(current, s.assetsAPIDomain(ctx)),
|
|
Details: &object_pb.Details{
|
|
Sequence: current.Sequence,
|
|
CreationDate: timestamppb.New(current.CreationDate),
|
|
ChangeDate: timestamppb.New(current.ChangeDate),
|
|
ResourceOwner: current.ResourceOwner,
|
|
},
|
|
}), nil
|
|
}
|
|
|
|
func (s *Server) GetDomainSettings(ctx context.Context, req *connect.Request[settings.GetDomainSettingsRequest]) (*connect.Response[settings.GetDomainSettingsResponse], error) {
|
|
current, err := s.query.DomainPolicyByOrg(ctx, true, object.ResourceOwnerFromReq(ctx, req.Msg.GetCtx()), false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return connect.NewResponse(&settings.GetDomainSettingsResponse{
|
|
Settings: domainSettingsToPb(current),
|
|
Details: &object_pb.Details{
|
|
Sequence: current.Sequence,
|
|
CreationDate: timestamppb.New(current.CreationDate),
|
|
ChangeDate: timestamppb.New(current.ChangeDate),
|
|
ResourceOwner: current.ResourceOwner,
|
|
},
|
|
}), nil
|
|
}
|
|
|
|
func (s *Server) GetLegalAndSupportSettings(ctx context.Context, req *connect.Request[settings.GetLegalAndSupportSettingsRequest]) (*connect.Response[settings.GetLegalAndSupportSettingsResponse], error) {
|
|
current, err := s.query.PrivacyPolicyByOrg(ctx, true, object.ResourceOwnerFromReq(ctx, req.Msg.GetCtx()), false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return connect.NewResponse(&settings.GetLegalAndSupportSettingsResponse{
|
|
Settings: legalAndSupportSettingsToPb(current),
|
|
Details: &object_pb.Details{
|
|
Sequence: current.Sequence,
|
|
CreationDate: timestamppb.New(current.CreationDate),
|
|
ChangeDate: timestamppb.New(current.ChangeDate),
|
|
ResourceOwner: current.ResourceOwner,
|
|
},
|
|
}), nil
|
|
}
|
|
|
|
func (s *Server) GetLockoutSettings(ctx context.Context, req *connect.Request[settings.GetLockoutSettingsRequest]) (*connect.Response[settings.GetLockoutSettingsResponse], error) {
|
|
current, err := s.query.LockoutPolicyByOrg(ctx, true, object.ResourceOwnerFromReq(ctx, req.Msg.GetCtx()))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return connect.NewResponse(&settings.GetLockoutSettingsResponse{
|
|
Settings: lockoutSettingsToPb(current),
|
|
Details: &object_pb.Details{
|
|
Sequence: current.Sequence,
|
|
CreationDate: timestamppb.New(current.CreationDate),
|
|
ChangeDate: timestamppb.New(current.ChangeDate),
|
|
ResourceOwner: current.ResourceOwner,
|
|
},
|
|
}), nil
|
|
}
|
|
|
|
func (s *Server) GetActiveIdentityProviders(ctx context.Context, req *connect.Request[settings.GetActiveIdentityProvidersRequest]) (*connect.Response[settings.GetActiveIdentityProvidersResponse], error) {
|
|
links, err := s.query.IDPLoginPolicyLinks(ctx, object.ResourceOwnerFromReq(ctx, req.Msg.GetCtx()), &query.IDPLoginPolicyLinksSearchQuery{}, false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return connect.NewResponse(&settings.GetActiveIdentityProvidersResponse{
|
|
Details: object.ToListDetails(links.SearchResponse),
|
|
IdentityProviders: identityProvidersToPb(links.Links),
|
|
}), nil
|
|
}
|
|
|
|
func (s *Server) GetGeneralSettings(ctx context.Context, _ *connect.Request[settings.GetGeneralSettingsRequest]) (*connect.Response[settings.GetGeneralSettingsResponse], error) {
|
|
instance := authz.GetInstance(ctx)
|
|
return connect.NewResponse(&settings.GetGeneralSettingsResponse{
|
|
SupportedLanguages: domain.LanguagesToStrings(i18n.SupportedLanguages()),
|
|
DefaultOrgId: instance.DefaultOrganisationID(),
|
|
DefaultLanguage: instance.DefaultLanguage().String(),
|
|
}), nil
|
|
}
|
|
|
|
func (s *Server) GetSecuritySettings(ctx context.Context, req *connect.Request[settings.GetSecuritySettingsRequest]) (*connect.Response[settings.GetSecuritySettingsResponse], error) {
|
|
policy, err := s.query.SecurityPolicy(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return connect.NewResponse(&settings.GetSecuritySettingsResponse{
|
|
Settings: securityPolicyToSettingsPb(policy),
|
|
}), nil
|
|
}
|
|
|
|
func (s *Server) SetSecuritySettings(ctx context.Context, req *connect.Request[settings.SetSecuritySettingsRequest]) (*connect.Response[settings.SetSecuritySettingsResponse], error) {
|
|
details, err := s.command.SetSecurityPolicy(ctx, securitySettingsToCommand(req.Msg))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return connect.NewResponse(&settings.SetSecuritySettingsResponse{
|
|
Details: object.DomainToDetailsPb(details),
|
|
}), nil
|
|
}
|