Skip to content

Commit ee66c48

Browse files
Starting to rename
1 parent 1feee98 commit ee66c48

File tree

16 files changed

+282
-154
lines changed

16 files changed

+282
-154
lines changed

docs/java-rest/low-level/configuration.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ include-tagged::{doc-tests}/RestClientDocumentation.java[rest-client-config-disa
7676
==== Elasticsearch Token Service tokens
7777

7878
If you want the client to authenticate with an Elasticsearch access token, set the relevant HTTP request header.
79-
If the client makes requests on behalf of a single user only, you can set the necessary `Authorization` header as a default header as shown
79+
If the client makes requests on behalf of a single user only, you can set the necessary `ElasticInferenceServiceAuthorizationHandler` header as a default header as shown
8080
in the following example:
8181

8282
["source","java",subs="attributes,callouts,macros"]
@@ -87,7 +87,7 @@ include-tagged::{doc-tests}/RestClientDocumentation.java[rest-client-auth-bearer
8787
==== Elasticsearch API keys
8888

8989
If you want the client to authenticate with an Elasticsearch API key, set the relevant HTTP request header.
90-
If the client makes requests on behalf of a single user only, you can set the necessary `Authorization` header as a default header as shown
90+
If the client makes requests on behalf of a single user only, you can set the necessary `ElasticInferenceServiceAuthorizationHandler` header as a default header as shown
9191
in the following example:
9292

9393
["source","java",subs="attributes,callouts,macros"]

docs/reference/rest-api/security/create-api-keys.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ API key information.
194194
<4> API key credentials which is the Base64-encoding of the UTF-8
195195
representation of the `id` and `api_key` joined by a colon (`:`).
196196

197-
To use the generated API key, send a request with an `Authorization` header that
197+
To use the generated API key, send a request with an `ElasticInferenceServiceAuthorizationHandler` header that
198198
contains an `ApiKey` prefix followed by the API key credentials
199199
(the `encoded` value from the response).
200200

docs/reference/rest-api/security/get-tokens.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ seconds) that the token expires in, and the type:
155155
// TESTRESPONSE[s/superuser/_es_test_root/]
156156

157157
The token returned by this API can be used by sending a request with an
158-
`Authorization` header with a value having the prefix "Bearer " followed
158+
`ElasticInferenceServiceAuthorizationHandler` header with a value having the prefix "Bearer " followed
159159
by the value of the `access_token`.
160160

161161
[source,shell]

docs/reference/security/authentication/token-authentication-services.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ generate access tokens and refresh tokens based on the OAuth2 specification.
4040
The access token is a short-lived token. By default, it expires after 20 minutes
4141
but it can be configured to last a maximum of 1 hour. It can be refreshed by
4242
using a refresh token, which has a lifetime of 24 hours. The access token is a
43-
bearer token. You can use it by sending a request with an `Authorization`
43+
bearer token. You can use it by sending a request with an `ElasticInferenceServiceAuthorizationHandler`
4444
header with a value that has the prefix "Bearer " followed by the value of the
4545
access token. For example:
4646
+
@@ -59,7 +59,7 @@ The API key service uses the
5959
By default, the API keys do not expire. When you make a request to create API
6060
keys, you can specify an expiration and permissions for the API key. The
6161
permissions are limited by the authenticated user's permissions. You can use the
62-
API key by sending a request with an `Authorization` header with a value that
62+
API key by sending a request with an `ElasticInferenceServiceAuthorizationHandler` header with a value that
6363
has the prefix "ApiKey " followed by the credentials. The credentials are the
6464
base64 encoding of the API key ID and the API key joined by a colon. For example:
6565
+

docs/reference/security/ccs-clients-integrations/http.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ es-secondary-authorization: Basic <TOKEN> <1>
6565
<1> The `<TOKEN>` is computed as `base64(USERNAME:PASSWORD)`
6666

6767
The `es-secondary-authorization` header has the same syntax as the
68-
`Authorization` header. It therefore also supports the use of
68+
`ElasticInferenceServiceAuthorizationHandler` header. It therefore also supports the use of
6969
<<token-authentication-services,token-based authentication services>>. For
7070
example:
7171

server/src/main/java/org/elasticsearch/inference/InferenceServiceConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public Builder setTaskTypes(List<String> taskTypes) {
194194
var enumTaskTypes = EnumSet.noneOf(TaskType.class);
195195

196196
for (var supportedTaskTypeString : taskTypes) {
197-
enumTaskTypes.add(TaskType.fromString(supportedTaskTypeString));
197+
enumTaskTypes.add(TaskType.fromStringOrStatusException(supportedTaskTypeString));
198198
}
199199
this.taskTypes = enumTaskTypes;
200200
return this;

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferencePlugin.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,7 @@ public Collection<?> createComponents(PluginServices services) {
284284

285285
ElasticInferenceServiceSettings inferenceServiceSettings = new ElasticInferenceServiceSettings(settings);
286286
String elasticInferenceUrl = this.getElasticInferenceServiceUrl(inferenceServiceSettings);
287-
elasticInferenceServiceComponents.set(new ElasticInferenceServiceComponents(elasticInferenceUrl
288-
// new ElasticInferenceServiceACL(Map.of("model-abc", EnumSet.of(TaskType.SPARSE_EMBEDDING, TaskType.CHAT_COMPLETION)))
289-
));
287+
elasticInferenceServiceComponents.set(new ElasticInferenceServiceComponents(elasticInferenceUrl));
290288

291289
inferenceServices.add(
292290
() -> List.of(
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
import java.net.URISyntaxException;
2121
import java.util.Objects;
2222

23-
public class ElasticInferenceServiceAclRequest implements ElasticInferenceServiceRequest {
23+
public class ElasticInferenceServiceAuthRequest implements ElasticInferenceServiceRequest {
2424

2525
private final URI uri;
2626
private final TraceContextHandler traceContextHandler;
2727

28-
public ElasticInferenceServiceAclRequest(String url, TraceContext traceContext) {
28+
public ElasticInferenceServiceAuthRequest(String url, TraceContext traceContext) {
2929
this.uri = createUri(Objects.requireNonNull(url));
3030
this.traceContextHandler = new TraceContextHandler(traceContext);
3131
}
Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,51 +30,58 @@
3030
import java.util.EnumSet;
3131
import java.util.Iterator;
3232
import java.util.List;
33-
import java.util.Locale;
3433
import java.util.Map;
3534
import java.util.Objects;
3635
import java.util.stream.Collectors;
3736

3837
import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;
3938

40-
public class ElasticInferenceServiceAclResponseEntity implements InferenceServiceResults {
39+
public class ElasticInferenceServiceAuthResponseEntity implements InferenceServiceResults {
4140

42-
public static final String NAME = "elastic_inference_service_acl_results";
43-
public static final String COMPLETION = TaskType.COMPLETION.name().toLowerCase(Locale.ROOT);
41+
public static final String NAME = "elastic_inference_service_auth_results";
42+
private static final Map<String, TaskType> ELASTIC_INFERENCE_SERVICE_TASK_TYPE_MAPPING = Map.of(
43+
"embedding/text/sparse",
44+
TaskType.SPARSE_EMBEDDING,
45+
"chat/completion",
46+
TaskType.CHAT_COMPLETION
47+
);
4448

4549
@SuppressWarnings("unchecked")
46-
public static ConstructingObjectParser<ElasticInferenceServiceAclResponseEntity, Void> PARSER = new ConstructingObjectParser<>(
47-
ElasticInferenceServiceAclResponseEntity.class.getSimpleName(),
48-
args -> new ElasticInferenceServiceAclResponseEntity((List<AllowedModel>) args[0])
50+
public static ConstructingObjectParser<ElasticInferenceServiceAuthResponseEntity, Void> PARSER = new ConstructingObjectParser<>(
51+
ElasticInferenceServiceAuthResponseEntity.class.getSimpleName(),
52+
args -> new ElasticInferenceServiceAuthResponseEntity((List<AuthorizedModel>) args[0])
4953
);
5054

5155
static {
52-
PARSER.declareObjectArray(constructorArg(), AllowedModel.ALLOWED_MODEL_PARSER::apply, new ParseField("allowed_models"));
56+
PARSER.declareObjectArray(constructorArg(), AuthorizedModel.ALLOWED_MODEL_PARSER::apply, new ParseField("models"));
5357
}
5458

55-
public record AllowedModel(String modelName, EnumSet<TaskType> taskTypes) implements Writeable, ToXContentObject {
59+
public record AuthorizedModel(String modelName, EnumSet<TaskType> taskTypes) implements Writeable, ToXContentObject {
5660

5761
@SuppressWarnings("unchecked")
58-
public static ConstructingObjectParser<AllowedModel, Void> ALLOWED_MODEL_PARSER = new ConstructingObjectParser<>(
59-
AllowedModel.class.getSimpleName(),
60-
args -> new AllowedModel((String) args[0], toTaskTypes((List<String>) args[1]))
62+
public static ConstructingObjectParser<AuthorizedModel, Void> ALLOWED_MODEL_PARSER = new ConstructingObjectParser<>(
63+
AuthorizedModel.class.getSimpleName(),
64+
args -> new AuthorizedModel((String) args[0], toTaskTypes((List<String>) args[1]))
6165
);
6266

6367
static {
64-
ALLOWED_MODEL_PARSER.declareString(constructorArg(), new ParseField("model_name"));
65-
ALLOWED_MODEL_PARSER.declareStringArray(constructorArg(), new ParseField("task_types"));
68+
ALLOWED_MODEL_PARSER.declareString(constructorArg(), new ParseField("model-name"));
69+
ALLOWED_MODEL_PARSER.declareStringArray(constructorArg(), new ParseField("task-types"));
6670
}
6771

6872
private static EnumSet<TaskType> toTaskTypes(List<String> stringTaskTypes) {
6973
var taskTypes = EnumSet.noneOf(TaskType.class);
7074
for (String taskType : stringTaskTypes) {
71-
taskTypes.add(TaskType.fromStringOrStatusException(taskType));
75+
var mappedTaskType = ELASTIC_INFERENCE_SERVICE_TASK_TYPE_MAPPING.get(taskType);
76+
if (mappedTaskType != null) {
77+
taskTypes.add(mappedTaskType);
78+
}
7279
}
7380

7481
return taskTypes;
7582
}
7683

77-
public AllowedModel(StreamInput in) throws IOException {
84+
public AuthorizedModel(StreamInput in) throws IOException {
7885
this(in.readString(), in.readEnumSet(TaskType.class));
7986
}
8087

@@ -97,25 +104,32 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
97104
}
98105
}
99106

100-
private final List<AllowedModel> allowedModels;
107+
private final List<AuthorizedModel> allowedModels;
101108

102-
public ElasticInferenceServiceAclResponseEntity(List<AllowedModel> allowedModels) {
109+
public ElasticInferenceServiceAuthResponseEntity(List<AuthorizedModel> allowedModels) {
103110
this.allowedModels = Objects.requireNonNull(allowedModels);
104111
}
105112

106-
public ElasticInferenceServiceAclResponseEntity(StreamInput in) throws IOException {
107-
this(in.readCollectionAsList(AllowedModel::new));
113+
/**
114+
* Create an empty response
115+
*/
116+
public ElasticInferenceServiceAuthResponseEntity() {
117+
this(List.of());
118+
}
119+
120+
public ElasticInferenceServiceAuthResponseEntity(StreamInput in) throws IOException {
121+
this(in.readCollectionAsList(AuthorizedModel::new));
108122
}
109123

110-
public static ElasticInferenceServiceAclResponseEntity fromResponse(Request request, HttpResult response) throws IOException {
124+
public static ElasticInferenceServiceAuthResponseEntity fromResponse(Request request, HttpResult response) throws IOException {
111125
var parserConfig = XContentParserConfiguration.EMPTY.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE);
112126

113127
try (XContentParser jsonParser = XContentFactory.xContent(XContentType.JSON).createParser(parserConfig, response.body())) {
114128
return PARSER.apply(jsonParser, null);
115129
}
116130
}
117131

118-
public List<AllowedModel> getAllowedModels() {
132+
public List<AuthorizedModel> getAllowedModels() {
119133
return allowedModels;
120134
}
121135

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/SenderService.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,7 @@ protected void doStart(Model model, ActionListener<Boolean> listener) {
148148
listener.onResponse(true);
149149
}
150150

151-
/**
152-
* Normally we shouldn't need to call this from a child service. This is handled when an inference request
153-
* is received automatically. Services that need to make one-off requests before inference requests are sent will
154-
* need to call this to initialize the internals.
155-
*/
156-
protected void init() {
151+
private void init() {
157152
sender.start();
158153
}
159154

0 commit comments

Comments
 (0)