|
1 | 1 | package io.qdrant.client; |
2 | 2 |
|
3 | | -import java.util.concurrent.Executor; |
4 | | - |
5 | 3 | import io.grpc.CallCredentials; |
6 | 4 | import io.grpc.Metadata; |
7 | 5 | import io.grpc.Status; |
| 6 | +import java.util.concurrent.Executor; |
8 | 7 |
|
9 | | -/** |
10 | | - * API key authentication credentials |
11 | | - */ |
| 8 | +/** API key authentication credentials */ |
12 | 9 | public class ApiKeyCredentials extends CallCredentials { |
13 | | - private final String apiKey; |
| 10 | + private final String apiKey; |
14 | 11 |
|
15 | | - /** |
16 | | - * Instantiates a new instance of {@link ApiKeyCredentials} |
17 | | - * @param apiKey The API key to use for authentication |
18 | | - */ |
19 | | - public ApiKeyCredentials(String apiKey) { |
20 | | - this.apiKey = apiKey; |
21 | | - } |
| 12 | + /** |
| 13 | + * Instantiates a new instance of {@link ApiKeyCredentials} |
| 14 | + * |
| 15 | + * @param apiKey The API key to use for authentication |
| 16 | + */ |
| 17 | + public ApiKeyCredentials(String apiKey) { |
| 18 | + this.apiKey = apiKey; |
| 19 | + } |
22 | 20 |
|
23 | | - @Override |
24 | | - public void applyRequestMetadata(RequestInfo requestInfo, Executor appExecutor, MetadataApplier applier) { |
25 | | - appExecutor.execute(() -> { |
26 | | - try { |
27 | | - Metadata headers = new Metadata(); |
28 | | - headers.put(Metadata.Key.of("api-key", Metadata.ASCII_STRING_MARSHALLER), apiKey); |
29 | | - applier.apply(headers); |
30 | | - } catch (Throwable e) { |
31 | | - applier.fail(Status.UNAUTHENTICATED.withCause(e)); |
32 | | - } |
| 21 | + @Override |
| 22 | + public void applyRequestMetadata( |
| 23 | + RequestInfo requestInfo, Executor appExecutor, MetadataApplier applier) { |
| 24 | + appExecutor.execute( |
| 25 | + () -> { |
| 26 | + try { |
| 27 | + Metadata headers = new Metadata(); |
| 28 | + headers.put(Metadata.Key.of("api-key", Metadata.ASCII_STRING_MARSHALLER), apiKey); |
| 29 | + applier.apply(headers); |
| 30 | + } catch (Throwable e) { |
| 31 | + applier.fail(Status.UNAUTHENTICATED.withCause(e)); |
| 32 | + } |
33 | 33 | }); |
34 | | - } |
| 34 | + } |
35 | 35 | } |
0 commit comments