From 6cfa7c4396534980328f18a53cb4e60b9e74c581 Mon Sep 17 00:00:00 2001 From: Aleksandr Tarasov Date: Wed, 6 Dec 2023 18:00:47 +0300 Subject: [PATCH] add metadata retrive method (#20) --- api/pbuf-registry/v1/entities.proto | 124 +++ api/pbuf-registry/v1/metadata.proto | 31 + cmd/main.go | 6 +- docker-compose.yml | 6 +- gen/pbuf-registry/v1/entities.pb.go | 878 ++++++++++++++++++++- gen/pbuf-registry/v1/metadata.pb.go | 240 ++++++ gen/pbuf-registry/v1/metadata.swagger.json | 334 ++++++++ gen/pbuf-registry/v1/metadata_grpc.pb.go | 109 +++ gen/pbuf-registry/v1/metadata_http.pb.go | 78 ++ internal/data/metadata.go | 40 + internal/mocks/metadata_repository.go | 30 + internal/server/grpc.go | 7 +- internal/server/http.go | 7 +- internal/server/metadata.go | 62 ++ internal/utils/metadata.go | 172 ++++ internal/utils/metadata_test.go | 85 ++ 16 files changed, 2189 insertions(+), 20 deletions(-) create mode 100644 api/pbuf-registry/v1/metadata.proto create mode 100644 gen/pbuf-registry/v1/metadata.pb.go create mode 100644 gen/pbuf-registry/v1/metadata.swagger.json create mode 100644 gen/pbuf-registry/v1/metadata_grpc.pb.go create mode 100644 gen/pbuf-registry/v1/metadata_http.pb.go create mode 100644 internal/server/metadata.go create mode 100644 internal/utils/metadata.go create mode 100644 internal/utils/metadata_test.go diff --git a/api/pbuf-registry/v1/entities.proto b/api/pbuf-registry/v1/entities.proto index 31d1bfb..8f1f2ab 100644 --- a/api/pbuf-registry/v1/entities.proto +++ b/api/pbuf-registry/v1/entities.proto @@ -38,4 +38,128 @@ message Dependency { // The tag of the dependency. string tag = 2; +} + +// Package is a proto file package used in a module +message Package { + // The name of the package. + string name = 1; + + // The proto files of the package. + repeated ParsedProtoFile proto_files = 2; + + // The dependencies of the package. + repeated PackageDependency dependencies = 3; +} + +// ParsedProtoFile is a proto file parsed by the registry +// contains information about messages and services in the proto file +message ParsedProtoFile { + // The filename of the proto file. + string filename = 1; + + // The messages in the proto file. + repeated Message messages = 2; + + // The services in the proto file. + repeated Service services = 3; +} + +// Message is a message in a proto file. +message Message { + // The name of the message. + string name = 1; + + // The fields of the message. + repeated Field fields = 2; + + // The nested messages of the message. + repeated Message nested_messages = 3; + + // The nested enums of the message. + repeated Enum nested_enums = 4; +} + +// Field is a field in a message. +message Field { + // The name of the field. + string name = 1; + + // The message_type of the field. + string message_type = 2; + + // The tag of the field. + int32 tag = 3; + + // The repeated flag of the field. + bool repeated = 4; + + // The map flag of the field. + bool map = 5; + + // The oneof flag of the field. + bool oneof = 6; + + // The optional flag of the field. + bool optional = 7; + + // The required flag of the field. + bool required = 8; + + // The one of names of the field + repeated string oneof_names = 9; + + // The one of types of the field + repeated string oneof_types = 10; + + // The map key type of the field. + string map_key_type = 11; + + // The map value type of the field. + string map_value_type = 12; +} + +// Enum is an enum in a proto file. +message Enum { + // The name of the enum. + string name = 1; + + // The values of the enum. + repeated EnumValue values = 2; +} + +// EnumValue is a value in an enum. +message EnumValue { + // The name of the value. + string name = 1; + + // The tag of the value. + int32 tag = 2; +} + +// Service is a service in a proto file. +message Service { + // The name of the service. + string name = 1; + + // The methods of the service. + repeated Method methods = 2; +} + +// Method is a method in a service. +message Method { + // The name of the method. + string name = 1; + + // The input type of the method. + string input_type = 2; + + // The output type of the method. + string output_type = 3; +} + +// PackageDependency is a dependency of a package. +message PackageDependency { + // The name of the dependency. + string name = 1; } \ No newline at end of file diff --git a/api/pbuf-registry/v1/metadata.proto b/api/pbuf-registry/v1/metadata.proto new file mode 100644 index 0000000..332b9c1 --- /dev/null +++ b/api/pbuf-registry/v1/metadata.proto @@ -0,0 +1,31 @@ +syntax = "proto3"; + +package pbufregistry.v1; + +import "google/api/annotations.proto"; +import "pbuf-registry/v1/entities.proto"; + +option go_package = "pbufregistry/api/v1;v1"; + +// The metadata service must return parsed information +service MetadataService { + rpc GetMetadata(GetMetadataRequest) returns (GetMetadataResponse) { + option (google.api.http) = { + post: "/v1/metadata" + body: "*" + }; + } +} + +message GetMetadataRequest { + // The module to get metadata for + string name = 1; + + // The tag id to get metadata for + string tag = 2; +} + +message GetMetadataResponse { + // The packages in the module + repeated Package packages = 1; +} \ No newline at end of file diff --git a/cmd/main.go b/cmd/main.go index 8be2600..2a629d6 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -32,6 +32,7 @@ type Launcher struct { compactionDaemon background.Daemon protoParsingDaemon background.Daemon } + func main() { config.NewLoader().MustLoad() @@ -48,6 +49,7 @@ func main() { registryRepository := data.NewRegistryRepository(pool, logger) metadataRepository := data.NewMetadataRepository(pool, logger) registryServer := server.NewRegistryServer(registryRepository, metadataRepository, logger) + metadataServer := server.NewMetadataServer(registryRepository, metadataRepository, logger) app := kratos.New( kratos.ID(id), @@ -56,8 +58,8 @@ func main() { kratos.Metadata(map[string]string{}), kratos.Logger(logger), kratos.Server( - server.NewGRPCServer(&config.Cfg.Server, registryServer, logger), - server.NewHTTPServer(&config.Cfg.Server, registryServer, logger), + server.NewGRPCServer(&config.Cfg.Server, registryServer, metadataServer, logger), + server.NewHTTPServer(&config.Cfg.Server, registryServer, metadataServer, logger), server.NewDebugServer(&config.Cfg.Server, logger), ), ) diff --git a/docker-compose.yml b/docker-compose.yml index fb1bab7..6fff638 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,7 +19,7 @@ services: timeout: 10s retries: 5 pbuf-registry: - image: ghcr.io/pbufio/registry:v0.4.0-wip.2 + image: ghcr.io/pbufio/registry:v0.4.0-wip.3 restart: always depends_on: - db @@ -49,7 +49,7 @@ services: command: > sh -c "/app/pbuf-migrations && /app/pbuf-registry" pbuf-registry-compaction: - image: ghcr.io/pbufio/registry:v0.4.0-wip.2 + image: ghcr.io/pbufio/registry:v0.4.0-wip.3 restart: always depends_on: - db @@ -68,7 +68,7 @@ services: command: > sh -c "/app/pbuf-registry compaction" pbuf-registry-protoparser: - image: ghcr.io/pbufio/registry:v0.4.0-wip.2 + image: ghcr.io/pbufio/registry:v0.4.0-wip.3 restart: always depends_on: - db diff --git a/gen/pbuf-registry/v1/entities.pb.go b/gen/pbuf-registry/v1/entities.pb.go index 7edde1c..e9e0555 100644 --- a/gen/pbuf-registry/v1/entities.pb.go +++ b/gen/pbuf-registry/v1/entities.pb.go @@ -221,6 +221,655 @@ func (x *Dependency) GetTag() string { return "" } +// Package is a proto file package used in a module +type Package struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The name of the package. + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // The proto files of the package. + ProtoFiles []*ParsedProtoFile `protobuf:"bytes,2,rep,name=proto_files,json=protoFiles,proto3" json:"proto_files,omitempty"` + // The dependencies of the package. + Dependencies []*PackageDependency `protobuf:"bytes,3,rep,name=dependencies,proto3" json:"dependencies,omitempty"` +} + +func (x *Package) Reset() { + *x = Package{} + if protoimpl.UnsafeEnabled { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Package) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Package) ProtoMessage() {} + +func (x *Package) ProtoReflect() protoreflect.Message { + mi := &file_pbuf_registry_v1_entities_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 Package.ProtoReflect.Descriptor instead. +func (*Package) Descriptor() ([]byte, []int) { + return file_pbuf_registry_v1_entities_proto_rawDescGZIP(), []int{3} +} + +func (x *Package) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Package) GetProtoFiles() []*ParsedProtoFile { + if x != nil { + return x.ProtoFiles + } + return nil +} + +func (x *Package) GetDependencies() []*PackageDependency { + if x != nil { + return x.Dependencies + } + return nil +} + +// ParsedProtoFile is a proto file parsed by the registry +// contains information about messages and services in the proto file +type ParsedProtoFile struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The filename of the proto file. + Filename string `protobuf:"bytes,1,opt,name=filename,proto3" json:"filename,omitempty"` + // The messages in the proto file. + Messages []*Message `protobuf:"bytes,2,rep,name=messages,proto3" json:"messages,omitempty"` + // The services in the proto file. + Services []*Service `protobuf:"bytes,3,rep,name=services,proto3" json:"services,omitempty"` +} + +func (x *ParsedProtoFile) Reset() { + *x = ParsedProtoFile{} + if protoimpl.UnsafeEnabled { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ParsedProtoFile) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ParsedProtoFile) ProtoMessage() {} + +func (x *ParsedProtoFile) ProtoReflect() protoreflect.Message { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[4] + 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 ParsedProtoFile.ProtoReflect.Descriptor instead. +func (*ParsedProtoFile) Descriptor() ([]byte, []int) { + return file_pbuf_registry_v1_entities_proto_rawDescGZIP(), []int{4} +} + +func (x *ParsedProtoFile) GetFilename() string { + if x != nil { + return x.Filename + } + return "" +} + +func (x *ParsedProtoFile) GetMessages() []*Message { + if x != nil { + return x.Messages + } + return nil +} + +func (x *ParsedProtoFile) GetServices() []*Service { + if x != nil { + return x.Services + } + return nil +} + +// Message is a message in a proto file. +type Message struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The name of the message. + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // The fields of the message. + Fields []*Field `protobuf:"bytes,2,rep,name=fields,proto3" json:"fields,omitempty"` + // The nested messages of the message. + NestedMessages []*Message `protobuf:"bytes,3,rep,name=nested_messages,json=nestedMessages,proto3" json:"nested_messages,omitempty"` + // The nested enums of the message. + NestedEnums []*Enum `protobuf:"bytes,4,rep,name=nested_enums,json=nestedEnums,proto3" json:"nested_enums,omitempty"` +} + +func (x *Message) Reset() { + *x = Message{} + if protoimpl.UnsafeEnabled { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Message) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Message) ProtoMessage() {} + +func (x *Message) ProtoReflect() protoreflect.Message { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[5] + 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 Message.ProtoReflect.Descriptor instead. +func (*Message) Descriptor() ([]byte, []int) { + return file_pbuf_registry_v1_entities_proto_rawDescGZIP(), []int{5} +} + +func (x *Message) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Message) GetFields() []*Field { + if x != nil { + return x.Fields + } + return nil +} + +func (x *Message) GetNestedMessages() []*Message { + if x != nil { + return x.NestedMessages + } + return nil +} + +func (x *Message) GetNestedEnums() []*Enum { + if x != nil { + return x.NestedEnums + } + return nil +} + +// Field is a field in a message. +type Field struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The name of the field. + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // The message_type of the field. + MessageType string `protobuf:"bytes,2,opt,name=message_type,json=messageType,proto3" json:"message_type,omitempty"` + // The tag of the field. + Tag int32 `protobuf:"varint,3,opt,name=tag,proto3" json:"tag,omitempty"` + // The repeated flag of the field. + Repeated bool `protobuf:"varint,4,opt,name=repeated,proto3" json:"repeated,omitempty"` + // The map flag of the field. + Map bool `protobuf:"varint,5,opt,name=map,proto3" json:"map,omitempty"` + // The oneof flag of the field. + Oneof bool `protobuf:"varint,6,opt,name=oneof,proto3" json:"oneof,omitempty"` + // The optional flag of the field. + Optional bool `protobuf:"varint,7,opt,name=optional,proto3" json:"optional,omitempty"` + // The required flag of the field. + Required bool `protobuf:"varint,8,opt,name=required,proto3" json:"required,omitempty"` + // The one of names of the field + OneofNames []string `protobuf:"bytes,9,rep,name=oneof_names,json=oneofNames,proto3" json:"oneof_names,omitempty"` + // The one of types of the field + OneofTypes []string `protobuf:"bytes,10,rep,name=oneof_types,json=oneofTypes,proto3" json:"oneof_types,omitempty"` + // The map key type of the field. + MapKeyType string `protobuf:"bytes,11,opt,name=map_key_type,json=mapKeyType,proto3" json:"map_key_type,omitempty"` + // The map value type of the field. + MapValueType string `protobuf:"bytes,12,opt,name=map_value_type,json=mapValueType,proto3" json:"map_value_type,omitempty"` +} + +func (x *Field) Reset() { + *x = Field{} + if protoimpl.UnsafeEnabled { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Field) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Field) ProtoMessage() {} + +func (x *Field) ProtoReflect() protoreflect.Message { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[6] + 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 Field.ProtoReflect.Descriptor instead. +func (*Field) Descriptor() ([]byte, []int) { + return file_pbuf_registry_v1_entities_proto_rawDescGZIP(), []int{6} +} + +func (x *Field) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Field) GetMessageType() string { + if x != nil { + return x.MessageType + } + return "" +} + +func (x *Field) GetTag() int32 { + if x != nil { + return x.Tag + } + return 0 +} + +func (x *Field) GetRepeated() bool { + if x != nil { + return x.Repeated + } + return false +} + +func (x *Field) GetMap() bool { + if x != nil { + return x.Map + } + return false +} + +func (x *Field) GetOneof() bool { + if x != nil { + return x.Oneof + } + return false +} + +func (x *Field) GetOptional() bool { + if x != nil { + return x.Optional + } + return false +} + +func (x *Field) GetRequired() bool { + if x != nil { + return x.Required + } + return false +} + +func (x *Field) GetOneofNames() []string { + if x != nil { + return x.OneofNames + } + return nil +} + +func (x *Field) GetOneofTypes() []string { + if x != nil { + return x.OneofTypes + } + return nil +} + +func (x *Field) GetMapKeyType() string { + if x != nil { + return x.MapKeyType + } + return "" +} + +func (x *Field) GetMapValueType() string { + if x != nil { + return x.MapValueType + } + return "" +} + +// Enum is an enum in a proto file. +type Enum struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The name of the enum. + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // The values of the enum. + Values []*EnumValue `protobuf:"bytes,2,rep,name=values,proto3" json:"values,omitempty"` +} + +func (x *Enum) Reset() { + *x = Enum{} + if protoimpl.UnsafeEnabled { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Enum) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Enum) ProtoMessage() {} + +func (x *Enum) ProtoReflect() protoreflect.Message { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[7] + 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 Enum.ProtoReflect.Descriptor instead. +func (*Enum) Descriptor() ([]byte, []int) { + return file_pbuf_registry_v1_entities_proto_rawDescGZIP(), []int{7} +} + +func (x *Enum) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Enum) GetValues() []*EnumValue { + if x != nil { + return x.Values + } + return nil +} + +// EnumValue is a value in an enum. +type EnumValue struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The name of the value. + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // The tag of the value. + Tag int32 `protobuf:"varint,2,opt,name=tag,proto3" json:"tag,omitempty"` +} + +func (x *EnumValue) Reset() { + *x = EnumValue{} + if protoimpl.UnsafeEnabled { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EnumValue) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EnumValue) ProtoMessage() {} + +func (x *EnumValue) ProtoReflect() protoreflect.Message { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[8] + 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 EnumValue.ProtoReflect.Descriptor instead. +func (*EnumValue) Descriptor() ([]byte, []int) { + return file_pbuf_registry_v1_entities_proto_rawDescGZIP(), []int{8} +} + +func (x *EnumValue) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *EnumValue) GetTag() int32 { + if x != nil { + return x.Tag + } + return 0 +} + +// Service is a service in a proto file. +type Service struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The name of the service. + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // The methods of the service. + Methods []*Method `protobuf:"bytes,2,rep,name=methods,proto3" json:"methods,omitempty"` +} + +func (x *Service) Reset() { + *x = Service{} + if protoimpl.UnsafeEnabled { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Service) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Service) ProtoMessage() {} + +func (x *Service) ProtoReflect() protoreflect.Message { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[9] + 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 Service.ProtoReflect.Descriptor instead. +func (*Service) Descriptor() ([]byte, []int) { + return file_pbuf_registry_v1_entities_proto_rawDescGZIP(), []int{9} +} + +func (x *Service) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Service) GetMethods() []*Method { + if x != nil { + return x.Methods + } + return nil +} + +// Method is a method in a service. +type Method struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The name of the method. + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // The input type of the method. + InputType string `protobuf:"bytes,2,opt,name=input_type,json=inputType,proto3" json:"input_type,omitempty"` + // The output type of the method. + OutputType string `protobuf:"bytes,3,opt,name=output_type,json=outputType,proto3" json:"output_type,omitempty"` +} + +func (x *Method) Reset() { + *x = Method{} + if protoimpl.UnsafeEnabled { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Method) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Method) ProtoMessage() {} + +func (x *Method) ProtoReflect() protoreflect.Message { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[10] + 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 Method.ProtoReflect.Descriptor instead. +func (*Method) Descriptor() ([]byte, []int) { + return file_pbuf_registry_v1_entities_proto_rawDescGZIP(), []int{10} +} + +func (x *Method) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Method) GetInputType() string { + if x != nil { + return x.InputType + } + return "" +} + +func (x *Method) GetOutputType() string { + if x != nil { + return x.OutputType + } + return "" +} + +// PackageDependency is a dependency of a package. +type PackageDependency struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The name of the dependency. + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (x *PackageDependency) Reset() { + *x = PackageDependency{} + if protoimpl.UnsafeEnabled { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PackageDependency) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PackageDependency) ProtoMessage() {} + +func (x *PackageDependency) ProtoReflect() protoreflect.Message { + mi := &file_pbuf_registry_v1_entities_proto_msgTypes[11] + 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 PackageDependency.ProtoReflect.Descriptor instead. +func (*PackageDependency) Descriptor() ([]byte, []int) { + return file_pbuf_registry_v1_entities_proto_rawDescGZIP(), []int{11} +} + +func (x *PackageDependency) GetName() string { + if x != nil { + return x.Name + } + return "" +} + var File_pbuf_registry_v1_entities_proto protoreflect.FileDescriptor var file_pbuf_registry_v1_entities_proto_rawDesc = []byte{ @@ -242,9 +891,86 @@ var file_pbuf_registry_v1_entities_proto_rawDesc = []byte{ 0x6e, 0x74, 0x22, 0x32, 0x0a, 0x0a, 0x44, 0x65, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x63, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x61, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x03, 0x74, 0x61, 0x67, 0x42, 0x18, 0x5a, 0x16, 0x70, 0x62, 0x75, 0x66, 0x72, 0x65, - 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x09, 0x52, 0x03, 0x74, 0x61, 0x67, 0x22, 0xa8, 0x01, 0x0a, 0x07, 0x50, 0x61, 0x63, 0x6b, 0x61, + 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x41, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x5f, + 0x66, 0x69, 0x6c, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x70, 0x62, + 0x75, 0x66, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, + 0x72, 0x73, 0x65, 0x64, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x0a, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x46, 0x69, 0x6c, 0x65, 0x73, 0x12, 0x46, 0x0a, 0x0c, 0x64, 0x65, 0x70, + 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x63, 0x69, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x22, 0x2e, 0x70, 0x62, 0x75, 0x66, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, 0x2e, 0x76, + 0x31, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x44, 0x65, 0x70, 0x65, 0x6e, 0x64, 0x65, + 0x6e, 0x63, 0x79, 0x52, 0x0c, 0x64, 0x65, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x63, 0x69, 0x65, + 0x73, 0x22, 0x99, 0x01, 0x0a, 0x0f, 0x50, 0x61, 0x72, 0x73, 0x65, 0x64, 0x50, 0x72, 0x6f, 0x74, + 0x6f, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, + 0x65, 0x12, 0x34, 0x0a, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x18, 0x02, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x62, 0x75, 0x66, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, + 0x72, 0x79, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x08, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x12, 0x34, 0x0a, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x62, 0x75, 0x66, + 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x22, 0xca, 0x01, + 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2e, 0x0a, + 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x16, 0x2e, + 0x70, 0x62, 0x75, 0x66, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x2e, + 0x46, 0x69, 0x65, 0x6c, 0x64, 0x52, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x12, 0x41, 0x0a, + 0x0f, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, + 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x62, 0x75, 0x66, 0x72, 0x65, 0x67, + 0x69, 0x73, 0x74, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x52, 0x0e, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, + 0x12, 0x38, 0x0a, 0x0c, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, + 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x70, 0x62, 0x75, 0x66, 0x72, 0x65, 0x67, + 0x69, 0x73, 0x74, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x52, 0x0b, 0x6e, + 0x65, 0x73, 0x74, 0x65, 0x64, 0x45, 0x6e, 0x75, 0x6d, 0x73, 0x22, 0xd6, 0x02, 0x0a, 0x05, 0x46, + 0x69, 0x65, 0x6c, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x6d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x74, + 0x61, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x74, 0x61, 0x67, 0x12, 0x1a, 0x0a, + 0x08, 0x72, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x08, 0x72, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x61, 0x70, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x03, 0x6d, 0x61, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x6f, + 0x6e, 0x65, 0x6f, 0x66, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x6f, 0x6e, 0x65, 0x6f, + 0x66, 0x12, 0x1a, 0x0a, 0x08, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x18, 0x07, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x08, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x12, 0x1a, 0x0a, + 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x6f, 0x6e, 0x65, + 0x6f, 0x66, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, + 0x6f, 0x6e, 0x65, 0x6f, 0x66, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x12, 0x1f, 0x0a, 0x0b, 0x6f, 0x6e, + 0x65, 0x6f, 0x66, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x18, 0x0a, 0x20, 0x03, 0x28, 0x09, 0x52, + 0x0a, 0x6f, 0x6e, 0x65, 0x6f, 0x66, 0x54, 0x79, 0x70, 0x65, 0x73, 0x12, 0x20, 0x0a, 0x0c, 0x6d, + 0x61, 0x70, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x6d, 0x61, 0x70, 0x4b, 0x65, 0x79, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, + 0x0e, 0x6d, 0x61, 0x70, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, + 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x6d, 0x61, 0x70, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x54, + 0x79, 0x70, 0x65, 0x22, 0x4e, 0x0a, 0x04, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, + 0x32, 0x0a, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x1a, 0x2e, 0x70, 0x62, 0x75, 0x66, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, 0x2e, 0x76, + 0x31, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x06, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x73, 0x22, 0x31, 0x0a, 0x09, 0x45, 0x6e, 0x75, 0x6d, 0x56, 0x61, 0x6c, 0x75, 0x65, + 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x61, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x03, 0x74, 0x61, 0x67, 0x22, 0x50, 0x0a, 0x07, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x31, 0x0a, 0x07, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, + 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x70, 0x62, 0x75, 0x66, 0x72, 0x65, 0x67, + 0x69, 0x73, 0x74, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x52, + 0x07, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x22, 0x5c, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x68, + 0x6f, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x5f, + 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x69, 0x6e, 0x70, 0x75, + 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, + 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x75, 0x74, 0x70, + 0x75, 0x74, 0x54, 0x79, 0x70, 0x65, 0x22, 0x27, 0x0a, 0x11, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, + 0x65, 0x44, 0x65, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x63, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x42, + 0x18, 0x5a, 0x16, 0x70, 0x62, 0x75, 0x66, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -259,18 +985,36 @@ func file_pbuf_registry_v1_entities_proto_rawDescGZIP() []byte { return file_pbuf_registry_v1_entities_proto_rawDescData } -var file_pbuf_registry_v1_entities_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_pbuf_registry_v1_entities_proto_msgTypes = make([]protoimpl.MessageInfo, 12) var file_pbuf_registry_v1_entities_proto_goTypes = []interface{}{ - (*Module)(nil), // 0: pbufregistry.v1.Module - (*ProtoFile)(nil), // 1: pbufregistry.v1.ProtoFile - (*Dependency)(nil), // 2: pbufregistry.v1.Dependency + (*Module)(nil), // 0: pbufregistry.v1.Module + (*ProtoFile)(nil), // 1: pbufregistry.v1.ProtoFile + (*Dependency)(nil), // 2: pbufregistry.v1.Dependency + (*Package)(nil), // 3: pbufregistry.v1.Package + (*ParsedProtoFile)(nil), // 4: pbufregistry.v1.ParsedProtoFile + (*Message)(nil), // 5: pbufregistry.v1.Message + (*Field)(nil), // 6: pbufregistry.v1.Field + (*Enum)(nil), // 7: pbufregistry.v1.Enum + (*EnumValue)(nil), // 8: pbufregistry.v1.EnumValue + (*Service)(nil), // 9: pbufregistry.v1.Service + (*Method)(nil), // 10: pbufregistry.v1.Method + (*PackageDependency)(nil), // 11: pbufregistry.v1.PackageDependency } var file_pbuf_registry_v1_entities_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] 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 + 4, // 0: pbufregistry.v1.Package.proto_files:type_name -> pbufregistry.v1.ParsedProtoFile + 11, // 1: pbufregistry.v1.Package.dependencies:type_name -> pbufregistry.v1.PackageDependency + 5, // 2: pbufregistry.v1.ParsedProtoFile.messages:type_name -> pbufregistry.v1.Message + 9, // 3: pbufregistry.v1.ParsedProtoFile.services:type_name -> pbufregistry.v1.Service + 6, // 4: pbufregistry.v1.Message.fields:type_name -> pbufregistry.v1.Field + 5, // 5: pbufregistry.v1.Message.nested_messages:type_name -> pbufregistry.v1.Message + 7, // 6: pbufregistry.v1.Message.nested_enums:type_name -> pbufregistry.v1.Enum + 8, // 7: pbufregistry.v1.Enum.values:type_name -> pbufregistry.v1.EnumValue + 10, // 8: pbufregistry.v1.Service.methods:type_name -> pbufregistry.v1.Method + 9, // [9:9] is the sub-list for method output_type + 9, // [9:9] is the sub-list for method input_type + 9, // [9:9] is the sub-list for extension type_name + 9, // [9:9] is the sub-list for extension extendee + 0, // [0:9] is the sub-list for field type_name } func init() { file_pbuf_registry_v1_entities_proto_init() } @@ -315,6 +1059,114 @@ func file_pbuf_registry_v1_entities_proto_init() { return nil } } + file_pbuf_registry_v1_entities_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Package); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pbuf_registry_v1_entities_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ParsedProtoFile); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pbuf_registry_v1_entities_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Message); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pbuf_registry_v1_entities_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Field); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pbuf_registry_v1_entities_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Enum); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pbuf_registry_v1_entities_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EnumValue); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pbuf_registry_v1_entities_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Service); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pbuf_registry_v1_entities_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Method); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pbuf_registry_v1_entities_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PackageDependency); 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{ @@ -322,7 +1174,7 @@ func file_pbuf_registry_v1_entities_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_pbuf_registry_v1_entities_proto_rawDesc, NumEnums: 0, - NumMessages: 3, + NumMessages: 12, NumExtensions: 0, NumServices: 0, }, diff --git a/gen/pbuf-registry/v1/metadata.pb.go b/gen/pbuf-registry/v1/metadata.pb.go new file mode 100644 index 0000000..83f1c40 --- /dev/null +++ b/gen/pbuf-registry/v1/metadata.pb.go @@ -0,0 +1,240 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc (unknown) +// source: pbuf-registry/v1/metadata.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 GetMetadataRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The module to get metadata for + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // The tag id to get metadata for + Tag string `protobuf:"bytes,2,opt,name=tag,proto3" json:"tag,omitempty"` +} + +func (x *GetMetadataRequest) Reset() { + *x = GetMetadataRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_pbuf_registry_v1_metadata_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetMetadataRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetMetadataRequest) ProtoMessage() {} + +func (x *GetMetadataRequest) ProtoReflect() protoreflect.Message { + mi := &file_pbuf_registry_v1_metadata_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 GetMetadataRequest.ProtoReflect.Descriptor instead. +func (*GetMetadataRequest) Descriptor() ([]byte, []int) { + return file_pbuf_registry_v1_metadata_proto_rawDescGZIP(), []int{0} +} + +func (x *GetMetadataRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *GetMetadataRequest) GetTag() string { + if x != nil { + return x.Tag + } + return "" +} + +type GetMetadataResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The packages in the module + Packages []*Package `protobuf:"bytes,1,rep,name=packages,proto3" json:"packages,omitempty"` +} + +func (x *GetMetadataResponse) Reset() { + *x = GetMetadataResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_pbuf_registry_v1_metadata_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetMetadataResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetMetadataResponse) ProtoMessage() {} + +func (x *GetMetadataResponse) ProtoReflect() protoreflect.Message { + mi := &file_pbuf_registry_v1_metadata_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 GetMetadataResponse.ProtoReflect.Descriptor instead. +func (*GetMetadataResponse) Descriptor() ([]byte, []int) { + return file_pbuf_registry_v1_metadata_proto_rawDescGZIP(), []int{1} +} + +func (x *GetMetadataResponse) GetPackages() []*Package { + if x != nil { + return x.Packages + } + return nil +} + +var File_pbuf_registry_v1_metadata_proto protoreflect.FileDescriptor + +var file_pbuf_registry_v1_metadata_proto_rawDesc = []byte{ + 0x0a, 0x1f, 0x70, 0x62, 0x75, 0x66, 0x2d, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, 0x2f, + 0x76, 0x31, 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x12, 0x0f, 0x70, 0x62, 0x75, 0x66, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, 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, + 0x1a, 0x1f, 0x70, 0x62, 0x75, 0x66, 0x2d, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, 0x2f, + 0x76, 0x31, 0x2f, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x69, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x22, 0x3a, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x74, + 0x61, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x74, 0x61, 0x67, 0x22, 0x4b, 0x0a, + 0x13, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x34, 0x0a, 0x08, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x73, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x62, 0x75, 0x66, 0x72, 0x65, 0x67, + 0x69, 0x73, 0x74, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, + 0x52, 0x08, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x73, 0x32, 0x84, 0x01, 0x0a, 0x0f, 0x4d, + 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x71, + 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x23, 0x2e, + 0x70, 0x62, 0x75, 0x66, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x2e, + 0x47, 0x65, 0x74, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x70, 0x62, 0x75, 0x66, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, + 0x79, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x17, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x11, + 0x3a, 0x01, 0x2a, 0x22, 0x0c, 0x2f, 0x76, 0x31, 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, + 0x61, 0x42, 0x18, 0x5a, 0x16, 0x70, 0x62, 0x75, 0x66, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, + 0x79, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, +} + +var ( + file_pbuf_registry_v1_metadata_proto_rawDescOnce sync.Once + file_pbuf_registry_v1_metadata_proto_rawDescData = file_pbuf_registry_v1_metadata_proto_rawDesc +) + +func file_pbuf_registry_v1_metadata_proto_rawDescGZIP() []byte { + file_pbuf_registry_v1_metadata_proto_rawDescOnce.Do(func() { + file_pbuf_registry_v1_metadata_proto_rawDescData = protoimpl.X.CompressGZIP(file_pbuf_registry_v1_metadata_proto_rawDescData) + }) + return file_pbuf_registry_v1_metadata_proto_rawDescData +} + +var file_pbuf_registry_v1_metadata_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_pbuf_registry_v1_metadata_proto_goTypes = []interface{}{ + (*GetMetadataRequest)(nil), // 0: pbufregistry.v1.GetMetadataRequest + (*GetMetadataResponse)(nil), // 1: pbufregistry.v1.GetMetadataResponse + (*Package)(nil), // 2: pbufregistry.v1.Package +} +var file_pbuf_registry_v1_metadata_proto_depIdxs = []int32{ + 2, // 0: pbufregistry.v1.GetMetadataResponse.packages:type_name -> pbufregistry.v1.Package + 0, // 1: pbufregistry.v1.MetadataService.GetMetadata:input_type -> pbufregistry.v1.GetMetadataRequest + 1, // 2: pbufregistry.v1.MetadataService.GetMetadata:output_type -> pbufregistry.v1.GetMetadataResponse + 2, // [2:3] is the sub-list for method output_type + 1, // [1:2] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_pbuf_registry_v1_metadata_proto_init() } +func file_pbuf_registry_v1_metadata_proto_init() { + if File_pbuf_registry_v1_metadata_proto != nil { + return + } + file_pbuf_registry_v1_entities_proto_init() + if !protoimpl.UnsafeEnabled { + file_pbuf_registry_v1_metadata_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetMetadataRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pbuf_registry_v1_metadata_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetMetadataResponse); 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_pbuf_registry_v1_metadata_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_pbuf_registry_v1_metadata_proto_goTypes, + DependencyIndexes: file_pbuf_registry_v1_metadata_proto_depIdxs, + MessageInfos: file_pbuf_registry_v1_metadata_proto_msgTypes, + }.Build() + File_pbuf_registry_v1_metadata_proto = out.File + file_pbuf_registry_v1_metadata_proto_rawDesc = nil + file_pbuf_registry_v1_metadata_proto_goTypes = nil + file_pbuf_registry_v1_metadata_proto_depIdxs = nil +} diff --git a/gen/pbuf-registry/v1/metadata.swagger.json b/gen/pbuf-registry/v1/metadata.swagger.json new file mode 100644 index 0000000..3588afc --- /dev/null +++ b/gen/pbuf-registry/v1/metadata.swagger.json @@ -0,0 +1,334 @@ +{ + "swagger": "2.0", + "info": { + "title": "pbuf-registry/v1/metadata.proto", + "version": "version not set" + }, + "tags": [ + { + "name": "MetadataService" + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/v1/metadata": { + "post": { + "operationId": "MetadataService_GetMetadata", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/v1GetMetadataResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1GetMetadataRequest" + } + } + ], + "tags": [ + "MetadataService" + ] + } + } + }, + "definitions": { + "protobufAny": { + "type": "object", + "properties": { + "@type": { + "type": "string" + } + }, + "additionalProperties": {} + }, + "rpcStatus": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + }, + "details": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/protobufAny" + } + } + } + }, + "v1Enum": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The name of the enum." + }, + "values": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/v1EnumValue" + }, + "description": "The values of the enum." + } + }, + "description": "Enum is an enum in a proto file." + }, + "v1EnumValue": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The name of the value." + }, + "tag": { + "type": "integer", + "format": "int32", + "description": "The tag of the value." + } + }, + "description": "EnumValue is a value in an enum." + }, + "v1Field": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The name of the field." + }, + "messageType": { + "type": "string", + "description": "The message_type of the field." + }, + "tag": { + "type": "integer", + "format": "int32", + "description": "The tag of the field." + }, + "repeated": { + "type": "boolean", + "description": "The repeated flag of the field." + }, + "map": { + "type": "boolean", + "description": "The map flag of the field." + }, + "oneof": { + "type": "boolean", + "description": "The oneof flag of the field." + }, + "optional": { + "type": "boolean", + "description": "The optional flag of the field." + }, + "required": { + "type": "boolean", + "description": "The required flag of the field." + }, + "oneofNames": { + "type": "array", + "items": { + "type": "string" + }, + "title": "The one of names of the field" + }, + "oneofTypes": { + "type": "array", + "items": { + "type": "string" + }, + "title": "The one of types of the field" + }, + "mapKeyType": { + "type": "string", + "description": "The map key type of the field." + }, + "mapValueType": { + "type": "string", + "description": "The map value type of the field." + } + }, + "description": "Field is a field in a message." + }, + "v1GetMetadataRequest": { + "type": "object", + "properties": { + "name": { + "type": "string", + "title": "The module to get metadata for" + }, + "tag": { + "type": "string", + "title": "The tag id to get metadata for" + } + } + }, + "v1GetMetadataResponse": { + "type": "object", + "properties": { + "packages": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/v1Package" + }, + "title": "The packages in the module" + } + } + }, + "v1Message": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The name of the message." + }, + "fields": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/v1Field" + }, + "description": "The fields of the message." + }, + "nestedMessages": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/v1Message" + }, + "description": "The nested messages of the message." + }, + "nestedEnums": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/v1Enum" + }, + "description": "The nested enums of the message." + } + }, + "description": "Message is a message in a proto file." + }, + "v1Method": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The name of the method." + }, + "inputType": { + "type": "string", + "description": "The input type of the method." + }, + "outputType": { + "type": "string", + "description": "The output type of the method." + } + }, + "description": "Method is a method in a service." + }, + "v1Package": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The name of the package." + }, + "protoFiles": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/v1ParsedProtoFile" + }, + "description": "The proto files of the package." + }, + "dependencies": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/v1PackageDependency" + }, + "description": "The dependencies of the package." + } + }, + "title": "Package is a proto file package used in a module" + }, + "v1PackageDependency": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The name of the dependency." + } + }, + "description": "PackageDependency is a dependency of a package." + }, + "v1ParsedProtoFile": { + "type": "object", + "properties": { + "filename": { + "type": "string", + "description": "The filename of the proto file." + }, + "messages": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/v1Message" + }, + "description": "The messages in the proto file." + }, + "services": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/v1Service" + }, + "description": "The services in the proto file." + } + }, + "title": "ParsedProtoFile is a proto file parsed by the registry\ncontains information about messages and services in the proto file" + }, + "v1Service": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The name of the service." + }, + "methods": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/v1Method" + }, + "description": "The methods of the service." + } + }, + "description": "Service is a service in a proto file." + } + } +} diff --git a/gen/pbuf-registry/v1/metadata_grpc.pb.go b/gen/pbuf-registry/v1/metadata_grpc.pb.go new file mode 100644 index 0000000..134abc8 --- /dev/null +++ b/gen/pbuf-registry/v1/metadata_grpc.pb.go @@ -0,0 +1,109 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc (unknown) +// source: pbuf-registry/v1/metadata.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 ( + MetadataService_GetMetadata_FullMethodName = "/pbufregistry.v1.MetadataService/GetMetadata" +) + +// MetadataServiceClient is the client API for MetadataService 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 MetadataServiceClient interface { + GetMetadata(ctx context.Context, in *GetMetadataRequest, opts ...grpc.CallOption) (*GetMetadataResponse, error) +} + +type metadataServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewMetadataServiceClient(cc grpc.ClientConnInterface) MetadataServiceClient { + return &metadataServiceClient{cc} +} + +func (c *metadataServiceClient) GetMetadata(ctx context.Context, in *GetMetadataRequest, opts ...grpc.CallOption) (*GetMetadataResponse, error) { + out := new(GetMetadataResponse) + err := c.cc.Invoke(ctx, MetadataService_GetMetadata_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MetadataServiceServer is the server API for MetadataService service. +// All implementations must embed UnimplementedMetadataServiceServer +// for forward compatibility +type MetadataServiceServer interface { + GetMetadata(context.Context, *GetMetadataRequest) (*GetMetadataResponse, error) + mustEmbedUnimplementedMetadataServiceServer() +} + +// UnimplementedMetadataServiceServer must be embedded to have forward compatible implementations. +type UnimplementedMetadataServiceServer struct { +} + +func (UnimplementedMetadataServiceServer) GetMetadata(context.Context, *GetMetadataRequest) (*GetMetadataResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetMetadata not implemented") +} +func (UnimplementedMetadataServiceServer) mustEmbedUnimplementedMetadataServiceServer() {} + +// UnsafeMetadataServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to MetadataServiceServer will +// result in compilation errors. +type UnsafeMetadataServiceServer interface { + mustEmbedUnimplementedMetadataServiceServer() +} + +func RegisterMetadataServiceServer(s grpc.ServiceRegistrar, srv MetadataServiceServer) { + s.RegisterService(&MetadataService_ServiceDesc, srv) +} + +func _MetadataService_GetMetadata_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetMetadataRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MetadataServiceServer).GetMetadata(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: MetadataService_GetMetadata_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MetadataServiceServer).GetMetadata(ctx, req.(*GetMetadataRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// MetadataService_ServiceDesc is the grpc.ServiceDesc for MetadataService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var MetadataService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "pbufregistry.v1.MetadataService", + HandlerType: (*MetadataServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetMetadata", + Handler: _MetadataService_GetMetadata_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "pbuf-registry/v1/metadata.proto", +} diff --git a/gen/pbuf-registry/v1/metadata_http.pb.go b/gen/pbuf-registry/v1/metadata_http.pb.go new file mode 100644 index 0000000..a544bdb --- /dev/null +++ b/gen/pbuf-registry/v1/metadata_http.pb.go @@ -0,0 +1,78 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.1 +// - protoc (unknown) +// source: pbuf-registry/v1/metadata.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 OperationMetadataServiceGetMetadata = "/pbufregistry.v1.MetadataService/GetMetadata" + +type MetadataServiceHTTPServer interface { + GetMetadata(context.Context, *GetMetadataRequest) (*GetMetadataResponse, error) +} + +func RegisterMetadataServiceHTTPServer(s *http.Server, srv MetadataServiceHTTPServer) { + r := s.Route("/") + r.POST("/v1/metadata", _MetadataService_GetMetadata0_HTTP_Handler(srv)) +} + +func _MetadataService_GetMetadata0_HTTP_Handler(srv MetadataServiceHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetMetadataRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationMetadataServiceGetMetadata) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetMetadata(ctx, req.(*GetMetadataRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetMetadataResponse) + return ctx.Result(200, reply) + } +} + +type MetadataServiceHTTPClient interface { + GetMetadata(ctx context.Context, req *GetMetadataRequest, opts ...http.CallOption) (rsp *GetMetadataResponse, err error) +} + +type MetadataServiceHTTPClientImpl struct { + cc *http.Client +} + +func NewMetadataServiceHTTPClient(client *http.Client) MetadataServiceHTTPClient { + return &MetadataServiceHTTPClientImpl{client} +} + +func (c *MetadataServiceHTTPClientImpl) GetMetadata(ctx context.Context, in *GetMetadataRequest, opts ...http.CallOption) (*GetMetadataResponse, error) { + var out GetMetadataResponse + pattern := "/v1/metadata" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationMetadataServiceGetMetadata)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, err +} diff --git a/internal/data/metadata.go b/internal/data/metadata.go index 1c7c374..7560813 100644 --- a/internal/data/metadata.go +++ b/internal/data/metadata.go @@ -2,6 +2,7 @@ package data import ( "context" + "encoding/json" "errors" "github.com/go-kratos/kratos/v2/log" @@ -10,12 +11,14 @@ import ( v1 "github.com/pbufio/pbuf-registry/gen/pbuf-registry/v1" "github.com/pbufio/pbuf-registry/internal/model" "github.com/pbufio/pbuf-registry/internal/utils" + "github.com/yoheimuta/go-protoparser/v4/interpret/unordered" ) type MetadataRepository interface { GetUnprocessedTagIds(ctx context.Context) ([]string, error) GetProtoFilesForTagId(ctx context.Context, tagId string) ([]*v1.ProtoFile, error) SaveParsedProtoFiles(ctx context.Context, tagId string, files []*model.ParsedProtoFile) error + GetParsedProtoFiles(ctx context.Context, tagId string) ([]*model.ParsedProtoFile, error) GetTagMetaByTagId(ctx context.Context, tagId string) (*model.TagMeta, error) } @@ -149,6 +152,43 @@ func (m *metadataRepo) GetTagMetaByTagId(ctx context.Context, tagId string) (*mo return &meta, nil } +func (m metadataRepo) GetParsedProtoFiles(ctx context.Context, tagId string) ([]*model.ParsedProtoFile, error) { + var parsedProtoFiles []*model.ParsedProtoFile + + rows, err := m.pool.Query(ctx, "SELECT filename, json FROM proto_parsed_data WHERE tag_id = $1", tagId) + if err != nil { + if errors.Is(err, pgx.ErrNoRows) { + return parsedProtoFiles, nil + } + m.logger.Errorf("error getting parsed proto files for tag id %s: %v", tagId, err) + return nil, err + } + defer rows.Close() + + for rows.Next() { + var filename, protoJson string + var proto *unordered.Proto + err = rows.Scan(&filename, &protoJson) + if err != nil { + m.logger.Errorf("error scanning parsed proto file: %v", err) + return nil, err + } + + err = json.Unmarshal([]byte(protoJson), &proto) + if err != nil { + m.logger.Errorf("error unmarshaling json: %v", err) + return nil, err + } + + parsedProtoFiles = append(parsedProtoFiles, &model.ParsedProtoFile{ + Filename: filename, + Proto: proto, + }) + } + + return parsedProtoFiles, nil +} + // NewMetadataRepository create a new metadata repository with pool func NewMetadataRepository(pool *pgxpool.Pool, logger log.Logger) MetadataRepository { return &metadataRepo{ diff --git a/internal/mocks/metadata_repository.go b/internal/mocks/metadata_repository.go index 46bcaf7..c4cbd72 100644 --- a/internal/mocks/metadata_repository.go +++ b/internal/mocks/metadata_repository.go @@ -17,6 +17,36 @@ type MetadataRepository struct { mock.Mock } +// GetParsedProtoFiles provides a mock function with given fields: ctx, tagId +func (_m *MetadataRepository) GetParsedProtoFiles(ctx context.Context, tagId string) ([]*model.ParsedProtoFile, error) { + ret := _m.Called(ctx, tagId) + + if len(ret) == 0 { + panic("no return value specified for GetParsedProtoFiles") + } + + var r0 []*model.ParsedProtoFile + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) ([]*model.ParsedProtoFile, error)); ok { + return rf(ctx, tagId) + } + if rf, ok := ret.Get(0).(func(context.Context, string) []*model.ParsedProtoFile); ok { + r0 = rf(ctx, tagId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.ParsedProtoFile) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, tagId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // GetProtoFilesForTagId provides a mock function with given fields: ctx, tagId func (_m *MetadataRepository) GetProtoFilesForTagId(ctx context.Context, tagId string) ([]*v1.ProtoFile, error) { ret := _m.Called(ctx, tagId) diff --git a/internal/server/grpc.go b/internal/server/grpc.go index aaa1942..b9b19f2 100644 --- a/internal/server/grpc.go +++ b/internal/server/grpc.go @@ -11,7 +11,11 @@ import ( ) // NewGRPCServer new a gRPC server. -func NewGRPCServer(cfg *config.Server, registryServer *RegistryServer, logger log.Logger) *grpc.Server { +func NewGRPCServer(cfg *config.Server, + registryServer *RegistryServer, + metadataServer *MetadataServer, + logger log.Logger, +) *grpc.Server { logHelper := log.NewHelper(logger) tlsConfig, err := createTLSConfig(cfg, logHelper) @@ -36,6 +40,7 @@ func NewGRPCServer(cfg *config.Server, registryServer *RegistryServer, logger lo grpcServer := grpc.NewServer(opts...) v1.RegisterRegistryServer(grpcServer, registryServer) + v1.RegisterMetadataServiceServer(grpcServer, metadataServer) return grpcServer } diff --git a/internal/server/http.go b/internal/server/http.go index bc32776..601178d 100644 --- a/internal/server/http.go +++ b/internal/server/http.go @@ -9,7 +9,11 @@ import ( ) // NewHTTPServer new a HTTP server. -func NewHTTPServer(cfg *config.Server, registryServer *RegistryServer, logger log.Logger) *kratosHttp.Server { +func NewHTTPServer(cfg *config.Server, + registryServer *RegistryServer, + metadataServer *MetadataServer, + logger log.Logger, +) *kratosHttp.Server { logHelper := log.NewHelper(logger) authMiddleware, err := middleware.CreateAuthMiddleware(&cfg.GRPC.Auth, logger) @@ -28,6 +32,7 @@ func NewHTTPServer(cfg *config.Server, registryServer *RegistryServer, logger lo srv := kratosHttp.NewServer(opts...) v1.RegisterRegistryHTTPServer(srv, registryServer) + v1.RegisterMetadataServiceHTTPServer(srv, metadataServer) return srv } diff --git a/internal/server/metadata.go b/internal/server/metadata.go new file mode 100644 index 0000000..5fb3a97 --- /dev/null +++ b/internal/server/metadata.go @@ -0,0 +1,62 @@ +package server + +import ( + "context" + "errors" + + "github.com/go-kratos/kratos/v2/log" + v1 "github.com/pbufio/pbuf-registry/gen/pbuf-registry/v1" + "github.com/pbufio/pbuf-registry/internal/data" + "github.com/pbufio/pbuf-registry/internal/utils" +) + +type MetadataServer struct { + v1.UnimplementedMetadataServiceServer + registryRepository data.RegistryRepository + metadataRepository data.MetadataRepository + logger *log.Helper +} + +func NewMetadataServer(registryRepository data.RegistryRepository, metadataRepository data.MetadataRepository, logger log.Logger) *MetadataServer { + return &MetadataServer{ + registryRepository: registryRepository, + metadataRepository: metadataRepository, + logger: log.NewHelper(log.With(logger, "module", "server/MetadataServer")), + } +} + +func (m MetadataServer) GetMetadata(ctx context.Context, request *v1.GetMetadataRequest) (*v1.GetMetadataResponse, error) { + if request.Name == "" { + return nil, errors.New("module name is required") + } + + if request.Tag == "" { + return nil, errors.New("tag is required") + } + + tagId, err := m.registryRepository.GetModuleTagId(ctx, request.Name, request.Tag) + if err != nil { + m.logger.Infof("error getting module tag id: %v", err) + return nil, err + } + + tagMeta, err := m.metadataRepository.GetTagMetaByTagId(ctx, tagId) + if err != nil { + m.logger.Infof("error getting tag meta: %v", err) + return nil, err + } + + if tagMeta == nil { + return nil, errors.New("tag meta not found") + } + + parsedProtoFiles, err := m.metadataRepository.GetParsedProtoFiles(ctx, tagId) + if err != nil { + m.logger.Infof("error getting metadata from DB: %v", err) + return nil, err + } + + return &v1.GetMetadataResponse{ + Packages: utils.ToMetadata(parsedProtoFiles), + }, nil +} diff --git a/internal/utils/metadata.go b/internal/utils/metadata.go new file mode 100644 index 0000000..f026064 --- /dev/null +++ b/internal/utils/metadata.go @@ -0,0 +1,172 @@ +package utils + +import ( + "sort" + "strconv" + + v1 "github.com/pbufio/pbuf-registry/gen/pbuf-registry/v1" + "github.com/pbufio/pbuf-registry/internal/model" + "github.com/yoheimuta/go-protoparser/v4/interpret/unordered" + "github.com/yoheimuta/go-protoparser/v4/parser" + "golang.org/x/exp/maps" +) + +// ToMetadata converts array of ParsedProtoFile to []v1.Packages +func ToMetadata(files []*model.ParsedProtoFile) []*v1.Package { + packagesMap := make(map[string]*v1.Package) + + for _, file := range files { + protoBody := file.Proto.ProtoBody + for _, pkg := range protoBody.Packages { + if _, ok := packagesMap[pkg.Name]; !ok { + packagesMap[pkg.Name] = &v1.Package{ + Name: pkg.Name, + } + } + + packagesMap[pkg.Name].ProtoFiles = append(packagesMap[pkg.Name].ProtoFiles, &v1.ParsedProtoFile{ + Filename: file.Filename, + Messages: retrieveMessages(protoBody.Messages), + Services: retrieveServices(protoBody.Services), + }) + } + } + + packagesNames := maps.Keys(packagesMap) + sort.Strings(packagesNames) + + var packages []*v1.Package + for _, packageName := range packagesNames { + packages = append(packages, packagesMap[packageName]) + } + + return packages +} + +func retrieveMessages(messages []*unordered.Message) []*v1.Message { + var result []*v1.Message + for _, message := range messages { + fields := retrieveFields(message.MessageBody.Fields) + fields = append(fields, retrieveOneOfFields(message.MessageBody.Oneofs)...) + fields = append(fields, retrieveMapFields(message.MessageBody.Maps)...) + result = append(result, &v1.Message{ + Name: message.MessageName, + Fields: fields, + NestedMessages: retrieveMessages(message.MessageBody.Messages), + NestedEnums: retrieveEnums(message.MessageBody.Enums), + }) + } + return result +} + +func retrieveFields(fields []*parser.Field) []*v1.Field { + var result []*v1.Field + for _, field := range fields { + fieldNumber, err := strconv.Atoi(field.FieldNumber) + if err != nil { + fieldNumber = -1 + } + + result = append(result, &v1.Field{ + Name: field.FieldName, + MessageType: field.Type, + Tag: int32(fieldNumber), + Repeated: field.IsRepeated, + Map: false, + Oneof: false, + Required: field.IsRequired, + Optional: field.IsOptional, + }) + } + return result +} + +func retrieveOneOfFields(oneofs []*parser.Oneof) []*v1.Field { + var result []*v1.Field + for _, oneof := range oneofs { + oneOfNames := make([]string, len(oneof.OneofFields)) + oneOfTypes := make([]string, len(oneof.OneofFields)) + for i, field := range oneof.OneofFields { + oneOfNames[i] = field.FieldName + oneOfTypes[i] = field.Type + } + + result = append(result, &v1.Field{ + Name: oneof.OneofName, + Oneof: true, + OneofNames: oneOfNames, + OneofTypes: oneOfTypes, + }) + } + + return result +} + +func retrieveMapFields(fields []*parser.MapField) []*v1.Field { + var result []*v1.Field + for _, field := range fields { + fieldNumber, err := strconv.Atoi(field.FieldNumber) + if err != nil { + fieldNumber = -1 + } + + result = append(result, &v1.Field{ + Name: field.MapName, + Tag: int32(fieldNumber), + Map: true, + MapKeyType: field.KeyType, + MapValueType: field.Type, + }) + } + return result +} + +func retrieveEnums(enums []*unordered.Enum) []*v1.Enum { + var result []*v1.Enum + for _, enum := range enums { + result = append(result, &v1.Enum{ + Name: enum.EnumName, + Values: retrieveEnumValues(enum.EnumBody.EnumFields), + }) + } + return result +} + +func retrieveEnumValues(fields []*parser.EnumField) []*v1.EnumValue { + var result []*v1.EnumValue + for _, field := range fields { + fieldNumber, err := strconv.Atoi(field.Number) + if err != nil { + fieldNumber = -1 + } + + result = append(result, &v1.EnumValue{ + Name: field.Ident, + Tag: int32(fieldNumber), + }) + } + return result +} + +func retrieveServices(services []*unordered.Service) []*v1.Service { + var result []*v1.Service + for _, service := range services { + result = append(result, &v1.Service{ + Name: service.ServiceName, + Methods: retrieveMethods(service.ServiceBody.RPCs), + }) + } + return result +} + +func retrieveMethods(cs []*parser.RPC) []*v1.Method { + var result []*v1.Method + for _, c := range cs { + result = append(result, &v1.Method{ + Name: c.RPCName, + InputType: c.RPCRequest.MessageType, + OutputType: c.RPCResponse.MessageType, + }) + } + return result +} diff --git a/internal/utils/metadata_test.go b/internal/utils/metadata_test.go new file mode 100644 index 0000000..92bb0a7 --- /dev/null +++ b/internal/utils/metadata_test.go @@ -0,0 +1,85 @@ +package utils + +import ( + "reflect" + "testing" + + v1 "github.com/pbufio/pbuf-registry/gen/pbuf-registry/v1" + "github.com/pbufio/pbuf-registry/internal/model" +) + +func TestToMetadata(t *testing.T) { + parsedProtoFiles, err := ParseProtoFilesContents([]*v1.ProtoFile{ + { + Filename: "test.proto", + Content: complexProtoFile, + }, + }) + if err != nil { + t.Errorf("ParseProtoFilesContents() error = %v", err) + return + } + + type args struct { + files []*model.ParsedProtoFile + } + tests := []struct { + name string + args args + want []*v1.Package + }{ + { + name: "complex proto file", + args: args{ + files: parsedProtoFiles, + }, + want: []*v1.Package{ + { + Name: "pbufregistry.v1", + ProtoFiles: []*v1.ParsedProtoFile{ + { + Filename: "test.proto", + Messages: []*v1.Message{ + { + Name: "ListModulesResponse", + Fields: []*v1.Field{ + { + Name: "modules", + MessageType: "test1.Module", + Tag: 1, + Repeated: true, + }, + { + Name: "next_page_token", + MessageType: "string", + Tag: 2, + }, + }, + }, + }, + Services: []*v1.Service{ + { + Name: "Registry", + Methods: []*v1.Method{ + { + Name: "ListModules", + InputType: "test2.ListModulesRequest", + OutputType: "ListModulesResponse", + }, + }, + }, + }, + }, + }, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := ToMetadata(tt.args.files); !reflect.DeepEqual(got, tt.want) { + t.Errorf("ToMetadata() = %v, want %v", got, tt.want) + } + }) + } +}