Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored inetnum status validation #1429

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ class InetnumIntegrationSpec extends BaseWhoisSourceSpec {
tech-c: TEST-PN
status: ALLOCATED PA
mnt-by: TEST-MNT
mnt-by: RIPE-NCC-HM-MNT
org: ORG-TOL1-TEST
source: TEST
password: update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public enum InetnumStatus implements InetStatus {
ASSIGNED_ANYCAST("ASSIGNED ANYCAST", LIR, OTHER),
LEGACY("LEGACY", LIR, OTHER);

private static final EnumSet<InetnumStatus> RS_MNTNER_STATUSES = EnumSet.of(ASSIGNED_ANYCAST, ALLOCATED_UNSPECIFIED);
private static final EnumSet<InetnumStatus> RS_MNTNER_STATUSES = EnumSet.of(ALLOCATED_PA, ASSIGNED_ANYCAST, ALLOCATED_UNSPECIFIED);
private static final EnumSet<InetnumStatus> NEEDS_ORG_REFERENCE = EnumSet.of(ALLOCATED_PA, ALLOCATED_UNSPECIFIED);
private static final EnumSet<InetnumStatus> NEEDS_PARENT_RS_MNTR = EnumSet.of(ALLOCATED_UNSPECIFIED);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,6 @@ private List<Message> validateStatusAgainstResourcesInTree(final PreparedUpdate
return validationMessages;
}

private void checkAuthorisationForStatus(final PreparedUpdate update, final UpdateContext updateContext, final List<Message> validationMessages) {
final RpslObject updatedObject = update.getUpdatedObject();
final Set<CIString> mntBy = updatedObject.getValuesForAttribute(AttributeType.MNT_BY);

final Inet6numStatus currentStatus = Inet6numStatus.getStatusFor(updatedObject.getValueForAttribute(STATUS));
if (currentStatus.requiresAllocMaintainer()) {
if (!updateContext.getSubject(update).hasPrincipal(Principal.ALLOC_MAINTAINER)) {
validationMessages.add(UpdateMessages.statusRequiresAuthorization(currentStatus.toString()));
return;
}
}

if (currentStatus.requiresRsMaintainer()) {
final boolean missingRsMaintainer = !maintainers.isRsMaintainer(mntBy);
if (missingRsMaintainer) {
validationMessages.add(UpdateMessages.statusRequiresAuthorization(updatedObject.getValueForAttribute(STATUS).toString()));
return;
}
if (!updateContext.getSubject(update).hasPrincipal(Principal.RS_MAINTAINER)) {
validationMessages.add(UpdateMessages.authorisationRequiredForSetStatus(currentStatus.toString()));
}
}
}

@SuppressWarnings("unchecked")
private boolean allChildrenHaveCorrectStatus(final PreparedUpdate update, List<Message> validationMessages) {
final RpslObject updatedObject = update.getUpdatedObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,9 @@ private boolean authByRs(final Subject subject) {
return subject.hasPrincipal(Principal.RS_MAINTAINER);
}

@CheckForNull
private RpslObject findParentWithRsMaintainer(final Ipv4Resource ipInterval) {
@SuppressWarnings("unchecked")
final List<Ipv4Entry> allLessSpecific = Lists.reverse(ipv4Tree.findAllLessSpecific(ipInterval));
for (final Ipv4Entry parent : allLessSpecific) {
final RpslObject parentObject = objectDao.getById(parent.getObjectId());
final Set<CIString> mntBy = parentObject.getValuesForAttribute(AttributeType.MNT_BY);

final boolean missingRsMaintainer = !maintainers.isRsMaintainer(mntBy);
if (!missingRsMaintainer) {
return parentObject;
}
}

return null;
}

private void checkAuthorisationForStatus(final PreparedUpdate update, final UpdateContext updateContext, final InetnumStatus currentStatus, final List<Message> validationMessages) {
final Set<CIString> mntBy = update.getUpdatedObject().getValuesForAttribute(AttributeType.MNT_BY);

if (currentStatus.requiresAllocMaintainer()) {
if (!updateContext.getSubject(update).hasPrincipal(Principal.ALLOC_MAINTAINER)) {
validationMessages.add(UpdateMessages.statusRequiresAuthorization(currentStatus.toString()));
return;
}
}

if (currentStatus.requiresRsMaintainer()) {
final boolean missingRsMaintainer = !maintainers.isRsMaintainer(mntBy);
if (missingRsMaintainer) {
Expand Down