Skip to content

Commit

Permalink
add function S3ListBuckets
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Aug 18, 2023
1 parent 4ee665c commit f18d4ab
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 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!
#Thu Aug 17 17:04:58 CEST 2023
build.number=4
#Fri Aug 18 11:06:26 CEST 2023
build.number=5
38 changes: 38 additions & 0 deletions source/fld/function.fld
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,44 @@
</function>


<!-- S3ListBuckets -->
<function>
<name>S3ListBuckets</name>
<class bundle-name="{bundle-name}" bundle-version="{bundle-version}">org.lucee.extension.resource.s3.function.S3ListBuckets</class>
<description>List all buckets</description>
<argument>
<name>accessKeyId</name>
<alias>accessKey</alias>
<type>string</type>
<required>No</required>
<description>S3 accessKeyId, if not defined it checks the system property/environment variable for [lucee.s3.accesskeyid].</description>
</argument>
<argument>
<name>secretAccessKey</name>
<alias>secretkey</alias>
<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>
<type>number</type>
<required>No</required>
<default>10000</default>
<description>timeout for this execution</description>
</argument>
<return>
<type>query</type>
</return>
</function>

<!-- S3ClearBucket -->
<function>
<name>S3ClearBucket</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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;
import lucee.runtime.PageContext;
import lucee.runtime.exp.PageException;
import lucee.runtime.type.Query;
import lucee.runtime.util.Cast;

public class S3ListBuckets extends S3Function {

private static final long serialVersionUID = -1304574485741405364L;

public static Query call(PageContext pc, 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, host), toTimeout(timeout));
return s3.listBucketsAsQuery();

}
catch (Exception e) {
throw CFMLEngineFactory.getInstance().getCastUtil().toPageException(e);
}
}

@Override
public Object invoke(PageContext pc, Object[] args) throws PageException {
CFMLEngine engine = CFMLEngineFactory.getInstance();
Cast cast = engine.getCastUtil();
if (args.length == 4) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), cast.toDoubleValue(args[3]));
if (args.length == 3) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toString(args[2]), 0);
if (args.length == 2) return call(pc, cast.toString(args[0]), cast.toString(args[1]), null, 0);
if (args.length == 1) return call(pc, cast.toString(args[0]), null, null, 0);
if (args.length == 0) return call(pc, null, null, null, 0);
throw engine.getExceptionUtil().createFunctionException(pc, "S3ListBuckets", 0, 4, args.length);
}
}

0 comments on commit f18d4ab

Please sign in to comment.