Skip to content

Commit

Permalink
RANGER-4648: updated GDS validation for name length
Browse files Browse the repository at this point in the history
Signed-off-by: Madhan Neethiraj <[email protected]>
  • Loading branch information
princeap173 authored and mneethiraj committed Jan 14, 2024
1 parent 42bbf5c commit 9e92583
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public enum ValidationErrorCode {
SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_INVALID_DEFAULT_INDEX(2019, "default index[{0}] for enum [{1}] is invalid"),
SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NULL_ENUM_ELEMENT(2020, "An enum element in enum element collection of enum [{0}] is null"),
SERVICE_DEF_VALIDATION_ERR_INVALID_SERVICE_RESOURCE_LEVELS(2021, "Resource-def levels are not in increasing order in an hierarchy"),
SERVICE_DEF_VALIDATION_ERR_NOT_LOWERCASE_NAME(2022, "{0}:[{1}] Invalid resource name. Resource name should consist of only lowercase, hyphen or underscore characters"),
SERVICE_DEF_VALIDATION_ERR_NOT_LOWERCASE_NAME(2022, "{0}:[{1}] Invalid resource name. Resource name should consist of only lowercase, hyphen or underscore characters"),
SERVICE_DEF_VALIDATION_ERR_INVALID_MANADORY_VALUE_FOR_SERVICE_RESOURCE(2023, "{0} cannot be mandatory because {1}(parent) is not mandatory"),

// POLICY VALIDATION
Expand Down Expand Up @@ -164,6 +164,9 @@ public enum ValidationErrorCode {
GDS_VALIDATION_ERR_UPDATE_IMMUTABLE_FIELD(4126, "[{0}] can't be updated"),
GDS_VALIDATION_ERR_DATASET_IN_PROJECT_ID_NOT_FOUND(4127, "Dataset-in-project with ID [{0}] does not exist"),
GDS_VALIDATION_ERR_SHARED_RESOURCE_CONFLICT(4128, "Shared resource with resources [{0}] already exists for data share [{1}]"),
GDS_DATASET_NAME_TOO_LONG(4129, "Invalid dataset name=[{0}]. Dataset name should not be longer than 512 characters"),
GDS_DATASHARE_NAME_TOO_LONG(4130, "Invalid datashare name=[{0}]. Datashare name should not be longer than 512 characters"),
GDS_PROJECT_NAME_TOO_LONG(4131, "Invalid project name=[{0}]. Project name should not be longer than 512 characters"),
;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class RangerGdsValidator {

private final RangerGdsValidationDataProvider dataProvider;

public static final Integer GDS_ENTITIES_NAME_MAX_LENGTH = 512;

@Autowired
RESTErrorUtil restErrorUtil;

Expand All @@ -70,6 +72,10 @@ public void validateCreate(RangerDataset dataset) {
result.addValidationFailure(new ValidationFailureDetails(ValidationErrorCode.GDS_VALIDATION_ERR_DATASET_NAME_CONFLICT, "name", dataset.getName(), existing));
}

if (dataset.getName().length() > GDS_ENTITIES_NAME_MAX_LENGTH) {
result.addValidationFailure(new ValidationFailureDetails(ValidationErrorCode.GDS_DATASET_NAME_TOO_LONG, "name", dataset.getName()));
}

validateAcl(dataset.getAcl(), "acl", result);

if (!result.isSuccess()) {
Expand Down Expand Up @@ -98,6 +104,10 @@ public void validateUpdate(RangerDataset dataset, RangerDataset existing) {
if (existingDatasetNameId != null) {
result.addValidationFailure(new ValidationFailureDetails(ValidationErrorCode.GDS_VALIDATION_ERR_DATASET_NAME_CONFLICT, "name", dataset.getName(), existingDatasetNameId));
}

if (dataset.getName().length() > GDS_ENTITIES_NAME_MAX_LENGTH) {
result.addValidationFailure(new ValidationFailureDetails(ValidationErrorCode.GDS_DATASET_NAME_TOO_LONG, "name", dataset.getName()));
}
}
}

Expand Down Expand Up @@ -136,6 +146,10 @@ public void validateCreate(RangerProject project) {
result.addValidationFailure(new ValidationFailureDetails(ValidationErrorCode.GDS_VALIDATION_ERR_PROJECT_NAME_CONFLICT, "name", project.getName(), existing));
}

if (project.getName().length() > GDS_ENTITIES_NAME_MAX_LENGTH) {
result.addValidationFailure(new ValidationFailureDetails(ValidationErrorCode.GDS_PROJECT_NAME_TOO_LONG, "name", project.getName()));
}

validateAcl(project.getAcl(), "acl", result);

if (!result.isSuccess()) {
Expand Down Expand Up @@ -164,6 +178,10 @@ public void validateUpdate(RangerProject project, RangerProject existing) {
if (existingProjectNameId != null) {
result.addValidationFailure(new ValidationFailureDetails(ValidationErrorCode.GDS_VALIDATION_ERR_PROJECT_NAME_CONFLICT, "name", project.getName(), existingProjectNameId));
}

if (project.getName().length() > GDS_ENTITIES_NAME_MAX_LENGTH) {
result.addValidationFailure(new ValidationFailureDetails(ValidationErrorCode.GDS_PROJECT_NAME_TOO_LONG, "name", project.getName()));
}
}
}

Expand Down Expand Up @@ -202,6 +220,10 @@ public void validateCreate(RangerDataShare dataShare) {
result.addValidationFailure(new ValidationFailureDetails(ValidationErrorCode.GDS_VALIDATION_ERR_DATA_SHARE_NAME_CONFLICT, "name", dataShare.getName(), existing));
}

if (dataShare.getName().length() > GDS_ENTITIES_NAME_MAX_LENGTH) {
result.addValidationFailure(new ValidationFailureDetails(ValidationErrorCode.GDS_DATASHARE_NAME_TOO_LONG, "name", dataShare.getName()));
}

validateServiceZoneAdmin(dataShare.getService(), dataShare.getZone(), result);

validateAcl(dataShare.getAcl(), "acl", result);
Expand Down Expand Up @@ -236,6 +258,10 @@ public void validateUpdate(RangerDataShare dataShare, RangerDataShare existing)
if (existingDataShareNameId != null) {
result.addValidationFailure(new ValidationFailureDetails(ValidationErrorCode.GDS_VALIDATION_ERR_DATA_SHARE_NAME_CONFLICT, "name", dataShare.getName(), existingDataShareNameId));
}

if (dataShare.getName().length() > GDS_ENTITIES_NAME_MAX_LENGTH) {
result.addValidationFailure(new ValidationFailureDetails(ValidationErrorCode.GDS_DATASHARE_NAME_TOO_LONG, "name", dataShare.getName()));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ const AddDatasetView = () => {
toast.error("Dataset name cannot be empty!!");
return;
}
else if (datasetName.length>512)
{
toast.error("Dataset name must not exceed 512 characters!!");
return;
}
setSaveButtonText("Continue");
setStep(step + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1500,16 +1500,27 @@ const DatasetDetailLayout = () => {
</Button>
<Button
variant="primary"
onClick={
activeKey == "accessGrants" &&
accessGrantFormValues != undefined &&
datasetNameEditable
? updateDatasetAndAccessGrant
: activeKey != "accessGrants" ||
(activeKey == "accessGrants" && datasetNameEditable)
? updateDatasetDetails
: updateDatasetAccessGrant
}
onClick={() => {
if(datasetName.length > 512) {
toast.error('Dataset name must be 512 characters or less');
}
else {
if (
activeKey === 'accessGrants' &&
accessGrantFormValues !== undefined &&
datasetNameEditable
) {
updateDatasetAndAccessGrant();
} else if (
activeKey !== 'accessGrants' ||
(activeKey === 'accessGrants' && datasetNameEditable)
) {
updateDatasetDetails();
} else {
updateDatasetAccessGrant();
}
}
}}
size="sm"
data-id="save"
data-cy="save"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ const AddDatashareView = () => {
if (datashareName == undefined) {
toast.error("Please add Datashare Name");
return;
} else if (datashareName.length>512)
{
toast.error("DataShare Name must not exceed 512 characters");
return;
} else if (selectedService == undefined) {
toast.error("Please add Service Name");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,12 @@ const DatashareDetailLayout = () => {
datashareInfo.conditionExpr = datashareConditionExpr;
datashareInfo.defaultAccessTypes = [];

if(datashareName.length>512)
{
toast.error("Datashare name must be 512 characters or less!");
return;
}

accessType?.forEach((access) =>
datashareInfo.defaultAccessTypes.push(access.value)
);
Expand Down

0 comments on commit 9e92583

Please sign in to comment.