Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Disable sdv.databroker.v1 by default #739

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions kuksa_databroker/databroker-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ pub struct Cli {
ca_cert: Option<String>,

#[arg(value_enum)]
#[clap(long, short = 'p', value_enum, default_value = "sdv-databroker-v1")]
protocol: CliAPI,
#[clap(long, short = 'p', value_enum, default_value_t = Protocol::KuksaValV1)]
protocol: Protocol,

// Sub command
#[clap(subcommand)]
Expand All @@ -77,7 +77,7 @@ impl Cli {
self.server.clone()
}

pub fn get_protocol(&mut self) -> CliAPI {
pub fn get_protocol(&mut self) -> Protocol {
self.protocol
}
}
Expand All @@ -93,8 +93,10 @@ pub enum Commands {
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum CliAPI {
pub enum Protocol {
#[clap(name = "kuksa.val.v1")]
KuksaValV1 = 1,
#[clap(name = "sdv.databroker.v1")]
SdvDatabrokerV1 = 2,
}

Expand Down
8 changes: 4 additions & 4 deletions kuksa_databroker/databroker-cli/src/kuksa_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const CLI_COMMANDS: &[(&str, &str, &str)] = &[
"<QUERY>",
"Subscribe to signals with QUERY, if you use kuksa feature comma separated list",
),
("feed", "<PATH> <VALUE>", "Publish signal value"),
("publish", "<PATH> <VALUE>", "Publish signal value"),
(
"metadata",
"[PATTERN]",
Expand Down Expand Up @@ -369,7 +369,7 @@ pub async fn kuksa_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
format!("{} is not an actuator.", path),
)?;
cli::print_info(
"If you want to provide the signal value, use `feed`.",
"If you want to act as a provider and publish a value, use `publish`.",
)?;
continue;
}
Expand Down Expand Up @@ -402,7 +402,7 @@ pub async fn kuksa_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
}
}
}
"feed" => {
"publish" => {
interface.add_history_unique(line.clone());

let (path, value) = cli::split_first_word(args);
Expand Down Expand Up @@ -902,7 +902,7 @@ impl<Term: Terminal> Completer<Term> for CliCompleter {
Some(compls)
}
// Complete command parameters
Some("set") | Some("feed") => {
Some("set") | Some("publish") => {
if words.count() == 0 {
self.complete_entry_path(word)
} else {
Expand Down
8 changes: 4 additions & 4 deletions kuksa_databroker/databroker-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
********************************************************************************/

use clap::Parser;
use cli::CliAPI;
use cli::Protocol;

pub mod cli;
mod kuksa_cli;
Expand All @@ -21,19 +21,19 @@ mod sdv_cli;
#[tokio::main]
async fn main() {
let mut cli = cli::Cli::parse();
if cli.get_protocol() == CliAPI::SdvDatabrokerV1 {
if cli.get_protocol() == Protocol::SdvDatabrokerV1 {
let err = sdv_cli::sdv_main(cli.clone()).await;
match err {
Ok(_) => (),
Err(e) => eprintln!("Error: {}", e),
}
} else if cli.get_protocol() == CliAPI::KuksaValV1 {
} else if cli.get_protocol() == Protocol::KuksaValV1 {
let err = kuksa_cli::kuksa_main(cli.clone()).await;
match err {
Ok(_) => (),
Err(e) => eprintln!("Error: {}", e),
}
} else {
println!("Choose one protocol of either kuksa-val-v1 or sdv-databroker-v1")
println!("Choose one protocol of either kuksa.val.v1 or sdv.databroker.v1")
}
}
8 changes: 4 additions & 4 deletions kuksa_databroker/databroker-cli/src/sdv_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const CLI_COMMANDS: &[(&str, &str, &str)] = &[
"<QUERY>",
"Subscribe to signals with QUERY, if you use kuksa feature comma separated list",
),
("feed", "<PATH> <VALUE>", "Publish signal value"),
("publish", "<PATH> <VALUE>", "Publish signal value"),
(
"metadata",
"[PATTERN]",
Expand Down Expand Up @@ -352,7 +352,7 @@ pub async fn sdv_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
format!("{} is not an actuator.", metadata.name),
)?;
cli::print_info(
"If you want to provide the signal value, use `feed`.",
"If you want to act as a provider and publish a value, use `publish`.",
)?;
continue;
}
Expand Down Expand Up @@ -404,7 +404,7 @@ pub async fn sdv_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
}
}
}
"feed" => {
"publish" => {
interface.add_history_unique(line.clone());

let (path, value) = cli::split_first_word(args);
Expand Down Expand Up @@ -916,7 +916,7 @@ impl<Term: Terminal> Completer<Term> for CliCompleter {
Some(compls)
}
// Complete command parameters
Some("set") | Some("feed") => {
Some("set") | Some("publish") => {
if words.count() == 0 {
self.complete_entry_path(word)
} else {
Expand Down
45 changes: 33 additions & 12 deletions kuksa_databroker/databroker/src/grpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ pub enum ServerTLS {
Enabled { tls_config: ServerTlsConfig },
}

#[derive(PartialEq)]
pub enum Api {
KuksaValV1,
SdvDatabrokerV1,
}

impl tonic::service::Interceptor for Authorization {
fn call(
&mut self,
Expand Down Expand Up @@ -93,6 +99,7 @@ pub async fn serve<F>(
addr: impl Into<std::net::SocketAddr>,
broker: broker::DataBroker,
#[cfg(feature = "tls")] server_tls: ServerTLS,
apis: &[Api],
authorization: Authorization,
signal: F,
) -> Result<(), Box<dyn std::error::Error>>
Expand All @@ -106,6 +113,7 @@ where
broker,
#[cfg(feature = "tls")]
server_tls,
apis,
authorization,
signal,
)
Expand All @@ -116,6 +124,7 @@ pub async fn serve_with_incoming_shutdown<F>(
listener: TcpListener,
broker: broker::DataBroker,
#[cfg(feature = "tls")] server_tls: ServerTLS,
apis: &[Api],
authorization: Authorization,
signal: F,
) -> Result<(), Box<dyn std::error::Error>>
Expand All @@ -128,15 +137,15 @@ where
}

let incoming = TcpListenerStream::new(listener);
let mut builder = Server::builder()
let mut server = Server::builder()
.http2_keepalive_interval(Some(Duration::from_secs(10)))
.http2_keepalive_timeout(Some(Duration::from_secs(20)));

#[cfg(feature = "tls")]
match server_tls {
ServerTLS::Enabled { tls_config } => {
info!("Using TLS");
builder = builder.tls_config(tls_config)?;
server = server.tls_config(tls_config)?;
}
ServerTLS::Disabled => {
info!("TLS is not enabled")
Expand All @@ -147,23 +156,35 @@ where
info!("Authorization is not enabled.");
}

builder
.add_service(
let kuksa_val_v1 = {
if apis.contains(&Api::KuksaValV1) {
Some(kuksa::val::v1::val_server::ValServer::with_interceptor(
broker.clone(),
authorization.clone(),
))
} else {
None
}
};

let mut router = server.add_optional_service(kuksa_val_v1);

if apis.contains(&Api::SdvDatabrokerV1) {
router = router.add_optional_service(Some(
sdv::databroker::v1::broker_server::BrokerServer::with_interceptor(
broker.clone(),
authorization.clone(),
),
)
.add_service(
));
router = router.add_optional_service(Some(
sdv::databroker::v1::collector_server::CollectorServer::with_interceptor(
broker.clone(),
authorization.clone(),
authorization,
),
)
.add_service(kuksa::val::v1::val_server::ValServer::with_interceptor(
broker.clone(),
authorization,
))
));
}

router
.serve_with_incoming_shutdown(incoming, shutdown(broker, signal))
.await?;

Expand Down
14 changes: 14 additions & 0 deletions kuksa_databroker/databroker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.long("disable-authorization")
.help("Disable authorization")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("enable-databroker-v1")
.display_order(30)
.long("enable-databroker-v1")
.help("Enable sdv.databroker.v1 (GRPC) service")
.action(ArgAction::SetTrue),
);

#[cfg(feature = "tls")]
Expand Down Expand Up @@ -437,11 +444,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}

let mut apis = vec![grpc::server::Api::KuksaValV1];

if args.get_flag("enable-databroker-v1") {
apis.push(grpc::server::Api::SdvDatabrokerV1);
}

grpc::server::serve(
addr,
broker,
#[cfg(feature = "tls")]
tls_config,
&apis,
authorization,
shutdown_handler(),
)
Expand Down
1 change: 1 addition & 0 deletions kuksa_databroker/databroker/tests/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ impl DataBrokerWorld {
data_broker,
#[cfg(feature = "tls")]
CERTS.server_tls_config(),
&[grpc::server::Api::KuksaValV1],
_authorization,
poll_fn(|cx| {
let mut state = owned_state
Expand Down
Loading