Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kurotych committed Nov 14, 2024
1 parent 58f0b9e commit 7f71e36
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
27 changes: 15 additions & 12 deletions mobile_config/src/gateway_info.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chrono::{DateTime, Utc};
use chrono::{DateTime, TimeZone, Utc};
use futures::stream::BoxStream;
use helium_crypto::PublicKeyBinary;
use helium_proto::services::mobile_config::{
Expand Down Expand Up @@ -31,7 +31,7 @@ impl GatewayInfo {
#[derive(thiserror::Error, Debug)]
pub enum GatewayInfoProtoParseError {
#[error("Invalid location string: {0}")]
InvalidLocation(String),
InvalidLocation(#[from] std::num::ParseIntError),
#[error("Invalid created_at: {0}")]
InvalidCreatedAt(u64),
#[error("Invalid refreshed_at: {0}")]
Expand All @@ -45,23 +45,26 @@ impl TryFrom<GatewayInfoProto> for GatewayInfo {
let metadata = if let Some(ref metadata) = info.metadata {
Some(
u64::from_str_radix(&metadata.location, 16)
.map(|location| GatewayMetadata { location })
.map_err(|_| {
GatewayInfoProtoParseError::InvalidLocation(metadata.location.clone())
})?,
.map(|location| GatewayMetadata { location })?,
)
} else {
None
};
let device_type = info.device_type().into();

let created_at = DateTime::<Utc>::from_timestamp(info.created_at as i64, 0).ok_or(
GatewayInfoProtoParseError::InvalidCreatedAt(info.created_at),
)?;
let created_at = Utc
.timestamp_opt(info.created_at as i64, 0)
.single()
.ok_or(GatewayInfoProtoParseError::InvalidCreatedAt(
info.created_at,
))?;

let refreshed_at = DateTime::<Utc>::from_timestamp(info.refreshed_at as i64, 0).ok_or(
GatewayInfoProtoParseError::InvalidRefreshedAt(info.refreshed_at),
)?;
let refreshed_at = Utc
.timestamp_opt(info.refreshed_at as i64, 0)
.single()
.ok_or(GatewayInfoProtoParseError::InvalidRefreshedAt(
info.refreshed_at,
))?;

Ok(Self {
address: info.address.into(),
Expand Down
6 changes: 4 additions & 2 deletions mobile_config/src/gateway_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
key_cache::KeyCache,
telemetry, verify_public_key, GrpcResult, GrpcStreamResult,
};
use chrono::{DateTime, Utc};
use chrono::{TimeZone, Utc};
use file_store::traits::{MsgVerify, TimestampEncode};
use futures::{
stream::{Stream, StreamExt, TryStreamExt},
Expand Down Expand Up @@ -163,7 +163,9 @@ impl mobile_config::Gateway for GatewayService {
let (tx, rx) = tokio::sync::mpsc::channel(100);

let device_types: Vec<DeviceType> = request.device_types().map(|v| v.into()).collect();
let min_refreshed_at = DateTime::<Utc>::from_timestamp(request.min_refreshed_at as i64, 0)
let min_refreshed_at = Utc
.timestamp_opt(request.min_refreshed_at as i64, 0)
.single()
.ok_or(Status::invalid_argument(
"Invalid min_refreshed_at argument",
))?;
Expand Down

0 comments on commit 7f71e36

Please sign in to comment.