neo3/neo_fs/
types.rs

1// Copyright (c) 2023-2025 R3E Network
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6//     http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14//! # NeoFS Core Types
15//!
16//! This module defines the core data types used in the NeoFS system.
17
18use derive_more::{Display, From};
19use serde::{Deserialize, Serialize};
20use std::collections::HashMap;
21
22/// Unique identifier for a container in NeoFS
23#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Display, From)]
24pub struct ContainerId(pub String);
25
26/// Unique identifier for an object in NeoFS
27#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Display, From)]
28pub struct ObjectId(pub String);
29
30/// Unique identifier for a user in the NeoFS network
31#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Display, From)]
32pub struct OwnerId(pub String);
33
34/// Represents the placement policy for objects in a container
35#[derive(Debug, Clone, Serialize, Deserialize)]
36pub struct PlacementPolicy {
37	/// Number of replicas to store
38	pub replicas: u32,
39	/// Rules that define the storage nodes selection
40	pub selectors: Vec<Selector>,
41	/// Filters for storage node properties
42	pub filters: Vec<Filter>,
43}
44
45impl Default for PlacementPolicy {
46	fn default() -> Self {
47		Self { replicas: 3, selectors: Vec::new(), filters: Vec::new() }
48	}
49}
50
51/// Selector for the placement policy
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct Selector {
54	/// Name of the selector
55	pub name: String,
56	/// Number of nodes to select
57	pub count: u32,
58	/// Attribute to use for selection
59	pub attribute: String,
60	/// ClauseOperator to apply
61	pub clause: ClauseOperator,
62	/// Value to compare with
63	pub value: String,
64}
65
66/// Filter for the placement policy
67#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct Filter {
69	/// Name of the filter
70	pub name: String,
71	/// Key to filter on
72	pub key: String,
73	/// Operator to apply
74	pub operation: MatchOperator,
75	/// Value to compare with
76	pub value: String,
77}
78
79/// Operators for clause matching
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub enum ClauseOperator {
82	/// Equals
83	EQ,
84	/// Not equals
85	NE,
86	/// Greater than
87	GT,
88	/// Greater than or equals
89	GE,
90	/// Less than
91	LT,
92	/// Less than or equals
93	LE,
94}
95
96/// Operators for filter matching
97#[derive(Debug, Clone, Serialize, Deserialize)]
98pub enum MatchOperator {
99	/// Equals
100	EQ,
101	/// Not equals
102	NE,
103	/// Regular expression match
104	RE,
105	/// Regular expression not match
106	NRE,
107}
108
109/// Type of NeoFS object
110#[derive(Debug, Clone, Serialize, Deserialize)]
111pub enum ObjectType {
112	/// Regular file
113	Regular,
114	/// Tombstone (marks deleted object)
115	Tombstone,
116	/// Storage group
117	StorageGroup,
118}
119
120/// Metadata attributes for NeoFS objects
121#[derive(Debug, Clone, Default, Serialize, Deserialize)]
122pub struct Attributes {
123	/// Key-value pairs of attributes
124	pub attributes: HashMap<String, String>,
125}
126
127impl Attributes {
128	/// Creates a new empty attributes collection
129	pub fn new() -> Self {
130		Self { attributes: HashMap::new() }
131	}
132
133	/// Adds an attribute
134	pub fn add(&mut self, key: impl Into<String>, value: impl Into<String>) {
135		self.attributes.insert(key.into(), value.into());
136	}
137
138	/// Gets an attribute value by key
139	pub fn get(&self, key: &str) -> Option<&String> {
140		self.attributes.get(key)
141	}
142}
143
144/// Access permissions for NeoFS containers and objects
145#[derive(Debug, Clone, Serialize, Deserialize)]
146pub enum AccessPermission {
147	/// Permission to put an object
148	PutObject,
149	/// Permission to get an object
150	GetObject,
151	/// Permission to head an object (retrieve metadata)
152	HeadObject,
153	/// Permission to delete an object
154	DeleteObject,
155	/// Permission to search objects
156	SearchObject,
157	/// Permission to get extended ACL
158	GetEACL,
159	/// Permission to set extended ACL
160	SetEACL,
161}
162
163/// Session token for authenticating with NeoFS
164#[derive(Debug, Clone, Serialize, Deserialize)]
165pub struct SessionToken {
166	/// Token ID
167	pub token_id: String,
168	/// Owner ID
169	pub owner_id: OwnerId,
170	/// Expires at
171	pub expires_at: u64,
172	/// Signature
173	pub signature: Vec<u8>,
174}
175
176// Multipart upload functionality moved to object.rs