Skip to content
Permalink
Browse files

Save the RDAP request time globally instead of passing it around

Also removed the rdapWhoisServer value, as it's just null and will likely stay that way (it isn't mentioned in the RDAP response profile)

If it'll ever become required, we can add it back.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=247643981
  • Loading branch information...
guyben13 authored and jianglai committed May 10, 2019
1 parent b10f880 commit a0040c5eda133616aa44e51d671c9bb4329192c0
@@ -969,20 +969,6 @@ public static int provideRdapResultSetMaxSize() {
return 100;
}

/**
* WHOIS server displayed in RDAP query responses. As per Gustavo Lozano of ICANN, this should
* be omitted, but the ICANN operational profile doesn't actually say that, so it's good to have
* the ability to reinstate this field if necessary.
*
* @see google.registry.rdap.RdapActionBase
*/
@Nullable
@Provides
@Config("rdapWhoisServer")
public static String provideRdapWhoisServer() {
return null;
}

/**
* Redaction text for email address in WHOIS
*
@@ -49,13 +49,11 @@
import google.registry.request.RequestMethod;
import google.registry.request.RequestPath;
import google.registry.request.Response;
import google.registry.util.Clock;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.inject.Inject;
import org.joda.time.DateTime;

@@ -86,15 +84,13 @@
}

@Inject Response response;
@Inject Clock clock;
@Inject @RequestMethod Action.Method requestMethod;
@Inject @RequestPath String requestPath;
@Inject RdapAuthorization rdapAuthorization;
@Inject RdapJsonFormatter rdapJsonFormatter;
@Inject @Parameter("registrar") Optional<String> registrarParam;
@Inject @Parameter("includeDeleted") Optional<Boolean> includeDeletedParam;
@Inject @Parameter("formatOutput") Optional<Boolean> formatOutputParam;
@Inject @Config("rdapWhoisServer") @Nullable String rdapWhoisServer;
@Inject @Config("rdapResultSetMaxSize") int rdapResultSetMaxSize;
@Inject RdapMetrics rdapMetrics;

@@ -242,8 +238,8 @@ DeletedItemHandling getDeletedItemHandling() {
* <p>This is true if the resource is not deleted, or the request wants to see deleted items, and
* is authorized to do so.
*/
boolean isAuthorized(EppResource eppResource, DateTime now) {
return now.isBefore(eppResource.getDeletionTime())
boolean isAuthorized(EppResource eppResource) {
return getRequestTime().isBefore(eppResource.getDeletionTime())
|| (shouldIncludeDeleted()
&& rdapAuthorization
.isAuthorizedForClientId(eppResource.getPersistedCurrentSponsorClientId()));
@@ -257,8 +253,8 @@ boolean isAuthorized(EppResource eppResource, DateTime now) {
* do so, and:
* 2. The request did not specify a registrar to filter on, or the registrar matches.
*/
boolean shouldBeVisible(EppResource eppResource, DateTime now) {
return isAuthorized(eppResource, now)
boolean shouldBeVisible(EppResource eppResource) {
return isAuthorized(eppResource)
&& (!registrarParam.isPresent()
|| registrarParam.get().equals(eppResource.getPersistedCurrentSponsorClientId()));
}
@@ -271,8 +267,8 @@ boolean shouldBeVisible(EppResource eppResource, DateTime now) {
* forward in time to empty),
* 2. The request did not specify a registrar to filter on, or the registrar matches.
*/
boolean shouldBeVisible(Optional<? extends EppResource> eppResource, DateTime now) {
return eppResource.isPresent() && shouldBeVisible(eppResource.get(), now);
boolean shouldBeVisible(Optional<? extends EppResource> eppResource) {
return eppResource.isPresent() && shouldBeVisible(eppResource.get());
}

/**
@@ -468,7 +464,6 @@ int getStandardQuerySizeLimit() {
*
* @param query an already-defined query to be run; a filter on currentSponsorClientId will be
* added if appropriate
* @param now the time as of which to evaluate the query
* @param checkForVisibility true if the results should be checked to make sure they are visible;
* normally this should be equal to the shouldIncludeDeleted setting, but in cases where
* the query could not check deletion status (due to Datastore limitations such as the
@@ -483,7 +478,7 @@ int getStandardQuerySizeLimit() {
* query is greater than or equal to the maximum number we might have expected
*/
<T extends EppResource> RdapResultSet<T> getMatchingResources(
Query<T> query, boolean checkForVisibility, DateTime now, int querySizeLimit) {
Query<T> query, boolean checkForVisibility, int querySizeLimit) {
Optional<String> desiredRegistrar = getDesiredRegistrar();
if (desiredRegistrar.isPresent()) {
query = query.filter("currentSponsorClientId", desiredRegistrar.get());
@@ -496,7 +491,7 @@ int getStandardQuerySizeLimit() {
int numResourcesQueried = 0;
boolean someExcluded = false;
for (T resource : query) {
if (shouldBeVisible(resource, now)) {
if (shouldBeVisible(resource)) {
resources.add(resource);
} else {
someExcluded = true;
@@ -542,4 +537,9 @@ RdapSearchPattern recordWildcardType(RdapSearchPattern partialStringQuery) {
metricInformationBuilder.setPrefixLength(partialStringQuery.getInitialString().length());
return partialStringQuery;
}

/** Returns the DateTime this request took place. */
DateTime getRequestTime() {
return rdapJsonFormatter.getRequestTime();
}
}
@@ -31,7 +31,6 @@
import google.registry.request.auth.Auth;
import java.util.Optional;
import javax.inject.Inject;
import org.joda.time.DateTime;

/** RDAP (new WHOIS) action for domain requests. */
@Action(
@@ -48,7 +47,6 @@

@Override
public RdapDomain getJsonObjectForResource(String pathSearchString, boolean isHeadRequest) {
DateTime now = clock.nowUtc();
pathSearchString = canonicalizeName(pathSearchString);
try {
validateDomainName(pathSearchString);
@@ -61,14 +59,14 @@ public RdapDomain getJsonObjectForResource(String pathSearchString, boolean isHe
// The query string is not used; the RDAP syntax is /rdap/domain/mydomain.com.
Optional<DomainBase> domainBase =
loadByForeignKey(
DomainBase.class, pathSearchString, shouldIncludeDeleted() ? START_OF_TIME : now);
if (!shouldBeVisible(domainBase, now)) {
DomainBase.class,
pathSearchString,
shouldIncludeDeleted() ? START_OF_TIME : rdapJsonFormatter.getRequestTime());
if (!shouldBeVisible(domainBase)) {
throw new NotFoundException(pathSearchString + " not found");
}
return rdapJsonFormatter.makeRdapJsonForDomain(
domainBase.get(),
rdapWhoisServer,
now,
OutputDataType.FULL);
}
}
Oops, something went wrong.

0 comments on commit a0040c5

Please sign in to comment.
You can’t perform that action at this time.