forked from opensearch-project/security
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Darshit Chanpura <[email protected]>
- Loading branch information
1 parent
bc67926
commit ccd5d07
Showing
7 changed files
with
64 additions
and
44 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
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
32 changes: 32 additions & 0 deletions
32
sample-resource-plugin/src/main/java/org/opensearch/sample/utils/Validation.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,32 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.sample.utils; | ||
|
||
import java.util.Arrays; | ||
import java.util.Set; | ||
|
||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.sample.SampleResourceScope; | ||
|
||
public class Validation { | ||
public static ActionRequestValidationException validateScopes(Set<String> scopes) { | ||
for (String s : scopes) { | ||
try { | ||
SampleResourceScope.valueOf(s); | ||
} catch (IllegalArgumentException | NullPointerException e) { | ||
ActionRequestValidationException exception = new ActionRequestValidationException(); | ||
exception.addValidationError( | ||
"Invalid scope: " + s + ". Scope must be one of: " + Arrays.toString(SampleResourceScope.values()) | ||
); | ||
return exception; | ||
} | ||
} | ||
return null; | ||
} | ||
} |