Skip to content

RANGER-4762:Prevent duplicate values for resource while validating policy#308

Closed
fateh288 wants to merge 3 commits intoapache:masterfrom
fateh288:RANGER-4762
Closed

RANGER-4762:Prevent duplicate values for resource while validating policy#308
fateh288 wants to merge 3 commits intoapache:masterfrom
fateh288:RANGER-4762

Conversation

@fateh288
Copy link
Copy Markdown
Contributor

Previously: Via REST, policy creation possible when duplicate values specified for a resource as a list e.g. for a resource, multiple dbs can be mentioned like db:[test_db1,test_db1] and this policy is considered different from a policy already created for the resource [test_db1]
The same scenario is already prevented by Ranger UI as it prevents duplicate values for a resource (in a given policy)

What changes were proposed in this pull request?

After this patch: Error is thrown for duplicate resource values like [test_db1,test_db1] - {"statusCode":1,"msgDesc":"(0) Validation failure: error code[3056], reason[Values for the resource=database contained a duplicate value=test_db1. Ensure all values for a resource are unique], field[resource-values], subfield[database], type[semantically incorrect] "}

How was this patch tested?

Unit tests added for the scenario
Manually tested via REST end points for policy creation that duplicate resource values for a resource throws above error.

…a policy

Previously: Via REST, policy creation possible when duplicate values specified for a resource as a list e.g. for a resource, multiple dbs can be mentioned like db:[test_db1,test_db1] and this policy is considered different from a policy already created for the resource [test_db1]
After this patch: Error is thrown for duplicate resource values like [test_db1,test_db1] - {"statusCode":1,"msgDesc":"(0) Validation failure: error code[3056], reason[Values for the resource=database contained a duplicate value=test_db1. Ensure all values for a resource are unique], field[resource-values], subfield[database], type[semantically incorrect] "}
Use removeIf() which uses iterator to remove blank values which avoid creation of full hashset and also allows breaking from the loop while finding duplicates.
Reorganize code into if-else format while checking for empty resource values - improves readability
@fateh288 fateh288 closed this Apr 3, 2024
@fateh288
Copy link
Copy Markdown
Contributor Author

fateh288 commented Apr 3, 2024

The changes have been merged : ffda775

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants