Skip to content

Commit 9754a08

Browse files
remove submodule protobuf (#26)
* remove submodule protobuf * up version to v0.2.0 * update readme for example/helloworld * update readme for example/helloworld * to publish v0.1.1 Co-authored-by: Michael Heilmann <mjheilmann@users.noreply.github.com> * remove google module from test_coverage/ignore_modules * update readme and docs * fix mix dialyzer * mix format --------- Co-authored-by: Michael Heilmann <mjheilmann@users.noreply.github.com>
1 parent 2603dd3 commit 9754a08

File tree

16 files changed

+46
-962
lines changed

16 files changed

+46
-962
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# GrpcReflection
22

3-
GrpcReclection is a grpc server built using `grpc-elixir`. This server adds grpc reflection support to a `grpc-elixir` based application.
3+
Server reflection allows servers to assist clients in runtime construction of requests without having stub information precompiled into the client.
4+
5+
Accoring to the [GRPC Server Reflection Protocol
6+
](https://github.com/grpc/grpc/blob/master/doc/server-reflection.md), the primary usecase for server reflection is to write (typically) command line debugging tools for talking to a grpc server. In particular, such a tool will take in a method and a payload (in human readable text format) send it to the server (typically in binary proto wire format), and then take the response and decode it to text to present to the user.
7+
8+
GrpcReflection, implemented as a gRPC server using `grpc-elixir`, adds reflection support to a `grpc-elixir` based application.
49

510
## Installation
611

@@ -21,7 +26,7 @@ be found at <https://hexdocs.pm/grpc_reflection>.
2126

2227
# Reflection
2328

24-
This is written and tested using grpcurl and postman. It supports both v1alpha and v1 reflection by using one or both of the provided servers: `rpcReflection.V1.Server` or `rpcReflection.V1alpha.Server`
29+
This is written and tested using [grpcurl](https://github.com/fullstorydev/grpcurl) and postman. It supports both v1alpha and v1 reflection by using one or both of the provided servers: `rpcReflection.V1.Server` or `rpcReflection.V1alpha.Server`
2530

2631
## Enable reflection on your application
2732

@@ -74,6 +79,12 @@ message HelloReply {
7479
optional string message = 1;
7580
optional .google.protobuf.Timestamp today = 2;
7681
}
82+
83+
$ grpcurl -plaintext -format text -d 'name: "faker"' localhost:50051 helloworld.Greeter.SayHello
84+
message: "Hello faker"
85+
today: <
86+
seconds:1708412184 nanos:671267628
87+
>
7788
```
7889

7990
## Protobuf Version Support

examples/helloworld/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ This example is mostly copied directly from `grpc-elixir`, with the exception th
88

99
## Usage
1010

11-
1. Fetch Protobuf Dependencies
12-
```shell
13-
git submodule init
14-
```
15-
1611
1. Install deps and compile
1712
```shell
1813
$ mix do deps.get, compile
@@ -52,6 +47,12 @@ message HelloReply {
5247
optional string message = 1;
5348
optional .google.protobuf.Timestamp today = 2;
5449
}
50+
51+
$ grpcurl -plaintext -format text -d 'name: "faker"' localhost:50051 helloworld.Greeter.SayHello
52+
message: "Hello faker"
53+
today: <
54+
seconds:1708412184 nanos:671267628
55+
>
5556
```
5657

5758
## Regenerate Elixir code from proto

examples/helloworld/generate_protos.sh

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,6 @@
33
rm -rf ./lib/protos
44
mkdir ./lib/protos
55

6-
GOOGLE_PROTOS=("
7-
protobuf/src/google/protobuf/any.proto
8-
protobuf/src/google/protobuf/duration.proto
9-
protobuf/src/google/protobuf/empty.proto
10-
protobuf/src/google/protobuf/field_mask.proto
11-
protobuf/src/google/protobuf/struct.proto
12-
protobuf/src/google/protobuf/timestamp.proto
13-
protobuf/src/google/protobuf/wrappers.proto
14-
")
15-
16-
for file in $GOOGLE_PROTOS; do
17-
protoc --elixir_opt=include_docs=true --elixir_out=plugins=grpc,gen_descriptors=true:./lib/protos --proto_path=protobuf/src/ $file
18-
done
19-
206
PROTOS=("
217
priv/protos/helloworld.proto
228
")

examples/helloworld/mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"},
44
"dialyxir": {:hex, :dialyxir, "1.4.2", "764a6e8e7a354f0ba95d58418178d486065ead1f69ad89782817c296d0d746a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "516603d8067b2fd585319e4b13d3674ad4f314a5902ba8130cd97dc902ce6bbd"},
55
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
6-
"google_protos": {:hex, :google_protos, "0.3.0", "15faf44dce678ac028c289668ff56548806e313e4959a3aaf4f6e1ebe8db83f4", [:mix], [{:protobuf, "~> 0.10", [hex: :protobuf, repo: "hexpm", optional: false]}], "hexpm", "1f6b7fb20371f72f418b98e5e48dae3e022a9a6de1858d4b254ac5a5d0b4035f"},
6+
"google_protos": {:hex, :google_protos, "0.4.0", "93e1be2c1a07517ffed761f69047776caf35e4acd385aac4f5ce4fedd07f3660", [:mix], [{:protobuf, "~> 0.10", [hex: :protobuf, repo: "hexpm", optional: false]}], "hexpm", "4c54983d78761a3643e2198adf0f5d40a5a8b08162f3fc91c50faa257f3fa19f"},
77
"grpc": {:hex, :grpc, "0.7.0", "a86eab356b0b84406b526786a947ca50e9b9eae87108c873b51e321f8a71e8ed", [:mix], [{:cowboy, "~> 2.10", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowlib, "~> 2.12", [hex: :cowlib, repo: "hexpm", optional: false]}, {:gun, "~> 2.0", [hex: :gun, repo: "hexpm", optional: false]}, {:mint, "~> 1.5", [hex: :mint, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "632a9507da8d3c12b112b197db4d60da3c95bad02594d37711eeb622d032f254"},
88
"gun": {:hex, :gun, "2.0.1", "160a9a5394800fcba41bc7e6d421295cf9a7894c2252c0678244948e3336ad73", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "a10bc8d6096b9502205022334f719cc9a08d9adcfbfc0dbee9ef31b56274a20b"},
99
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},

examples/helloworld/protobuf

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/grpc_reflection/server.ex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,34 @@ defmodule GrpcReflection.Server do
3535
@doc """
3636
Get the reflection reponse containing the given symbol, if it is exposed by a configured service
3737
"""
38-
@spec get_by_symbol(binary()) :: {:ok, GrpcReflection.descriptor_t()} | {:error, binary}
38+
@spec get_by_symbol(binary()) ::
39+
{:ok, GrpcReflection.Server.descriptor_t()} | {:error, binary}
3940
def get_by_symbol(symbol) do
4041
Service.get_by_symbol(@cfg, symbol)
4142
end
4243

4344
@doc """
4445
Get the reflection response for the named file, if it is exposed by a configured service
4546
"""
46-
@spec get_by_filename(binary()) :: {:ok, GrpcReflection.descriptor_t()} | {:error, binary}
47+
@spec get_by_filename(binary()) ::
48+
{:ok, GrpcReflection.Server.descriptor_t()} | {:error, binary}
4749
def get_by_filename(filename) do
4850
Service.get_by_filename(@cfg, filename)
4951
end
5052

5153
@doc """
5254
Get the extension numbers for the given type, if it is exposed by a configured service
5355
"""
54-
@spec get_extension_numbers_by_type(module()) :: {:ok, list(integer())} | {:error, binary}
56+
@spec get_extension_numbers_by_type(binary()) :: {:ok, list(integer())} | {:error, binary}
5557
def get_extension_numbers_by_type(mod) do
5658
Service.get_extension_numbers_by_type(@cfg, mod)
5759
end
5860

5961
@doc """
6062
Get the reflection response for the given extension, if it is exposed by a configured service
6163
"""
62-
@spec get_by_extension(binary()) :: {:ok, GrpcReflection.descriptor_t()} | {:error, binary}
64+
@spec get_by_extension(binary()) ::
65+
{:ok, GrpcReflection.Server.descriptor_t()} | {:error, binary}
6366
def get_by_extension(containing_type) do
6467
Service.get_by_extension(@cfg, containing_type)
6568
end

mix.exs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
defmodule GrpcReflection.MixProject do
22
use Mix.Project
33

4-
@version "0.1.0"
4+
@version "0.1.1"
5+
@source_url "https://github.com/elixir-grpc/grpc-reflection"
56
@description "gRPC reflection server for Elixir"
67

78
def project do
@@ -14,10 +15,10 @@ defmodule GrpcReflection.MixProject do
1415
start_permanent: Mix.env() == :prod,
1516
deps: deps(),
1617
package: package(),
18+
docs: docs(),
1719
aliases: aliases(),
1820
test_coverage: [
1921
ignore_modules: [
20-
~r/^Google\./,
2122
~r/^Grpc\./,
2223
~r/^Helloworld\./,
2324
~r/^TestserviceV2\./,
@@ -42,7 +43,8 @@ defmodule GrpcReflection.MixProject do
4243
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},
4344
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false},
4445
{:grpc, "~> 0.7"},
45-
{:protobuf, "~> 0.11"}
46+
{:protobuf, "~> 0.11"},
47+
{:google_protos, "~> 0.4.0"}
4648
]
4749
end
4850

@@ -96,8 +98,20 @@ defmodule GrpcReflection.MixProject do
9698
%{
9799
name: "grpc_reflection",
98100
files: ~w(.formatter.exs mix.exs lib),
99-
links: %{"GitHub" => "https://github.com/elixir-grpc/grpc-reflection"},
101+
links: %{"GitHub" => @source_url},
100102
licenses: ["Apache-2.0"]
101103
}
102104
end
105+
106+
defp docs do
107+
[
108+
extras: [
109+
"README.md": [title: "Overview"]
110+
],
111+
main: "readme",
112+
source_url: @source_url,
113+
source_ref: "#{@version}",
114+
formatters: ["html"]
115+
]
116+
end
103117
end

mix.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"dialyxir": {:hex, :dialyxir, "1.4.2", "764a6e8e7a354f0ba95d58418178d486065ead1f69ad89782817c296d0d746a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "516603d8067b2fd585319e4b13d3674ad4f314a5902ba8130cd97dc902ce6bbd"},
77
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
88
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
9+
"google_protos": {:hex, :google_protos, "0.4.0", "93e1be2c1a07517ffed761f69047776caf35e4acd385aac4f5ce4fedd07f3660", [:mix], [{:protobuf, "~> 0.10", [hex: :protobuf, repo: "hexpm", optional: false]}], "hexpm", "4c54983d78761a3643e2198adf0f5d40a5a8b08162f3fc91c50faa257f3fa19f"},
910
"grpc": {:hex, :grpc, "0.7.0", "a86eab356b0b84406b526786a947ca50e9b9eae87108c873b51e321f8a71e8ed", [:mix], [{:cowboy, "~> 2.10", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowlib, "~> 2.12", [hex: :cowlib, repo: "hexpm", optional: false]}, {:gun, "~> 2.0", [hex: :gun, repo: "hexpm", optional: false]}, {:mint, "~> 1.5", [hex: :mint, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "632a9507da8d3c12b112b197db4d60da3c95bad02594d37711eeb622d032f254"},
1011
"gun": {:hex, :gun, "2.0.1", "160a9a5394800fcba41bc7e6d421295cf9a7894c2252c0678244948e3336ad73", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "a10bc8d6096b9502205022334f719cc9a08d9adcfbfc0dbee9ef31b56274a20b"},
1112
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},

test/support/protos/google/protobuf/any.pb.ex

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)