Skip to content
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

Merged
merged 24 commits into from
Nov 29, 2018
Merged

HLRC: Add delete user action #35294

merged 24 commits into from
Nov 29, 2018

Conversation

iverase
Copy link
Contributor

@iverase iverase commented Nov 6, 2018

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 elastic#29827
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@iverase
Copy link
Contributor Author

iverase commented Nov 6, 2018

@elasticmachine test this please

1 similar comment
@iverase
Copy link
Contributor Author

iverase commented Nov 6, 2018

@elasticmachine test this please

Copy link
Contributor

@hub-cap hub-cap left a 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.

/**
* Response for a role being deleted from the native realm
*/
public final class DeleteUserResponse {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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 ;)

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

@iverase
Copy link
Contributor Author

iverase commented Nov 7, 2018

@elasticmachine test this please

/**
* Response for a user being deleted from the native realm
*/
public final class DeleteUserResponse extends AcknowledgedResponse {
Copy link
Contributor

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.

Copy link
Contributor

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?

@hub-cap
Copy link
Contributor

hub-cap commented Nov 14, 2018

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 :/

@iverase
Copy link
Contributor Author

iverase commented Nov 19, 2018

@elasticmachine test this please

@iverase
Copy link
Contributor Author

iverase commented Nov 19, 2018

@elasticmachine test this please

*/
public DeleteUserResponse deleteUser(DeleteUserRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request, SecurityRequestConverters::deleteUser, options,
DeleteUserResponse::fromXContent, singleton(404));
Copy link
Contributor

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

Copy link
Contributor Author

@iverase iverase Nov 21, 2018

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@iverase iverase merged commit 93ed8b7 into elastic:master Nov 29, 2018
iverase added a commit that referenced this pull request Nov 29, 2018
* HLRC: Add delete user action

It adds delete user action to the high level rest client.

Relates #29827
@iverase iverase deleted the deleteUser branch November 29, 2018 06:55
@jimczi jimczi added v7.0.0-beta1 and removed v7.0.0 labels Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants