From dbc422c33e7753f4379e369564ccdf296162e333 Mon Sep 17 00:00:00 2001 From: Satyam Singh Date: Wed, 28 Dec 2022 14:22:27 +0530 Subject: [PATCH] Refactor stream metadata --- server/src/storage.rs | 28 +++++++--------------------- server/src/storage/object_storage.rs | 10 +++++----- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/server/src/storage.rs b/server/src/storage.rs index db0687e1d..2d62cee2e 100644 --- a/server/src/storage.rs +++ b/server/src/storage.rs @@ -62,7 +62,7 @@ const MAX_OBJECT_STORE_REQUESTS: usize = 1000; // const PERMISSIONS_WRITE: &str = "writeonly"; // const PERMISSIONS_DELETE: &str = "delete"; // const PERMISSIONS_READ_WRITE: &str = "readwrite"; -const PERMISSIONS_ALL: &str = "all"; +const ACCESS_ALL: &str = "all"; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct ObjectStoreFormat { @@ -72,7 +72,7 @@ pub struct ObjectStoreFormat { #[serde(rename = "created-at")] pub created_at: String, pub owner: Owner, - pub access: Access, + pub permissions: Vec, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -88,29 +88,18 @@ impl Owner { } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct Access { - pub objects: Vec, -} - -impl Access { - pub fn new(objects: Vec) -> Self { - Self { objects } - } -} - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct AccessObject { +pub struct Permisssion { pub id: String, pub group: String, - pub permissions: Vec, + pub access: Vec, } -impl AccessObject { +impl Permisssion { pub fn new(id: String) -> Self { Self { id: id.clone(), group: id, - permissions: vec![PERMISSIONS_ALL.to_string()], + access: vec![ACCESS_ALL.to_string()], } } } @@ -122,7 +111,7 @@ impl Default for ObjectStoreFormat { objectstore_format: "v1".to_string(), created_at: Local::now().to_rfc3339(), owner: Owner::new("".to_string(), "".to_string()), - access: Access::new(vec![]), + permissions: vec![Permisssion::new("parseable".to_string())], } } } @@ -132,9 +121,6 @@ impl ObjectStoreFormat { self.owner.id.clone_from(&id); self.owner.group = id; } - fn set_access(&mut self, access: Vec) { - self.access.objects = access; - } } pub async fn resolve_parseable_metadata() -> Result<(), ObjectStorageError> { diff --git a/server/src/storage/object_storage.rs b/server/src/storage/object_storage.rs index 2eab417ad..a830a60ee 100644 --- a/server/src/storage/object_storage.rs +++ b/server/src/storage/object_storage.rs @@ -17,8 +17,8 @@ */ use super::{ - file_link::CacheState, AccessObject, LogStream, MoveDataError, ObjectStorageError, - ObjectStoreFormat, StorageDir, StorageMetadata, CACHED_FILES, + file_link::CacheState, LogStream, MoveDataError, ObjectStorageError, ObjectStoreFormat, + Permisssion, StorageDir, StorageMetadata, CACHED_FILES, }; use crate::{alerts::Alerts, metadata::STREAM_INFO, option::CONFIG, query::Query, stats::Stats}; @@ -44,7 +44,7 @@ use std::{ }; // metadata file names in a Stream prefix -const STREAM_METADATA_FILE_NAME: &str = ".metadata.json"; +const STREAM_METADATA_FILE_NAME: &str = ".stream.json"; pub(super) const PARSEABLE_METADATA_FILE_NAME: &str = ".parseable.json"; const SCHEMA_FILE_NAME: &str = ".schema"; const ALERT_FILE_NAME: &str = ".alert.json"; @@ -83,8 +83,8 @@ pub trait ObjectStorage: Sync + 'static { async fn create_stream(&self, stream_name: &str) -> Result<(), ObjectStorageError> { let mut format = ObjectStoreFormat::default(); format.set_id(CONFIG.parseable.username.clone()); - let access_object = AccessObject::new(CONFIG.parseable.username.clone()); - format.set_access(vec![access_object]); + let permission = Permisssion::new(CONFIG.parseable.username.clone()); + format.permissions = vec![permission]; let format_json = to_bytes(&format);