-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added input parameter validation with few small changes
1. Added datasource name validation in delete/update api 2. Added datasource name validation in processor creation method 3. Changed index name delimiter from `.` to `-` to be consistent with others Signed-off-by: Heemin Kim <heemin@amazon.com>
- Loading branch information
Showing
12 changed files
with
232 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/org/opensearch/geospatial/ip2geo/common/ParameterValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.geospatial.ip2geo.common; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.opensearch.common.Strings; | ||
|
||
/** | ||
* Parameter validator for IP2Geo APIs | ||
*/ | ||
public class ParameterValidator { | ||
private static final int MAX_DATASOURCE_NAME_BYTES = 127; | ||
|
||
/** | ||
* Validate datasource name and return list of error messages | ||
* | ||
* @param datasourceName datasource name | ||
* @return Error messages. Empty list if there is no violation. | ||
*/ | ||
public List<String> validateDatasourceName(final String datasourceName) { | ||
List<String> errorMsgs = new ArrayList<>(); | ||
if (StringUtils.isBlank(datasourceName)) { | ||
errorMsgs.add("datasource name must not be empty"); | ||
return errorMsgs; | ||
} | ||
|
||
if (!Strings.validFileName(datasourceName)) { | ||
errorMsgs.add( | ||
String.format(Locale.ROOT, "datasource name must not contain the following characters %s", Strings.INVALID_FILENAME_CHARS) | ||
); | ||
} | ||
if (datasourceName.contains("#")) { | ||
errorMsgs.add("datasource name must not contain '#'"); | ||
} | ||
if (datasourceName.contains(":")) { | ||
errorMsgs.add("datasource name must not contain ':'"); | ||
} | ||
if (datasourceName.charAt(0) == '_' || datasourceName.charAt(0) == '-' || datasourceName.charAt(0) == '+') { | ||
errorMsgs.add("datasource name must not start with '_', '-', or '+'"); | ||
} | ||
int byteCount = datasourceName.getBytes(StandardCharsets.UTF_8).length; | ||
if (byteCount > MAX_DATASOURCE_NAME_BYTES) { | ||
errorMsgs.add(String.format(Locale.ROOT, "datasource name is too long, (%d > %d)", byteCount, MAX_DATASOURCE_NAME_BYTES)); | ||
} | ||
if (datasourceName.equals(".") || datasourceName.equals("..")) { | ||
errorMsgs.add("datasource name must not be '.' or '..'"); | ||
} | ||
return errorMsgs; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.