-
Notifications
You must be signed in to change notification settings - Fork 11
Fix descriptor recursion by grouping proto files in reflection builder #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix descriptor recursion by grouping proto files in reflection builder #60
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a pretty significant amount of changes, I'm not sure I follow all of them and their need
defmodule GrpcReflection.Service.Builder.Acc do | ||
@moduledoc false | ||
|
||
defstruct services: [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like State, except it externalizes the update/merge operations
end | ||
|
||
cond do | ||
String.contains?(base, "/priv/protos/") -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/priv/protos/
and /test/support/protos
are magic strings that might only apply to this project and the examples directories.
It is not appropriate to risk leaking users file directory structure if they don't align with one of these. This might need some configuration to identify source proto paths to properly and safely trim from dynamic locations
"testserviceV2.TestService.proto", | ||
"testserviceV2.TestService.proto" | ||
] | ||
assert Enum.sort(Enum.uniq(names)) == |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Enu.uniq
covering for something?
alias GrpcReflection.Service.State | ||
|
||
@spec build_reflection_tree(any()) :: | ||
{:error, <<_::216>>} | {:ok, GrpcReflection.Service.State.t()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{:error, <<_::216>>}
is an odd and specific typespec, where is this coming from?
def trim_symbol("." <> symbol), do: symbol | ||
def trim_symbol(symbol), do: symbol | ||
|
||
def proto_filename(module) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is reliable when there are protobuf options like https://github.com/elixir-protobuf/protobuf?tab=readme-ov-file#one-file-per-module that can be triggered by users. We would need to restrict them from using that option or find an alternative
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You really raised a good point. I will do more investigation about this.
module.__info__(:compile) | ||
|> Keyword.get(:source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this information normally available in a production build?
Add an accumulator (GrpcReflection.Service.Builder.Acc) so the builder gathers all symbols and aliases before emitting a single FileDescriptorProto per actual proto file.