Skip to content

Commit

Permalink
LDEV-4707 add addional arguments to the function
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Sep 28, 2023
1 parent 44b1ef1 commit dabd135
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
4 changes: 2 additions & 2 deletions build.number
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Thu Sep 28 09:34:15 CEST 2023
build.number=15
#Thu Sep 28 13:07:44 CEST 2023
build.number=16
7 changes: 7 additions & 0 deletions source/fld/function.fld
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,13 @@
<type>boolean</type>
<required>No</required>
<description>A flag to specify if the object has zero-byte content.</description>
</argument>
<argument>
<name>responseHeaders</name>
<alias>customResponseHeaders</alias>
<type>struct</type>
<required>No</required>
<description>Struct of custom response headers for custom metadata prefixed with "x-amz-meta-" (prefix is optional, function will add it if missed).</description>
</argument>
<argument>
<name>accessKeyId</name>
Expand Down
24 changes: 22 additions & 2 deletions source/java/src/org/lucee/extension/resource/s3/S3.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import lucee.runtime.type.Struct;
import lucee.runtime.util.Cast;
import lucee.runtime.util.Creation;
import lucee.runtime.util.Strings;

public class S3 {
private static final short CHECK_EXISTS = 1;
Expand Down Expand Up @@ -409,15 +410,16 @@ public S3ObjectSummary getInfo(String bucketName, String objectName) throws S3Ex
* @param contentEncoding Specifies content encodings applied to the object, like gzip.
* @param versionId The version ID of the object if versioning is enabled.
* @param zeroByteContent A flag to specify if the object has zero-byte content.
* @param responseHeaders Struct of response headers.
* @param customResponseHeaders Struct of custom response headers for custom metadata prefixed with
* "x-amz-meta-" (prefix is optional).
*
* @return The generated pre-signed URL.
*
* @throws S3Exception If there's an issue generating the pre-signed URL or invalid input
* parameters.
*/
public URL generatePresignedURL(String bucketName, String objectName, Date expireDate, String httpMethod, String sseAlgorithm, String sseCustomerKey, String checksum,
String contentType, String contentDisposition, String contentEncoding, String versionId, Boolean zeroByteContent) throws S3Exception {
String contentType, String contentDisposition, String contentEncoding, String versionId, Boolean zeroByteContent, Struct customResponseHeaders) throws S3Exception {
bucketName = improveBucketName(bucketName);
objectName = improveObjectName(objectName);

Expand Down Expand Up @@ -515,8 +517,26 @@ public URL generatePresignedURL(String bucketName, String objectName, Date expir
generatePresignedUrlRequest.withExpiration(expireDate);
}

if (customResponseHeaders != null && !customResponseHeaders.isEmpty()) {
Iterator<Entry<Key, Object>> it = customResponseHeaders.entryIterator();
Entry<Key, Object> e;
String name;
CFMLEngine eng = CFMLEngineFactory.getInstance();
Strings util = CFMLEngineFactory.getInstance().getStringUtil();
Cast caster = eng.getCastUtil();
while (it.hasNext()) {
e = it.next();
name = e.getKey().getString();
if (!util.startsWithIgnoreCase(name, "x-amz-meta-")) name = "x-amz-meta-" + name;
generatePresignedUrlRequest.addRequestParameter(name, caster.toString(e.getValue()));
}
}

return client.generatePresignedUrl(generatePresignedUrlRequest);
}
catch (PageException pe) {
throw toS3Exception(pe);
}
catch (AmazonServiceException ase) {
throw toS3Exception(ase);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import lucee.loader.util.Util;
import lucee.runtime.PageContext;
import lucee.runtime.exp.PageException;
import lucee.runtime.type.Struct;
import lucee.runtime.type.dt.DateTime;
import lucee.runtime.util.Cast;

Expand All @@ -24,7 +25,7 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {
CFMLEngine eng = CFMLEngineFactory.getInstance();
Cast cast = eng.getCastUtil();

if (args.length < 1 || args.length < 16) throw eng.getExceptionUtil().createFunctionException(pc, "S3GeneratePresignedURL", 1, 16, args.length);
if (args.length < 1 || args.length < 17) throw eng.getExceptionUtil().createFunctionException(pc, "S3GeneratePresignedURL", 1, 17, args.length);
String tmp;

// required
Expand All @@ -42,10 +43,11 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {
String contentEncoding = args.length > 9 && args[9] != null ? cast.toString(args[9]) : null;
String versionId = args.length > 10 && args[10] != null ? cast.toString(args[10]) : null;
Boolean zeroByteContent = args.length > 11 && !isEmpty(args[11]) ? cast.toBoolean(args[11]) : null;
String accessKeyId = args.length > 12 && args[12] != null ? cast.toString(args[12]) : null;
String secretAccessKey = args.length > 13 && args[13] != null ? cast.toString(args[13]) : null;
String host = args.length > 14 && args[14] != null ? cast.toString(args[14]) : null;
double timeout = args.length > 15 && !isEmpty(args[15]) ? cast.toDoubleValue(args[15]) : null;
Struct customResponseHeaders = args.length > 12 && !isEmpty(args[12]) ? cast.toStruct(args[12]) : null;
String accessKeyId = args.length > 13 && args[13] != null ? cast.toString(args[13]) : null;
String secretAccessKey = args.length > 14 && args[14] != null ? cast.toString(args[14]) : null;
String host = args.length > 15 && args[15] != null ? cast.toString(args[15]) : null;
double timeout = args.length > 16 && !isEmpty(args[16]) ? cast.toDoubleValue(args[16]) : null;

// for backward compatibility, when host was not existing
if (eng.getDecisionUtil().isNumber(host)) {
Expand All @@ -67,7 +69,7 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {
}

return s3.generatePresignedURL(bucketNameOrPath, objectName, expireDate, httpMethod, sseAlgorithm, sseCustomerKey, checksum, contentType, contentDisposition,
contentEncoding, versionId, zeroByteContent).toExternalForm();
contentEncoding, versionId, zeroByteContent, customResponseHeaders).toExternalForm();

}
catch (Exception e) {
Expand Down

0 comments on commit dabd135

Please sign in to comment.