Skip to content

Commit 98302e5

Browse files
authored
Refactor stream metadata (#228)
1 parent 784c0aa commit 98302e5

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

server/src/storage.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const MAX_OBJECT_STORE_REQUESTS: usize = 1000;
6262
// const PERMISSIONS_WRITE: &str = "writeonly";
6363
// const PERMISSIONS_DELETE: &str = "delete";
6464
// const PERMISSIONS_READ_WRITE: &str = "readwrite";
65-
const PERMISSIONS_ALL: &str = "all";
65+
const ACCESS_ALL: &str = "all";
6666

6767
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6868
pub struct ObjectStoreFormat {
@@ -72,7 +72,7 @@ pub struct ObjectStoreFormat {
7272
#[serde(rename = "created-at")]
7373
pub created_at: String,
7474
pub owner: Owner,
75-
pub access: Access,
75+
pub permissions: Vec<Permisssion>,
7676
}
7777

7878
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -88,29 +88,18 @@ impl Owner {
8888
}
8989

9090
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
91-
pub struct Access {
92-
pub objects: Vec<AccessObject>,
93-
}
94-
95-
impl Access {
96-
pub fn new(objects: Vec<AccessObject>) -> Self {
97-
Self { objects }
98-
}
99-
}
100-
101-
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
102-
pub struct AccessObject {
91+
pub struct Permisssion {
10392
pub id: String,
10493
pub group: String,
105-
pub permissions: Vec<String>,
94+
pub access: Vec<String>,
10695
}
10796

108-
impl AccessObject {
97+
impl Permisssion {
10998
pub fn new(id: String) -> Self {
11099
Self {
111100
id: id.clone(),
112101
group: id,
113-
permissions: vec![PERMISSIONS_ALL.to_string()],
102+
access: vec![ACCESS_ALL.to_string()],
114103
}
115104
}
116105
}
@@ -122,7 +111,7 @@ impl Default for ObjectStoreFormat {
122111
objectstore_format: "v1".to_string(),
123112
created_at: Local::now().to_rfc3339(),
124113
owner: Owner::new("".to_string(), "".to_string()),
125-
access: Access::new(vec![]),
114+
permissions: vec![Permisssion::new("parseable".to_string())],
126115
}
127116
}
128117
}
@@ -132,9 +121,6 @@ impl ObjectStoreFormat {
132121
self.owner.id.clone_from(&id);
133122
self.owner.group = id;
134123
}
135-
fn set_access(&mut self, access: Vec<AccessObject>) {
136-
self.access.objects = access;
137-
}
138124
}
139125

140126
pub async fn resolve_parseable_metadata() -> Result<(), ObjectStorageError> {

server/src/storage/object_storage.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818

1919
use super::{
20-
file_link::CacheState, AccessObject, LogStream, MoveDataError, ObjectStorageError,
21-
ObjectStoreFormat, StorageDir, StorageMetadata, CACHED_FILES,
20+
file_link::CacheState, LogStream, MoveDataError, ObjectStorageError, ObjectStoreFormat,
21+
Permisssion, StorageDir, StorageMetadata, CACHED_FILES,
2222
};
2323
use crate::{alerts::Alerts, metadata::STREAM_INFO, option::CONFIG, query::Query, stats::Stats};
2424

@@ -44,7 +44,7 @@ use std::{
4444
};
4545

4646
// metadata file names in a Stream prefix
47-
const STREAM_METADATA_FILE_NAME: &str = ".metadata.json";
47+
const STREAM_METADATA_FILE_NAME: &str = ".stream.json";
4848
pub(super) const PARSEABLE_METADATA_FILE_NAME: &str = ".parseable.json";
4949
const SCHEMA_FILE_NAME: &str = ".schema";
5050
const ALERT_FILE_NAME: &str = ".alert.json";
@@ -83,8 +83,8 @@ pub trait ObjectStorage: Sync + 'static {
8383
async fn create_stream(&self, stream_name: &str) -> Result<(), ObjectStorageError> {
8484
let mut format = ObjectStoreFormat::default();
8585
format.set_id(CONFIG.parseable.username.clone());
86-
let access_object = AccessObject::new(CONFIG.parseable.username.clone());
87-
format.set_access(vec![access_object]);
86+
let permission = Permisssion::new(CONFIG.parseable.username.clone());
87+
format.permissions = vec![permission];
8888

8989
let format_json = to_bytes(&format);
9090

0 commit comments

Comments
 (0)