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

Allow for requests to configure the user/token making the request #8458

Closed
ethanjonez opened this issue Feb 14, 2025 · 2 comments
Closed

Allow for requests to configure the user/token making the request #8458

ethanjonez opened this issue Feb 14, 2025 · 2 comments
Labels

Comments

@ethanjonez
Copy link

Is your feature request related to a problem? Please describe.
We are facing an issue when running tests as different users (via token authentication). The Elastic client states it should be a singleton, however, there is only one chance upon initialisation of the Elastic client to define the connection settings. This means each time we run a test we have to create a new client with a new set of connection settings for the selected user to be tested on.

Describe the solution you'd like
A nice solution would be to configure the token used for each request. Or alternatively, making the Elastic client an IDisposable type.

Describe alternatives you've considered
For now, we are running these tests synchronously and relying on the garbage collector to "dispose" of these when the test has finished.

Additional context
none

@flobernd
Copy link
Member

Hi @ethanjonez ,

A nice solution would be to configure the token used for each request.

This is already possible:

var createIndexResponse = await client.Indices.CreateAsync<Person>("index_name", c => c
    // ...
    .RequestConfiguration(x => x.Authentication(new ApiKey("...")))
);

Or alternatively, making the Elastic client an IDisposable type.

The client itself is not disposable, the ElasticsearchClientSettings however is. All of the native resources like sockets etc. are managed by the ElasticsearchClientSettings and they should be released as soon as you dispose the settings.

Please let me know if that solves your problem!

@ethanjonez
Copy link
Author

ethanjonez commented Feb 20, 2025

I think this solves our problem... Thanks for the timely response. This is really neat though, I don't think we'll need to dispose of any client settings now we can configure tokens on specific requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants