diff --git a/internal/api/api.go b/internal/api/api.go index 1f1e798455..7de3ff62ba 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -90,6 +90,7 @@ func (a *API) healthHandler() http.Handler { handler := http.NewServeMux() handler.HandleFunc("/healthz", handleHealth) handler.HandleFunc("/ready", handleReadiness(checks)) + handler.HandleFunc("/validate", handleValidate(checks)) handler.HandleFunc("/clientID", a.handleClientID) return handler @@ -102,12 +103,23 @@ func handleHealth(w http.ResponseWriter, r *http.Request) { func handleReadiness(checks []ValidationFunction) func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - err := validate(r.Context(), checks) - if err == nil { + errors := validate(r.Context(), checks) + if len(errors) == 0 { http_util.MarshalJSON(w, "ok", nil, http.StatusOK) return } - http_util.MarshalJSON(w, nil, err, http.StatusPreconditionFailed) + http_util.MarshalJSON(w, nil, errors[0], http.StatusPreconditionFailed) + } +} + +func handleValidate(checks []ValidationFunction) func(w http.ResponseWriter, r *http.Request) { + return func(w http.ResponseWriter, r *http.Request) { + errors := validate(r.Context(), checks) + if len(errors) == 0 { + http_util.MarshalJSON(w, "ok", nil, http.StatusOK) + return + } + http_util.MarshalJSON(w, errors, nil, http.StatusOK) } } @@ -122,12 +134,13 @@ func (a *API) handleClientID(w http.ResponseWriter, r *http.Request) { type ValidationFunction func(ctx context.Context) error -func validate(ctx context.Context, validations []ValidationFunction) error { +func validate(ctx context.Context, validations []ValidationFunction) []error { + errors := make([]error, 0) for _, validation := range validations { if err := validation(ctx); err != nil { logging.Log("API-vf823").WithError(err).WithField("traceID", tracing.TraceIDFromCtx(ctx)).Error("validation failed") - return err + errors = append(errors, err) } } - return nil + return errors } diff --git a/internal/api/grpc/admin/probes.go b/internal/api/grpc/admin/probes.go index 91214a5884..632471bf2d 100644 --- a/internal/api/grpc/admin/probes.go +++ b/internal/api/grpc/admin/probes.go @@ -4,19 +4,8 @@ import ( "context" "github.com/golang/protobuf/ptypes/empty" - pb_struct "github.com/golang/protobuf/ptypes/struct" - - "github.com/caos/zitadel/internal/errors" ) func (s *Server) Healthz(_ context.Context, e *empty.Empty) (*empty.Empty, error) { return &empty.Empty{}, nil } - -func (s *Server) Ready(ctx context.Context, e *empty.Empty) (*empty.Empty, error) { - return &empty.Empty{}, s.repo.Health(ctx) -} - -func (s *Server) Validate(ctx context.Context, _ *empty.Empty) (*pb_struct.Struct, error) { - return nil, errors.ThrowUnimplemented(nil, "GRPC-98Gse", "Not implemented") -} diff --git a/internal/api/grpc/auth/probes.go b/internal/api/grpc/auth/probes.go index a98afa6c1a..dff417eb02 100644 --- a/internal/api/grpc/auth/probes.go +++ b/internal/api/grpc/auth/probes.go @@ -4,19 +4,8 @@ import ( "context" "github.com/golang/protobuf/ptypes/empty" - pb_struct "github.com/golang/protobuf/ptypes/struct" - - "github.com/caos/zitadel/internal/errors" ) func (s *Server) Healthz(_ context.Context, e *empty.Empty) (*empty.Empty, error) { - return nil, errors.ThrowUnimplemented(nil, "GRPC-bst5W", "Not implemented") -} - -func (s *Server) Ready(ctx context.Context, e *empty.Empty) (*empty.Empty, error) { - return nil, errors.ThrowUnimplemented(nil, "GRPC-or0vW", "Not implemented") -} - -func (s *Server) Validate(ctx context.Context, _ *empty.Empty) (*pb_struct.Struct, error) { - return nil, errors.ThrowUnimplemented(nil, "GRPC-lo6Eg", "Not implemented") + return &empty.Empty{}, nil } diff --git a/internal/api/grpc/management/probes.go b/internal/api/grpc/management/probes.go index 6f6e3173f5..f5217f2300 100644 --- a/internal/api/grpc/management/probes.go +++ b/internal/api/grpc/management/probes.go @@ -2,19 +2,9 @@ package management import ( "context" - "github.com/caos/zitadel/internal/errors" "github.com/golang/protobuf/ptypes/empty" - pb_struct "github.com/golang/protobuf/ptypes/struct" ) func (s *Server) Healthz(_ context.Context, e *empty.Empty) (*empty.Empty, error) { - return nil, errors.ThrowUnimplemented(nil, "GRPC-mkd3y", "Not implemented") -} - -func (s *Server) Ready(ctx context.Context, e *empty.Empty) (*empty.Empty, error) { - return nil, errors.ThrowUnimplemented(nil, "GRPC-pl6BM", "Not implemented") -} - -func (s *Server) Validate(ctx context.Context, _ *empty.Empty) (*pb_struct.Struct, error) { - return nil, errors.ThrowUnimplemented(nil, "GRPC-2wxF", "Not implemented") + return &empty.Empty{}, nil } diff --git a/pkg/grpc/admin/mock/admin.proto.mock.go b/pkg/grpc/admin/mock/admin.proto.mock.go index c2d9ed267e..4b7af79812 100644 --- a/pkg/grpc/admin/mock/admin.proto.mock.go +++ b/pkg/grpc/admin/mock/admin.proto.mock.go @@ -10,7 +10,6 @@ import ( gomock "github.com/golang/mock/gomock" grpc "google.golang.org/grpc" emptypb "google.golang.org/protobuf/types/known/emptypb" - structpb "google.golang.org/protobuf/types/known/structpb" reflect "reflect" ) @@ -577,26 +576,6 @@ func (mr *MockAdminServiceClientMockRecorder) ReactivateIdpConfig(arg0, arg1 int return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReactivateIdpConfig", reflect.TypeOf((*MockAdminServiceClient)(nil).ReactivateIdpConfig), varargs...) } -// Ready mocks base method -func (m *MockAdminServiceClient) Ready(arg0 context.Context, arg1 *emptypb.Empty, arg2 ...grpc.CallOption) (*emptypb.Empty, error) { - m.ctrl.T.Helper() - varargs := []interface{}{arg0, arg1} - for _, a := range arg2 { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Ready", varargs...) - ret0, _ := ret[0].(*emptypb.Empty) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Ready indicates an expected call of Ready -func (mr *MockAdminServiceClientMockRecorder) Ready(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0, arg1}, arg2...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ready", reflect.TypeOf((*MockAdminServiceClient)(nil).Ready), varargs...) -} - // RemoveFailedEvent mocks base method func (m *MockAdminServiceClient) RemoveFailedEvent(arg0 context.Context, arg1 *admin.FailedEventID, arg2 ...grpc.CallOption) (*emptypb.Empty, error) { m.ctrl.T.Helper() @@ -996,23 +975,3 @@ func (mr *MockAdminServiceClientMockRecorder) UpdateOrgIamPolicy(arg0, arg1 inte varargs := append([]interface{}{arg0, arg1}, arg2...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateOrgIamPolicy", reflect.TypeOf((*MockAdminServiceClient)(nil).UpdateOrgIamPolicy), varargs...) } - -// Validate mocks base method -func (m *MockAdminServiceClient) Validate(arg0 context.Context, arg1 *emptypb.Empty, arg2 ...grpc.CallOption) (*structpb.Struct, error) { - m.ctrl.T.Helper() - varargs := []interface{}{arg0, arg1} - for _, a := range arg2 { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Validate", varargs...) - ret0, _ := ret[0].(*structpb.Struct) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Validate indicates an expected call of Validate -func (mr *MockAdminServiceClientMockRecorder) Validate(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0, arg1}, arg2...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Validate", reflect.TypeOf((*MockAdminServiceClient)(nil).Validate), varargs...) -} diff --git a/pkg/grpc/admin/proto/admin.proto b/pkg/grpc/admin/proto/admin.proto index 8733f742ed..3e0b685a0c 100644 --- a/pkg/grpc/admin/proto/admin.proto +++ b/pkg/grpc/admin/proto/admin.proto @@ -4,7 +4,6 @@ syntax = "proto3"; import "google/api/annotations.proto"; import "google/protobuf/empty.proto"; import "google/protobuf/timestamp.proto"; -import "google/protobuf/struct.proto"; import "validate/validate.proto"; import "protoc-gen-swagger/options/annotations.proto"; import "authoption/options.proto"; @@ -43,19 +42,6 @@ service AdminService { }; } - // Ready returns status OK as soon as all dependent services are available - rpc Ready(google.protobuf.Empty) returns (google.protobuf.Empty) { - option (google.api.http) = { - get: "/ready" - }; - } - - rpc Validate(google.protobuf.Empty) returns (google.protobuf.Struct) { - option (google.api.http) = { - get: "/validate" - }; - } - //ORG rpc IsOrgUnique(UniqueOrgRequest) returns (UniqueOrgResponse) { option (google.api.http) = { diff --git a/pkg/grpc/auth/mock/auth.proto.mock.go b/pkg/grpc/auth/mock/auth.proto.mock.go index 0ea651809c..22f851fa4c 100644 --- a/pkg/grpc/auth/mock/auth.proto.mock.go +++ b/pkg/grpc/auth/mock/auth.proto.mock.go @@ -10,7 +10,6 @@ import ( gomock "github.com/golang/mock/gomock" grpc "google.golang.org/grpc" emptypb "google.golang.org/protobuf/types/known/emptypb" - structpb "google.golang.org/protobuf/types/known/structpb" reflect "reflect" ) @@ -377,26 +376,6 @@ func (mr *MockAuthServiceClientMockRecorder) Healthz(arg0, arg1 interface{}, arg return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Healthz", reflect.TypeOf((*MockAuthServiceClient)(nil).Healthz), varargs...) } -// Ready mocks base method -func (m *MockAuthServiceClient) Ready(arg0 context.Context, arg1 *emptypb.Empty, arg2 ...grpc.CallOption) (*emptypb.Empty, error) { - m.ctrl.T.Helper() - varargs := []interface{}{arg0, arg1} - for _, a := range arg2 { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Ready", varargs...) - ret0, _ := ret[0].(*emptypb.Empty) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Ready indicates an expected call of Ready -func (mr *MockAuthServiceClientMockRecorder) Ready(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0, arg1}, arg2...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ready", reflect.TypeOf((*MockAuthServiceClient)(nil).Ready), varargs...) -} - // RemoveMfaOTP mocks base method func (m *MockAuthServiceClient) RemoveMfaOTP(arg0 context.Context, arg1 *emptypb.Empty, arg2 ...grpc.CallOption) (*emptypb.Empty, error) { m.ctrl.T.Helper() @@ -597,26 +576,6 @@ func (mr *MockAuthServiceClientMockRecorder) UpdateMyUserProfile(arg0, arg1 inte return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateMyUserProfile", reflect.TypeOf((*MockAuthServiceClient)(nil).UpdateMyUserProfile), varargs...) } -// Validate mocks base method -func (m *MockAuthServiceClient) Validate(arg0 context.Context, arg1 *emptypb.Empty, arg2 ...grpc.CallOption) (*structpb.Struct, error) { - m.ctrl.T.Helper() - varargs := []interface{}{arg0, arg1} - for _, a := range arg2 { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Validate", varargs...) - ret0, _ := ret[0].(*structpb.Struct) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Validate indicates an expected call of Validate -func (mr *MockAuthServiceClientMockRecorder) Validate(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0, arg1}, arg2...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Validate", reflect.TypeOf((*MockAuthServiceClient)(nil).Validate), varargs...) -} - // VerifyMfaOTP mocks base method func (m *MockAuthServiceClient) VerifyMfaOTP(arg0 context.Context, arg1 *auth.VerifyMfaOtp, arg2 ...grpc.CallOption) (*emptypb.Empty, error) { m.ctrl.T.Helper() diff --git a/pkg/grpc/auth/proto/auth.proto b/pkg/grpc/auth/proto/auth.proto index c30c3f6e17..723a614f86 100644 --- a/pkg/grpc/auth/proto/auth.proto +++ b/pkg/grpc/auth/proto/auth.proto @@ -39,18 +39,6 @@ service AuthService { }; } - rpc Ready(google.protobuf.Empty) returns (google.protobuf.Empty) { - option (google.api.http) = { - get: "/ready" - }; - } - - rpc Validate(google.protobuf.Empty) returns (google.protobuf.Struct) { - option (google.api.http) = { - get: "/validate" - }; - } - // Authorization rpc GetMyUserSessions(google.protobuf.Empty) returns (UserSessionViews) { option (google.api.http) = { diff --git a/pkg/grpc/management/mock/management.proto.mock.go b/pkg/grpc/management/mock/management.proto.mock.go index 14f877f20c..b76d47eaf5 100644 --- a/pkg/grpc/management/mock/management.proto.mock.go +++ b/pkg/grpc/management/mock/management.proto.mock.go @@ -10,7 +10,6 @@ import ( gomock "github.com/golang/mock/gomock" grpc "google.golang.org/grpc" emptypb "google.golang.org/protobuf/types/known/emptypb" - structpb "google.golang.org/protobuf/types/known/structpb" reflect "reflect" ) @@ -1717,26 +1716,6 @@ func (mr *MockManagementServiceClientMockRecorder) ReactivateUserGrant(arg0, arg return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReactivateUserGrant", reflect.TypeOf((*MockManagementServiceClient)(nil).ReactivateUserGrant), varargs...) } -// Ready mocks base method -func (m *MockManagementServiceClient) Ready(arg0 context.Context, arg1 *emptypb.Empty, arg2 ...grpc.CallOption) (*emptypb.Empty, error) { - m.ctrl.T.Helper() - varargs := []interface{}{arg0, arg1} - for _, a := range arg2 { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Ready", varargs...) - ret0, _ := ret[0].(*emptypb.Empty) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Ready indicates an expected call of Ready -func (mr *MockManagementServiceClientMockRecorder) Ready(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0, arg1}, arg2...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ready", reflect.TypeOf((*MockManagementServiceClient)(nil).Ready), varargs...) -} - // RegenerateOIDCClientSecret mocks base method func (m *MockManagementServiceClient) RegenerateOIDCClientSecret(arg0 context.Context, arg1 *management.ApplicationID, arg2 ...grpc.CallOption) (*management.ClientSecret, error) { m.ctrl.T.Helper() @@ -2897,26 +2876,6 @@ func (mr *MockManagementServiceClientMockRecorder) UserGrantByID(arg0, arg1 inte return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UserGrantByID", reflect.TypeOf((*MockManagementServiceClient)(nil).UserGrantByID), varargs...) } -// Validate mocks base method -func (m *MockManagementServiceClient) Validate(arg0 context.Context, arg1 *emptypb.Empty, arg2 ...grpc.CallOption) (*structpb.Struct, error) { - m.ctrl.T.Helper() - varargs := []interface{}{arg0, arg1} - for _, a := range arg2 { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Validate", varargs...) - ret0, _ := ret[0].(*structpb.Struct) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Validate indicates an expected call of Validate -func (mr *MockManagementServiceClientMockRecorder) Validate(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0, arg1}, arg2...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Validate", reflect.TypeOf((*MockManagementServiceClient)(nil).Validate), varargs...) -} - // ValidateMyOrgDomain mocks base method func (m *MockManagementServiceClient) ValidateMyOrgDomain(arg0 context.Context, arg1 *management.ValidateOrgDomainRequest, arg2 ...grpc.CallOption) (*emptypb.Empty, error) { m.ctrl.T.Helper() diff --git a/pkg/grpc/management/proto/management.proto b/pkg/grpc/management/proto/management.proto index 19eac49b24..ceeece9f15 100644 --- a/pkg/grpc/management/proto/management.proto +++ b/pkg/grpc/management/proto/management.proto @@ -42,18 +42,6 @@ service ManagementService { }; } - rpc Ready(google.protobuf.Empty) returns (google.protobuf.Empty) { - option (google.api.http) = { - get: "/ready" - }; - } - - rpc Validate(google.protobuf.Empty) returns (google.protobuf.Struct) { - option (google.api.http) = { - get: "/validate" - }; - } - rpc GetZitadelDocs(google.protobuf.Empty) returns (ZitadelDocs) { option (google.api.http) = { get: "/zitadel/docs"