chibenwa commented on code in PR #2960:
URL: https://github.com/apache/james-project/pull/2960#discussion_r2973190499


##########
server/blob/blob-api/src/main/java/org/apache/james/blob/api/BlobStoreDAO.java:
##########
@@ -25,23 +25,77 @@
 import java.nio.charset.StandardCharsets;
 import java.util.Collection;
 import java.util.Map;
+import java.util.Optional;
 
 import org.reactivestreams.Publisher;
 
+import com.google.common.base.CharMatcher;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.io.ByteSource;
 import com.google.common.io.FileBackedOutputStream;
 
 public interface BlobStoreDAO {
     record BlobMetadataName(String name) {
-        // TODO validation (a-z,A-Z,0-9 -_) &length 128 char & non empty
+        private static final CharMatcher CHAR_MATCHER = 
CharMatcher.inRange('a', 'z')
+            .or(CharMatcher.inRange('A', 'Z'))
+            .or(CharMatcher.inRange('0', '9'))
+            .or(CharMatcher.is('-'));
+
+        public BlobMetadataName {
+            Preconditions.checkArgument(CHAR_MATCHER.matchesAllOf(name), 
"Invalid char in metadata name. Must be a-z,A-Z,0-9 or - got " + name);
+            Preconditions.checkArgument(name.length() < 128, "Metadata name is 
too long. Size exceed 128 chars");
+        }
     }
+
     record BlobMetadataValue(String value) {
+        public BlobMetadataValue {
+            Preconditions.checkArgument(value.length() < 128, "Metadata value 
is too long. Size exceed 128 chars");
+        }
+    }
+
+    record ContentTransferEncoding(String value) {
+        public static BlobMetadataName NAME = new 
BlobMetadataName("content-transfer-encoding");
+        public static ContentTransferEncoding ZSTD = new 
ContentTransferEncoding("zstd");
+
+        public static ContentTransferEncoding fromValue(BlobMetadataValue 
value) {
+            return new ContentTransferEncoding(value.value());
+        }
+
+        public ContentTransferEncoding {
+            Preconditions.checkArgument(value.length() < 128, 
"ContentTransferEncoding value is too long. Size exceed 128 chars");
+        }
+
+        public BlobMetadataValue asValue() {
+            return new BlobMetadataValue(value);
+        }
 
     }
 
+    record BlobMetadata(Map<BlobMetadataName, BlobMetadataValue> metadata) {

Review Comment:
   I am not using a mutable map here but explicitly immutable one which is a 
common pattern for ASF james.
   
   As for naming, do you have suggestions? I fall a bit sort here... Happy to 
update if we can come up with something relevant.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to