mirror of
https://github.com/google/nomulus.git
synced 2025-05-16 09:27:16 +02:00
Document StatusValue better and add per-resource restrictions
This generalizes the "LINKED can't be anywhere" idea into more targeted restrictions. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=146158204
This commit is contained in:
parent
7f3941a843
commit
50c5f856a2
8 changed files with 88 additions and 26 deletions
|
@ -243,9 +243,14 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable {
|
|||
|
||||
/** Set this resource's status values. */
|
||||
public B setStatusValues(ImmutableSet<StatusValue> statusValues) {
|
||||
Class<? extends EppResource> resourceClass = getInstance().getClass();
|
||||
for (StatusValue statusValue : nullToEmpty(statusValues)) {
|
||||
checkArgument(
|
||||
!nullToEmpty(statusValues).contains(StatusValue.LINKED),
|
||||
"LINKED is a virtual status value that should never be set on an EppResource");
|
||||
!statusValue.isForbiddenOn(resourceClass),
|
||||
"The %s status cannot be set on %s",
|
||||
statusValue,
|
||||
resourceClass.getSimpleName());
|
||||
}
|
||||
getInstance().status = statusValues;
|
||||
return thisCastToDerived();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,12 @@ import static com.google.common.base.CaseFormat.LOWER_CAMEL;
|
|||
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
|
||||
import static com.google.common.base.Strings.nullToEmpty;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.contact.ContactResource;
|
||||
import google.registry.model.domain.DomainApplication;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
import google.registry.model.host.HostResource;
|
||||
import google.registry.model.translators.EnumToAttributeAdapter.EppEnum;
|
||||
import google.registry.model.translators.StatusValueAdapter;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
@ -43,22 +49,69 @@ public enum StatusValue implements EppEnum {
|
|||
CLIENT_RENEW_PROHIBITED,
|
||||
CLIENT_TRANSFER_PROHIBITED,
|
||||
CLIENT_UPDATE_PROHIBITED,
|
||||
INACTIVE,
|
||||
|
||||
/**
|
||||
* A status that means a resource has an incoming reference from an active domain.
|
||||
* A status for a domain with no nameservers that has all the other requirements for {@link #OK}.
|
||||
*
|
||||
* <p>Only domains can have this status, and it supersedes OK.
|
||||
*/
|
||||
INACTIVE(ContactResource.class, HostResource.class, DomainApplication.class),
|
||||
|
||||
/**
|
||||
* A status for a resource has an incoming reference from an active domain.
|
||||
*
|
||||
* <p>LINKED is a "virtual" status value that should never be persisted to Datastore on any
|
||||
* resource. It must be computed on the fly when we need it, as the set of domains using a
|
||||
* resource can change at any time.
|
||||
*/
|
||||
LINKED,
|
||||
LINKED(ContactResource.class, DomainApplication.class, DomainResource.class, HostResource.class),
|
||||
|
||||
/**
|
||||
* A status for a resource that has no other statuses.
|
||||
*
|
||||
* <p>Domains that have no other statuses but also have no nameservers get {@link #INACTIVE}
|
||||
* instead. The spec also allows a resource to have {@link #LINKED} along with OK, but we
|
||||
* implement LINKED as a virtual status that gets appended to outputs (such as info commands) on
|
||||
* the fly, so we can ignore LINKED when dealing with persisted resources.
|
||||
*/
|
||||
OK,
|
||||
PENDING_CREATE,
|
||||
PENDING_DELETE,
|
||||
PENDING_TRANSFER,
|
||||
PENDING_UPDATE,
|
||||
|
||||
/**
|
||||
* A status for a resource undergoing asynchronous creation.
|
||||
*
|
||||
* <p>We only use this for unallocated applications.
|
||||
*/
|
||||
PENDING_CREATE(ContactResource.class, DomainResource.class, HostResource.class),
|
||||
|
||||
/**
|
||||
* A status for a resource undergoing asynchronous deletion or for a recently deleted domain.
|
||||
*
|
||||
* <p>Contacts and hosts are deleted asynchronously because we need to check their incoming
|
||||
* references with strong consistency, requiring a mapreduce.
|
||||
*
|
||||
* <p>Domains that are deleted after the add grace period ends go into a redemption grace period,
|
||||
* and when that ends they go into pending delete for 5 days.
|
||||
*
|
||||
* <p>Applications are deleted synchronously and can never have this status.
|
||||
*/
|
||||
PENDING_DELETE(DomainApplication.class),
|
||||
|
||||
/**
|
||||
* A status for a resource with an unresolved transfer request.
|
||||
*
|
||||
* <p>Applications can't be transferred. Hosts transfer indirectly via superordinate domain.
|
||||
*/
|
||||
// TODO(b/34844887): Remove PENDING_TRANSFER from all host resources and forbid it here.
|
||||
PENDING_TRANSFER(DomainApplication.class),
|
||||
|
||||
/**
|
||||
* A status for a resource undergoing an asynchronous update.
|
||||
*
|
||||
* <p>This status is here for completeness, but it is not used by our system.
|
||||
*/
|
||||
PENDING_UPDATE(
|
||||
ContactResource.class, DomainApplication.class, DomainResource.class, HostResource.class),
|
||||
|
||||
SERVER_DELETE_PROHIBITED,
|
||||
SERVER_HOLD,
|
||||
SERVER_RENEW_PROHIBITED,
|
||||
|
@ -66,6 +119,12 @@ public enum StatusValue implements EppEnum {
|
|||
SERVER_UPDATE_PROHIBITED;
|
||||
|
||||
private final String xmlName = UPPER_UNDERSCORE.to(LOWER_CAMEL, name());
|
||||
private final ImmutableSet<Class<? extends EppResource>> forbiddenOn;
|
||||
|
||||
@SafeVarargs
|
||||
private StatusValue(Class<? extends EppResource>... forbiddenOn) {
|
||||
this.forbiddenOn = ImmutableSet.copyOf(forbiddenOn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getXmlName() {
|
||||
|
@ -81,6 +140,10 @@ public enum StatusValue implements EppEnum {
|
|||
return xmlName.startsWith("server") && xmlName.endsWith("Prohibited");
|
||||
}
|
||||
|
||||
public boolean isForbiddenOn(Class<? extends EppResource> resource) {
|
||||
return forbiddenOn.contains(resource);
|
||||
}
|
||||
|
||||
public static StatusValue fromXmlName(String xmlName) {
|
||||
return StatusValue.valueOf(LOWER_CAMEL.to(UPPER_UNDERSCORE, nullToEmpty(xmlName)));
|
||||
}
|
||||
|
|
|
@ -408,9 +408,7 @@ public class DomainResourceToXjcConverterTest {
|
|||
.setLastEppUpdateClientId("CeilingCat")
|
||||
.setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z"))
|
||||
.setRepoId(repoId)
|
||||
.setStatusValues(ImmutableSet.of(
|
||||
StatusValue.OK,
|
||||
StatusValue.PENDING_UPDATE))
|
||||
.setStatusValues(ImmutableSet.of(StatusValue.OK))
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ public class HostResourceToXjcConverterTest {
|
|||
.setLastEppUpdateClientId("CeilingCat")
|
||||
.setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z"))
|
||||
.setRepoId("2-roid")
|
||||
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_UPDATE))
|
||||
.setStatusValues(ImmutableSet.of(StatusValue.OK))
|
||||
.build());
|
||||
|
||||
assertThat(bean.getAddrs()).hasSize(1);
|
||||
|
@ -94,8 +94,8 @@ public class HostResourceToXjcConverterTest {
|
|||
assertThat(bean.getRoid()).isEqualTo("2-roid");
|
||||
|
||||
assertThat(bean.getStatuses()).hasSize(1);
|
||||
assertThat(bean.getStatuses().get(0).getS()).isEqualTo(XjcHostStatusValueType.PENDING_UPDATE);
|
||||
assertThat(bean.getStatuses().get(0).getS().toString()).isEqualTo("PENDING_UPDATE");
|
||||
assertThat(bean.getStatuses().get(0).getS()).isEqualTo(XjcHostStatusValueType.OK);
|
||||
assertThat(bean.getStatuses().get(0).getS().toString()).isEqualTo("OK");
|
||||
assertThat(bean.getStatuses().get(0).getValue()).isNull();
|
||||
assertThat(bean.getStatuses().get(0).getLang()).isEqualTo("en");
|
||||
|
||||
|
@ -120,7 +120,7 @@ public class HostResourceToXjcConverterTest {
|
|||
.setLastEppUpdateClientId("CeilingCat")
|
||||
.setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z"))
|
||||
.setRepoId("2-LOL")
|
||||
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_UPDATE))
|
||||
.setStatusValues(ImmutableSet.of(StatusValue.OK))
|
||||
.build());
|
||||
assertThat(bean.getAddrs()).hasSize(1);
|
||||
assertThat(bean.getAddrs().get(0).getIp().value()).isEqualTo("v6");
|
||||
|
|
|
@ -233,9 +233,7 @@ final class RdeFixtures {
|
|||
.setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z"))
|
||||
.setLastEppUpdateClientId("CeilingCat")
|
||||
.setLastEppUpdateTime(clock.nowUtc())
|
||||
.setStatusValues(ImmutableSet.of(
|
||||
StatusValue.OK,
|
||||
StatusValue.PENDING_UPDATE))
|
||||
.setStatusValues(ImmutableSet.of(StatusValue.OK))
|
||||
.build());
|
||||
}
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@
|
|||
<rdeHost:host>
|
||||
<rdeHost:name>bird.or.devil.xn--q9jyb4c</rdeHost:name>
|
||||
<rdeHost:roid>8-ROID</rdeHost:roid>
|
||||
<rdeHost:status s="pendingUpdate"/>
|
||||
<rdeHost:status s="ok"/>
|
||||
<rdeHost:addr ip="v4">1.2.3.4</rdeHost:addr>
|
||||
<rdeHost:clID>BusinessCat</rdeHost:clID>
|
||||
<rdeHost:crRr>LawyerCat</rdeHost:crRr>
|
||||
|
@ -117,7 +117,7 @@
|
|||
<rdeHost:host>
|
||||
<rdeHost:name>ns2.cat.xn--q9jyb4c</rdeHost:name>
|
||||
<rdeHost:roid>9-ROID</rdeHost:roid>
|
||||
<rdeHost:status s="pendingUpdate"/>
|
||||
<rdeHost:status s="ok"/>
|
||||
<rdeHost:addr ip="v6">bad:f00d:cafe::15:beef</rdeHost:addr>
|
||||
<rdeHost:clID>BusinessCat</rdeHost:clID>
|
||||
<rdeHost:crRr>LawyerCat</rdeHost:crRr>
|
||||
|
|
|
@ -204,9 +204,7 @@ public class GenerateEscrowDepositCommandTest
|
|||
.setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z"))
|
||||
.setLastEppUpdateClientId("CeilingCat")
|
||||
.setLastEppUpdateTime(clock.nowUtc())
|
||||
.setStatusValues(ImmutableSet.of(
|
||||
StatusValue.OK,
|
||||
StatusValue.PENDING_UPDATE))
|
||||
.setStatusValues(ImmutableSet.of(StatusValue.OK))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
<rdeHost:host>
|
||||
<rdeHost:name>ns1.cat.lol</rdeHost:name>
|
||||
<rdeHost:roid>5-ROID</rdeHost:roid>
|
||||
<rdeHost:status s="pendingUpdate"/>
|
||||
<rdeHost:status s="ok"/>
|
||||
<rdeHost:addr ip="v6">feed::a:bee</rdeHost:addr>
|
||||
<rdeHost:clID>BusinessCat</rdeHost:clID>
|
||||
<rdeHost:crRr>LawyerCat</rdeHost:crRr>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue