forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request awsdocs#166 from walkerk1980/Java_GuardDuty_ListDe…
…tectors Added GuardDuty ListDetectors() example for Java
- Loading branch information
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
all: target/aws-guardduty-examples-1.0.jar | ||
|
||
target/aws-guardduty-examples-1.0.jar: src/main/java/aws/example/guardduty/*.java | ||
mvn package | ||
|
||
clean: | ||
mvn clean | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>aws.example.guardduty</groupId> | ||
<artifactId>aws-guardduty-examples</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.0</version> | ||
<name>Amazon GuardDuty Examples</name> | ||
<url>http://maven.apache.org</url> | ||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-java-sdk-bom</artifactId> | ||
<version>1.11.375</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-java-sdk-guardduty</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>3.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
if [[ -z $* ]] ; then | ||
echo 'Supply the name of one of the example classes as an argument.' | ||
echo 'If there are arguments to the class, put them in quotes after the class name.' | ||
exit 1 | ||
fi | ||
export CLASSPATH=target/aws-guardduty-examples-1.0.jar | ||
export className=$1 | ||
echo "## Running $className..." | ||
shift | ||
echo "## arguments $@..." | ||
mvn exec:java -Dexec.mainClass="aws.example.guardduty.$className" -Dexec.args="$@" -Dexec.cleanupDaemonThreads=false |
48 changes: 48 additions & 0 deletions
48
java/example_code/guardduty/src/main/java/aws/example/guardduty/ListDetectors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
package aws.example.guardduty; | ||
import com.amazonaws.AmazonClientException; | ||
import com.amazonaws.AmazonServiceException; | ||
import com.amazonaws.services.guardduty.AmazonGuardDuty; | ||
import com.amazonaws.services.guardduty.AmazonGuardDutyClientBuilder; | ||
import com.amazonaws.services.guardduty.model.*; | ||
/** | ||
* List GuardDuty Detectors in the current AWS Region | ||
*/ | ||
public class ListDetectors { | ||
public static void main(String[] args) { | ||
|
||
AmazonGuardDuty guardduty = | ||
AmazonGuardDutyClientBuilder.defaultClient(); | ||
|
||
try { | ||
ListDetectorsRequest request = new ListDetectorsRequest(); | ||
|
||
ListDetectorsResult response = guardduty.listDetectors(request); | ||
|
||
for (String detectorId : response.getDetectorIds()) | ||
{ | ||
System.out.println("DetectorId: " + detectorId ); | ||
} | ||
} catch (AmazonServiceException ase) { | ||
System.out.println("Caught Exception: " + ase.getMessage()); | ||
System.out.println("Reponse Status Code: " + ase.getStatusCode()); | ||
System.out.println("Error Code: " + ase.getErrorCode()); | ||
System.out.println("Request ID: " + ase.getRequestId()); | ||
} | ||
|
||
} | ||
} | ||
|