Gargi-jais11 commented on code in PR #12161:
URL: https://github.com/apache/ozone/pull/12161#discussion_r4783781982


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/S3LifecycleConfiguration.java:
##########
@@ -654,4 +661,87 @@ private static AndOperator convertFromOzoneAndOperator(
 
     return andOperator;
   }
+
+  /**
+   * Builds the value of the {@code x-amz-expiration} response header for a 
newly written object, in the form
+   * {@code expiry-date="Fri, 27 Nov 2026 00:00:00 GMT", rule-id="rule1"}. 
Among the enabled rules with an
+   * Expiration action that match the object, the one with the earliest expiry 
date is used. For a Days rule,
+   * the expiry date is the creation time plus the given days, rounded up to 
the next midnight UTC, as AWS S3 does.
+   *
+   * @param lifecycleConfiguration lifecycle configuration of the bucket
+   * @param keyName name of the object
+   * @param tags tags of the object
+   * @param creationTime creation time of the object in milliseconds since 
epoch
+   * @return the header value, or null if no enabled Expiration rule matches 
the object
+   */
+  public static String getExpirationHeader(OzoneLifecycleConfiguration 
lifecycleConfiguration, String keyName,
+      Map<String, String> tags, long creationTime) {
+    ZonedDateTime earliest = null;
+    String ruleId = null;
+    for (OzoneLifecycleConfiguration.OzoneLCRule rule : 
lifecycleConfiguration.getRules()) {
+      if (!STATUS_ENABLED.equals(rule.getStatus()) || rule.getExpiration() == 
null
+          || !matches(rule, keyName, tags)) {
+        continue;
+      }
+      ZonedDateTime expiry = getExpiryDate(rule.getExpiration(), creationTime);
+      if (expiry != null && (earliest == null || expiry.isBefore(earliest))) {
+        earliest = expiry;
+        ruleId = rule.getId();
+      }
+    }
+    if (earliest == null) {
+      return null;
+    }
+    return "expiry-date=\"" + RFC1123Util.FORMAT.format(earliest) + "\", 
rule-id=\"" + ruleId + "\"";

Review Comment:
   nit: the header assumes the rule ID never contains `"`, but Ozone doesn’t 
enforce that, so a valid lifecycle config can produce a malformed 
x-amz-expiration header for strict S3 clients.



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