diff --git a/services/identity/src/constants.rs b/services/identity/src/constants.rs --- a/services/identity/src/constants.rs +++ b/services/identity/src/constants.rs @@ -235,6 +235,8 @@ pub mod request_metadata { pub const CODE_VERSION: &str = "code_version"; + pub const STATE_VERSION: &str = "state_version"; + pub const MAJOR_DESKTOP_VERSION: &str = "major_desktop_version"; pub const DEVICE_TYPE: &str = "device_type"; pub const USER_ID: &str = "user_id"; pub const DEVICE_ID: &str = "device_id"; diff --git a/services/identity/src/grpc_services/shared.rs b/services/identity/src/grpc_services/shared.rs --- a/services/identity/src/grpc_services/shared.rs +++ b/services/identity/src/grpc_services/shared.rs @@ -4,6 +4,14 @@ use crate::constants::{request_metadata, MIN_SUPPORTED_NATIVE_VERSION}; +#[derive(Clone, Debug)] +pub struct PlatformMetadata { + pub device_type: String, + pub code_version: u64, + pub state_version: Option, + pub major_desktop_version: Option, +} + pub fn version_interceptor(req: Request<()>) -> Result, Status> { trace!("Intercepting request to check version: {:?}", req); @@ -18,7 +26,9 @@ } } -fn get_version_info(req: &Request<()>) -> Option<(u64, String)> { +fn get_version_info( + req: &Request, +) -> Option<(u64, String)> { trace!("Retrieving version info for request: {:?}", req); let code_version: u64 = get_value(req, request_metadata::CODE_VERSION)? @@ -29,6 +39,26 @@ Some((code_version, device_type)) } +pub fn get_platform_metadata( + req: &Request, +) -> Result { + let (code_version, device_type) = get_version_info(req).ok_or_else(|| { + Status::invalid_argument("missing platform or code version metadata") + })?; + let state_version = get_value(req, request_metadata::STATE_VERSION) + .and_then(|it| it.parse().ok()); + let major_desktop_version = + get_value(req, request_metadata::MAJOR_DESKTOP_VERSION) + .and_then(|it| it.parse().ok()); + + Ok(PlatformMetadata { + code_version, + device_type, + state_version, + major_desktop_version, + }) +} + pub fn get_value(req: &Request, key: &str) -> Option { let raw_value = req.metadata().get(key)?; raw_value.to_str().ok().map(|s| s.to_string())