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


##########
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:
   ```
   record BlobMetadata(ImmutableMap<BlobMetadataName, BlobMetadataValue> 
metadata) {
   ```
   java.util.Map allows for mutable implementations and doesn't inform 
consumers that the property is immutable
   



-- 
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