Deal with some getOfyKey() references (#1696)

Now that ofy keys aren't necessarily being restored, it seemed prudent to
audit existing uses to verify that we aren't relying on any keys that may now
be null.

This fixes one case that appeared to be potentially problematic (in
ResourceFlowUtils), removes a few methods that call getOfyKey() but are no
longer used, and adds comments to one use of the key that appears to be safe
after visual inspection.
This commit is contained in:
Michael Muller 2022-07-01 16:59:03 -04:00 committed by GitHub
parent f62732547f
commit af63b63477
3 changed files with 3 additions and 27 deletions

View file

@ -169,7 +169,7 @@ public final class ResourceFlowUtils {
// The roid should match one of the contacts. // The roid should match one of the contacts.
Optional<VKey<ContactResource>> foundContact = Optional<VKey<ContactResource>> foundContact =
domain.getReferencedContacts().stream() domain.getReferencedContacts().stream()
.filter(key -> key.getOfyKey().getName().equals(authRepoId)) .filter(key -> key.getSqlKey().equals(authRepoId))
.findFirst(); .findFirst();
if (!foundContact.isPresent()) { if (!foundContact.isPresent()) {
throw new BadAuthInfoForResourceException(); throw new BadAuthInfoForResourceException();

View file

@ -32,7 +32,6 @@ import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Ignore; import com.googlecode.objectify.annotation.Ignore;
import com.googlecode.objectify.annotation.IgnoreSave; import com.googlecode.objectify.annotation.IgnoreSave;
import com.googlecode.objectify.annotation.Index; import com.googlecode.objectify.annotation.Index;
import com.googlecode.objectify.annotation.OnLoad;
import com.googlecode.objectify.annotation.Parent; import com.googlecode.objectify.annotation.Parent;
import com.googlecode.objectify.condition.IfNull; import com.googlecode.objectify.condition.IfNull;
import google.registry.model.Buildable; import google.registry.model.Buildable;
@ -205,12 +204,6 @@ public abstract class BillingEvent extends ImmutableObject
domainHistoryRevisionId); domainHistoryRevisionId);
} }
@OnLoad
void onLoad() {
domainHistoryRevisionId = parent.getId();
domainRepoId = parent.getParent().getName();
}
public String getRegistrarId() { public String getRegistrarId() {
return clientId; return clientId;
} }
@ -437,15 +430,6 @@ public abstract class BillingEvent extends ImmutableObject
return new Builder(clone(this)); return new Builder(clone(this));
} }
@Override
void onLoad() {
super.onLoad();
if (cancellationMatchingBillingEvent != null) {
recurringEventHistoryRevisionId =
cancellationMatchingBillingEvent.getOfyKey().getParent().getId();
}
}
@Override @Override
void postLoad() { void postLoad() {
super.postLoad(); super.postLoad();
@ -493,6 +477,7 @@ public abstract class BillingEvent extends ImmutableObject
public Builder setCancellationMatchingBillingEvent( public Builder setCancellationMatchingBillingEvent(
VKey<Recurring> cancellationMatchingBillingEvent) { VKey<Recurring> cancellationMatchingBillingEvent) {
getInstance().cancellationMatchingBillingEvent = cancellationMatchingBillingEvent; getInstance().cancellationMatchingBillingEvent = cancellationMatchingBillingEvent;
// getOfyKey() here is safe, recurring billing event VKeys have a valid ofy key.
getInstance().recurringEventHistoryRevisionId = getInstance().recurringEventHistoryRevisionId =
cancellationMatchingBillingEvent.getOfyKey().getParent().getId(); cancellationMatchingBillingEvent.getOfyKey().getParent().getId();
return this; return this;
@ -526,6 +511,7 @@ public abstract class BillingEvent extends ImmutableObject
== (instance.cancellationMatchingBillingEvent != null), == (instance.cancellationMatchingBillingEvent != null),
"Cancellation matching billing event must be set if and only if the SYNTHETIC flag " "Cancellation matching billing event must be set if and only if the SYNTHETIC flag "
+ "is set."); + "is set.");
// getOfyKey() here is safe, billing event VKeys have a valid ofy key.
checkState( checkState(
!instance.getFlags().contains(Flag.SYNTHETIC) !instance.getFlags().contains(Flag.SYNTHETIC)
|| (instance.cancellationMatchingBillingEvent.getOfyKey().getParent().getId() || (instance.cancellationMatchingBillingEvent.getOfyKey().getParent().getId()

View file

@ -122,16 +122,6 @@ public class DomainTransferData extends TransferData<DomainTransferData.Builder>
return super.copyConstantFieldsToBuilder().setTransferPeriod(this.transferPeriod); return super.copyConstantFieldsToBuilder().setTransferPeriod(this.transferPeriod);
} }
/**
* Fix the VKey "kind" for the PollMessage keys.
*
* <p>For use by DomainBase/DomainHistory OnLoad methods ONLY.
*/
public void convertVKeys() {
serverApproveAutorenewPollMessage =
PollMessage.Autorenew.convertVKey(serverApproveAutorenewPollMessage);
}
public Period getTransferPeriod() { public Period getTransferPeriod() {
return transferPeriod; return transferPeriod;
} }