Skip to content

Commit

Permalink
Refactor prehog & teleterm protos to match project conventions (gravi…
Browse files Browse the repository at this point in the history
…tational#20810)

* Adjust go_package of lib/prehog Go protobufs

This makes them follow the pattern set out by api/proto and proto.

* Adjust go_package of lib/teleterm Go protobufs

* Use single buf.gen.yaml to generate JS protos

This also entailed changing the location of lib/teleterm protos and changing
the value of their package specifier to match the conventions in other parts
of the codebase. This is a breaking change but that is fine for Connect
as the protos are used locally only and each build ships with matching
protobufs.

* Make web/packages/teleterm use protobufs from gen-proto-js

We used to copy protobufs over to web/packages/teleterm/src/services/tshd
since webapps used to be in a separate repo.

This is no longer the case, so we can just make teleterm use protobufs
from gen-proto-js.

* Move prehog & teleterm protos into proto/teleport/lib

* Generate JS protos to gen/proto/js

* Move lib/teleterm Go protobufs to gen/proto/go

* Move lib/prehog Go protobufs to gen/proto/go

* Rename lib/teleterm proto package

* Re-enable linter rules for teleterm & prehog

* Update prehogv1 path in usagereporter_test.go

* Use except instead of ignore_only to allow Google API-style responses

* Add UNARY_RPC to api/proto & proto

* Ignore gen/ when running addlicense

* buf-js.gen.yaml: Remove comment about lack of go_package for JS

* Move prehog protos to proto/prehog/v1alpha

* Adjust prehog's go_package to match proto package
  • Loading branch information
ravicious authored Feb 3, 2023
1 parent 641eeb1 commit 3ac5a0a
Show file tree
Hide file tree
Showing 187 changed files with 7,457 additions and 37,051 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,9 @@ ADDLICENSE_ARGS := -c 'Gravitational, Inc' -l apache \
-ignore 'api/version.go' \
-ignore 'docs/pages/includes/**/*.go' \
-ignore 'e/**' \
-ignore 'gen/**' \
-ignore 'gitref.go' \
-ignore 'lib/srv/desktop/rdp/rdpclient/target/**' \
-ignore 'lib/teleterm/api/protogen/**' \
-ignore 'lib/prehog/gen/**' \
-ignore 'lib/prehog/gen-js/**' \
-ignore 'lib/web/build/**' \
-ignore 'version.go' \
-ignore 'webassets/**' \
Expand Down
15 changes: 15 additions & 0 deletions api/proto/buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ lint:
use:
- DEFAULT
- PACKAGE_NO_IMPORT_CYCLE
- UNARY_RPC
# Top-level types require comments.
- COMMENT_ENUM
- COMMENT_MESSAGE
Expand All @@ -33,6 +34,20 @@ lint:
PACKAGE_VERSION_SUFFIX:
- teleport/legacy/client/proto/joinservice.proto
- teleport/legacy/types/webauthn/webauthn.proto
# Allow only certain services to use streaming RPCs.
#
# We should avoid streaming RPCs until we have a compelling reason to use them (e.g. the
# implementation needs 1-N messages or the server cannot dial directly to the client).
#
# Check out the links below. If you still have questions or doubts, reach out to @codingllama.
#
# https://docs.buf.build/lint/rules#unary_rpc
# https://github.com/gravitational/teleport/pull/16043#issuecomment-1235728212
# https://github.com/twitchtv/twirp/issues/70#issuecomment-470367807
UNARY_RPC:
- teleport/devicetrust/v1/devicetrust_service.proto
- teleport/legacy/client/proto/joinservice.proto
- teleport/proxy/v1/proxy_service.proto
breaking:
use:
- FILE
8 changes: 8 additions & 0 deletions buf-connect-go.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: v1
plugins:
- name: go
path: lib/prehog/bin/protoc-gen-go
out: .
- name: connect-go
path: lib/prehog/bin/protoc-gen-connect-go
out: .
18 changes: 18 additions & 0 deletions buf-js.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: v1
plugins:
# https://github.com/protocolbuffers/protobuf/tree/v3.20.1/js
- name: js
out: gen/proto/js
opt:
- import_style=commonjs,binary

# https://github.com/grpc/grpc-node/tree/grpc-tools%401.11.2/packages/grpc-tools/
- name: grpc
out: gen/proto/js
opt: grpc_js
path: grpc_tools_node_protoc_plugin

# https://github.com/agreatfool/grpc_tools_node_protoc_ts/tree/v5.0.1
- name: ts
out: gen/proto/js
opt: "service=grpc-node"
2 changes: 0 additions & 2 deletions buf.work.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
version: v1
directories:
- api/proto
- lib/prehog/proto
- lib/teleterm/api/proto
- proto
26 changes: 13 additions & 13 deletions build.assets/genproto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ main() {
# Generated protos are written to
# <teleport-root>/github.com/gravitational/teleport/..., so we copy them to
# the correct relative path.
trap 'rm -fr github.com' EXIT # don't leave github.com/ behind
# cleanup gen/proto folders
rm -fr api/gen/proto gen/proto lib/teleterm/api/protogen lib/prehog/gen lib/prehog/gen-js
trap 'rm -fr github.com' EXIT # don't leave github.com/ behind
rm -fr api/gen/proto gen/proto # cleanup gen/proto folders

# Generate Gogo protos.
buf generate --template=buf-gogo.gen.yaml api/proto
Expand All @@ -24,16 +23,17 @@ main() {
--path=api/proto/teleport/devicetrust/ \
--path=api/proto/teleport/loginrule/ \
--path=api/proto/teleport/proxy/ \
--path=proto/teleport/lib/multiplexer/
buf generate --template=lib/prehog/buf.gen.yaml lib/prehog/proto

# Generate lib/teleterm & JS protos.
# TODO(ravicious): Refactor generating JS protos to follow the approach from above, that is have a
# separate call to generate Go protos and another for JS protos instead of having
# teleterm-specific buf.gen.yaml files.
# https://github.com/gravitational/teleport/pull/19774#discussion_r1061524458
buf generate --template=lib/prehog/buf-teleterm.gen.yaml lib/prehog/proto
buf generate --template=lib/teleterm/buf.gen.yaml lib/teleterm/api/proto
--path=proto/teleport/lib/multiplexer/ \
--path=proto/teleport/lib/teleterm/

# Generate connect-go protos.
buf generate --template=buf-connect-go.gen.yaml \
--path=proto/prehog/

# Generate JS protos.
buf generate --template=buf-js.gen.yaml \
--path=proto/prehog/ \
--path=proto/teleport/lib/teleterm/

cp -r github.com/gravitational/teleport/* .
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3ac5a0a

Please sign in to comment.