Page MenuHomePhabricator

D12270.id40918.diff
No OneTemporary

D12270.id40918.diff

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";
@@ -249,12 +251,14 @@
pub const DEFAULT_MAX_AGE: Duration = Duration::from_secs(24 * 60 * 60);
pub const DEFAULT_EXPOSED_HEADERS: [&str; 3] =
["grpc-status", "grpc-message", "grpc-status-details-bin"];
- pub const DEFAULT_ALLOW_HEADERS: [&str; 9] = [
+ pub const DEFAULT_ALLOW_HEADERS: [&str; 11] = [
"x-grpc-web",
"content-type",
"x-user-agent",
"grpc-timeout",
super::request_metadata::CODE_VERSION,
+ super::request_metadata::STATE_VERSION,
+ super::request_metadata::MAJOR_DESKTOP_VERSION,
super::request_metadata::DEVICE_TYPE,
super::request_metadata::USER_ID,
super::request_metadata::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<u64>,
+ pub major_desktop_version: Option<u64>,
+}
+
pub fn version_interceptor(req: Request<()>) -> Result<Request<()>, 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<T: std::fmt::Debug>(
+ req: &Request<T>,
+) -> 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<T: std::fmt::Debug>(
+ req: &Request<T>,
+) -> Result<PlatformMetadata, Status> {
+ 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<T>(req: &Request<T>, key: &str) -> Option<String> {
let raw_value = req.metadata().get(key)?;
raw_value.to_str().ok().map(|s| s.to_string())

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 15, 8:57 AM (5 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2493802
Default Alt Text
D12270.id40918.diff (2 KB)

Event Timeline