|
6 | 6 | package org.opensearch.ml.common.transport.connector;
|
7 | 7 |
|
8 | 8 | import static org.opensearch.action.ValidateActions.addValidationError;
|
9 |
| -import static org.opensearch.ml.common.utils.StringUtils.isSafeText; |
| 9 | +import static org.opensearch.ml.common.utils.StringUtils.validateFields; |
10 | 10 |
|
11 | 11 | import java.io.ByteArrayInputStream;
|
12 | 12 | import java.io.ByteArrayOutputStream;
|
13 | 13 | import java.io.IOException;
|
14 | 14 | import java.io.UncheckedIOException;
|
| 15 | +import java.util.HashMap; |
| 16 | +import java.util.Map; |
15 | 17 |
|
16 | 18 | import org.opensearch.action.ActionRequest;
|
17 | 19 | import org.opensearch.action.ActionRequestValidationException;
|
@@ -39,29 +41,14 @@ public MLCreateConnectorRequest(StreamInput in) throws IOException {
|
39 | 41 |
|
40 | 42 | @Override
|
41 | 43 | public ActionRequestValidationException validate() {
|
42 |
| - ActionRequestValidationException exception = null; |
43 |
| - |
44 | 44 | if (mlCreateConnectorInput == null) {
|
45 |
| - return addValidationError("ML Connector input can't be null", exception); |
46 |
| - } |
47 |
| - |
48 |
| - String modelName = mlCreateConnectorInput.getName(); |
49 |
| - String description = mlCreateConnectorInput.getDescription(); |
50 |
| - |
51 |
| - if (modelName != null && !isSafeText(modelName)) { |
52 |
| - exception = addValidationError( |
53 |
| - "Model connector name can only contain letters, digits, spaces, underscores (_), hyphens (-), and dots (.)", |
54 |
| - exception |
55 |
| - ); |
56 |
| - } |
57 |
| - if (description != null && !isSafeText(description)) { |
58 |
| - exception = addValidationError( |
59 |
| - "Model connector description can only contain letters, digits, spaces, underscores (_), hyphens (-), and dots (.)", |
60 |
| - exception |
61 |
| - ); |
| 45 | + return addValidationError("ML Connector input can't be null", null); |
62 | 46 | }
|
| 47 | + Map<String, String> fieldsToValidate = new HashMap<>(); |
| 48 | + fieldsToValidate.put("Model connector name", mlCreateConnectorInput.getName()); |
| 49 | + fieldsToValidate.put("Model connector description", mlCreateConnectorInput.getDescription()); |
63 | 50 |
|
64 |
| - return exception; |
| 51 | + return validateFields(fieldsToValidate); |
65 | 52 | }
|
66 | 53 |
|
67 | 54 | @Override
|
|
0 commit comments