SaketaChalamchala commented on code in PR #6607:
URL: https://github.com/apache/ozone/pull/6607#discussion_r1586811837


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/EndpointBase.java:
##########
@@ -345,6 +353,82 @@ protected void addCustomMetadataHeaders(
     }
   }
 
+  protected Map<String, String> getTaggingFromHeaders(HttpHeaders httpHeaders)
+      throws OS3Exception {
+    String tagString = httpHeaders.getHeaderString(TAG_HEADER);
+
+    if (StringUtils.isEmpty(tagString)) {
+      return Collections.emptyMap();
+    }
+
+    List<NameValuePair> tagPairs = URLEncodedUtils.parse(tagString, UTF_8);
+
+    if (tagPairs.isEmpty()) {
+      return Collections.emptyMap();
+    }
+
+    Map<String, String> tags = new HashMap<>();
+    // Tag restrictions: 
https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_S3Tag.html
+    for (NameValuePair tagPair: tagPairs) {
+      if (StringUtils.isEmpty(tagPair.getName())) {
+        OS3Exception ex = newError(INVALID_TAG, TAG_HEADER);
+        ex.setErrorMessage("Some tag keys are empty, please specify the 
non-empty tag keys");
+        throw ex;
+      }
+
+      if (tagPair.getValue() == null) {
+        // For example for query parameter with only value (e.g. "tag1")
+        OS3Exception ex = newError(INVALID_TAG, tagPair.getName());
+        ex.setErrorMessage("Some tag values are not specified, please specify 
the tag values");
+        throw ex;
+      }
+
+      if (tags.containsKey(tagPair.getName())) {
+        // Tags that are associated with an object must have unique tag keys
+        // Reject request if the same key is used twice on the same resource
+        OS3Exception ex = newError(INVALID_TAG, tagPair.getName());
+        ex.setErrorMessage("There are tags with duplicate tag keys, tag keys 
should be unique");
+        throw ex;
+      }
+
+      if (!TAG_REGEX_PATTERN.matcher(tagPair.getName()).matches()) {
+        OS3Exception ex = newError(INVALID_TAG, tagPair.getName());
+        ex.setErrorMessage("The tag key does not have a valid pattern");
+        throw ex;
+      }
+
+      if (!TAG_REGEX_PATTERN.matcher(tagPair.getValue()).matches()) {
+        OS3Exception ex = newError(INVALID_TAG, tagPair.getValue());
+        ex.setErrorMessage("The tag value does not have a valid pattern");
+        throw ex;
+      }
+
+      if (tagPair.getName().length() > TAG_KEY_LENGTH_LIMIT) {
+        OS3Exception ex = newError(INVALID_TAG, tagPair.getName());

Review Comment:
   Thanks for the patch @ivandika3.
   nit: Could you move the tag key and value length checks before the tag regex 
matching checks?



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