-
Notifications
You must be signed in to change notification settings - Fork 25k
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
HLRC: Add delete user action #35294
HLRC: Add delete user action #35294
Conversation
It adds delete user action to the high level rest client. Relates elastic#29827
Pinging @elastic/es-core-infra |
@elasticmachine test this please |
1 similar comment
@elasticmachine test this please |
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.
Great work. The biggest thing here is the comment about the Optional
stuff going on. I think the deciding factor is whether it throws a 404 or not for a bad user. Rest of the stuff is small.
client/rest-high-level/src/main/java/org/elasticsearch/client/SecurityRequestConverters.java
Outdated
Show resolved
Hide resolved
...rest-high-level/src/test/java/org/elasticsearch/client/security/DeleteUserResponseTests.java
Show resolved
Hide resolved
client/rest-high-level/src/main/java/org/elasticsearch/client/SecurityClient.java
Show resolved
Hide resolved
/** | ||
* Response for a role being deleted from the native realm | ||
*/ | ||
public final class DeleteUserResponse { |
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.
this could probably extend AcknowledgedResponse
. See StartRollupJobResponse
for what I mean. It is just a generic {"name": boolean}
class that allows you to specify name
.
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.
I would prefer not to extend that class as it seems weird to have a dependency in this class to rollup package. In addition the response is not an acknowledge but a boolean defining if the user was found or not.
If you still thing it is better to use AcknowledgedResponse
as a base class I will change it.
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.
its being moved to core in another PR thats currently in flight ;)
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.
I also think its worth potentially renaming it because this is really just {"SomethingNamed": boolean}
, and it just started as acknowledged response.
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.
Touche :) I will implement it that way then
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.
I reimplement it by extending AcknowledgedResponse
.
@elasticmachine test this please |
/** | ||
* Response for a user being deleted from the native realm | ||
*/ | ||
public final class DeleteUserResponse extends AcknowledgedResponse { |
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.
I think we can gut this altogether since optional has a "isPresent()" field. See #35470 and leave your thoughts there or here.
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.
Im still on the fence for whether we even need a found true/false in the code since we return an optional. WDYT?
ok, so going back to this i think its worthwhile to 1) throw a 404 if it does not exist, 2) remove found=true if it does exist, 3) remove the optional. Sorry for the rework, this was being fleshed out while we discussed :/ |
@elasticmachine test this please |
@elasticmachine test this please |
*/ | ||
public DeleteUserResponse deleteUser(DeleteUserRequest request, RequestOptions options) throws IOException { | ||
return restHighLevelClient.performRequestAndParseEntity(request, SecurityRequestConverters::deleteUser, options, | ||
DeleteUserResponse::fromXContent, singleton(404)); |
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.
Hey I saw some updates on this PR and I just wanted to throw a reminder out that we are not going to do a singleton(404) here, because we want a delete that is not found to throw an exception. Also, last time we spoke you were going to change this to AcknowledgedResponse. <3
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.
I have tried those approaches but they seem not to work. If I use AcknowledgedResponse
, then you get the following error:
> Throwable #1: java.io.IOException: Unable to parse response body for Response{requestLine=DELETE /_xpack/security/user/testUser?refresh=true HTTP/1.1, host=http://[::1]:58075, response=HTTP/1.1 200 OK}
> at __randomizedtesting.SeedInfo.seed([311ED8EAD4721921:2905907290C29FEC]:0)
> at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1417)
> at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1383)
> at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1350)
> at org.elasticsearch.client.SecurityClient.deleteUser(SecurityClient.java:114)
> at org.elasticsearch.client.documentation.SecurityDocumentationIT.testDeleteUser(SecurityDocumentationIT.java:158)
> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> at java.base/java.lang.Thread.run(Thread.java:834)
> Caused by: java.lang.IllegalArgumentException: Required [acknowledged
I think I need to override the class to be able to parse the response. Then I tried not to catch the exception and then I got the following error:
> Throwable #1: ElasticsearchStatusException[Unable to parse response body]; nested: ResponseException[method [DELETE], host [http://[::1]:57316], URI [/_xpack/security/user/testUser?refresh=true], status line [HTTP/1.1 404 Not Found]
> {"found":false}]; nested: ResponseException[method [DELETE], host [http://[::1]:57316], URI [/_xpack/security/user/testUser?refresh=true], status line [HTTP/1.1 404 Not Found]
> {"found":false}];
> at __randomizedtesting.SeedInfo.seed([1E08456835E2EAC7:6130DF071526C0A]:0)
> at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:1650)
> at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1411)
> at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1383)
> at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1350)
> at org.elasticsearch.client.SecurityClient.deleteUser(SecurityClient.java:113)
> at org.elasticsearch.client.documentation.SecurityDocumentationIT.testDeleteUser(SecurityDocumentationIT.java:166)
> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> at java.base/java.lang.Thread.run(Thread.java:834)
> Suppressed: ParsingException[Failed to parse object: expecting field with name [error] but found [found]]
Not sure if I can implement it in any other way without changing the underlaying implementation.
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.
It might also depend on which implementation of AcknowledgedResponse
you are using, since we have two, yay duplication!!! You should have a look at StartRollupJobResponse
, which is an example of changing the word from acknowledged
to started
. this should get you on the right track.
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.
DeleteUserResponse
is a subclass of AcknowledgedResponse
. I am using the same pattern.
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.
heh, duh... Sorry, ive been on vacation and full of turkey since last week.
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.
so the only thing here now is to remove singleton(404)
, right?
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.
No problem, happy you enjoyed your time off!
Yes, the issue we have is the 404
and as I showed before, the problem is that if I do not capture the error there is a parsing error because the framework is expecting a different type of message:
Suppressed: ParsingException[Failed to parse object: expecting field with name [error] but found [found]]
Not sure if we can avoid without changing the current implementation.
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.
Apologies, I misread the comment before. Since server side is not throwing exceptions, lets keep the singleton(404)
, so we dont have to mod the parsing code. This is something we should definitely fix server side.
* HLRC: Add delete user action It adds delete user action to the high level rest client. Relates #29827
It adds delete user action to the high level rest client.
Relates #29827