Skip to content

Commit fa9b8f4

Browse files
committed
Add tonic reflection service
1 parent f9b7325 commit fa9b8f4

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

dscbicep/build.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
use std::{env, path::PathBuf};
5+
46
fn main() -> Result<(), Box<dyn std::error::Error>> {
7+
let descriptor_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bicep.bin");
8+
59
tonic_prost_build::configure()
6-
.build_client(false)
7-
// TODO: Configure and commit the out_dir to avoid dependency on protoc
8-
// .out_dir(out_dir)
9-
.compile_protos(&["proto/bicep.proto"], &["proto"])?;
10+
.build_client(false)
11+
.file_descriptor_set_path(&descriptor_path)
12+
// TODO: Configure and commit the out_dir to avoid dependency on protoc
13+
// .out_dir(out_dir)
14+
.compile_protos(&["proto/bicep.proto"], &["proto"])?;
1015
Ok(())
1116
}

dscbicep/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use tonic::{transport::Server, Request, Response, Status};
1010
// Include the generated protobuf code
1111
pub mod proto {
1212
tonic::include_proto!("extension");
13+
pub(crate) const FILE_DESCRIPTOR_SET: &[u8] = tonic::include_file_descriptor_set!("bicep");
1314
}
1415

1516
use proto::bicep_extension_server::{BicepExtension, BicepExtensionServer};
@@ -227,6 +228,10 @@ async fn run_server(
227228
http: Option<String>,
228229
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
229230
let service = BicepExtensionService;
231+
let reflection_service = tonic_reflection::server::Builder::configure()
232+
.register_encoded_file_descriptor_set(proto::FILE_DESCRIPTOR_SET)
233+
.build_v1()
234+
.unwrap();
230235

231236
#[cfg(unix)]
232237
if let Some(socket_path) = socket {
@@ -242,6 +247,7 @@ async fn run_server(
242247
let uds_stream = UnixListenerStream::new(uds);
243248

244249
Server::builder()
250+
.add_service(reflection_service)
245251
.add_service(BicepExtensionServer::new(service))
246252
.serve_with_incoming(uds_stream)
247253
.await?;
@@ -263,6 +269,7 @@ async fn run_server(
263269
tracing::info!("Starting Bicep gRPC server on HTTP: {addr}");
264270

265271
Server::builder()
272+
.add_service(reflection_service)
266273
.add_service(BicepExtensionServer::new(service))
267274
.serve(addr)
268275
.await?;

0 commit comments

Comments
 (0)