-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support disabling any form of OpenSearch index management (#1420)
Support using Data Prepper without any form of OpenSearch index management through the addition of the management_disabled index_type. Resolves #1051. Signed-off-by: David Venable <[email protected]>
- Loading branch information
Showing
11 changed files
with
410 additions
and
31 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
60 changes: 60 additions & 0 deletions
60
...nTest/java/com/amazon/dataprepper/plugins/sink/opensearch/OpenSearchSecurityAccessor.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,60 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.amazon.dataprepper.plugins.sink.opensearch; | ||
|
||
import org.opensearch.client.Request; | ||
import org.opensearch.client.Response; | ||
import org.opensearch.client.RestClient; | ||
import org.opensearch.common.Strings; | ||
import org.opensearch.common.xcontent.XContentFactory; | ||
|
||
import javax.ws.rs.HttpMethod; | ||
import java.io.IOException; | ||
|
||
class OpenSearchSecurityAccessor { | ||
private static final String PLUGINS_SECURITY_API = "_opendistro/_security/api/"; | ||
private final RestClient client; | ||
|
||
OpenSearchSecurityAccessor(final RestClient client) { | ||
this.client = client; | ||
} | ||
|
||
void createBulkWritingRole(final String role, final String indexPattern) throws IOException { | ||
createRole(role, indexPattern, "indices:data/write/index", "indices:data/write/bulk*"); | ||
} | ||
|
||
private void createRole(final String role, final String indexPattern, final String... allowedActions) throws IOException { | ||
final Request request = new Request(HttpMethod.PUT, PLUGINS_SECURITY_API + "roles/" + role); | ||
|
||
final String createRoleJson = Strings.toString( | ||
XContentFactory.jsonBuilder() | ||
.startObject() | ||
.startArray("index_permissions") | ||
.startObject() | ||
.array("index_patterns", new String[]{indexPattern}) | ||
.array("allowed_actions", allowedActions) | ||
.endObject() | ||
.endArray() | ||
.endObject() | ||
); | ||
request.setJsonEntity(createRoleJson); | ||
final Response response = client.performRequest(request); | ||
} | ||
|
||
public void createUser(final String username, final String password, final String... roles) throws IOException { | ||
final Request request = new Request(HttpMethod.PUT, PLUGINS_SECURITY_API + "internalusers/" + username); | ||
|
||
final String createUserJson = Strings.toString( | ||
XContentFactory.jsonBuilder() | ||
.startObject() | ||
.field("password", password) | ||
.array("opendistro_security_roles", roles) | ||
.endObject() | ||
); | ||
request.setJsonEntity(createUserJson); | ||
final Response response = client.performRequest(request); | ||
} | ||
} |
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
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
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
Oops, something went wrong.