-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
entire custom logtype implementation
Signed-off-by: Subhobrata Dey <[email protected]>
- Loading branch information
Showing
50 changed files
with
3,368 additions
and
303 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
21 changes: 21 additions & 0 deletions
21
src/main/java/org/opensearch/securityanalytics/action/DeleteCustomLogTypeAction.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,21 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.securityanalytics.action; | ||
|
||
import org.opensearch.action.ActionType; | ||
|
||
public class DeleteCustomLogTypeAction extends ActionType<DeleteCustomLogTypeResponse> { | ||
|
||
public static final DeleteCustomLogTypeAction INSTANCE = new DeleteCustomLogTypeAction(); | ||
public static final String NAME = "cluster:admin/opensearch/securityanalytics/logtype/delete"; | ||
|
||
public DeleteCustomLogTypeAction() { | ||
super(NAME, DeleteCustomLogTypeResponse::new); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/org/opensearch/securityanalytics/action/DeleteCustomLogTypeRequest.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,54 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.securityanalytics.action; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.action.support.WriteRequest; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
public class DeleteCustomLogTypeRequest extends ActionRequest { | ||
|
||
private String logTypeId; | ||
|
||
private WriteRequest.RefreshPolicy refreshPolicy; | ||
|
||
public DeleteCustomLogTypeRequest(String logTypeId, WriteRequest.RefreshPolicy refreshPolicy) { | ||
super(); | ||
this.logTypeId = logTypeId; | ||
this.refreshPolicy = refreshPolicy; | ||
} | ||
|
||
public DeleteCustomLogTypeRequest(StreamInput sin) throws IOException { | ||
this(sin.readString(), | ||
WriteRequest.RefreshPolicy.readFrom(sin)); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(logTypeId); | ||
refreshPolicy.writeTo(out); | ||
} | ||
|
||
public String getLogTypeId() { | ||
return logTypeId; | ||
} | ||
|
||
public WriteRequest.RefreshPolicy getRefreshPolicy() { | ||
return refreshPolicy; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/org/opensearch/securityanalytics/action/DeleteCustomLogTypeResponse.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,59 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.securityanalytics.action; | ||
|
||
import org.opensearch.action.ActionResponse; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
import org.opensearch.core.xcontent.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.rest.RestStatus; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.opensearch.securityanalytics.util.RestHandlerUtils._ID; | ||
import static org.opensearch.securityanalytics.util.RestHandlerUtils._VERSION; | ||
|
||
public class DeleteCustomLogTypeResponse extends ActionResponse implements ToXContentObject { | ||
|
||
private String id; | ||
|
||
private Long version; | ||
|
||
private RestStatus status; | ||
|
||
public DeleteCustomLogTypeResponse(String id, Long version, RestStatus status) { | ||
super(); | ||
this.id = id; | ||
this.version = version; | ||
this.status = status; | ||
} | ||
|
||
public DeleteCustomLogTypeResponse(StreamInput sin) throws IOException { | ||
this( | ||
sin.readString(), | ||
sin.readLong(), | ||
sin.readEnum(RestStatus.class) | ||
); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject() | ||
.field(_ID, id) | ||
.field(_VERSION, version); | ||
return builder.endObject(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(id); | ||
out.writeLong(version); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/org/opensearch/securityanalytics/action/IndexCustomLogTypeAction.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,21 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.securityanalytics.action; | ||
|
||
import org.opensearch.action.ActionType; | ||
|
||
public class IndexCustomLogTypeAction extends ActionType<IndexCustomLogTypeResponse> { | ||
|
||
public static final IndexCustomLogTypeAction INSTANCE = new IndexCustomLogTypeAction(); | ||
public static final String NAME = "cluster:admin/opensearch/securityanalytics/logtype/write"; | ||
|
||
public IndexCustomLogTypeAction() { | ||
super(NAME, IndexCustomLogTypeResponse::new); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/org/opensearch/securityanalytics/action/IndexCustomLogTypeRequest.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,90 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.securityanalytics.action; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.action.support.WriteRequest; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.securityanalytics.model.CustomLogType; | ||
|
||
import java.io.IOException; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class IndexCustomLogTypeRequest extends ActionRequest { | ||
|
||
private String logTypeId; | ||
|
||
private WriteRequest.RefreshPolicy refreshPolicy; | ||
|
||
private RestRequest.Method method; | ||
|
||
private CustomLogType customLogType; | ||
|
||
private static final Pattern IS_VALID_CUSTOM_LOG_NAME = Pattern.compile("[a-zA-Z0-9 _,-.]{5,50}"); | ||
|
||
public IndexCustomLogTypeRequest( | ||
String logTypeId, | ||
WriteRequest.RefreshPolicy refreshPolicy, | ||
RestRequest.Method method, | ||
CustomLogType customLogType | ||
) { | ||
super(); | ||
this.logTypeId = logTypeId; | ||
this.refreshPolicy = refreshPolicy; | ||
this.method = method; | ||
this.customLogType = customLogType; | ||
} | ||
|
||
public IndexCustomLogTypeRequest(StreamInput sin) throws IOException { | ||
this( | ||
sin.readString(), | ||
WriteRequest.RefreshPolicy.readFrom(sin), | ||
sin.readEnum(RestRequest.Method.class), | ||
CustomLogType.readFrom(sin) | ||
); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
Matcher matcher = IS_VALID_CUSTOM_LOG_NAME.matcher(customLogType.getName()); | ||
boolean find = matcher.matches(); | ||
if (!find) { | ||
throw new ActionRequestValidationException(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(logTypeId); | ||
refreshPolicy.writeTo(out); | ||
out.writeEnum(method); | ||
customLogType.writeTo(out); | ||
} | ||
|
||
public String getLogTypeId() { | ||
return logTypeId; | ||
} | ||
|
||
public WriteRequest.RefreshPolicy getRefreshPolicy() { | ||
return refreshPolicy; | ||
} | ||
|
||
public RestRequest.Method getMethod() { | ||
return method; | ||
} | ||
|
||
public CustomLogType getCustomLogType() { | ||
return customLogType; | ||
} | ||
} |
Oops, something went wrong.