diff --git a/Makefile b/Makefile index 3de9f8a..504ea93 100644 --- a/Makefile +++ b/Makefile @@ -63,6 +63,13 @@ all: make config; make generate; +.PHONY: run +# run api locally +run: + ./bin/ciam-rebac -conf configs + + + # show help help: @echo '' diff --git a/README.md b/README.md index 8fd6153..362fba8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ -# Kratos Project Template +# Rebac Service + +## Build +`make build` + +## Run +`make run` ## Install Kratos ``` diff --git a/api/health/v1/health.pb.go b/api/health/v1/health.pb.go new file mode 100644 index 0000000..4f65418 --- /dev/null +++ b/api/health/v1/health.pb.go @@ -0,0 +1,310 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.32.0 +// protoc v3.19.4 +// source: health/v1/health.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetLivezRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *GetLivezRequest) Reset() { + *x = GetLivezRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_health_v1_health_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetLivezRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetLivezRequest) ProtoMessage() {} + +func (x *GetLivezRequest) ProtoReflect() protoreflect.Message { + mi := &file_health_v1_health_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetLivezRequest.ProtoReflect.Descriptor instead. +func (*GetLivezRequest) Descriptor() ([]byte, []int) { + return file_health_v1_health_proto_rawDescGZIP(), []int{0} +} + +type GetLivezReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *GetLivezReply) Reset() { + *x = GetLivezReply{} + if protoimpl.UnsafeEnabled { + mi := &file_health_v1_health_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetLivezReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetLivezReply) ProtoMessage() {} + +func (x *GetLivezReply) ProtoReflect() protoreflect.Message { + mi := &file_health_v1_health_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetLivezReply.ProtoReflect.Descriptor instead. +func (*GetLivezReply) Descriptor() ([]byte, []int) { + return file_health_v1_health_proto_rawDescGZIP(), []int{1} +} + +type GetReadyzRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *GetReadyzRequest) Reset() { + *x = GetReadyzRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_health_v1_health_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetReadyzRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetReadyzRequest) ProtoMessage() {} + +func (x *GetReadyzRequest) ProtoReflect() protoreflect.Message { + mi := &file_health_v1_health_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetReadyzRequest.ProtoReflect.Descriptor instead. +func (*GetReadyzRequest) Descriptor() ([]byte, []int) { + return file_health_v1_health_proto_rawDescGZIP(), []int{2} +} + +type GetReadyzReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *GetReadyzReply) Reset() { + *x = GetReadyzReply{} + if protoimpl.UnsafeEnabled { + mi := &file_health_v1_health_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetReadyzReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetReadyzReply) ProtoMessage() {} + +func (x *GetReadyzReply) ProtoReflect() protoreflect.Message { + mi := &file_health_v1_health_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetReadyzReply.ProtoReflect.Descriptor instead. +func (*GetReadyzReply) Descriptor() ([]byte, []int) { + return file_health_v1_health_proto_rawDescGZIP(), []int{3} +} + +var File_health_v1_health_proto protoreflect.FileDescriptor + +var file_health_v1_health_proto_rawDesc = []byte{ + 0x0a, 0x16, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x2f, 0x76, 0x31, 0x2f, 0x68, 0x65, 0x61, 0x6c, + 0x74, 0x68, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0d, 0x61, 0x70, 0x69, 0x2e, 0x68, 0x65, + 0x61, 0x6c, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x11, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x4c, 0x69, 0x76, 0x65, + 0x7a, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x0f, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x4c, + 0x69, 0x76, 0x65, 0x7a, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x12, 0x0a, 0x10, 0x47, 0x65, 0x74, + 0x52, 0x65, 0x61, 0x64, 0x79, 0x7a, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x10, 0x0a, + 0x0e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x61, 0x64, 0x79, 0x7a, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x32, + 0xc0, 0x01, 0x0a, 0x06, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x12, 0x58, 0x0a, 0x08, 0x47, 0x65, + 0x74, 0x4c, 0x69, 0x76, 0x65, 0x7a, 0x12, 0x1e, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x68, 0x65, 0x61, + 0x6c, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4c, 0x69, 0x76, 0x65, 0x7a, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x68, 0x65, 0x61, + 0x6c, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4c, 0x69, 0x76, 0x65, 0x7a, 0x52, + 0x65, 0x70, 0x6c, 0x79, 0x22, 0x0e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x08, 0x12, 0x06, 0x2f, 0x6c, + 0x69, 0x76, 0x65, 0x7a, 0x12, 0x5c, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x52, 0x65, 0x61, 0x64, 0x79, + 0x7a, 0x12, 0x1f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x2e, 0x76, + 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x61, 0x64, 0x79, 0x7a, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x2e, + 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x61, 0x64, 0x79, 0x7a, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x0f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x09, 0x12, 0x07, 0x2f, 0x72, 0x65, 0x61, 0x64, + 0x79, 0x7a, 0x42, 0x2e, 0x0a, 0x0d, 0x61, 0x70, 0x69, 0x2e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, + 0x2e, 0x76, 0x31, 0x50, 0x01, 0x5a, 0x1b, 0x63, 0x69, 0x61, 0x6d, 0x2d, 0x72, 0x65, 0x62, 0x61, + 0x63, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x2f, 0x76, 0x31, 0x3b, + 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_health_v1_health_proto_rawDescOnce sync.Once + file_health_v1_health_proto_rawDescData = file_health_v1_health_proto_rawDesc +) + +func file_health_v1_health_proto_rawDescGZIP() []byte { + file_health_v1_health_proto_rawDescOnce.Do(func() { + file_health_v1_health_proto_rawDescData = protoimpl.X.CompressGZIP(file_health_v1_health_proto_rawDescData) + }) + return file_health_v1_health_proto_rawDescData +} + +var file_health_v1_health_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_health_v1_health_proto_goTypes = []interface{}{ + (*GetLivezRequest)(nil), // 0: api.health.v1.GetLivezRequest + (*GetLivezReply)(nil), // 1: api.health.v1.GetLivezReply + (*GetReadyzRequest)(nil), // 2: api.health.v1.GetReadyzRequest + (*GetReadyzReply)(nil), // 3: api.health.v1.GetReadyzReply +} +var file_health_v1_health_proto_depIdxs = []int32{ + 0, // 0: api.health.v1.Health.GetLivez:input_type -> api.health.v1.GetLivezRequest + 2, // 1: api.health.v1.Health.GetReadyz:input_type -> api.health.v1.GetReadyzRequest + 1, // 2: api.health.v1.Health.GetLivez:output_type -> api.health.v1.GetLivezReply + 3, // 3: api.health.v1.Health.GetReadyz:output_type -> api.health.v1.GetReadyzReply + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_health_v1_health_proto_init() } +func file_health_v1_health_proto_init() { + if File_health_v1_health_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_health_v1_health_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetLivezRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_health_v1_health_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetLivezReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_health_v1_health_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetReadyzRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_health_v1_health_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetReadyzReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_health_v1_health_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_health_v1_health_proto_goTypes, + DependencyIndexes: file_health_v1_health_proto_depIdxs, + MessageInfos: file_health_v1_health_proto_msgTypes, + }.Build() + File_health_v1_health_proto = out.File + file_health_v1_health_proto_rawDesc = nil + file_health_v1_health_proto_goTypes = nil + file_health_v1_health_proto_depIdxs = nil +} diff --git a/api/health/v1/health.proto b/api/health/v1/health.proto new file mode 100644 index 0000000..6435dc0 --- /dev/null +++ b/api/health/v1/health.proto @@ -0,0 +1,28 @@ +syntax = "proto3"; + +package api.health.v1; + +import "google/api/annotations.proto"; + +option go_package = "ciam-rebac/api/health/v1;v1"; +option java_multiple_files = true; +option java_package = "api.health.v1"; + +service Health { + rpc GetLivez (GetLivezRequest) returns (GetLivezReply){ + option (google.api.http) = { + get: "/livez" + }; + }; + rpc GetReadyz (GetReadyzRequest) returns (GetReadyzReply){ + option (google.api.http) = { + get: "/readyz" + }; + }; +} + +message GetLivezRequest {} +message GetLivezReply {} + +message GetReadyzRequest {} +message GetReadyzReply {} diff --git a/api/health/v1/health_grpc.pb.go b/api/health/v1/health_grpc.pb.go new file mode 100644 index 0000000..c7fc2ac --- /dev/null +++ b/api/health/v1/health_grpc.pb.go @@ -0,0 +1,146 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v3.19.4 +// source: health/v1/health.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + Health_GetLivez_FullMethodName = "/api.health.v1.Health/GetLivez" + Health_GetReadyz_FullMethodName = "/api.health.v1.Health/GetReadyz" +) + +// HealthClient is the client API for Health service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type HealthClient interface { + GetLivez(ctx context.Context, in *GetLivezRequest, opts ...grpc.CallOption) (*GetLivezReply, error) + GetReadyz(ctx context.Context, in *GetReadyzRequest, opts ...grpc.CallOption) (*GetReadyzReply, error) +} + +type healthClient struct { + cc grpc.ClientConnInterface +} + +func NewHealthClient(cc grpc.ClientConnInterface) HealthClient { + return &healthClient{cc} +} + +func (c *healthClient) GetLivez(ctx context.Context, in *GetLivezRequest, opts ...grpc.CallOption) (*GetLivezReply, error) { + out := new(GetLivezReply) + err := c.cc.Invoke(ctx, Health_GetLivez_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *healthClient) GetReadyz(ctx context.Context, in *GetReadyzRequest, opts ...grpc.CallOption) (*GetReadyzReply, error) { + out := new(GetReadyzReply) + err := c.cc.Invoke(ctx, Health_GetReadyz_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// HealthServer is the server API for Health service. +// All implementations must embed UnimplementedHealthServer +// for forward compatibility +type HealthServer interface { + GetLivez(context.Context, *GetLivezRequest) (*GetLivezReply, error) + GetReadyz(context.Context, *GetReadyzRequest) (*GetReadyzReply, error) + mustEmbedUnimplementedHealthServer() +} + +// UnimplementedHealthServer must be embedded to have forward compatible implementations. +type UnimplementedHealthServer struct { +} + +func (UnimplementedHealthServer) GetLivez(context.Context, *GetLivezRequest) (*GetLivezReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetLivez not implemented") +} +func (UnimplementedHealthServer) GetReadyz(context.Context, *GetReadyzRequest) (*GetReadyzReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetReadyz not implemented") +} +func (UnimplementedHealthServer) mustEmbedUnimplementedHealthServer() {} + +// UnsafeHealthServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to HealthServer will +// result in compilation errors. +type UnsafeHealthServer interface { + mustEmbedUnimplementedHealthServer() +} + +func RegisterHealthServer(s grpc.ServiceRegistrar, srv HealthServer) { + s.RegisterService(&Health_ServiceDesc, srv) +} + +func _Health_GetLivez_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetLivezRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(HealthServer).GetLivez(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Health_GetLivez_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(HealthServer).GetLivez(ctx, req.(*GetLivezRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Health_GetReadyz_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetReadyzRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(HealthServer).GetReadyz(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Health_GetReadyz_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(HealthServer).GetReadyz(ctx, req.(*GetReadyzRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Health_ServiceDesc is the grpc.ServiceDesc for Health service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Health_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "api.health.v1.Health", + HandlerType: (*HealthServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetLivez", + Handler: _Health_GetLivez_Handler, + }, + { + MethodName: "GetReadyz", + Handler: _Health_GetReadyz_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "health/v1/health.proto", +} diff --git a/api/health/v1/health_http.pb.go b/api/health/v1/health_http.pb.go new file mode 100644 index 0000000..a7f4c68 --- /dev/null +++ b/api/health/v1/health_http.pb.go @@ -0,0 +1,111 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.2 +// - protoc v3.19.4 +// source: health/v1/health.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationHealthGetLivez = "/api.health.v1.Health/GetLivez" +const OperationHealthGetReadyz = "/api.health.v1.Health/GetReadyz" + +type HealthHTTPServer interface { + GetLivez(context.Context, *GetLivezRequest) (*GetLivezReply, error) + GetReadyz(context.Context, *GetReadyzRequest) (*GetReadyzReply, error) +} + +func RegisterHealthHTTPServer(s *http.Server, srv HealthHTTPServer) { + r := s.Route("/") + r.GET("/livez", _Health_GetLivez0_HTTP_Handler(srv)) + r.GET("/readyz", _Health_GetReadyz0_HTTP_Handler(srv)) +} + +func _Health_GetLivez0_HTTP_Handler(srv HealthHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetLivezRequest + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationHealthGetLivez) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetLivez(ctx, req.(*GetLivezRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetLivezReply) + return ctx.Result(200, reply) + } +} + +func _Health_GetReadyz0_HTTP_Handler(srv HealthHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetReadyzRequest + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationHealthGetReadyz) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetReadyz(ctx, req.(*GetReadyzRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetReadyzReply) + return ctx.Result(200, reply) + } +} + +type HealthHTTPClient interface { + GetLivez(ctx context.Context, req *GetLivezRequest, opts ...http.CallOption) (rsp *GetLivezReply, err error) + GetReadyz(ctx context.Context, req *GetReadyzRequest, opts ...http.CallOption) (rsp *GetReadyzReply, err error) +} + +type HealthHTTPClientImpl struct { + cc *http.Client +} + +func NewHealthHTTPClient(client *http.Client) HealthHTTPClient { + return &HealthHTTPClientImpl{client} +} + +func (c *HealthHTTPClientImpl) GetLivez(ctx context.Context, in *GetLivezRequest, opts ...http.CallOption) (*GetLivezReply, error) { + var out GetLivezReply + pattern := "/livez" + path := binding.EncodeURL(pattern, in, true) + opts = append(opts, http.Operation(OperationHealthGetLivez)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) + if err != nil { + return nil, err + } + return &out, err +} + +func (c *HealthHTTPClientImpl) GetReadyz(ctx context.Context, in *GetReadyzRequest, opts ...http.CallOption) (*GetReadyzReply, error) { + var out GetReadyzReply + pattern := "/readyz" + path := binding.EncodeURL(pattern, in, true) + opts = append(opts, http.Operation(OperationHealthGetReadyz)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) + if err != nil { + return nil, err + } + return &out, err +} diff --git a/api/rebac/v1/relationships.pb.go b/api/rebac/v1/relationships.pb.go index c9c12a7..7c2e4c4 100644 --- a/api/rebac/v1/relationships.pb.go +++ b/api/rebac/v1/relationships.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.32.0 -// protoc v3.12.4 +// protoc v3.19.4 // source: rebac/v1/relationships.proto package v1 diff --git a/api/rebac/v1/relationships_grpc.pb.go b/api/rebac/v1/relationships_grpc.pb.go index e01246c..4c0ff35 100644 --- a/api/rebac/v1/relationships_grpc.pb.go +++ b/api/rebac/v1/relationships_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v3.12.4 +// - protoc v3.19.4 // source: rebac/v1/relationships.proto package v1 diff --git a/api/rebac/v1/relationships_http.pb.go b/api/rebac/v1/relationships_http.pb.go index b5d88a9..cdcc0e1 100644 --- a/api/rebac/v1/relationships_http.pb.go +++ b/api/rebac/v1/relationships_http.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-http. DO NOT EDIT. // versions: // - protoc-gen-go-http v2.7.2 -// - protoc v3.12.4 +// - protoc v3.19.4 // source: rebac/v1/relationships.proto package v1 diff --git a/cmd/ciam-rebac/main.go b/cmd/ciam-rebac/main.go index d1e6343..bc0222b 100644 --- a/cmd/ciam-rebac/main.go +++ b/cmd/ciam-rebac/main.go @@ -30,7 +30,7 @@ var ( ) func init() { - flag.StringVar(&flagconf, "conf", "../configs", "config path, eg: -conf config.yaml") + flag.StringVar(&flagconf, "conf", "../../configs", "config path, eg: -conf config.yaml") } func newApp(logger log.Logger, gs *grpc.Server, hs *http.Server) *kratos.App { diff --git a/cmd/ciam-rebac/wire_gen.go b/cmd/ciam-rebac/wire_gen.go index 562561f..14d1ff0 100644 --- a/cmd/ciam-rebac/wire_gen.go +++ b/cmd/ciam-rebac/wire_gen.go @@ -23,8 +23,9 @@ import ( // wireApp init kratos application. func wireApp(confServer *conf.Server, data *conf.Data, logger log.Logger) (*kratos.App, func(), error) { relationshipsService := service.NewRelationshipsService(logger) - grpcServer := server.NewGRPCServer(confServer, relationshipsService, logger) - httpServer := server.NewHTTPServer(confServer, relationshipsService, logger) + healthService := service.NewHealthService() + grpcServer := server.NewGRPCServer(confServer, relationshipsService, healthService, logger) + httpServer := server.NewHTTPServer(confServer, relationshipsService, healthService, logger) app := newApp(logger, grpcServer, httpServer) return app, func() { }, nil diff --git a/go.mod b/go.mod index becc3ca..8a68427 100644 --- a/go.mod +++ b/go.mod @@ -18,17 +18,21 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/go-playground/form/v4 v4.2.0 // indirect github.com/golang/protobuf v1.5.3 // indirect + github.com/google/subcommands v1.0.1 // indirect github.com/google/uuid v1.4.0 // indirect github.com/gorilla/mux v1.8.0 // indirect github.com/imdario/mergo v0.3.16 // indirect github.com/kr/text v0.2.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect go.opentelemetry.io/otel v1.16.0 // indirect go.opentelemetry.io/otel/metric v1.16.0 // indirect go.opentelemetry.io/otel/trace v1.16.0 // indirect + golang.org/x/mod v0.8.0 // indirect golang.org/x/net v0.18.0 // indirect golang.org/x/sync v0.5.0 // indirect golang.org/x/sys v0.14.0 // indirect golang.org/x/text v0.14.0 // indirect + golang.org/x/tools v0.6.0 // indirect google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 7baf860..6fe8a72 100644 --- a/go.sum +++ b/go.sum @@ -25,6 +25,7 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/subcommands v1.0.1 h1:/eqq+otEXm5vhfBrbREPCSVQbvofip6kIz+mX5TUH7k= github.com/google/subcommands v1.0.1/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -52,6 +53,8 @@ go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLk go.uber.org/automaxprocs v1.5.3 h1:kWazyxZUrS3Gs4qUpbwo5kEIMGe/DAvi5Z4tl2NW4j8= go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= @@ -65,6 +68,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 h1:wpZ8pe2x1Q3f2KyT5f8oP/fa9rHAKgFPr/HZdNuS+PQ= google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:J7XzRzVy1+IPwWHZUzoD0IccYZIrXILAQpc+Qy9CMhY= diff --git a/internal/conf/conf.pb.go b/internal/conf/conf.pb.go index 7cdf0a2..a4a5936 100644 --- a/internal/conf/conf.pb.go +++ b/internal/conf/conf.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.32.0 -// protoc v3.12.4 +// protoc v3.19.4 // source: conf/conf.proto package conf diff --git a/internal/server/grpc.go b/internal/server/grpc.go index 40cabdd..855edee 100644 --- a/internal/server/grpc.go +++ b/internal/server/grpc.go @@ -1,6 +1,7 @@ package server import ( + h "ciam-rebac/api/health/v1" v1 "ciam-rebac/api/rebac/v1" "ciam-rebac/internal/conf" "ciam-rebac/internal/service" @@ -11,7 +12,7 @@ import ( ) // NewGRPCServer new a gRPC server. -func NewGRPCServer(c *conf.Server, relations *service.RelationshipsService, logger log.Logger) *grpc.Server { +func NewGRPCServer(c *conf.Server, relations *service.RelationshipsService, health *service.HealthService, logger log.Logger) *grpc.Server { var opts = []grpc.ServerOption{ grpc.Middleware( recovery.Recovery(), @@ -28,5 +29,6 @@ func NewGRPCServer(c *conf.Server, relations *service.RelationshipsService, logg } srv := grpc.NewServer(opts...) v1.RegisterRelationshipsServer(srv, relations) + h.RegisterHealthServer(srv, health) return srv } diff --git a/internal/server/http.go b/internal/server/http.go index d05d1fa..1e6428b 100644 --- a/internal/server/http.go +++ b/internal/server/http.go @@ -1,6 +1,7 @@ package server import ( + h "ciam-rebac/api/health/v1" v1 "ciam-rebac/api/rebac/v1" "ciam-rebac/internal/conf" "ciam-rebac/internal/service" @@ -11,7 +12,7 @@ import ( ) // NewHTTPServer new an HTTP server. -func NewHTTPServer(c *conf.Server, relationships *service.RelationshipsService, logger log.Logger) *http.Server { +func NewHTTPServer(c *conf.Server, relationships *service.RelationshipsService, health *service.HealthService, logger log.Logger) *http.Server { var opts = []http.ServerOption{ http.Middleware( recovery.Recovery(), @@ -29,5 +30,6 @@ func NewHTTPServer(c *conf.Server, relationships *service.RelationshipsService, srv := http.NewServer(opts...) v1.RegisterRelationshipsHTTPServer(srv, relationships) + h.RegisterHealthHTTPServer(srv, health) return srv } diff --git a/internal/service/health.go b/internal/service/health.go new file mode 100644 index 0000000..3fe27bd --- /dev/null +++ b/internal/service/health.go @@ -0,0 +1,22 @@ +package service + +import ( + "context" + + pb "ciam-rebac/api/health/v1" +) + +type HealthService struct { + pb.UnimplementedHealthServer +} + +func NewHealthService() *HealthService { + return &HealthService{} +} + +func (s *HealthService) GetLivez(ctx context.Context, req *pb.GetLivezRequest) (*pb.GetLivezReply, error) { + return &pb.GetLivezReply{}, nil +} +func (s *HealthService) GetReadyz(ctx context.Context, req *pb.GetReadyzRequest) (*pb.GetReadyzReply, error) { + return &pb.GetReadyzReply{}, nil +} diff --git a/internal/service/service.go b/internal/service/service.go index d3f15fb..5f7cfe2 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -3,4 +3,4 @@ package service import "github.com/google/wire" // ProviderSet is service providers. -var ProviderSet = wire.NewSet(NewRelationshipsService) +var ProviderSet = wire.NewSet(NewRelationshipsService, NewHealthService) diff --git a/openapi.yaml b/openapi.yaml index 667397c..e45692e 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -3,9 +3,33 @@ openapi: 3.0.3 info: - title: Relationships API + title: "" version: 0.0.1 paths: + /livez: + get: + tags: + - Health + operationId: Health_GetLivez + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/api.health.v1.GetLivezReply' + /readyz: + get: + tags: + - Health + operationId: Health_GetReadyz + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/api.health.v1.GetReadyzReply' /relationships: get: tags: @@ -98,6 +122,12 @@ paths: $ref: '#/components/schemas/api.rebac.v1.DeleteRelationshipsResponse' components: schemas: + api.health.v1.GetLivezReply: + type: object + properties: {} + api.health.v1.GetReadyzReply: + type: object + properties: {} api.rebac.v1.CreateRelationshipsRequest: type: object properties: @@ -144,4 +174,5 @@ components: object: $ref: '#/components/schemas/api.rebac.v1.ObjectReference' tags: + - name: Health - name: Relationships