diff --git a/build.number b/build.number index 58e6618..23a09b9 100644 --- a/build.number +++ b/build.number @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Wed Jan 24 14:57:19 CET 2024 -build.number=15 +#Wed Feb 07 14:30:53 CET 2024 +build.number=16 diff --git a/source/java/src/org/lucee/extension/resource/s3/S3.java b/source/java/src/org/lucee/extension/resource/s3/S3.java index 6b784ea..4b746f6 100755 --- a/source/java/src/org/lucee/extension/resource/s3/S3.java +++ b/source/java/src/org/lucee/extension/resource/s3/S3.java @@ -31,7 +31,6 @@ import org.lucee.extension.resource.s3.region.RegionFactory; import org.lucee.extension.resource.s3.region.RegionFactory.Region; import org.lucee.extension.resource.s3.util.XMLUtil; -import org.lucee.extension.resource.s3.util.print; import com.amazonaws.AmazonServiceException; import com.amazonaws.HttpMethod; @@ -161,7 +160,7 @@ public static S3 getInstance(S3Properties props, long cache, Config config) { } } instances.put(keyS3, s3 = new S3(c, props.getAccessKeyId(), props.getSecretAccessKey(), props.getHost(), props.getDefaultLocation(), cache, - S3.DEFAULT_LIVE_TIMEOUT, true, config)); + S3.DEFAULT_LIVE_TIMEOUT, props.getCacheRegion(), config)); } } } @@ -227,7 +226,6 @@ private S3(S3Cache cache, String accessKeyId, String secretAccessKey, String hos this.host = host; this.cacheTimeout = cacheTimeout; this.liveTimeout = liveTimeout; - print.ds(); if (!Util.isEmpty(defaultLocation, true)) { try { defaultRegion = toString(RegionFactory.getInstance(defaultLocation)); @@ -1038,8 +1036,6 @@ public List list(String bucketName, final String objectName, boolean rec private List improveResult(ValidUntilMap objects, String bucketName, String objectName, boolean recursive, boolean listPseudoFolder, boolean onlyChildren, boolean noCache) throws S3Exception { bucketName = improveBucketName(bucketName); - print.e("--- improveResult ----"); - print.e("- " + objects.size()); Iterator it = objects.values().iterator(); Map map = new LinkedHashMap(); S3Info info; @@ -1047,13 +1043,11 @@ private List improveResult(ValidUntilMap objects, String bucketN info = it.next(); add(map, info, objectName, recursive, listPseudoFolder, onlyChildren); } - print.e("- " + map.size()); Iterator iit = map.values().iterator(); List list = new ArrayList(); while (iit.hasNext()) { list.add(iit.next()); } - print.e("- " + list.size()); return list; } diff --git a/source/java/src/org/lucee/extension/resource/s3/S3Properties.java b/source/java/src/org/lucee/extension/resource/s3/S3Properties.java index 22cdc87..cc04dc9 100644 --- a/source/java/src/org/lucee/extension/resource/s3/S3Properties.java +++ b/source/java/src/org/lucee/extension/resource/s3/S3Properties.java @@ -37,6 +37,7 @@ public class S3Properties { private String defaultLocation; private long cache; private String mapping; + private boolean cacheRegion = false; public void setBucket(String bucket) { if (!Util.isEmpty(bucket, true)) this.bucket = bucket; @@ -116,11 +117,20 @@ public String getMapping() { return mapping; } + public boolean getCacheRegion() { + return cacheRegion; + } + + public void setCacheRegion(boolean cacheRegion) { + this.cacheRegion = cacheRegion; + } + @Override public String toString() { return new StringBuilder().append("host:").append(getHost()).append(";").append("accessKeyId:").append(getAccessKeyId()).append(";").append("secretAccessKey:") - .append(getSecretAccessKey()).append(";acl:").append(getACL()).append(";location:").append(getDefaultLocation()).append(";").toString(); + .append(getSecretAccessKey()).append(";acl:").append(getACL()).append(";location:").append(getDefaultLocation()).append(";cacheRegion:").append(getCacheRegion()) + .append(";").toString(); } public void setACL(Object acl) { @@ -246,11 +256,13 @@ private static S3Properties toS3(CFMLEngine eng, Struct sct) throws S3Exception if (Util.isEmpty(sk)) sk = eng.getCastUtil().toString(sct.get("secretKey", null), null); return toS3(eng.getCastUtil().toString(sct.get("accessKeyId", null), null), sk, eng.getCastUtil().toString(sct.get("defaultLocation", null), null), host, bucket, - eng.getCastUtil().toString(sct.get("acl", null), null), eng.getCastUtil().toTimespan(sct.get("cache", null), null)); + eng.getCastUtil().toString(sct.get("acl", null), null), eng.getCastUtil().toBoolean(sct.get("cacheregion", null), null), + eng.getCastUtil().toTimespan(sct.get("cache", null), null)); } - private static S3Properties toS3(String accessKeyId, String awsSecretKey, String defaultLocation, String host, String bucket, String acl, TimeSpan cache) throws S3Exception { + private static S3Properties toS3(String accessKeyId, String awsSecretKey, String defaultLocation, String host, String bucket, String acl, Boolean cacheRegion, TimeSpan cache) + throws S3Exception { S3Properties s3 = new S3Properties(); defaultLocation = S3Util.extractLocationFromHostIfNecessary(defaultLocation, host); @@ -261,6 +273,7 @@ private static S3Properties toS3(String accessKeyId, String awsSecretKey, String if (!Util.isEmpty(host)) s3.setHost(host); if (!Util.isEmpty(bucket)) s3.setBucket(bucket); if (!Util.isEmpty(acl)) s3.setACL(AccessControlListUtil.toAccessControlList(acl)); + if (cacheRegion != null) s3.setCacheRegion(cacheRegion.booleanValue()); if (cache != null) s3.setCache(cache.getMillis()); return s3; diff --git a/source/java/src/org/lucee/extension/resource/s3/S3ResourceProvider.java b/source/java/src/org/lucee/extension/resource/s3/S3ResourceProvider.java index 9602fbf..72781c5 100755 --- a/source/java/src/org/lucee/extension/resource/s3/S3ResourceProvider.java +++ b/source/java/src/org/lucee/extension/resource/s3/S3ResourceProvider.java @@ -125,6 +125,7 @@ public static String loadWithNewPattern(S3Properties properties, RefString stora boolean hasCustomCredentials = false; String accessKeyId, host, secretAccessKey, defaultLocation, bucket, mapping = null; Object defaultACL; + Boolean cacheRegion = null; Struct appData = null; // env var / system prop @@ -150,6 +151,15 @@ public static String loadWithNewPattern(S3Properties properties, RefString stora defaultACL = S3Util.getSystemPropOrEnvVar("lucee.s3.acl", null); if (defaultACL == null) defaultACL = S3Util.getSystemPropOrEnvVar("lucee.s3.accesscontrollist", null); + + String tmp = S3Util.getSystemPropOrEnvVar("lucee.s3.cacheregion", null); + if (!Util.isEmpty(tmp, true)) { + try { + cacheRegion = Util.toBooleanValue(tmp.trim()); + } + catch (Exception e) { + } + } } // Application Context Data @@ -270,6 +280,7 @@ public static String loadWithNewPattern(S3Properties properties, RefString stora properties.setCustomCredentials(hasCustomCredentials); properties.setCustomHost(hasCustomHost); properties.setMapping(mapping); + if (cacheRegion != null) properties.setCacheRegion(cacheRegion); if (defaultACL != null) properties.setACL(defaultACL); if (defaultLocation != null) properties.setDefaultLocation(defaultLocation); if (!hasCustomHost && !Util.isEmpty(host, true)) properties.setHost(host); diff --git a/source/java/src/org/lucee/extension/resource/s3/function/S3Function.java b/source/java/src/org/lucee/extension/resource/s3/function/S3Function.java index 849b31a..f271a79 100644 --- a/source/java/src/org/lucee/extension/resource/s3/function/S3Function.java +++ b/source/java/src/org/lucee/extension/resource/s3/function/S3Function.java @@ -94,6 +94,9 @@ protected static S3Properties toS3Properties(PageContext pc, String accessKeyId, if (Util.isEmpty(host, true)) host = S3Util.getSystemPropOrEnvVar("lucee.s3.server", null); if (Util.isEmpty(host, true)) host = S3Util.getSystemPropOrEnvVar("lucee.s3.provider", null); + String strCacheRegion = S3Util.getSystemPropOrEnvVar("lucee.s3.cacheregion", null); + Boolean cacheRegion = (Util.isEmpty(strCacheRegion, true)) ? null : CFMLEngineFactory.getInstance().getCastUtil().toBoolean(strCacheRegion.trim(), null); + if (Util.isEmpty(secretAccessKey, true) || Util.isEmpty(accessKeyId, true)) throw CFMLEngineFactory.getInstance().getExceptionUtil().createApplicationException( "missing S3 credentials", "you can define the credentials as argument for the function [accessKeyId, secretAccessKey], in the application.cfc [this.s3.accessKeyId, this.s3.secretAccessKey] or in the system properties/environment variables [lucee.s3.secretaccesskey,lucee.s3.accesskeyid]"); @@ -107,6 +110,7 @@ protected static S3Properties toS3Properties(PageContext pc, String accessKeyId, props.setCustomHost(true); } else props.setCustomHost(false); + if (cacheRegion != null) props.setCacheRegion(cacheRegion.booleanValue()); return props; }