Skip to content

Commit

Permalink
Ensure that index_prefix is lower case
Browse files Browse the repository at this point in the history
Fixes #3476
  • Loading branch information
Jochen Schalanda committed Feb 16, 2017
1 parent af1a258 commit 37cf0a5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Expand Up @@ -32,6 +32,7 @@
import javax.annotation.Nullable;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.time.ZonedDateTime;

import static com.google.common.base.Strings.isNullOrEmpty;
Expand All @@ -45,6 +46,7 @@
public abstract class IndexSetConfig implements Comparable<IndexSetConfig> {
public static final String FIELD_INDEX_PREFIX = "index_prefix";
public static final String FIELD_CREATION_DATE = "creation_date";
public static final String INDEX_PREFIX_REGEX = "^[a-z0-9][a-z0-9_+-]*$";

@JsonProperty("id")
@Nullable
Expand All @@ -65,6 +67,7 @@ public abstract class IndexSetConfig implements Comparable<IndexSetConfig> {

@JsonProperty(FIELD_INDEX_PREFIX)
@NotBlank
@Pattern(regexp = INDEX_PREFIX_REGEX)
public abstract String indexPrefix();

@JsonProperty("index_match_pattern")
Expand Down Expand Up @@ -123,7 +126,7 @@ public static IndexSetConfig create(@Id @ObjectId @JsonProperty("_id") @Nullable
@JsonProperty("title") @NotBlank String title,
@JsonProperty("description") @Nullable String description,
@JsonProperty("writable") @Nullable Boolean isWritable,
@JsonProperty(FIELD_INDEX_PREFIX) @NotBlank String indexPrefix,
@JsonProperty(FIELD_INDEX_PREFIX) @Pattern(regexp = INDEX_PREFIX_REGEX) String indexPrefix,
@JsonProperty("index_match_pattern") @Nullable String indexMatchPattern,
@JsonProperty("index_wildcard") @Nullable String indexWildcard,
@JsonProperty("shards") @Min(1) int shards,
Expand Down
Expand Up @@ -29,6 +29,7 @@
import javax.annotation.Nullable;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.time.ZonedDateTime;

@AutoValue
Expand All @@ -54,7 +55,7 @@ public abstract class IndexSetSummary {
public abstract boolean isWritable();

@JsonProperty("index_prefix")
@NotBlank
@Pattern(regexp = IndexSetConfig.INDEX_PREFIX_REGEX)
public abstract String indexPrefix();

@JsonProperty("shards")
Expand Down Expand Up @@ -102,7 +103,7 @@ public static IndexSetSummary create(@JsonProperty("id") @Nullable String id,
@JsonProperty("description") @Nullable String description,
@JsonProperty("default") boolean isDefault,
@JsonProperty("writable") boolean isWritable,
@JsonProperty("index_prefix") @NotBlank String indexPrefix,
@JsonProperty("index_prefix") @Pattern(regexp = IndexSetConfig.INDEX_PREFIX_REGEX) String indexPrefix,
@JsonProperty("shards") @Min(1) int shards,
@JsonProperty("replicas") @Min(0) int replicas,
@JsonProperty("rotation_strategy_class") @NotNull String rotationStrategyClass,
Expand Down
Expand Up @@ -35,7 +35,7 @@ const IndexSetConfigurationForm = React.createClass({
_validateIndexPrefix(event) {
const value = event.target.value;

if (value.match(/^[A-Za-z0-9][A-Za-z0-9_\-+]*$/)) {
if (value.match(/^[a-z0-9][a-z0-9_\-+]*$/)) {
if (this.state.validationErrors[event.target.name]) {
const nextValidationErrors = Object.assign({}, this.state.validationErrors);
delete nextValidationErrors[event.target.name];
Expand All @@ -47,6 +47,8 @@ const IndexSetConfigurationForm = React.createClass({
nextValidationErrors[event.target.name] = 'Invalid index prefix: cannot be empty';
} else if (value.indexOf('_') === 0 || value.indexOf('-') === 0 || value.indexOf('+') === 0) {
nextValidationErrors[event.target.name] = 'Invalid index prefix: must start with a letter or number';
} else if (value.toLowerCase() !== value) {
nextValidationErrors[event.target.name] = 'Invalid index prefix: must be lower case';
} else {
nextValidationErrors[event.target.name] = 'Invalid index prefix: must only contain letters, numbers, \'_\', \'-\' and \'+\'';
}
Expand Down

0 comments on commit 37cf0a5

Please sign in to comment.