Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDEV-3379 - Add a method to the S3 extension to delete objects. #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions build.number

This file was deleted.

55 changes: 54 additions & 1 deletion source/fld/function.fld
Original file line number Diff line number Diff line change
Expand Up @@ -368,5 +368,58 @@
<type>void</type>
</return>
</function>



<!-- S3Delete -->
<function>
<name>S3Delete</name>
<class bundle-name="{bundle-name}" bundle-version="{bundle-version}">org.lucee.extension.resource.s3.function.S3Delete</class>
<description>Removes an object from S3.</description>
<argument>
<name>bucketName</name>
<alias>bucket</alias>
<type>string</type>
<required>Yes</required>
<description>Name of the bucket to list objects from.</description>
</argument>
<argument>
<name>objectName</name>
<alias>object,path</alias>
<type>string</type>
<required>Yes</required>
<description>Name of the object (path) within the bucket of your object to delete.</description>
</argument>
<argument>
<name>forceDelete</name>
<type>boolean</type>
<required>No</required>
<default>0</default>
<description>Force non-empty folders to be deleted.</description>
</argument>
<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>timeout</name>
<type>number</type>
<required>No</required>
<default>10000</default>
<description>timeout for this execution</description>
</argument>
<return>
<type>void</type>
</return>
</function>

</func-lib>
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.util.Cast;

public class S3Delete extends S3Function {

private static final long serialVersionUID = -2904887068889788095L;

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

try {
S3 s3 = S3ResourceProvider.getS3(toS3Properties(pc, accessKeyId, secretAccessKey), toTimeout(timeout));
s3.delete(bucketName, objectName, forceDelete);
}

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

return null;

}

@Override
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]), cast.toString(args[1]), cast.toBoolean(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.toBoolean(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.toBoolean(args[2]), cast.toString(args[3]), null, 0);
if (args.length == 3) return call(pc, cast.toString(args[0]), cast.toString(args[1]), cast.toBoolean(args[2]), null, null, 0);
if (args.length == 2) return call(pc, cast.toString(args[0]), cast.toString(args[1]), false, null, null, 0);

throw engine.getExceptionUtil().createFunctionException(pc, "S3Delete", 2, 6, args.length);
}
}