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

update to latest version: v1.0.1 #8

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 3 additions & 9 deletions .github/workflows/publish-to-maven.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# This workflow will publish Trend Vision One File Security Java SDK to Maven Central with OSSRH
# This workflow will publish AMaaS Java SDK to Maven Central with OSSRH

name: Java with Maven

on:
push:

permissions:
contents: read
release:
types: [published]

jobs:
build:
Expand All @@ -28,8 +26,6 @@ jobs:
# Setup Envvar for build
- name: Set env
run: |
VERSION=$(cat ./VERSION)
echo "AMAAS_JAVA_MODULE_VERSION_ID=$VERSION" >> $GITHUB_ENV
if [[ "${{ github.ref }}" == "refs/tags/v"* ]];
then
echo "PACK_CMD=deploy" >> $GITHUB_ENV
Expand All @@ -40,11 +36,9 @@ jobs:
# package and optionally publish Java SDK to Maven Central
- name: Package and optionally deploy with Maven
run: |
sed -i 's/__PACKAGE_VERSION__/${{env.AMAAS_JAVA_MODULE_VERSION_ID}}/' pom.xml
mkdir -p src/main/proto/
cp protos/scan.proto src/main/proto/
mvn -B clean ${{env.PACK_CMD}}
sed -i 's/${{env.AMAAS_JAVA_MODULE_VERSION_ID}}/__PACKAGE_VERSION__/' pom.xml
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This workflow will publish AMaaS Java SDK to Maven Central with OSSRH

name: Java SDK Unit Tests

on:
pull_request:
branches:
- main

jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Maven and Java
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'adopt'

- name: Run unit tests
run: |
mkdir -p src/main/proto/
cp protos/scan.proto src/main/proto/
mvn test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# general things to ignore
**/target/
**/output/
*~
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# CHANGELOG

## 1.0.0 - 2023-11-7
## 1.0.1 - 2023-11-23
* Update to latest code

## 1.0.0 - 2023-11-21
* Initial release
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ a project may be further defined and clarified by project maintainers.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at amaas@trendmicro.com. All
reported by contacting the project team at legal_notice@trendmicro.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Expand Down
27 changes: 15 additions & 12 deletions examples/filescan/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
import com.trend.cloudone.amaas.AMaasException;


public class App {
public final class App {
private static final Logger logger = Logger.getLogger(App.class.getName());

private static void info(String msg, Object... params) {
private App() {
}

private static void info(final String msg, final Object... params) {
logger.log(Level.INFO, msg, params);
}

public static String[] listFiles(String pathName) {
private static String[] listFiles(final String pathName) {
File fObj = new File(pathName);
if (!fObj.isDirectory()) {
return new String[]{pathName};
Expand All @@ -31,7 +34,7 @@ public static String[] listFiles(String pathName) {
.collect(Collectors.toList()).toArray(new String[] {});
}

static void scanFilesInSequential(AMaasClient client, String[] fList) {
static void scanFilesInSequential(final AMaasClient client, final String[] fList) {
for (String fileName: fList) {
try {
info("===============> Scanning file {0}", fileName);
Expand All @@ -43,7 +46,7 @@ static void scanFilesInSequential(AMaasClient client, String[] fList) {
} catch (AMaasException err) {
info("Exception {0}", err.getMessage());
}
}
}
}

private static Options getCmdOptions() {
Expand All @@ -54,16 +57,16 @@ private static Options getCmdOptions() {
optionList.addOption("t", "timeout", true, "Per scan timeout in seconds");
return optionList;
}
/*
* The program takes 4 options and respecive values to configure the AMaaS SDK client.
* @param String[] Input options:

/**
* The program takes 4 options and respective values to configure the AMaaS SDK client.
* @param args Input options:
* -f a file or a directory to be scanned
* -k the API key or bearer authentication token
* -r region where the key/token was applied. eg, us-east-1
* -t optional client maximum waiting time in seconds for a scan. 0 or missing means default.
*/
public static void main(String[] args) {
public static void main(final String[] args) {
String pathname = "";
String apikey = null;
String region = "";
Expand All @@ -90,9 +93,9 @@ public static void main(String[] args) {
AMaasClient client = new AMaasClient(region, apikey, timeout);
String[] listOfFiles = listFiles(pathname);
long totalStartTs = System.currentTimeMillis();

scanFilesInSequential(client, listOfFiles);

long totalEndTs = System.currentTimeMillis();
info("*************** Total scan time {0}", totalEndTs - totalStartTs);
} catch (ParseException err) {
Expand Down
56 changes: 31 additions & 25 deletions examples/parallelscan/ConcurrentApp.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import java.io.File;
import java.io.File;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletionService;
Expand All @@ -22,15 +22,20 @@
import com.trend.cloudone.amaas.AMaasClient;
import com.trend.cloudone.amaas.AMaasException;

public class ConcurrentApp {
public final class ConcurrentApp {
private static final Logger logger = Logger.getLogger(ConcurrentApp.class.getName());
private static final int MAX_NUM_OF_THREADS = 5;
private static final int MILLISEC_PER_SEC = 1000;
private static final int DELAY_MILLISEC = 500;

private static void info(String msg, Object... params) {
private ConcurrentApp() {
}

private static void info(final String msg, final Object... params) {
logger.log(Level.INFO, msg, params);
}

public static String[] listFiles(String pathName) {
private static String[] listFiles(final String pathName) {
File fObj = new File(pathName);
if (!fObj.isDirectory()) {
return new String[]{pathName};
Expand All @@ -45,14 +50,15 @@ public static String[] listFiles(String pathName) {
* Value object class for tracking a scan result.
*/
private static final class ScanResult {
String scanResult;
long scanTime;
public ScanResult(String result, long scanTime) {
private String scanResult;
private long scanTime;
ScanResult(final String result, final long scanTime) {
this.scanResult = result;
this.scanTime = scanTime;
}
@Override
public String toString(){

@Override
public String toString() {
return scanResult + " " + scanTime;
}
}
Expand All @@ -64,12 +70,12 @@ private static final class Task implements Callable<ScanResult> {
private final String fileName;
private final AMaasClient client;

Task(AMaasClient client, String fileName){
Task(final AMaasClient client, final String fileName) {
this.fileName = fileName;
this.client = client;
}
@Override

@Override
public ScanResult call() throws Exception {
ScanResult result = null;
try {
Expand All @@ -84,10 +90,10 @@ public ScanResult call() throws Exception {
}
return result;
}

}

static void scanFilesInParallel(AMaasClient client, String[] fList, long timeout) {
static void scanFilesInParallel(final AMaasClient client, final String[] fList, final long timeout) {
info("Scan files in Parallel");
int numThreads = MAX_NUM_OF_THREADS;
if (fList.length < numThreads) {
Expand All @@ -97,14 +103,14 @@ static void scanFilesInParallel(AMaasClient client, String[] fList, long timeout
try {
executor = Executors.newFixedThreadPool(numThreads);
CompletionService<ScanResult> scanService = new ExecutorCompletionService<>(executor);
for(String file : fList){
for (String file : fList) {
Task task = new Task(client, file);
scanService.submit(task);
}
for(int i = 0; i < fList.length; i++){

for (int i = 0; i < fList.length; i++) {
Future<ScanResult> future = scanService.take();
ScanResult result = future.get(timeout * 1000 + 500, TimeUnit.MILLISECONDS);
ScanResult result = future.get(timeout * MILLISEC_PER_SEC + DELAY_MILLISEC, TimeUnit.MILLISECONDS);
if (result != null) {
info(future.get().toString());
}
Expand All @@ -128,16 +134,16 @@ private static Options getCmdOptions() {
optionList.addOption("t", "timeout", true, "Per scan timeout in seconds");
return optionList;
}
/*
* The program takes 4 options and respecive values to configure the AMaaS SDK client.
* @param String[] Input options:

/**
* The program takes 4 options and respective values to configure the AMaaS SDK client.
* @param args Input options:
* -f a file or a directory to be scanned
* -k the API key or bearer authentication token
* -r region where the key/token was applied. eg, us-east-1
* -t optional client maximum waiting time in seconds for a scan. 0 or missing means default.
*/
public static void main(String[] args) {
public static void main(final String[] args) {
String pathName = "";
String apikey = null;
String region = "";
Expand All @@ -160,12 +166,12 @@ public static void main(String[] args) {
if (cmd.hasOption("t")) {
timeout = Long.parseLong(cmd.getOptionValue("t"));
}

AMaasClient client = new AMaasClient(region, apikey, timeout);
String[] listOfFiles = listFiles(pathName);
long totalStartTs = System.currentTimeMillis();
scanFilesInParallel(client, listOfFiles, timeout);

long totalEndTs = System.currentTimeMillis();
info("*************** Total scan time {0}", totalEndTs - totalStartTs);
} catch (ParseException err) {
Expand Down
37 changes: 20 additions & 17 deletions examples/s3app/S3App.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,35 @@
import com.trend.cloudone.amaas.AMaasClient;
import com.trend.cloudone.amaas.AMaasException;

public class S3App {
public final class S3App {
private static final Logger logger = Logger.getLogger(S3App.class.getName());
private static final int BUFFER_LENGTH = 16483;
private S3App() {
}

private static void info(String msg, Object... params) {
private static void info(final String msg, final Object... params) {
logger.log(Level.INFO, msg, params);
}
public static byte[] serialize(ResponseInputStream<GetObjectResponse> data) {

private static byte[] serialize(final ResponseInputStream<GetObjectResponse> data) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();

int nRead;
byte[] byteArray = new byte[16384];
byte[] byteArray = new byte[BUFFER_LENGTH];

try {
while ((nRead = data.read(byteArray, 0, byteArray.length)) != -1) {
buffer.write(byteArray, 0, nRead);
}
} catch (IOException e) {
info("I/O error while serializing data: {} | {}", e.getMessage(), e);
}

return buffer.toByteArray();
}

public static byte[] downloadS3Object(String regionstr, String bucketName, String key) throws Exception {
private static byte[] downloadS3Object(final String regionstr, final String bucketName, final String key) throws Exception {

S3Client s3 = S3Client.builder()
.credentialsProvider(ProfileCredentialsProvider.create())
.region(Region.of(regionstr))
Expand All @@ -69,17 +72,17 @@ private static Options getCmdOptions() {
return optionList;
}

/*
/**
* The program takes 6 options and respecive values to configure the AMaaS SDK client.
* @param String[] Input options:
* -a AWS region
* @param args Input options:
* -a AWS region
* -b S3 bucket name
* -f S3 key to be scanned
* -k the API key or bearer authentication token
* -r region where the C1 key/token was applied. eg, us-east-1
* -t optional client maximum waiting time in seconds for a scan. 0 or missing means default.
*/
public static void main(String[] args) {
public static void main(final String[] args) {
String awsRegion = "";
String bucketName = "";
String keyName = "";
Expand All @@ -97,7 +100,7 @@ public static void main(String[] args) {
}
if (cmd.hasOption("b")) {
bucketName = cmd.getOptionValue("b");
}
}
if (cmd.hasOption("f")) {
keyName = cmd.getOptionValue("f");
}
Expand All @@ -110,14 +113,14 @@ public static void main(String[] args) {
if (cmd.hasOption("t")) {
timeout = Long.parseLong(cmd.getOptionValue("t"));
}

info("Downloading S3 Object....");
byte[] bytes = downloadS3Object(awsRegion, bucketName, keyName);
info("Completed downloading S3 Object....");
AMaasClient client = new AMaasClient(amaasRegion, apikey, timeout);
long totalStartTs = System.currentTimeMillis();
client.scanBuffer(bytes, keyName);

long totalEndTs = System.currentTimeMillis();
info("*************** Total scan time {0}", totalEndTs - totalStartTs);
} catch (ParseException err) {
Expand Down
Loading
Loading