Skip to content

Commit

Permalink
Prevent setting default index set readonly. (#3339)
Browse files Browse the repository at this point in the history
* Prevent setting default index set readonly.

Without this change it was possible to update the default index set and
make it read only, leading to unwanted behavior. After this change, when
updating an index set we check if it is the default index set and kindly
refuse setting it read only.

Fixes #3331.

* Removing superfluous id property from IndexSetUpdateRequest.

The id property of the IndexSetUpdateRequest DTO is unneeded, as the id
of the index set to update is already given in the URL. It is actually
misleading and requires an additional unneeded check to see if the ids
of the URL and the body are consistent.
Therefore the id is removed from the IndexSetUpdateRequest and the one
from the URL is used only.

* Prevent making non-writable index sets the default index set.

* Add read only labels and disable setting default in index sets ui.
  • Loading branch information
dennisoelkers authored and kroepke committed Jan 12, 2017
1 parent d4eb29e commit faf0800
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 61 deletions.
Expand Up @@ -211,17 +211,20 @@ public IndexSetSummary update(@ApiParam(name = "id", required = true)
@ApiParam(name = "Index set configuration", required = true) @ApiParam(name = "Index set configuration", required = true)
@Valid @NotNull IndexSetUpdateRequest updateRequest) { @Valid @NotNull IndexSetUpdateRequest updateRequest) {
checkPermission(RestPermissions.INDEXSETS_EDIT, id); checkPermission(RestPermissions.INDEXSETS_EDIT, id);
if (!id.equals(updateRequest.id())) {
throw new ClientErrorException("Mismatch of IDs in URI path and payload", Response.Status.CONFLICT);
}


final IndexSetConfig oldConfig = indexSetService.get(id) final IndexSetConfig oldConfig = indexSetService.get(id)
.orElseThrow(() -> new NotFoundException("Index set <" + id + "> not found")); .orElseThrow(() -> new NotFoundException("Index set <" + id + "> not found"));


final IndexSetConfig savedObject = indexSetService.save(updateRequest.toIndexSetConfig(oldConfig));
final IndexSetConfig defaultIndexSet = indexSetService.getDefault(); final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
final boolean isDefaultSet = oldConfig.equals(defaultIndexSet);

if (isDefaultSet && !updateRequest.isWritable()) {
throw new ClientErrorException("Default index set must be writable.", Response.Status.CONFLICT);
}


return IndexSetSummary.fromIndexSetConfig(savedObject, savedObject.equals(defaultIndexSet)); final IndexSetConfig savedObject = indexSetService.save(updateRequest.toIndexSetConfig(id, oldConfig));

return IndexSetSummary.fromIndexSetConfig(savedObject, isDefaultSet);
} }


@PUT @PUT
Expand All @@ -239,6 +242,10 @@ public IndexSetSummary setDefault(@ApiParam(name = "id", required = true)
final IndexSetConfig indexSet = indexSetService.get(id) final IndexSetConfig indexSet = indexSetService.get(id)
.orElseThrow(() -> new NotFoundException("Index set <" + id + "> does not exist")); .orElseThrow(() -> new NotFoundException("Index set <" + id + "> does not exist"));


if (!indexSet.isWritable()) {
throw new ClientErrorException("Default index set must be writable.", Response.Status.CONFLICT);
}

clusterConfigService.write(DefaultIndexSetConfig.create(indexSet.id())); clusterConfigService.write(DefaultIndexSetConfig.create(indexSet.id()));


final IndexSetConfig defaultIndexSet = indexSetService.getDefault(); final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
Expand Down
Expand Up @@ -34,9 +34,6 @@
@JsonAutoDetect @JsonAutoDetect
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public abstract class IndexSetUpdateRequest { public abstract class IndexSetUpdateRequest {
@JsonProperty("id")
public abstract String id();

@JsonProperty("title") @JsonProperty("title")
@NotBlank @NotBlank
public abstract String title(); public abstract String title();
Expand Down Expand Up @@ -81,8 +78,7 @@ public abstract class IndexSetUpdateRequest {


@JsonCreator @JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public static IndexSetUpdateRequest create(@JsonProperty("id") String id, public static IndexSetUpdateRequest create(@JsonProperty("title") @NotBlank String title,
@JsonProperty("title") @NotBlank String title,
@JsonProperty("description") @Nullable String description, @JsonProperty("description") @Nullable String description,
@JsonProperty("writable") boolean isWritable, @JsonProperty("writable") boolean isWritable,
@JsonProperty("shards") @Min(1) int shards, @JsonProperty("shards") @Min(1) int shards,
Expand All @@ -93,14 +89,13 @@ public static IndexSetUpdateRequest create(@JsonProperty("id") String id,
@JsonProperty("retention_strategy") @NotNull RetentionStrategyConfig retentionStrategy, @JsonProperty("retention_strategy") @NotNull RetentionStrategyConfig retentionStrategy,
@JsonProperty("index_optimization_max_num_segments") @Min(1L) int indexOptimizationMaxNumSegments, @JsonProperty("index_optimization_max_num_segments") @Min(1L) int indexOptimizationMaxNumSegments,
@JsonProperty("index_optimization_disabled") boolean indexOptimizationDisabled) { @JsonProperty("index_optimization_disabled") boolean indexOptimizationDisabled) {
return new AutoValue_IndexSetUpdateRequest(id, title, description, isWritable, shards, replicas, return new AutoValue_IndexSetUpdateRequest(title, description, isWritable, shards, replicas,
rotationStrategyClass, rotationStrategy, retentionStrategyClass, retentionStrategy, rotationStrategyClass, rotationStrategy, retentionStrategyClass, retentionStrategy,
indexOptimizationMaxNumSegments, indexOptimizationDisabled); indexOptimizationMaxNumSegments, indexOptimizationDisabled);
} }


public static IndexSetUpdateRequest fromIndexSetConfig(IndexSetConfig indexSet) { public static IndexSetUpdateRequest fromIndexSetConfig(IndexSetConfig indexSet) {
return create( return create(
indexSet.id(),
indexSet.title(), indexSet.title(),
indexSet.description(), indexSet.description(),
indexSet.isWritable(), indexSet.isWritable(),
Expand All @@ -115,9 +110,9 @@ public static IndexSetUpdateRequest fromIndexSetConfig(IndexSetConfig indexSet)


} }


public IndexSetConfig toIndexSetConfig(IndexSetConfig oldConfig) { public IndexSetConfig toIndexSetConfig(String id, IndexSetConfig oldConfig) {
return IndexSetConfig.builder() return IndexSetConfig.builder()
.id(id()) .id(id)
.title(title()) .title(title())
.description(description()) .description(description())
.isWritable(isWritable()) .isWritable(isWritable())
Expand Down

0 comments on commit faf0800

Please sign in to comment.