Skip to content

Commit

Permalink
add argument "host" to all functions
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Aug 17, 2023
1 parent 3e92bbf commit 33290c2
Show file tree
Hide file tree
Showing 14 changed files with 259 additions and 98 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!
#Tue Aug 15 18:24:05 CEST 2023
build.number=3
#Thu Aug 17 17:04:58 CEST 2023
build.number=4
70 changes: 70 additions & 0 deletions source/fld/function.fld
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@
<type>string</type>
<required>No</required>
<description>S3 secretAccessKey, if not defined it checks the system property/environment variable for [lucee.s3.secretaccesskey].</description>
</argument>
<argument>
<name>host</name>
<alias>provider,server</alias>
<type>string</type>
<required>No</required>
<description>the provider to connect, if not set Amazon AWS is used.</description>
</argument>
<argument>
<name>timeout</name>
Expand Down Expand Up @@ -194,6 +201,13 @@
<type>string</type>
<required>No</required>
<description>S3 secretAccessKey, if not defined it checks the system property/environment variable for [lucee.s3.secretaccesskey].</description>
</argument>
<argument>
<name>host</name>
<alias>provider,server</alias>
<type>string</type>
<required>No</required>
<description>the provider to connect, if not set Amazon AWS is used.</description>
</argument>
<argument>
<name>timeout</name>
Expand Down Expand Up @@ -238,6 +252,13 @@
<type>string</type>
<required>No</required>
<description>S3 secretAccessKey, if not defined it checks the system property/environment variable for [lucee.s3.secretaccesskey].</description>
</argument>
<argument>
<name>host</name>
<alias>provider,server</alias>
<type>string</type>
<required>No</required>
<description>the provider to connect, if not set Amazon AWS is used.</description>
</argument>
<argument>
<name>timeout</name>
Expand Down Expand Up @@ -317,6 +338,13 @@
<type>string</type>
<required>No</required>
<description>S3 secretAccessKey, if not defined it checks the system property/environment variable for [lucee.s3.secretaccesskey].</description>
</argument>
<argument>
<name>host</name>
<alias>provider,server</alias>
<type>string</type>
<required>No</required>
<description>the provider to connect, if not set Amazon AWS is used.</description>
</argument>
<argument>
<name>timeout</name>
Expand Down Expand Up @@ -356,6 +384,13 @@
<type>string</type>
<required>No</required>
<description>S3 secretAccessKey, if not defined it checks the system property/environment variable for [lucee.s3.secretaccesskey].</description>
</argument>
<argument>
<name>host</name>
<alias>provider,server</alias>
<type>string</type>
<required>No</required>
<description>the provider to connect, if not set Amazon AWS is used.</description>
</argument>
<argument>
<name>timeout</name>
Expand Down Expand Up @@ -402,6 +437,13 @@
<type>string</type>
<required>No</required>
<description>S3 secretAccessKey, if not defined it checks the system property/environment variable for [lucee.s3.secretaccesskey].</description>
</argument>
<argument>
<name>host</name>
<alias>provider,server</alias>
<type>string</type>
<required>No</required>
<description>the provider to connect, if not set Amazon AWS is used.</description>
</argument>
<argument>
<name>timeout</name>
Expand Down Expand Up @@ -477,6 +519,13 @@
<type>string</type>
<required>No</required>
<description>S3 secretAccessKey, if not defined it checks the system property/environment variable for [lucee.s3.secretaccesskey].</description>
</argument>
<argument>
<name>host</name>
<alias>provider,server</alias>
<type>string</type>
<required>No</required>
<description>the provider to connect, if not set Amazon AWS is used.</description>
</argument>
<argument>
<name>timeout</name>
Expand Down Expand Up @@ -552,6 +601,13 @@
<type>string</type>
<required>No</required>
<description>S3 secretAccessKey, if not defined it checks the system property/environment variable for [lucee.s3.secretaccesskey].</description>
</argument>
<argument>
<name>host</name>
<alias>provider,server</alias>
<type>string</type>
<required>No</required>
<description>the provider to connect, if not set Amazon AWS is used.</description>
</argument>
<argument>
<name>timeout</name>
Expand Down Expand Up @@ -604,6 +660,13 @@
<type>string</type>
<required>No</required>
<description>S3 secretAccessKey, if not defined it checks the system property/environment variable for [lucee.s3.secretaccesskey].</description>
</argument>
<argument>
<name>host</name>
<alias>provider,server</alias>
<type>string</type>
<required>No</required>
<description>the provider to connect, if not set Amazon AWS is used.</description>
</argument>
<argument>
<name>timeout</name>
Expand Down Expand Up @@ -675,6 +738,13 @@
<type>string</type>
<required>No</required>
<description>S3 secretAccessKey, if not defined it checks the system property/environment variable for [lucee.s3.secretaccesskey].</description>
</argument>
<argument>
<name>host</name>
<alias>provider,server</alias>
<type>string</type>
<required>No</required>
<description>the provider to connect, if not set Amazon AWS is used.</description>
</argument>
<argument>
<name>timeout</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ public class S3ClearBucket extends S3Function {

private static final long serialVersionUID = -2904887068889788095L;

public static Object call(PageContext pc, String bucketName, TimeSpan maxAge, String accessKeyId, String secretAccessKey, double timeout) throws PageException {
public static Object call(PageContext pc, String bucketName, TimeSpan maxAge, String accessKeyId, String secretAccessKey, String host, double timeout) throws PageException {
CFMLEngine eng = CFMLEngineFactory.getInstance();

// for backward compatibility, when host was not existing
if (eng.getDecisionUtil().isNumber(host)) {
timeout = eng.getCastUtil().toDoubleValue(host);
host = null;
}
try {
S3 s3 = S3ResourceProvider.getS3(toS3Properties(pc, accessKeyId, secretAccessKey), toTimeout(timeout));
S3 s3 = S3ResourceProvider.getS3(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
s3.clear(bucketName, maxAge == null ? 0 : maxAge.getMillis());
}
catch (Exception e) {
Expand All @@ -31,12 +35,14 @@ public static Object call(PageContext pc, String bucketName, TimeSpan maxAge, St
public Object invoke(PageContext pc, Object[] args) throws PageException {
CFMLEngine engine = CFMLEngineFactory.getInstance();
Cast cast = engine.getCastUtil();
if (args.length == 6) return call(pc, cast.toString(args[0]), args[1] == null ? null : cast.toTimespan(args[1]), cast.toString(args[2]), cast.toString(args[3]),
cast.toString(args[4]), cast.toDoubleValue(args[5]));
if (args.length == 5)
return call(pc, cast.toString(args[0]), args[1] == null ? null : cast.toTimespan(args[1]), cast.toString(args[2]), cast.toString(args[3]), cast.toDoubleValue(args[4]));
if (args.length == 4) return call(pc, cast.toString(args[0]), args[1] == null ? null : cast.toTimespan(args[1]), cast.toString(args[2]), cast.toString(args[3]), 0);
if (args.length == 3) return call(pc, cast.toString(args[0]), args[1] == null ? null : cast.toTimespan(args[1]), cast.toString(args[2]), null, 0);
if (args.length == 2) return call(pc, cast.toString(args[0]), args[1] == null ? null : cast.toTimespan(args[1]), null, null, 0);
if (args.length == 1) return call(pc, cast.toString(args[0]), null, null, null, 0);
throw engine.getExceptionUtil().createFunctionException(pc, "S3ClearBucket", 1, 5, args.length);
return call(pc, cast.toString(args[0]), args[1] == null ? null : cast.toTimespan(args[1]), cast.toString(args[2]), cast.toString(args[3]), cast.toString(args[4]), 0);
if (args.length == 4) return call(pc, cast.toString(args[0]), args[1] == null ? null : cast.toTimespan(args[1]), cast.toString(args[2]), cast.toString(args[3]), null, 0);
if (args.length == 3) return call(pc, cast.toString(args[0]), args[1] == null ? null : cast.toTimespan(args[1]), cast.toString(args[2]), null, null, 0);
if (args.length == 2) return call(pc, cast.toString(args[0]), args[1] == null ? null : cast.toTimespan(args[1]), null, null, null, 0);
if (args.length == 1) return call(pc, cast.toString(args[0]), null, null, null, null, 0);
throw engine.getExceptionUtil().createFunctionException(pc, "S3ClearBucket", 1, 6, args.length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ public class S3Copy extends S3Function {
private static final long serialVersionUID = 7678256258034826909L;

public static Object call(PageContext pc, String srcBucketName, String srcObjectName, String trgBucketName, String trgObjectName, Object objACL, String location,
String accessKeyId, String secretAccessKey, double timeout) throws PageException {
String accessKeyId, String secretAccessKey, String host, double timeout) throws PageException {
CFMLEngine eng = CFMLEngineFactory.getInstance();

// for backward compatibility, when host was not existing
if (eng.getDecisionUtil().isNumber(host)) {
timeout = eng.getCastUtil().toDoubleValue(host);
host = null;
}

if (Util.isEmpty(trgObjectName, true)) trgObjectName = srcObjectName;

Object acl = null;
Expand All @@ -32,7 +39,7 @@ public static Object call(PageContext pc, String srcBucketName, String srcObject

try {
// create S3 Instance
S3 s3 = S3ResourceProvider.getS3(toS3Properties(pc, accessKeyId, secretAccessKey), toTimeout(timeout));
S3 s3 = S3ResourceProvider.getS3(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));
s3.copyObject(srcBucketName, srcObjectName, trgBucketName, trgObjectName, acl, location);
}
catch (Exception e) {
Expand All @@ -46,18 +53,20 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {
CFMLEngine engine = CFMLEngineFactory.getInstance();
Cast cast = engine.getCastUtil();

if (args.length == 10) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), cast.toString(args[3]), args[4], cast.toString(args[5]),
cast.toString(args[6]), cast.toString(args[7]), cast.toString(args[8]), cast.toDoubleValue(args[9]));
if (args.length == 9) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), cast.toString(args[3]), args[4], cast.toString(args[5]),
cast.toString(args[6]), cast.toString(args[7]), cast.toDoubleValue(args[8]));
cast.toString(args[6]), cast.toString(args[7]), cast.toString(args[8]), 0);
if (args.length == 8) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), cast.toString(args[3]), args[4], cast.toString(args[5]),
cast.toString(args[6]), cast.toString(args[7]), 0);
cast.toString(args[6]), cast.toString(args[7]), null, 0);
if (args.length == 7) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), cast.toString(args[3]), args[4], cast.toString(args[5]),
cast.toString(args[6]), null, 0);
cast.toString(args[6]), null, null, 0);
if (args.length == 6)
return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), cast.toString(args[3]), args[4], cast.toString(args[5]), null, null, 0);
if (args.length == 5) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), cast.toString(args[3]), args[4], null, null, null, 0);
if (args.length == 4) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), cast.toString(args[3]), null, null, null, null, 0);
if (args.length == 3) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), null, null, null, null, null, 0);
return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), cast.toString(args[3]), args[4], cast.toString(args[5]), null, null, null, 0);
if (args.length == 5) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), cast.toString(args[3]), args[4], null, null, null, null, 0);
if (args.length == 4) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), cast.toString(args[3]), null, null, null, null, null, 0);
if (args.length == 3) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), null, null, null, null, null, null, 0);

throw engine.getExceptionUtil().createFunctionException(pc, "S3Copy", 3, 9, args.length);
throw engine.getExceptionUtil().createFunctionException(pc, "S3Copy", 3, 10, args.length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ public class S3Exists extends S3Function {

private static final long serialVersionUID = -3512292354903523227L;

public static boolean call(PageContext pc, String bucketName, String objectName, String accessKeyId, String secretAccessKey, double timeout) throws PageException {
public static boolean call(PageContext pc, String bucketName, String objectName, String accessKeyId, String host, String secretAccessKey, double timeout) throws PageException {
CFMLEngine eng = CFMLEngineFactory.getInstance();
// for backward compatibility, when host was not existing
if (eng.getDecisionUtil().isNumber(host)) {
timeout = eng.getCastUtil().toDoubleValue(host);
host = null;
}
try {
// create S3 Instance
S3 s3 = S3ResourceProvider.getS3(toS3Properties(pc, accessKeyId, secretAccessKey), toTimeout(timeout));
S3 s3 = S3ResourceProvider.getS3(toS3Properties(pc, accessKeyId, secretAccessKey, host), toTimeout(timeout));

if (Util.isEmpty(objectName)) return s3.exists(bucketName);
return s3.exists(bucketName, objectName);
Expand All @@ -33,12 +38,14 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {
CFMLEngine engine = CFMLEngineFactory.getInstance();
Cast cast = engine.getCastUtil();

if (args.length == 5) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), cast.toString(args[3]), cast.toDoubleValue(args[4]));
if (args.length == 4) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), cast.toString(args[3]), 0);
if (args.length == 3) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), null, 0);
if (args.length == 2) return call(pc, cast.toString(args[0]), cast.toString(args[1]), null, null, 0);
if (args.length == 1) return call(pc, cast.toString(args[0]), null, null, null, 0);
if (args.length == 6)
return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), cast.toString(args[3]), cast.toString(args[4]), cast.toDoubleValue(args[5]));
if (args.length == 5) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), cast.toString(args[3]), cast.toString(args[4]), 0);
if (args.length == 4) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), cast.toString(args[3]), null, 0);
if (args.length == 3) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), null, null, 0);
if (args.length == 2) return call(pc, cast.toString(args[0]), cast.toString(args[1]), null, null, null, 0);
if (args.length == 1) return call(pc, cast.toString(args[0]), null, null, null, null, 0);

throw engine.getExceptionUtil().createFunctionException(pc, "S3Exists", 1, 5, args.length);
throw engine.getExceptionUtil().createFunctionException(pc, "S3Exists", 1, 6, args.length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ public abstract class S3Function extends BIF {
private static final long serialVersionUID = 5591490809164267541L;
private static final long DEFAULT_TIMEOUT = 10000L;

protected static S3Properties toS3Properties(PageContext pc, String accessKeyId, String secretAccessKey) throws PageException, RuntimeException {
protected static S3Properties toS3Properties(PageContext pc, String accessKeyId, String secretAccessKey, String host) throws PageException, RuntimeException {

// directly
if (!Util.isEmpty(accessKeyId, true) && !Util.isEmpty(secretAccessKey, true)) {
S3Properties props = new S3Properties();
props.setSecretAccessKey(secretAccessKey);
props.setAccessKeyId(accessKeyId);
if (!Util.isEmpty(host, true)) {
props.setHost(host);
props.setCustomHost(true);
}
props.setCustomCredentials(true);
return props;
}
Expand All @@ -63,8 +67,11 @@ protected static S3Properties toS3Properties(PageContext pc, String accessKeyId,
s3props.setSecretAccessKey(secretAccessKey);
s3props.setAccessKeyId(accessKeyId);
s3props.setCustomCredentials(false);
s3props.setCustomHost(false);
if (props.getHost() != null) s3props.setHost(props.getHost());
if (props.getHost() != null) {
s3props.setHost(props.getHost());
s3props.setCustomHost(true);
}
else s3props.setCustomHost(false);
return s3props;
}
}
Expand All @@ -76,6 +83,10 @@ protected static S3Properties toS3Properties(PageContext pc, String accessKeyId,
if (Util.isEmpty(accessKeyId, true)) accessKeyId = S3Util.getSystemPropOrEnvVar("lucee.s3.accesskeyid", null);
if (Util.isEmpty(accessKeyId, true)) accessKeyId = S3Util.getSystemPropOrEnvVar("lucee.s3.accesskey", null);

if (Util.isEmpty(host, true)) host = S3Util.getSystemPropOrEnvVar("lucee.s3.host", null);
if (Util.isEmpty(host, true)) host = S3Util.getSystemPropOrEnvVar("lucee.s3.server", null);
if (Util.isEmpty(host, true)) host = S3Util.getSystemPropOrEnvVar("lucee.s3.provider", 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]");
Expand All @@ -84,7 +95,11 @@ protected static S3Properties toS3Properties(PageContext pc, String accessKeyId,
props.setSecretAccessKey(secretAccessKey);
props.setAccessKeyId(accessKeyId);
props.setCustomCredentials(false);
props.setCustomHost(false);
if (!Util.isEmpty(host, true)) {
props.setHost(host);
props.setCustomHost(true);
}
else props.setCustomHost(false);

return props;
}
Expand Down
Loading

0 comments on commit 33290c2

Please sign in to comment.