-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add level parameter validation in REST layer (#94136)
Relates #93981
- Loading branch information
1 parent
ab1d891
commit fc9c0ce
Showing
21 changed files
with
303 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 94136 | ||
summary: Add level parameter validation in REST layer | ||
area: Infra/REST API | ||
type: bug | ||
issues: [93981] |
40 changes: 40 additions & 0 deletions
40
server/src/main/java/org/elasticsearch/action/ClusterStatsLevel.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,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action; | ||
|
||
import org.elasticsearch.xcontent.ToXContent; | ||
|
||
public enum ClusterStatsLevel { | ||
CLUSTER("cluster"), | ||
INDICES("indices"), | ||
SHARDS("shards"); | ||
|
||
private final String level; | ||
|
||
ClusterStatsLevel(String level) { | ||
this.level = level; | ||
} | ||
|
||
public String getLevel() { | ||
return level; | ||
} | ||
|
||
public static ClusterStatsLevel of(String level) { | ||
for (ClusterStatsLevel value : values()) { | ||
if (value.getLevel().equalsIgnoreCase(level)) { | ||
return value; | ||
} | ||
} | ||
throw new IllegalArgumentException("level parameter must be one of [cluster] or [indices] or [shards] but was [" + level + "]"); | ||
} | ||
|
||
public static ClusterStatsLevel of(ToXContent.Params params, ClusterStatsLevel defaultLevel) { | ||
return ClusterStatsLevel.of(params.param("level", defaultLevel.getLevel())); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
server/src/main/java/org/elasticsearch/action/NodeStatsLevel.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,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action; | ||
|
||
import org.elasticsearch.xcontent.ToXContent; | ||
|
||
public enum NodeStatsLevel { | ||
NODE("node"), | ||
INDICES("indices"), | ||
SHARDS("shards"); | ||
|
||
private final String level; | ||
|
||
NodeStatsLevel(String level) { | ||
this.level = level; | ||
} | ||
|
||
public String getLevel() { | ||
return level; | ||
} | ||
|
||
public static NodeStatsLevel of(String level) { | ||
for (NodeStatsLevel value : values()) { | ||
if (value.getLevel().equalsIgnoreCase(level)) { | ||
return value; | ||
} | ||
} | ||
throw new IllegalArgumentException("level parameter must be one of [node] or [indices] or [shards] but was [" + level + "]"); | ||
} | ||
|
||
public static NodeStatsLevel of(ToXContent.Params params, NodeStatsLevel defaultLevel) { | ||
return NodeStatsLevel.of(params.param("level", defaultLevel.getLevel())); | ||
} | ||
} |
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
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
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.