Skip to content

Commit

Permalink
add additional logging to S3
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Nov 15, 2023
1 parent b2f257e commit efb9bbd
Show file tree
Hide file tree
Showing 27 changed files with 174 additions and 62 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!
#Mon Nov 13 16:47:10 CET 2023
build.number=9
#Wed Nov 15 10:40:45 CET 2023
build.number=10
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static AmazonS3Client get(String accessKeyId, String secretAccessKey, Str
client = pool.get(key);
if (client == null || client.isExpired()) {
pool.put(key, client = new AmazonS3Client(accessKeyId, secretAccessKey, host, region, key, liveTimeout, pathStyleAccess, log));
if (log != null) log.debug("S3", "create client for [" + accessKeyId + ":...@" + host + "]");
}
}

Expand Down
141 changes: 113 additions & 28 deletions source/java/src/org/lucee/extension/resource/s3/S3.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public static Struct getApplicationData(PageContext pc) {
}
}
catch (Exception e) {
Log log = pc.getConfig().getLog("application");
Log log = S3.getLog(pc != null ? pc.getConfig() : CFMLEngineFactory.getInstance().getThreadConfig());
if (log != null) log.error("S3", e);
}

Expand All @@ -196,7 +196,7 @@ else if (eng.getClassUtil().isInstaneOf("lucee.runtime.listener.ClassicApplicati
}
}
catch (Exception e) {
Log log = pc.getConfig().getLog("application");
Log log = S3.getLog(pc != null ? pc.getConfig() : CFMLEngineFactory.getInstance().getThreadConfig());
if (log != null) log.error("S3", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ public void createFile(boolean createParentWhenNotExists) throws IOException {

@Override
public InputStream getInputStream() throws IOException {
engine.getResourceUtil().checkGetInputStreamOK(this);
provider.read(this);
return engine.getIOUtil().toBufferedInputStream(s3.getInputStream(bucketName, objectName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Resource getResource(String path) {
* props.getCustomHost());
*/

return new S3Resource(engine, S3.getInstance(props, cache), props, location.getValue(), this, path);
return new S3Resource(engine, S3.getInstance(props, cache, engine.getThreadConfig()), props, location.getValue(), this, path);
}

public static String loadWithNewPattern(S3Properties properties, RefString storage, String path, boolean errorWhenNoCred) {
Expand Down
34 changes: 34 additions & 0 deletions source/java/src/org/lucee/extension/resource/s3/S3Util.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
package org.lucee.extension.resource.s3;

import java.lang.reflect.Method;
import java.util.Collection;

import lucee.commons.io.res.Resource;
import lucee.loader.engine.CFMLEngineFactory;
import lucee.loader.util.Util;
import lucee.runtime.PageContext;
import lucee.runtime.config.Config;
import lucee.runtime.exp.PageException;

public class S3Util {
private static final Class[] EMPTY_CLASS = new Class[0];
private static final Object[] EMPTY_OBJ = new Object[0];
private static Method pcGetLogNames;
private static Method configGetLogNames;

public static String getSystemPropOrEnvVar(String name, String defaultValue) {
// env
String value = System.getenv(name);
Expand Down Expand Up @@ -59,4 +70,27 @@ public static String removeSecret(Resource res, String msg) {
}
return msg;
}

// java.util.Collection<String> getLogNames()
public static java.util.Collection<String> getLogNames(PageContext pc) throws PageException {
try {
if (pcGetLogNames == null || pcGetLogNames.getDeclaringClass() != pc.getClass()) pcGetLogNames = pc.getClass().getMethod("getLogNames", EMPTY_CLASS);
return (Collection<String>) pcGetLogNames.invoke(pc, EMPTY_OBJ);
}
catch (Exception e) {
throw CFMLEngineFactory.getInstance().getCastUtil().toPageException(e);
}
}

// public String[] getLogNames() {
public static String[] getLogNames(Config config) throws PageException {
try {
if (configGetLogNames == null || configGetLogNames.getDeclaringClass() != config.getClass())
configGetLogNames = config.getClass().getMethod("getLogNames", EMPTY_CLASS);
return (String[]) configGetLogNames.invoke(config, EMPTY_OBJ);
}
catch (Exception e) {
throw CFMLEngineFactory.getInstance().getCastUtil().toPageException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Object invoke(final PageContext pc, final Object[] args) throws PageExcep

try {
// create S3 Instance
S3 s3 = S3.getInstance(pae.props != null ? pae.props : toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(pae.props != null ? pae.props : toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());
s3.addAccessControlList(pae.bucketName, pae.objectName, objACL);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static Object call(PageContext pc, String bucketName, TimeSpan maxAge, St
host = null;
}
try {
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());
s3.clear(bucketName, maxAge == null ? 0 : maxAge.getMillis());
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.lucee.extension.resource.s3.AccessControlListUtil;
import org.lucee.extension.resource.s3.S3;
import org.lucee.extension.resource.s3.S3Exception;
import org.lucee.extension.resource.s3.S3ResourceProvider;

import lucee.loader.engine.CFMLEngine;
import lucee.loader.engine.CFMLEngineFactory;
Expand Down Expand Up @@ -39,7 +38,7 @@ public static Object call(PageContext pc, String srcBucketName, String srcObject

try {
// create S3 Instance
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());
s3.copyObject(srcBucketName, srcObjectName, trgBucketName, trgObjectName, acl, location);
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {
Object acl = null;
try {
acl = objACL != null ? AccessControlListUtil.toAccessControlList(objACL) : null;
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());
s3.createDirectory(bucketName, acl, location);
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static Object call(PageContext pc, String bucketName, String objectName,
host = null;
}
try {
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());
if (Util.isEmpty(objectName, true)) s3.delete(bucketName, force);
else s3.delete(bucketName, objectName, force);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ else if (target instanceof Component) {
boolean hasBefore = toFunction(csa.get(BEFORE), null) != null;
boolean hasAfter = toFunction(csa.get(AFTER), null) != null;
UDF invoke = toFunction(csa.get(INVOKE), null);
if (invoke == null) throw eng.getExceptionUtil().createFunctionException(pc, "DirectoryEvery", 2, "component",
if (invoke == null) throw eng.getExceptionUtil().createFunctionException(pc, "S3Download", 2, "component",
"the listener component does not contain a instance function with name [invoke] that is required", null);
validateInvoke(pc, invoke, mode, blockSize, false);
}
Expand All @@ -92,7 +92,7 @@ else if ((targetRes = S3Write.toResource(pc, target, false, null)) == null) {

// create S3 Instance
try {
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());
S3Object obj = s3.getData(bucketName, objectName);
Cast caster = eng.getCastUtil();
// stream to UDF
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.lucee.extension.resource.s3.function;

import org.lucee.extension.resource.s3.S3;
import org.lucee.extension.resource.s3.S3ResourceProvider;

import lucee.loader.engine.CFMLEngine;
import lucee.loader.engine.CFMLEngineFactory;
Expand All @@ -23,7 +22,7 @@ public static boolean call(PageContext pc, String bucketName, String objectName,
}
try {
// create S3 Instance
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());

if (Util.isEmpty(objectName)) return s3.exists(bucketName);
return s3.exists(bucketName, objectName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {
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));
S3 s3 = S3.getInstance(pae.props != null ? pae.props : toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());
return s3.generatePresignedURL(pae.bucketName, pae.objectName, expireDate, httpMethod, sseAlgorithm, sseCustomerKey, checksum, contentType, contentDisposition,
contentEncoding, versionId, zeroByteContent, customResponseHeaders).toExternalForm();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {
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));
S3 s3 = S3.getInstance(pae.props != null ? pae.props : toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());

if (Util.isEmpty(type, true) || (type = type.trim()).equalsIgnoreCase("virtualhost")) {
return s3.generateURI(pae.bucketName, pae.objectName, S3.URI_STYLE_VIRTUAL_HOST, secure);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {

try {
// create S3 Instance
S3 s3 = S3.getInstance(pae.props != null ? pae.props : toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(pae.props != null ? pae.props : toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());
return s3.getAccessControlList(pae.bucketName, pae.objectName);
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {
S3Properties props = pae.props != null ? pae.props : toS3Properties(pc, accessKeyId, secretAccessKey, host);
try {
// create S3 Instance
S3 s3 = S3.getInstance(props, toTimeout(timeout));
S3 s3 = S3.getInstance(props, toTimeout(timeout), pc.getConfig());
return s3.getMetaData(pae.bucketName, pae.objectName);
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.lucee.extension.resource.s3.function;

import org.lucee.extension.resource.s3.S3;
import org.lucee.extension.resource.s3.S3ResourceProvider;

import lucee.loader.engine.CFMLEngine;
import lucee.loader.engine.CFMLEngineFactory;
Expand All @@ -23,7 +22,7 @@ public static Query call(PageContext pc, String bucketName, String accessKeyId,
host = null;
}
try {
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());
return s3.listObjectsAsQuery(bucketName);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.lucee.extension.resource.s3.function;

import org.lucee.extension.resource.s3.S3;
import org.lucee.extension.resource.s3.S3ResourceProvider;

import lucee.loader.engine.CFMLEngine;
import lucee.loader.engine.CFMLEngineFactory;
Expand All @@ -23,7 +22,7 @@ public static Query call(PageContext pc, String accessKeyId, String secretAccess
host = null;
}
try {
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());
return s3.listBucketsAsQuery();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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

import com.amazonaws.services.s3.model.CannedAccessControlList;

Expand Down Expand Up @@ -42,7 +41,7 @@ public static Object call(PageContext pc, String srcBucketName, String srcObject

try {
// create S3 Instance
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());
s3.moveObject(srcBucketName, srcObjectName, trgBucketName, trgObjectName, acl, location);
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.lucee.extension.resource.s3.function;

import org.lucee.extension.resource.s3.S3;
import org.lucee.extension.resource.s3.S3ResourceProvider;

import com.amazonaws.services.s3.model.S3Object;

Expand All @@ -25,7 +24,7 @@ public static String call(PageContext pc, String bucketName, String objectName,
}
try {
// create S3 Instance
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());
S3Object obj = s3.getData(bucketName, objectName);

// copy data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.ByteArrayOutputStream;

import org.lucee.extension.resource.s3.S3;
import org.lucee.extension.resource.s3.S3ResourceProvider;

import com.amazonaws.services.s3.model.S3Object;

Expand All @@ -26,7 +25,7 @@ public static byte[] call(PageContext pc, String bucketName, String objectName,
}
try {
// create S3 Instance
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());
S3Object obj = s3.getData(bucketName, objectName);

// copy data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {

try {
// create S3 Instance
S3 s3 = S3.getInstance(pae.props != null ? pae.props : toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(pae.props != null ? pae.props : toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());
s3.setAccessControlList(null, pae.bucketName, pae.objectName, objACL);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {

try {
// create S3 Instance
S3 s3 = S3.getInstance(pae.props != null ? pae.props : toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(pae.props != null ? pae.props : toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());
s3.setMetaData(pae.bucketName, pae.objectName, metadata);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {
Object acl = null;
try {
acl = objACL != null ? AccessControlListUtil.toAccessControlList(objACL) : null;
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());
s3.write(bucketName, objectName, source, acl, location);
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static Object call(PageContext pc, String bucketName, String objectName,

try {
// create S3 Instance
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout), pc.getConfig());

value = toResource(pc, value);

Expand Down

0 comments on commit efb9bbd

Please sign in to comment.