Skip to content

Commit 9e09c13

Browse files
zaharidichevalpeb
andauthored
fix(spiffe-proto): generate proto bindings without embedding package definition (#4324)
Our workload.proto package has a package definition in it. We rely on that package definition for naming our generated protobuf file. We however do not want the package details being part of the service/method names of the generated client code. For that purpose we have used the `disable_package_emission` method successfully in the past in order to generate code that does not have the package details in the service/method names. When we moved to tonic_prost_build however in [this PR](bdf10e47#diff-4a9729833e19e5f140e358c372e53f7ccf5e23de7c23062e4282127512dd621f), we have lost this functionality as the `emit_package` method does not seem to be honored. In order to fix that and revert back to generating code with the correct service definitions while still preserving the name of the generated rust file, this PR: * removes the package definition from the protobuf file * adds a post processing step that renames the generated `_.rs` file to what it is supposed to be --- * fix(spiffe-proto): generate proto bindings without embedding package definition Signed-off-by: Zahari Dichev <[email protected]> * fmt Signed-off-by: Zahari Dichev <[email protected]> * set default package name instead of renaming file --------- Signed-off-by: Zahari Dichev <[email protected]> Co-authored-by: Alejandro Pedraza <[email protected]>
1 parent 63438a0 commit 9e09c13

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

spiffe-proto/spiffe/proto/workload.proto

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
syntax = "proto3";
22

3-
package spiffe.workloadapi;
4-
53
service SpiffeWorkloadAPI {
64
// Fetch X.509-SVIDs for all SPIFFE identities the workload is entitled to,
75
// as well as related information like trust bundles and CRLs. As this

spiffe-proto/src/gen/spiffe.workloadapi.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,11 @@ pub mod spiffe_workload_api_client {
143143
})?;
144144
let codec = tonic_prost::ProstCodec::default();
145145
let path = http::uri::PathAndQuery::from_static(
146-
"/spiffe.workloadapi.SpiffeWorkloadAPI/FetchX509SVID",
146+
"/SpiffeWorkloadAPI/FetchX509SVID",
147147
);
148148
let mut req = request.into_request();
149149
req.extensions_mut()
150-
.insert(
151-
GrpcMethod::new(
152-
"spiffe.workloadapi.SpiffeWorkloadAPI",
153-
"FetchX509SVID",
154-
),
155-
);
150+
.insert(GrpcMethod::new("SpiffeWorkloadAPI", "FetchX509SVID"));
156151
self.inner.server_streaming(req, path, codec).await
157152
}
158153
}

spiffe-proto/tests/bootstrap.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ fn bootstrap() {
2222
/// Generates protobuf bindings into the given directory
2323
fn generate(out_dir: &std::path::Path) {
2424
let iface_files = &["spiffe/proto/workload.proto"];
25+
let mut config = tonic_prost_build::Config::new();
26+
config.default_package_filename("spiffe.workloadapi");
27+
2528
if let Err(error) = tonic_prost_build::configure()
2629
.build_client(true)
2730
.build_server(false)
2831
.emit_rerun_if_changed(false)
2932
.emit_package(false)
3033
.out_dir(out_dir)
31-
.compile_protos(iface_files, &["."])
34+
.compile_with_config(config, iface_files, &["."])
3235
{
3336
panic!("failed to compile protobuf: {error}")
3437
}

0 commit comments

Comments
 (0)