-
Notifications
You must be signed in to change notification settings - Fork 275
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
Clean up REST API (Part 1) #2900
Merged
stephen-crawford
merged 2 commits into
opensearch-project:main
from
willyborankin:clean-up-rest-api-classes
Jul 27, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,16 +14,20 @@ | |
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.ImmutableSet; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.bouncycastle.crypto.generators.OpenBSDBCrypt; | ||
|
||
import org.opensearch.action.index.IndexResponse; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.cluster.service.ClusterService; | ||
import org.opensearch.core.common.bytes.BytesReference; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.transport.TransportAddress; | ||
import org.opensearch.common.util.concurrent.ThreadContext; | ||
|
@@ -38,8 +42,8 @@ | |
import org.opensearch.security.auditlog.AuditLog; | ||
import org.opensearch.security.configuration.AdminDNs; | ||
import org.opensearch.security.configuration.ConfigurationRepository; | ||
import org.opensearch.security.dlic.rest.validation.AbstractConfigurationValidator; | ||
import org.opensearch.security.dlic.rest.validation.AccountValidator; | ||
import org.opensearch.security.dlic.rest.validation.RequestContentValidator; | ||
import org.opensearch.security.dlic.rest.validation.RequestContentValidator.DataType; | ||
import org.opensearch.security.privileges.PrivilegesEvaluator; | ||
import org.opensearch.security.securityconf.Hashed; | ||
import org.opensearch.security.securityconf.impl.CType; | ||
|
@@ -58,6 +62,9 @@ | |
* Currently this action serves GET and PUT request for /_opendistro/_security/api/account endpoint | ||
*/ | ||
public class AccountApiAction extends AbstractApiAction { | ||
|
||
private final static Logger LOGGER = LogManager.getLogger(AccountApiAction.class); | ||
|
||
private static final String RESOURCE_NAME = "account"; | ||
private static final List<Route> routes = addRoutesPrefix( | ||
ImmutableList.of(new Route(Method.GET, "/account"), new Route(Method.PUT, "/account")) | ||
|
@@ -154,7 +161,7 @@ | |
|
||
response = new BytesRestResponse(RestStatus.OK, builder); | ||
} catch (final Exception exception) { | ||
log.error(exception.toString()); | ||
LOGGER.error(exception.toString()); | ||
|
||
builder.startObject().field("error", exception.toString()).endObject(); | ||
|
||
|
@@ -241,9 +248,29 @@ | |
} | ||
|
||
@Override | ||
protected AbstractConfigurationValidator getValidator(RestRequest request, BytesReference ref, Object... params) { | ||
protected RequestContentValidator createValidator(final Object... params) { | ||
final User user = threadContext.getTransient(ConfigConstants.OPENDISTRO_SECURITY_USER); | ||
return new AccountValidator(request, ref, this.settings, user.getName()); | ||
return RequestContentValidator.of(new RequestContentValidator.ValidationContext() { | ||
@Override | ||
public Object[] params() { | ||
return new Object[] { user.getName() }; | ||
} | ||
|
||
@Override | ||
public Settings settings() { | ||
return settings; | ||
} | ||
|
||
@Override | ||
public Set<String> mandatoryKeys() { | ||
return ImmutableSet.of("current_password"); | ||
} | ||
|
||
@Override | ||
public Map<String, RequestContentValidator.DataType> allowedKeys() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is much cleaner than now. Ultimately, I'd like to see this defined with an OpenAPI spec like syntax one day |
||
return ImmutableMap.of("hash", DataType.STRING, "password", DataType.STRING, "current_password", DataType.STRING); | ||
stephen-crawford marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}); | ||
} | ||
|
||
@Override | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do
handleDelete
andhandleGet
use the JsonNode parameter anywhere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are not, I intentionally left them as is, the next PR will change this logic