Cleanup clippy warnings.

This commit is contained in:
Orne Brocaar 2022-07-22 13:00:30 +01:00
parent 4d665d3ded
commit b187efe84c
41 changed files with 94 additions and 109 deletions

View File

@ -135,7 +135,7 @@ impl Handler for Algorithm {
resp.dr = drs
.choose(&mut rand::thread_rng())
.cloned()
.ok_or(anyhow!("Random returned None"))?;
.ok_or_else(|| anyhow!("Random returned None"))?;
resp.nb_trans = 1; // 1 is the recommeded value
resp.tx_power_index = 0; // for now this ADR algorithm only controls the DR

View File

@ -581,7 +581,7 @@ impl DeviceService for Device {
let start = SystemTime::try_from(
req.start
.as_ref()
.ok_or(anyhow!("start is None"))
.ok_or_else(|| anyhow!("start is None"))
.map_err(|e| e.status())?
.clone(),
)
@ -590,7 +590,7 @@ impl DeviceService for Device {
let end = SystemTime::try_from(
req.end
.as_ref()
.ok_or(anyhow!("end is None"))
.ok_or_else(|| anyhow!("end is None"))
.map_err(|e| e.status())?
.clone(),
)
@ -690,7 +690,7 @@ impl DeviceService for Device {
let start = SystemTime::try_from(
req.start
.as_ref()
.ok_or(anyhow!("start is None"))
.ok_or_else(|| anyhow!("start is None"))
.map_err(|e| e.status())?
.clone(),
)
@ -699,7 +699,7 @@ impl DeviceService for Device {
let end = SystemTime::try_from(
req.end
.as_ref()
.ok_or(anyhow!("end is None"))
.ok_or_else(|| anyhow!("end is None"))
.map_err(|e| e.status())?
.clone(),
)

View File

@ -279,7 +279,7 @@ impl GatewayService for Gateway {
let start = SystemTime::try_from(
req.start
.as_ref()
.ok_or(anyhow!("start is None"))
.ok_or_else(|| anyhow!("start is None"))
.map_err(|e| e.status())?
.clone(),
)
@ -288,7 +288,7 @@ impl GatewayService for Gateway {
let end = SystemTime::try_from(
req.end
.as_ref()
.ok_or(anyhow!("end is None"))
.ok_or_else(|| anyhow!("end is None"))
.map_err(|e| e.status())?
.clone(),
)

View File

@ -75,17 +75,6 @@ pub async fn callback_handler(args: CallbackArgs) -> Result<impl Reply, Rejectio
))
}
fn handle_error<T: std::error::Error>(fail: &T, msg: &'static str) {
let mut err_msg = format!("ERROR: {}", msg);
let mut cur_fail: Option<&dyn std::error::Error> = Some(fail);
while let Some(cause) = cur_fail {
err_msg += &format!("\n caused by: {}", cause);
cur_fail = cause.source();
}
println!("{}", err_msg);
panic!("boom");
}
pub async fn get_user(code: &str, state: &str) -> Result<User> {
let state = CsrfToken::new(state.to_string());
let nonce = get_nonce(&state).await?;
@ -94,11 +83,7 @@ pub async fn get_user(code: &str, state: &str) -> Result<User> {
let token_response = client
.exchange_code(AuthorizationCode::new(code.to_string()))
.request_async(async_http_client)
.await
.unwrap_or_else(|err| {
handle_error(&err, "token extahcnage");
unreachable!();
});
.await?;
let id_token_verifier: CoreIdTokenVerifier = client.id_token_verifier();
let _id_token_claims: &CoreIdTokenClaims = token_response

View File

@ -717,9 +717,9 @@ impl CayenneLpp {
};
if let Some(prost_types::value::Kind::StructValue(s)) = &v.kind {
let x = s.fields.get("x").ok_or(anyhow!("x field is missing"))?;
let y = s.fields.get("y").ok_or(anyhow!("y field is missing"))?;
let z = s.fields.get("z").ok_or(anyhow!("z field is missing"))?;
let x = s.fields.get("x").ok_or_else(|| anyhow!("x field is missing"))?;
let y = s.fields.get("y").ok_or_else(|| anyhow!("y field is missing"))?;
let z = s.fields.get("z").ok_or_else(|| anyhow!("z field is missing"))?;
if let Some(prost_types::value::Kind::NumberValue(v)) = &x.kind {
item.x = *v;
@ -789,9 +789,9 @@ impl CayenneLpp {
};
if let Some(prost_types::value::Kind::StructValue(s)) = &v.kind {
let x = s.fields.get("x").ok_or(anyhow!("x field is missing"))?;
let y = s.fields.get("y").ok_or(anyhow!("y field is missing"))?;
let z = s.fields.get("z").ok_or(anyhow!("z field is missing"))?;
let x = s.fields.get("x").ok_or_else(|| anyhow!("x field is missing"))?;
let y = s.fields.get("y").ok_or_else(|| anyhow!("y field is missing"))?;
let z = s.fields.get("z").ok_or_else(|| anyhow!("z field is missing"))?;
if let Some(prost_types::value::Kind::NumberValue(v)) = &x.kind {
item.x = *v;
@ -849,15 +849,15 @@ impl CayenneLpp {
let lat = s
.fields
.get("latitude")
.ok_or(anyhow!("latitude field is missing"))?;
.ok_or_else(|| anyhow!("latitude field is missing"))?;
let lon = s
.fields
.get("longitude")
.ok_or(anyhow!("longitude field is missing"))?;
.ok_or_else(|| anyhow!("longitude field is missing"))?;
let alt = s
.fields
.get("altitude")
.ok_or(anyhow!("altitude field is missing"))?;
.ok_or_else(|| anyhow!("altitude field is missing"))?;
if let Some(prost_types::value::Kind::NumberValue(v)) = &lat.kind {
item.latitude = *v;

View File

@ -44,11 +44,11 @@ impl Data {
let region_name = uplink_rx_info[0]
.get_metadata_string("region_name")
.ok_or(anyhow!("No region_name in metadata"))?;
.ok_or_else(|| anyhow!("No region_name in metadata"))?;
let region_common_name = uplink_rx_info[0]
.get_metadata_string("region_common_name")
.ok_or(anyhow!("No region_common_name in metadata"))?;
.ok_or_else(|| anyhow!("No region_common_name in metadata"))?;
let region_common_name = CommonName::from_str(&region_common_name)?;
let mut ctx = Data {
@ -78,7 +78,7 @@ impl Data {
.uplink_rx_info
.first()
.cloned()
.ok_or(anyhow!("rx_info is empty"))?;
.ok_or_else(|| anyhow!("rx_info is empty"))?;
self.downlink_frame.gateway_id = rx_info.gateway_id.clone();
if self.dl_meta_data.dl_freq_1.is_some()

View File

@ -77,7 +77,7 @@ impl Multicast {
let region_name = &*(gw.properties)
.get("region_name")
.cloned()
.ok_or(anyhow!("Gateway does not have region_name property"))?;
.ok_or_else(|| anyhow!("Gateway does not have region_name property"))?;
self.region_name = region_name.to_string();
Ok(())

View File

@ -126,7 +126,7 @@ impl TxAck {
let gw_df = &df
.downlink_frame
.as_ref()
.ok_or(anyhow!("downlink_frame is None"))?;
.ok_or_else(|| anyhow!("downlink_frame is None"))?;
// Validate that we don't receive more ack items than downlink items that were
// sent to the gateway. Receiving less acks is valid, e.g. the gateway might
@ -384,7 +384,7 @@ impl TxAck {
let gw_df = df
.downlink_frame
.as_ref()
.ok_or(anyhow!("downlink_frame is None"))?;
.ok_or_else(|| anyhow!("downlink_frame is None"))?;
let dfi = self.downlink_frame_item.as_ref().unwrap();
let phy = self.phy_payload.as_mut().unwrap();

View File

@ -68,7 +68,7 @@ impl Integration {
let client = aws_sdk_sns::Client::new(&config);
Ok(Integration {
json: match Encoding::from_i32(conf.encoding).ok_or(anyhow!("Invalid encoding"))? {
json: match Encoding::from_i32(conf.encoding).ok_or_else(|| anyhow!("Invalid encoding"))? {
Encoding::Json => true,
Encoding::Protobuf => false,
},

View File

@ -32,7 +32,7 @@ impl Integration {
Ok(Integration {
timeout: Duration::from_secs(5),
json: match Encoding::from_i32(conf.encoding).ok_or(anyhow!("Invalid encoding"))? {
json: match Encoding::from_i32(conf.encoding).ok_or_else(|| anyhow!("Invalid encoding"))? {
Encoding::Json => true,
Encoding::Protobuf => false,
},

View File

@ -48,7 +48,7 @@ impl Integration {
let auth_manager = AuthenticationManager::from(service_account);
Ok(Integration {
json: match Encoding::from_i32(conf.encoding).ok_or(anyhow!("Invalid encoding"))? {
json: match Encoding::from_i32(conf.encoding).ok_or_else(|| anyhow!("Invalid encoding"))? {
Encoding::Json => true,
Encoding::Protobuf => false,
},

View File

@ -38,13 +38,13 @@ impl Integration {
Ok(Integration {
timeout: Duration::from_secs(5),
endpoint: conf.endpoint.clone(),
version: InfluxDbVersion::from_i32(conf.version).ok_or(anyhow!("Invalid version"))?,
version: InfluxDbVersion::from_i32(conf.version).ok_or_else(|| anyhow!("Invalid version"))?,
db: conf.db.clone(),
username: conf.username.clone(),
password: conf.password.clone(),
retention_policy_name: conf.retention_policy_name.clone(),
precision: match InfluxDbPrecision::from_i32(conf.precision)
.ok_or(anyhow!("Invalid precision"))?
.ok_or_else(|| anyhow!("Invalid precision"))?
{
InfluxDbPrecision::Ns => "ns",
InfluxDbPrecision::U => "u",

View File

@ -201,7 +201,7 @@ pub async fn uplink_event(
}
for e in join_all(futures).await {
let _ = e?;
e?;
}
Ok(())
@ -226,7 +226,7 @@ pub async fn join_event(
}
for e in join_all(futures).await {
let _ = e?;
e?;
}
Ok(())
@ -251,7 +251,7 @@ pub async fn ack_event(
}
for e in join_all(futures).await {
let _ = e?;
e?;
}
Ok(())
@ -276,7 +276,7 @@ pub async fn txack_event(
}
for e in join_all(futures).await {
let _ = e?;
e?;
}
Ok(())
@ -301,7 +301,7 @@ pub async fn log_event(
}
for e in join_all(futures).await {
let _ = e?;
e?;
}
Ok(())
@ -326,7 +326,7 @@ pub async fn status_event(
}
for e in join_all(futures).await {
let _ = e?;
e?;
}
Ok(())
@ -351,7 +351,7 @@ pub async fn location_event(
}
for e in join_all(futures).await {
let _ = e?;
e?;
}
Ok(())
@ -376,7 +376,7 @@ pub async fn integration_event(
}
for e in join_all(futures).await {
let _ = e?;
e?;
}
Ok(())
@ -423,7 +423,7 @@ async fn handle_down_command(application_id: String, pl: integration::DownlinkCo
..Default::default()
};
let _ = device_queue::enqueue_item(qi).await?;
device_queue::enqueue_item(qi).await?;
Ok(())
}

View File

@ -202,7 +202,7 @@ impl IntegrationTrait for Integration<'_> {
let dev_info = pl
.device_info
.as_ref()
.ok_or(anyhow!("device_info is None"))?;
.ok_or_else(|| anyhow!("device_info is None"))?;
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "up")?;
let b = match self.json {
@ -221,7 +221,7 @@ impl IntegrationTrait for Integration<'_> {
let dev_info = pl
.device_info
.as_ref()
.ok_or(anyhow!("device_info is None"))?;
.ok_or_else(|| anyhow!("device_info is None"))?;
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "join")?;
let b = match self.json {
@ -240,7 +240,7 @@ impl IntegrationTrait for Integration<'_> {
let dev_info = pl
.device_info
.as_ref()
.ok_or(anyhow!("device_info is None"))?;
.ok_or_else(|| anyhow!("device_info is None"))?;
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "ack")?;
let b = match self.json {
@ -259,7 +259,7 @@ impl IntegrationTrait for Integration<'_> {
let dev_info = pl
.device_info
.as_ref()
.ok_or(anyhow!("device_info is None"))?;
.ok_or_else(|| anyhow!("device_info is None"))?;
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "txack")?;
let b = match self.json {
@ -278,7 +278,7 @@ impl IntegrationTrait for Integration<'_> {
let dev_info = pl
.device_info
.as_ref()
.ok_or(anyhow!("device_info is None"))?;
.ok_or_else(|| anyhow!("device_info is None"))?;
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "log")?;
let b = match self.json {
@ -297,7 +297,7 @@ impl IntegrationTrait for Integration<'_> {
let dev_info = pl
.device_info
.as_ref()
.ok_or(anyhow!("device_info is None"))?;
.ok_or_else(|| anyhow!("device_info is None"))?;
let topic = self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "status")?;
let b = match self.json {
@ -316,7 +316,7 @@ impl IntegrationTrait for Integration<'_> {
let dev_info = pl
.device_info
.as_ref()
.ok_or(anyhow!("device_info is None"))?;
.ok_or_else(|| anyhow!("device_info is None"))?;
let topic =
self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "location")?;
@ -336,7 +336,7 @@ impl IntegrationTrait for Integration<'_> {
let dev_info = pl
.device_info
.as_ref()
.ok_or(anyhow!("device_info is None"))?;
.ok_or_else(|| anyhow!("device_info is None"))?;
let topic =
self.get_event_topic(&dev_info.application_id, &dev_info.dev_eui, "integration")?;

View File

@ -28,7 +28,7 @@ impl IntegrationTrait for Integration {
let dev_info = pl
.device_info
.as_ref()
.ok_or(anyhow!("device_info is None"))?;
.ok_or_else(|| anyhow!("device_info is None"))?;
let b = pl.encode_to_vec();
eventlog::log_event_for_device("up", &dev_info.dev_eui, &b).await
}
@ -41,7 +41,7 @@ impl IntegrationTrait for Integration {
let dev_info = pl
.device_info
.as_ref()
.ok_or(anyhow!("device_info is None"))?;
.ok_or_else(|| anyhow!("device_info is None"))?;
let b = pl.encode_to_vec();
eventlog::log_event_for_device("join", &dev_info.dev_eui, &b).await
}
@ -54,7 +54,7 @@ impl IntegrationTrait for Integration {
let dev_info = pl
.device_info
.as_ref()
.ok_or(anyhow!("device_info is None"))?;
.ok_or_else(|| anyhow!("device_info is None"))?;
let b = pl.encode_to_vec();
eventlog::log_event_for_device("ack", &dev_info.dev_eui, &b).await
}
@ -67,7 +67,7 @@ impl IntegrationTrait for Integration {
let dev_info = pl
.device_info
.as_ref()
.ok_or(anyhow!("device_info is None"))?;
.ok_or_else(|| anyhow!("device_info is None"))?;
let b = pl.encode_to_vec();
eventlog::log_event_for_device("txack", &dev_info.dev_eui, &b).await
}
@ -80,7 +80,7 @@ impl IntegrationTrait for Integration {
let dev_info = pl
.device_info
.as_ref()
.ok_or(anyhow!("device_info is None"))?;
.ok_or_else(|| anyhow!("device_info is None"))?;
let b = pl.encode_to_vec();
eventlog::log_event_for_device("log", &dev_info.dev_eui, &b).await
}
@ -93,7 +93,7 @@ impl IntegrationTrait for Integration {
let dev_info = pl
.device_info
.as_ref()
.ok_or(anyhow!("device_info is None"))?;
.ok_or_else(|| anyhow!("device_info is None"))?;
let b = pl.encode_to_vec();
eventlog::log_event_for_device("status", &dev_info.dev_eui, &b).await
}
@ -106,7 +106,7 @@ impl IntegrationTrait for Integration {
let dev_info = pl
.device_info
.as_ref()
.ok_or(anyhow!("device_info is None"))?;
.ok_or_else(|| anyhow!("device_info is None"))?;
let b = pl.encode_to_vec();
eventlog::log_event_for_device("location", &dev_info.dev_eui, &b).await
}
@ -119,7 +119,7 @@ impl IntegrationTrait for Integration {
let dev_info = pl
.device_info
.as_ref()
.ok_or(anyhow!("device_info is None"))?;
.ok_or_else(|| anyhow!("device_info is None"))?;
let b = pl.encode_to_vec();
eventlog::log_event_for_device("integration", &dev_info.dev_eui, &b).await
}

View File

@ -23,7 +23,7 @@ pub async fn handle(
dev: &device::Device,
block: &lrwn::MACCommandSet,
) -> Result<Option<lrwn::MACCommandSet>> {
let mac = (&**block).first().ok_or(anyhow!("Expected DevStatusAns"))?;
let mac = (&**block).first().ok_or_else(|| anyhow!("Expected DevStatusAns"))?;
if let lrwn::MACCommand::DevStatusAns(pl) = mac {
info!(dev_eui = %dev.dev_eui, battery = pl.battery, margin = pl.margin, "DevStatusAns received");

View File

@ -8,7 +8,7 @@ pub async fn handle(
) -> Result<Option<lrwn::MACCommandSet>> {
let mac = (&**block)
.first()
.ok_or(anyhow!("Expected DeviceModeInd"))?;
.ok_or_else(|| anyhow!("Expected DeviceModeInd"))?;
if let lrwn::MACCommand::DeviceModeInd(pl) = mac {
device::set_enabled_class(&dev.dev_eui, &pl.class.to_string()).await?;

View File

@ -15,7 +15,7 @@ pub fn handle(
) -> Result<Option<lrwn::MACCommandSet>> {
let _ = (&**block)
.first()
.ok_or(anyhow!("Expected DeviceTimeReq"))?;
.ok_or_else(|| anyhow!("Expected DeviceTimeReq"))?;
let rx_time: DateTime<Utc> = helpers::get_rx_timestamp(&uplink_frame_set.rx_info_set).into();
let gps_time = rx_time.to_gps_time();

View File

@ -11,7 +11,7 @@ pub fn handle(
dev: &device::Device,
block: &lrwn::MACCommandSet,
) -> Result<Option<lrwn::MACCommandSet>> {
let _ = (&**block).first().ok_or(anyhow!("Expected LinkCheckReq"));
let _ = (&**block).first().ok_or_else(|| anyhow!("Expected LinkCheckReq"));
info!(dev_eui = %dev.dev_eui, "Received LinkCheckReq");
@ -19,11 +19,11 @@ pub fn handle(
.tx_info
.modulation
.as_ref()
.ok_or(anyhow!("modulation can not be None"))?;
.ok_or_else(|| anyhow!("modulation can not be None"))?;
let mod_params = mod_info
.parameters
.as_ref()
.ok_or(anyhow!("parameters can not be None"))?;
.ok_or_else(|| anyhow!("parameters can not be None"))?;
if let gw::modulation::Parameters::Lora(pl) = mod_params {
let required_snr = config::get_required_snr_for_sf(pl.spreading_factor as u8)?;

View File

@ -24,7 +24,7 @@ pub fn handle(
let pending_macs = &**pending.unwrap();
let req_pl = if let lrwn::MACCommand::PingSlotChannelReq(pl) =
pending_macs.first().ok_or(anyhow!("Empty MACCommandSet"))?
pending_macs.first().ok_or_else(|| anyhow!("Empty MACCommandSet"))?
{
pl
} else {
@ -32,7 +32,7 @@ pub fn handle(
};
let ans_pl = if let lrwn::MACCommand::PingSlotChannelAns(pl) =
block_macs.first().ok_or(anyhow!("Empty MACCommandSet"))?
block_macs.first().ok_or_else(|| anyhow!("Empty MACCommandSet"))?
{
pl
} else {

View File

@ -11,7 +11,7 @@ pub fn handle(
) -> Result<Option<lrwn::MACCommandSet>> {
let mac = (&**block)
.first()
.ok_or(anyhow!("MACCommandSet is empty"))?;
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
let pl = if let lrwn::MACCommand::PingSlotInfoReq(pl) = &mac {
pl

View File

@ -25,10 +25,10 @@ pub fn handle(
let ans_mac = (&**block)
.first()
.ok_or(anyhow!("MACCommandSet is empty"))?;
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
let req_mac = (&**pending.unwrap())
.first()
.ok_or(anyhow!("MACCommandSet is empty"))?;
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
let req_pl = if let lrwn::MACCommand::RejoinParamSetupReq(pl) = req_mac {
pl

View File

@ -11,7 +11,7 @@ pub fn handle(
) -> Result<Option<lrwn::MACCommandSet>> {
let block_mac = (&**block)
.first()
.ok_or(anyhow!("MACCommandSet is empty"))?;
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
let req_pl = if let lrwn::MACCommand::RekeyInd(pl) = block_mac {
pl

View File

@ -14,7 +14,7 @@ pub fn handle(
) -> Result<Option<lrwn::MACCommandSet>> {
let block_mac = (&**block)
.first()
.ok_or(anyhow!("MACCommandSet is empty"))?;
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
let block_pl = if let lrwn::MACCommand::ResetInd(pl) = block_mac {
pl
} else {

View File

@ -29,10 +29,10 @@ pub fn handle(
let req_mac = (&**pending.unwrap())
.first()
.ok_or(anyhow!("MACCommandSet is empty"))?;
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
let ans_mac = (&**block)
.first()
.ok_or(anyhow!("MACCommandSet is empty"))?;
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
let req_pl = if let lrwn::MACCommand::RxParamSetupReq(pl) = req_mac {
pl

View File

@ -22,7 +22,7 @@ pub fn handle(
let req_mac = (&**pending.unwrap())
.first()
.ok_or(anyhow!("MACCommandSet is empty"))?;
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
let req_pl = if let lrwn::MACCommand::RxTimingSetupReq(pl) = req_mac {
pl

View File

@ -40,7 +40,7 @@ pub fn handle(
let req_mac = (&**pending.unwrap())
.first()
.ok_or(anyhow!("MACCommandSet is empty"))?;
.ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
let req_pl = if let lrwn::MACCommand::TxParamSetupReq(pl) = req_mac {
pl

View File

@ -10,7 +10,7 @@ use super::error::Error;
use super::schema::api_key;
use super::{error, get_db_conn};
#[derive(Queryable, Insertable, AsChangeset, PartialEq, Debug)]
#[derive(Queryable, Insertable, PartialEq, Debug)]
#[diesel(table_name = api_key)]
pub struct ApiKey {
pub id: Uuid,

View File

@ -19,7 +19,7 @@ use super::error::Error;
use super::get_db_conn;
use super::schema::{application, application_integration};
#[derive(Clone, Queryable, Insertable, AsChangeset, PartialEq, Debug)]
#[derive(Clone, Queryable, Insertable, PartialEq, Debug)]
#[diesel(table_name = application)]
pub struct Application {
pub id: Uuid,
@ -255,7 +255,7 @@ pub struct IftttConfiguration {
pub uplink_values: [String; 2], // The first value is reserved for the DevEUI
}
#[derive(Clone, Queryable, Insertable, AsChangeset, PartialEq, Debug)]
#[derive(Clone, Queryable, Insertable, PartialEq, Debug)]
#[diesel(table_name = application_integration)]
pub struct Integration {
pub application_id: Uuid,

View File

@ -15,7 +15,7 @@ use super::schema::{application, device, device_profile, multicast_group_device,
use super::{error::Error, fields, get_db_conn, get_redis_conn, redis_key};
use crate::config;
#[derive(Queryable, QueryableByName, Insertable, AsChangeset, PartialEq, Debug, Clone)]
#[derive(Queryable, QueryableByName, Insertable, PartialEq, Debug, Clone)]
#[diesel(table_name = device)]
pub struct Device {
pub dev_eui: EUI64,

View File

@ -16,7 +16,7 @@ use super::{error, fields, get_db_conn};
use crate::codec::Codec;
use chirpstack_api::internal;
#[derive(Clone, Queryable, Insertable, AsChangeset, Debug, PartialEq)]
#[derive(Clone, Queryable, Insertable, Debug, PartialEq)]
#[diesel(table_name = device_profile)]
pub struct DeviceProfile {
pub id: Uuid,

View File

@ -15,7 +15,7 @@ use super::schema::device_profile_template;
use super::{error, fields, get_db_conn};
use crate::codec::Codec;
#[derive(Clone, Queryable, Insertable, AsChangeset, Debug, PartialEq)]
#[derive(Clone, Queryable, Insertable, Debug, PartialEq)]
#[diesel(table_name = device_profile_template)]
pub struct DeviceProfileTemplate {
pub id: String,

View File

@ -10,7 +10,7 @@ use super::get_db_conn;
use super::schema::device_queue_item;
use lrwn::EUI64;
#[derive(Queryable, Insertable, AsChangeset, PartialEq, Debug, Clone)]
#[derive(Queryable, Insertable, PartialEq, Debug, Clone)]
#[diesel(table_name = device_queue_item)]
pub struct DeviceQueueItem {
pub id: Uuid,

View File

@ -13,7 +13,7 @@ use lrwn::EUI64;
use super::schema::{gateway, tenant};
use super::{error::Error, fields, get_db_conn};
#[derive(Queryable, Insertable, AsChangeset, PartialEq, Debug)]
#[derive(Queryable, Insertable, PartialEq, Debug)]
#[diesel(table_name = gateway)]
pub struct Gateway {
pub gateway_id: EUI64,

View File

@ -15,7 +15,7 @@ use super::schema::{device, multicast_group, multicast_group_device, multicast_g
use crate::downlink::classb;
use crate::{config, gpstime::ToDateTime, gpstime::ToGpsTime};
#[derive(Clone, Queryable, Insertable, AsChangeset, Debug, PartialEq)]
#[derive(Clone, Queryable, Insertable, Debug, PartialEq)]
#[diesel(table_name = multicast_group)]
pub struct MulticastGroup {
pub id: Uuid,

View File

@ -10,7 +10,7 @@ use super::error::Error;
use super::get_db_conn;
use super::schema::{tenant, tenant_user, user};
#[derive(Queryable, Insertable, AsChangeset, PartialEq, Debug, Clone)]
#[derive(Queryable, Insertable, PartialEq, Debug, Clone)]
#[diesel(table_name = tenant)]
pub struct Tenant {
pub id: Uuid,

View File

@ -16,7 +16,7 @@ use super::error::Error;
use super::get_db_conn;
use super::schema::user;
#[derive(Queryable, Insertable, AsChangeset, PartialEq, Debug, Clone)]
#[derive(Queryable, Insertable, PartialEq, Debug, Clone)]
#[diesel(table_name = user)]
pub struct User {
pub id: Uuid,

View File

@ -13,12 +13,12 @@ pub fn get_uplink_dr(region_name: &str, tx_info: &chirpstack_api::gw::UplinkTxIn
let mod_info = tx_info
.modulation
.as_ref()
.ok_or(anyhow!("modulation must not be None"))?;
.ok_or_else(|| anyhow!("modulation must not be None"))?;
let mod_params = mod_info
.parameters
.as_ref()
.ok_or(anyhow!("parameters must not be None"))?;
.ok_or_else(|| anyhow!("parameters must not be None"))?;
let dr_modulation = match &mod_params {
chirpstack_api::gw::modulation::Parameters::Lora(v) => {

View File

@ -104,7 +104,7 @@ impl JoinRequest {
ctx.set_pr_start_ans_payload()?;
ctx.pr_start_ans
.ok_or(anyhow!("PRStartAnsPayload is not set"))
.ok_or_else(|| anyhow!("PRStartAnsPayload is not set"))
}
fn get_join_request_payload(&mut self) -> Result<()> {

View File

@ -264,11 +264,11 @@ pub async fn handle_uplink(deduplication_id: Uuid, uplink: gw::UplinkFrameSet) -
let region_name = rx_info
.get_metadata_string("region_name")
.ok_or(anyhow!("No region_name in metadata"))?;
.ok_or_else(|| anyhow!("No region_name in metadata"))?;
let common_name = rx_info
.get_metadata_string("region_common_name")
.ok_or(anyhow!("No region_common_name in metadata"))?;
.ok_or_else(|| anyhow!("No region_common_name in metadata"))?;
let common_name = CommonName::from_str(&common_name)?;
@ -354,18 +354,18 @@ fn filter_rx_info_by_tenant_id(tenant_id: &Uuid, uplink: &mut UplinkFrameSet) ->
let gateway_id = EUI64::from_str(&rx_info.gateway_id)?;
let region_name = rx_info
.get_metadata_string("region_name")
.ok_or(anyhow!("No region_name in rx_info metadata"))?;
.ok_or_else(|| anyhow!("No region_name in rx_info metadata"))?;
let force_gws_private = config::get_force_gws_private(&region_name)?;
if !(*uplink
.gateway_private_map
.get(&gateway_id)
.ok_or(anyhow!("gateway_id missing in gateway_private_map"))?
.ok_or_else(|| anyhow!("gateway_id missing in gateway_private_map"))?
|| force_gws_private)
|| uplink
.gateway_tenant_id_map
.get(&gateway_id)
.ok_or(anyhow!("gateway_id is missing in gateway_tenant_id_map"))?
.ok_or_else(|| anyhow!("gateway_id is missing in gateway_tenant_id_map"))?
== tenant_id
{
rx_info_set.push(rx_info.clone());
@ -388,7 +388,7 @@ fn filter_rx_info_by_public_only(uplink: &mut UplinkFrameSet) -> Result<()> {
if !(*uplink
.gateway_private_map
.get(&gateway_id)
.ok_or(anyhow!("gateway_id missing in gateway_private_map"))?)
.ok_or_else(|| anyhow!("gateway_id missing in gateway_private_map"))?)
{
rx_info_set.push(rx_info.clone());
}

View File

@ -42,7 +42,7 @@ impl Stats {
async fn _handle(gateway_id: EUI64, s: gw::GatewayStats) -> Result<()> {
let mut ctx = Stats {
gateway_id: gateway_id,
gateway_id,
stats: s,
gateway: None,
};
@ -96,7 +96,7 @@ impl Stats {
.stats
.meta_data
.get("region_name")
.ok_or(anyhow!("No region_name in meta-data"))?;
.ok_or_else(|| anyhow!("No region_name in meta-data"))?;
let tx_per_dr =
per_modultation_to_per_dr(region_name, false, &self.stats.tx_packets_per_modulation)
@ -244,11 +244,11 @@ fn per_modultation_to_per_dr(
let modu = item
.modulation
.as_ref()
.ok_or(anyhow!("modulation is None"))?;
.ok_or_else(|| anyhow!("modulation is None"))?;
let params = modu
.parameters
.as_ref()
.ok_or(anyhow!("parameters is None"))?;
.ok_or_else(|| anyhow!("parameters is None"))?;
let dr_modulation = match params {
gw::modulation::Parameters::Lora(v) => {