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

Commit

Permalink
Add (optional) VISSv2 interface
Browse files Browse the repository at this point in the history
- Add VISSv2 interface to databroker
- Gated by feature flag `viss` (not built by default)
- Supports "get", "set", "subscribe" & "unsubscribe"
- Supports authorization (same jwt scope format as other interfaces)

Not implemented:
- Filters
- TLS
  • Loading branch information
argerus committed Sep 5, 2023
1 parent e4fdad2 commit 7cedfec
Show file tree
Hide file tree
Showing 11 changed files with 1,767 additions and 11 deletions.
243 changes: 238 additions & 5 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion kuksa_databroker/databroker-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
continue;
}

if metadata.entry_type != proto::v1::EntryType::Actuator.into() {
if metadata.entry_type != proto::v1::EntryType::Actuator as i32 {
print_error(
cmd,
format!("{} is not an actuator.", metadata.name),
Expand Down
8 changes: 7 additions & 1 deletion kuksa_databroker/databroker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@ jemallocator = { version = "0.5.0", optional = true }
lazy_static = "1.4.0"
thiserror = "1.0.47"

# VISS
axum = { version = "0.6.20", optional = true, features = ["ws"] }
futures = { version = "0.3.28", optional = true }
chrono = { version = "0.4.26", optional = true, features = ["std", "time"] }
uuid = { version = "1.4.1", optional = true, features = ["v4"] }

[features]
default = ["tls"]
tls = ["tonic/tls"]
# to enable jemalloc use --features jemalloc
jemalloc = ["dep:jemallocator"]
viss = ["dep:axum", "dep:chrono", "dep:futures", "dep:uuid"]
libtest = []

[build-dependencies]
Expand Down
3 changes: 3 additions & 0 deletions kuksa_databroker/databroker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub mod query;
pub mod types;
pub mod vss;

#[cfg(feature = "viss")]
pub mod viss;

use std::fmt::Write;

use tracing::info;
Expand Down
63 changes: 59 additions & 4 deletions kuksa_databroker/databroker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use tracing::{debug, error, info};

use clap::{Arg, ArgAction, Command};

#[cfg(feature = "viss")]
use databroker::viss;
use databroker::{broker, grpc, permissions, vss};

// Hardcoded datapoints
Expand Down Expand Up @@ -260,7 +262,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
)
.arg(
Arg::new("dummy-metadata")
.display_order(10)
.display_order(100)
.long("dummy-metadata")
.action(ArgAction::Set)
.help("Populate data broker with dummy metadata")
Expand All @@ -272,14 +274,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
parser = parser
.arg(
Arg::new("insecure")
.display_order(6)
.display_order(20)
.long("insecure")
.help("Allow insecure connections")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("tls-cert")
.display_order(5)
.display_order(21)
.long("tls-cert")
.help("TLS certificate file (.pem)")
.action(ArgAction::Set)
Expand All @@ -288,7 +290,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
)
.arg(
Arg::new("tls-private-key")
.display_order(5)
.display_order(22)
.long("tls-private-key")
.help("TLS private key file (.key)")
.action(ArgAction::Set)
Expand All @@ -297,6 +299,41 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
);
}

#[cfg(feature = "viss")]
{
parser = parser
.arg(
Arg::new("enable-viss")
.display_order(30)
.long("enable-viss")
.help("Enable VISSv2 service")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("viss-address")
.display_order(31)
.long("viss-address")
.help("VISS address")
.action(ArgAction::Set)
.value_name("IP")
.required(false)
.env("KUKSA_DATABROKER_VISS_ADDR")
.default_value("127.0.0.1"),
)
.arg(
Arg::new("viss-port")
.display_order(32)
.long("viss-port")
.help("VISS port")
.action(ArgAction::Set)
.value_name("PORT")
.required(false)
.env("KUKSA_DATABROKER_VISS_PORT")
.value_parser(clap::value_parser!(u16))
.default_value("8090"),
);
}

let args = parser.get_matches();

// install global collector configured based on RUST_LOG env var.
Expand Down Expand Up @@ -420,6 +457,24 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
None => Authorization::Disabled,
};

#[cfg(feature = "viss")]
{
let viss_port = args
.get_one::<u16>("viss-port")
.expect("port should be a number");
let viss_addr = std::net::SocketAddr::new(ip_addr, *viss_port);

if args.get_flag("enable-viss") {
let broker = broker.clone();
let authorization = authorization.clone();
tokio::spawn(async move {
if let Err(err) = viss::server::serve(viss_addr, broker, authorization).await {
error!("{err}");
}
});
}
}

grpc::server::serve(
addr,
broker,
Expand Down
15 changes: 15 additions & 0 deletions kuksa_databroker/databroker/src/viss/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License 2.0 which is available at
* http://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

pub mod server;
pub mod v2;
Loading

0 comments on commit 7cedfec

Please sign in to comment.