Skip to content

Commit

Permalink
centralize VFS handling in S3GenerateURI
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Oct 6, 2023
1 parent cd542ac commit fdb040d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 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!
#Fri Oct 06 11:58:40 CEST 2023
build.number=25
#Fri Oct 06 12:02:49 CEST 2023
build.number=26
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import org.lucee.extension.resource.s3.S3;
import org.lucee.extension.resource.s3.S3Exception;
import org.lucee.extension.resource.s3.S3Properties;
import org.lucee.extension.resource.s3.S3Resource;
import org.lucee.extension.resource.s3.S3ResourceProvider;

import lucee.commons.lang.types.RefString;
import lucee.loader.engine.CFMLEngine;
import lucee.loader.engine.CFMLEngineFactory;
import lucee.loader.util.Util;
Expand All @@ -31,29 +27,23 @@ public static String call(PageContext pc, String bucketNameOrPath, String object
host = null;
}
try {
// create S3 Instance
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));

if (Util.isEmpty(objectName) && ("" + bucketNameOrPath).toLowerCase().startsWith("s3://")) {
S3Properties props = new S3Properties();
RefString location = eng.getCreationUtil().createRefString(null);
String[] bo = S3Resource.toBO(S3ResourceProvider.loadWithNewPattern(props, location, bucketNameOrPath.substring(5), Util.isEmpty(accessKeyId)));
bucketNameOrPath = bo[0];
objectName = bo[1];
if (objectName != null && objectName.endsWith("/")) objectName = objectName.substring(0, objectName.length() - 1);
}
PropsAndEndpoint pae = extractFromPath(eng, bucketNameOrPath, objectName, accessKeyId, secretAccessKey, host);

// create S3 Instance
S3 s3 = S3.getInstance(pae.props != null ? pae.props : toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));

if (Util.isEmpty(type, true) || (type = type.trim()).equalsIgnoreCase("virtualhost")) {
return s3.generateURI(bucketNameOrPath, objectName, S3.URI_STYLE_VIRTUAL_HOST, secure);
return s3.generateURI(pae.bucketName, pae.objectName, S3.URI_STYLE_VIRTUAL_HOST, secure);
}
else if (type.equalsIgnoreCase("path")) {
return s3.generateURI(bucketNameOrPath, objectName, S3.URI_STYLE_PATH, secure);
return s3.generateURI(pae.bucketName, pae.objectName, S3.URI_STYLE_PATH, secure);
}
else if (type.equalsIgnoreCase("s3")) {
return s3.generateURI(bucketNameOrPath, objectName, S3.URI_STYLE_S3, secure);
return s3.generateURI(pae.bucketName, pae.objectName, S3.URI_STYLE_S3, secure);
}
else if (type.equalsIgnoreCase("arn")) {
return s3.generateURI(bucketNameOrPath, objectName, S3.URI_STYLE_ARN, secure);
return s3.generateURI(pae.bucketName, pae.objectName, S3.URI_STYLE_ARN, secure);
}
else {
throw new S3Exception("type [" + type + "] is invalid, valid types are [virtualhost, path, arn or s3]");
Expand Down

0 comments on commit fdb040d

Please sign in to comment.