mirror of
https://github.com/google/nomulus.git
synced 2025-05-31 09:44:03 +02:00
Remove TLD parameters from WHOIS command factory methods
The small efficiency increase in not having to look up the TLDs again did not justify making the externally extensible API more complicated. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=145465971
This commit is contained in:
parent
6c11ac5392
commit
579e4cb74e
5 changed files with 13 additions and 49 deletions
|
@ -19,18 +19,13 @@ import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.net.InternetDomainName;
|
import com.google.common.net.InternetDomainName;
|
||||||
import google.registry.model.domain.DomainResource;
|
import google.registry.model.domain.DomainResource;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
/** Represents a WHOIS lookup on a domain name (i.e. SLD). */
|
/** Represents a WHOIS lookup on a domain name (i.e. SLD). */
|
||||||
public class DomainLookupCommand extends DomainOrHostLookupCommand {
|
public class DomainLookupCommand extends DomainOrHostLookupCommand {
|
||||||
|
|
||||||
DomainLookupCommand(InternetDomainName domainName) {
|
public DomainLookupCommand(InternetDomainName domainName) {
|
||||||
this(domainName, null);
|
super(domainName, "Domain");
|
||||||
}
|
|
||||||
|
|
||||||
public DomainLookupCommand(InternetDomainName domainName, @Nullable InternetDomainName tld) {
|
|
||||||
super(domainName, tld, "Domain");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,7 +22,6 @@ import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.net.InternetDomainName;
|
import com.google.common.net.InternetDomainName;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
/** Represents a WHOIS lookup on a domain name (i.e. SLD) or a nameserver. */
|
/** Represents a WHOIS lookup on a domain name (i.e. SLD) or a nameserver. */
|
||||||
|
@ -32,21 +31,15 @@ public abstract class DomainOrHostLookupCommand implements WhoisCommand {
|
||||||
|
|
||||||
private final String errorPrefix;
|
private final String errorPrefix;
|
||||||
|
|
||||||
private Optional<InternetDomainName> tld;
|
DomainOrHostLookupCommand(InternetDomainName domainName, String errorPrefix) {
|
||||||
|
|
||||||
DomainOrHostLookupCommand(
|
|
||||||
InternetDomainName domainName, @Nullable InternetDomainName tld, String errorPrefix) {
|
|
||||||
this.errorPrefix = errorPrefix;
|
this.errorPrefix = errorPrefix;
|
||||||
this.domainOrHostName = checkNotNull(domainName, "domainOrHostName");
|
this.domainOrHostName = checkNotNull(domainName, "domainOrHostName");
|
||||||
this.tld = Optional.fromNullable(tld);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final WhoisResponse executeQuery(final DateTime now) throws WhoisException {
|
public final WhoisResponse executeQuery(final DateTime now) throws WhoisException {
|
||||||
if (!tld.isPresent()) {
|
Optional<InternetDomainName> tld = findTldForName(domainOrHostName);
|
||||||
tld = findTldForName(domainOrHostName);
|
// Google Registry Policy: Do not return records under TLDs for which we're not authoritative.
|
||||||
}
|
|
||||||
// Google Policy: Do not return records under TLDs for which we're not authoritative.
|
|
||||||
if (tld.isPresent() && getTlds().contains(tld.get().toString())) {
|
if (tld.isPresent() && getTlds().contains(tld.get().toString())) {
|
||||||
final Optional<WhoisResponse> response = getResponse(domainOrHostName, now);
|
final Optional<WhoisResponse> response = getResponse(domainOrHostName, now);
|
||||||
if (response.isPresent()) {
|
if (response.isPresent()) {
|
||||||
|
|
|
@ -19,18 +19,13 @@ import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.net.InternetDomainName;
|
import com.google.common.net.InternetDomainName;
|
||||||
import google.registry.model.host.HostResource;
|
import google.registry.model.host.HostResource;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
/** Represents a WHOIS lookup on a nameserver based on its hostname. */
|
/** Represents a WHOIS lookup on a nameserver based on its hostname. */
|
||||||
public class NameserverLookupByHostCommand extends DomainOrHostLookupCommand {
|
public class NameserverLookupByHostCommand extends DomainOrHostLookupCommand {
|
||||||
|
|
||||||
NameserverLookupByHostCommand(InternetDomainName hostName) {
|
NameserverLookupByHostCommand(InternetDomainName hostName) {
|
||||||
this(hostName, null);
|
super(hostName, "Nameserver");
|
||||||
}
|
|
||||||
|
|
||||||
NameserverLookupByHostCommand(InternetDomainName hostName, @Nullable InternetDomainName tld) {
|
|
||||||
super(hostName, tld, "Nameserver");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,7 +17,6 @@ package google.registry.whois;
|
||||||
import com.google.common.net.InternetDomainName;
|
import com.google.common.net.InternetDomainName;
|
||||||
import google.registry.config.RegistryConfig.ConfigModule;
|
import google.registry.config.RegistryConfig.ConfigModule;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class used to configure WHOIS commands.
|
* A class used to configure WHOIS commands.
|
||||||
|
@ -28,17 +27,8 @@ import javax.annotation.Nullable;
|
||||||
public class WhoisCommandFactory {
|
public class WhoisCommandFactory {
|
||||||
|
|
||||||
/** Returns a new {@link WhoisCommand} to perform a domain lookup on the specified domain name. */
|
/** Returns a new {@link WhoisCommand} to perform a domain lookup on the specified domain name. */
|
||||||
public final WhoisCommand domainLookup(InternetDomainName domainName) {
|
public WhoisCommand domainLookup(InternetDomainName domainName) {
|
||||||
return domainLookup(domainName, null);
|
return new DomainLookupCommand(domainName);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a new {@link WhoisCommand} to perform a domain lookup on the specified domain name in
|
|
||||||
* the specified TLD.
|
|
||||||
*/
|
|
||||||
public WhoisCommand domainLookup(
|
|
||||||
InternetDomainName domainName, @Nullable InternetDomainName tld) {
|
|
||||||
return new DomainLookupCommand(domainName, tld);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,17 +41,8 @@ public class WhoisCommandFactory {
|
||||||
/**
|
/**
|
||||||
* Returns a new {@link WhoisCommand} to perform a nameserver lookup on the specified host name.
|
* Returns a new {@link WhoisCommand} to perform a nameserver lookup on the specified host name.
|
||||||
*/
|
*/
|
||||||
public final WhoisCommand nameserverLookupByHost(InternetDomainName hostName) {
|
public WhoisCommand nameserverLookupByHost(InternetDomainName hostName) {
|
||||||
return nameserverLookupByHost(hostName, null);
|
return new NameserverLookupByHostCommand(hostName);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a new {@link WhoisCommand} to perform a nameserver lookup on the specified host name in
|
|
||||||
* the specified TLD.
|
|
||||||
*/
|
|
||||||
public WhoisCommand nameserverLookupByHost(
|
|
||||||
InternetDomainName hostName, @Nullable InternetDomainName tld) {
|
|
||||||
return new NameserverLookupByHostCommand(hostName, tld);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -179,14 +179,14 @@ class WhoisReader {
|
||||||
return new RegistrarLookupCommand(arg1);
|
return new RegistrarLookupCommand(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the target is exactly one level above the TLD, then this is an second level domain
|
// If the target is exactly one level above the TLD, then this is a second level domain
|
||||||
// (SLD) and we should do a domain lookup on it.
|
// (SLD) and we should do a domain lookup on it.
|
||||||
if (targetName.parent().equals(tld.get())) {
|
if (targetName.parent().equals(tld.get())) {
|
||||||
return commandFactory.domainLookup(targetName, tld.get());
|
return commandFactory.domainLookup(targetName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The target is more than one level above the TLD, so we'll assume it's a nameserver.
|
// The target is more than one level above the TLD, so we'll assume it's a nameserver.
|
||||||
return commandFactory.nameserverLookupByHost(targetName, tld.get());
|
return commandFactory.nameserverLookupByHost(targetName);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// Silently ignore this exception.
|
// Silently ignore this exception.
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue