-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds new tif source config type - url download
Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
- Loading branch information
Showing
3 changed files
with
69 additions
and
5 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
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
63 changes: 63 additions & 0 deletions
63
src/main/java/org/opensearch/securityanalytics/threatIntel/model/UrlDownloadSource.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,63 @@ | ||
package org.opensearch.securityanalytics.threatIntel.model; | ||
|
||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
import org.opensearch.core.xcontent.ToXContent; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
|
||
/** | ||
* This is a Threat Intel Source config where the iocs are downloaded from the URL | ||
*/ | ||
public class UrlDownloadSource extends Source implements Writeable, ToXContent { | ||
public static final String URL_FIELD = "url"; | ||
public static final String SOURCE_NAME = "URL_DOWNLOAD"; | ||
|
||
private final URL url; | ||
|
||
public UrlDownloadSource(URL url) { | ||
this.url = url; | ||
} | ||
|
||
public UrlDownloadSource(StreamInput sin) throws IOException { | ||
this(new URL(sin.readString())); | ||
} | ||
|
||
@Override | ||
String name() { | ||
return SOURCE_NAME; | ||
} | ||
|
||
public URL getUrl() { | ||
return url; | ||
} | ||
|
||
public static UrlDownloadSource parse(XContentParser xcp) throws IOException { | ||
URL url = null; | ||
while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { | ||
String fieldName = xcp.currentName(); | ||
xcp.nextToken(); | ||
switch (fieldName) { | ||
case URL_FIELD: | ||
String urlString = xcp.text(); | ||
url = new URL(urlString); | ||
break; | ||
default: | ||
xcp.skipChildren(); | ||
} | ||
} | ||
return new UrlDownloadSource(url); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return builder.startObject() | ||
.startObject(URL_DOWNLOAD_FIELD) | ||
.field(URL_FIELD, url) | ||
.endObject() | ||
.endObject(); | ||
} | ||
} |