Skip to content

Commit

Permalink
improve exception
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Oct 6, 2023
1 parent fe67b16 commit 342c5fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,18 @@ PropsAndEndpoint extractFromPath(CFMLEngine eng, String bucketName, String objec
props.setAccessKeyId(accessKeyId);
props.setSecretAccessKey(secretAccessKey);
props.setHost(host);

RefString location = eng.getCreationUtil().createRefString(null);
String[] bo = S3Resource.toBO(S3ResourceProvider.loadWithNewPattern(props, location, bucketName.substring(5), Util.isEmpty(accessKeyId)));
bucketName = bo[0];
objectName = bo[1];

if (objectName != null && objectName.endsWith("/")) objectName = objectName.substring(0, objectName.length() - 1);

// explicit credentals overrule in path credentials!
if (!Util.isEmpty(accessKeyId)) props.setAccessKeyId(accessKeyId);
if (!Util.isEmpty(secretAccessKey)) props.setSecretAccessKey(secretAccessKey);
if (!Util.isEmpty(host)) props.setHost(host);

if (objectName != null && objectName.endsWith("/")) objectName = objectName.substring(0, objectName.length() - 1);
}
return new PropsAndEndpoint(props, bucketName, objectName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.lucee.extension.resource.s3.function;

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

import lucee.loader.engine.CFMLEngine;
import lucee.loader.engine.CFMLEngineFactory;
Expand Down Expand Up @@ -55,14 +56,15 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {
* secretAccessKey, host)); print.e("pae.bucketName:" + pae.bucketName); print.e("pae.objectName:" +
* pae.objectName);
*/

S3Properties props = pae.props != null ? pae.props : toS3Properties(pc, accessKeyId, secretAccessKey, host);
try {
// create S3 Instance
S3 s3 = S3.getInstance(pae.props != null ? pae.props : toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
S3 s3 = S3.getInstance(props, toTimeout(timeout));
return s3.getMetaData(pae.bucketName, pae.objectName);
}
catch (Exception e) {
throw eng.getCastUtil().toPageException(e);
throw eng.getExceptionUtil().createApplicationException(eng.getStringUtil().replace(props.toString(), secretAccessKey, "...", false, true));
// throw eng.getCastUtil().toPageException(e);
}
}
}

0 comments on commit 342c5fc

Please sign in to comment.