mirror of
https://github.com/google/nomulus
synced 2026-09-19 14:34:18 +00:00
Add WHOIS disclaimer text to ConfigModule
This fixes #23 for @parsoj by allowing a custom disclaimer to be specified via dependency injection modules. By making the disclaimer part of the dependency injection graph, it can come from anywhere. For example, if I was Donuts, I would have my own repository. I'd use an external http_archive() repository for Domain Registry. Then I would write my own Dagger @Component for each App Engine module. My Component would have a list of Dagger Modules, which I copied from the Domain Registry version. Then I would swap out ConfigModule with my own DonutsConfigModule, which provides the same values. So long as a method exists that @Provides @Config("whoisRegistry"), and the module containing it is listed in the @Component, the dependency injection graph becomes valid and complete for the whois package (provided other dependencies are met.) ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=128082921
This commit is contained in:
@@ -8,7 +8,6 @@ licenses(["notice"]) # Apache 2.0
|
||||
java_library(
|
||||
name = "whois",
|
||||
srcs = glob(["*.java"]),
|
||||
resources = ["disclaimer.txt"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//java/com/google/common/annotations",
|
||||
|
||||
@@ -61,39 +61,41 @@ final class DomainWhoisResponse extends WhoisResponseImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlainTextOutput(final boolean preferUnicode) {
|
||||
public String getPlainTextOutput(final boolean preferUnicode, String disclaimer) {
|
||||
Registrar registrar = getRegistrar(domain.getCurrentSponsorClientId());
|
||||
return new DomainEmitter()
|
||||
.emitField("Domain Name",
|
||||
maybeFormatHostname(domain.getFullyQualifiedDomainName(), preferUnicode))
|
||||
.emitField("Domain ID", domain.getRepoId())
|
||||
.emitField("WHOIS Server", registrar.getWhoisServer())
|
||||
.emitField("Referral URL", registrar.getReferralUrl())
|
||||
.emitField("Updated Date", getFormattedString(domain.getLastEppUpdateTime()))
|
||||
.emitField("Creation Date", getFormattedString(domain.getCreationTime()))
|
||||
.emitField("Registry Expiry Date",
|
||||
getFormattedString(domain.getRegistrationExpirationTime()))
|
||||
.emitField("Sponsoring Registrar", registrar.getRegistrarName())
|
||||
.emitField("Sponsoring Registrar IANA ID",
|
||||
registrar.getIanaIdentifier() == null ? null : registrar.getIanaIdentifier().toString())
|
||||
.emitStatusValues(domain.getStatusValues(), domain.getGracePeriods())
|
||||
.emitContact("Registrant", domain.getRegistrant(), preferUnicode)
|
||||
.emitContact("Admin", getContactReference(Type.ADMIN), preferUnicode)
|
||||
.emitContact("Tech", getContactReference(Type.TECH), preferUnicode)
|
||||
.emitContact("Billing", getContactReference(Type.BILLING), preferUnicode)
|
||||
.emitSet(
|
||||
"Name Server",
|
||||
domain.loadNameserverFullyQualifiedHostNames(),
|
||||
new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String hostName) {
|
||||
return maybeFormatHostname(hostName, preferUnicode);
|
||||
}})
|
||||
.emitField("DNSSEC", isNullOrEmpty(domain.getDsData()) ? "unsigned" : "signedDelegation")
|
||||
.emitLastUpdated(getTimestamp())
|
||||
.emitAwipMessage()
|
||||
.emitFooter()
|
||||
.toString();
|
||||
.emitField(
|
||||
"Domain Name", maybeFormatHostname(domain.getFullyQualifiedDomainName(), preferUnicode))
|
||||
.emitField("Domain ID", domain.getRepoId())
|
||||
.emitField("WHOIS Server", registrar.getWhoisServer())
|
||||
.emitField("Referral URL", registrar.getReferralUrl())
|
||||
.emitField("Updated Date", getFormattedString(domain.getLastEppUpdateTime()))
|
||||
.emitField("Creation Date", getFormattedString(domain.getCreationTime()))
|
||||
.emitField(
|
||||
"Registry Expiry Date", getFormattedString(domain.getRegistrationExpirationTime()))
|
||||
.emitField("Sponsoring Registrar", registrar.getRegistrarName())
|
||||
.emitField(
|
||||
"Sponsoring Registrar IANA ID",
|
||||
registrar.getIanaIdentifier() == null ? null : registrar.getIanaIdentifier().toString())
|
||||
.emitStatusValues(domain.getStatusValues(), domain.getGracePeriods())
|
||||
.emitContact("Registrant", domain.getRegistrant(), preferUnicode)
|
||||
.emitContact("Admin", getContactReference(Type.ADMIN), preferUnicode)
|
||||
.emitContact("Tech", getContactReference(Type.TECH), preferUnicode)
|
||||
.emitContact("Billing", getContactReference(Type.BILLING), preferUnicode)
|
||||
.emitSet(
|
||||
"Name Server",
|
||||
domain.loadNameserverFullyQualifiedHostNames(),
|
||||
new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String hostName) {
|
||||
return maybeFormatHostname(hostName, preferUnicode);
|
||||
}
|
||||
})
|
||||
.emitField("DNSSEC", isNullOrEmpty(domain.getDsData()) ? "unsigned" : "signedDelegation")
|
||||
.emitLastUpdated(getTimestamp())
|
||||
.emitAwipMessage()
|
||||
.emitFooter(disclaimer)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/** Returns the contact of the given type, or null if it does not exist. */
|
||||
|
||||
@@ -42,7 +42,7 @@ final class NameserverWhoisResponse extends WhoisResponseImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlainTextOutput(boolean preferUnicode) {
|
||||
public String getPlainTextOutput(boolean preferUnicode, String disclaimer) {
|
||||
BasicEmitter emitter = new BasicEmitter();
|
||||
for (int i = 0; i < hosts.size(); i++) {
|
||||
HostResource host = hosts.get(i);
|
||||
@@ -63,6 +63,6 @@ final class NameserverWhoisResponse extends WhoisResponseImpl {
|
||||
emitter.emitNewline();
|
||||
}
|
||||
}
|
||||
return emitter.emitLastUpdated(getTimestamp()).emitFooter().toString();
|
||||
return emitter.emitLastUpdated(getTimestamp()).emitFooter(disclaimer).toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,29 +43,29 @@ class RegistrarWhoisResponse extends WhoisResponseImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlainTextOutput(boolean preferUnicode) {
|
||||
public String getPlainTextOutput(boolean preferUnicode, String disclaimer) {
|
||||
Set<RegistrarContact> contacts = registrar.getContacts();
|
||||
return new RegistrarEmitter()
|
||||
.emitField("Registrar Name", registrar.getRegistrarName())
|
||||
.emitAddress(null, chooseByUnicodePreference(
|
||||
preferUnicode,
|
||||
registrar.getLocalizedAddress(),
|
||||
registrar.getInternationalizedAddress()))
|
||||
.emitAddress(
|
||||
null,
|
||||
chooseByUnicodePreference(
|
||||
preferUnicode,
|
||||
registrar.getLocalizedAddress(),
|
||||
registrar.getInternationalizedAddress()))
|
||||
.emitPhonesAndEmail(
|
||||
registrar.getPhoneNumber(),
|
||||
registrar.getFaxNumber(),
|
||||
registrar.getEmailAddress())
|
||||
registrar.getPhoneNumber(), registrar.getFaxNumber(), registrar.getEmailAddress())
|
||||
.emitField("WHOIS Server", registrar.getWhoisServer())
|
||||
.emitField("Referral URL", registrar.getReferralUrl())
|
||||
.emitRegistrarContacts("Admin", contacts, AdminOrTech.ADMIN)
|
||||
.emitRegistrarContacts("Technical", contacts, AdminOrTech.TECH)
|
||||
.emitRegistrarContacts("Technical", contacts, AdminOrTech.TECH)
|
||||
.emitLastUpdated(getTimestamp())
|
||||
.emitFooter()
|
||||
.emitFooter(disclaimer)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/** An emitter with logic for registrars. */
|
||||
class RegistrarEmitter extends Emitter<RegistrarEmitter> {
|
||||
static class RegistrarEmitter extends Emitter<RegistrarEmitter> {
|
||||
/** Emits the registrar contact of the given type. */
|
||||
RegistrarEmitter emitRegistrarContacts(
|
||||
String contactLabel,
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package google.registry.whois;
|
||||
|
||||
import google.registry.config.ConfigModule.Config;
|
||||
import google.registry.util.Clock;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
@@ -24,23 +25,24 @@ import org.joda.time.DateTime;
|
||||
public final class Whois {
|
||||
|
||||
private final Clock clock;
|
||||
private final String disclaimer;
|
||||
|
||||
@Inject
|
||||
public Whois(Clock clock) {
|
||||
public Whois(Clock clock, @Config("whoisDisclaimer") String disclaimer) {
|
||||
this.clock = clock;
|
||||
this.disclaimer = disclaimer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a WHOIS lookup on a plaintext query string.
|
||||
*
|
||||
* @throws WhoisException if the record is not found or the query is invalid
|
||||
*/
|
||||
public WhoisResponse lookup(String query) throws WhoisException {
|
||||
/** Performs a WHOIS lookup on a plaintext query string. */
|
||||
public String lookup(String query, boolean preferUnicode) {
|
||||
DateTime now = clock.nowUtc();
|
||||
try {
|
||||
return new WhoisReader(new StringReader(query), now)
|
||||
.readCommand()
|
||||
.executeQuery(now);
|
||||
.executeQuery(now)
|
||||
.getPlainTextOutput(preferUnicode, disclaimer);
|
||||
} catch (WhoisException e) {
|
||||
return e.getPlainTextOutput(preferUnicode, disclaimer);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -60,11 +60,11 @@ public final class WhoisException extends Exception implements WhoisResponse {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlainTextOutput(boolean preferUnicode) {
|
||||
public String getPlainTextOutput(boolean preferUnicode, String disclaimer) {
|
||||
return new WhoisResponseImpl.BasicEmitter()
|
||||
.emitRawLine(getMessage())
|
||||
.emitLastUpdated(getTimestamp())
|
||||
.emitFooter()
|
||||
.emitFooter(disclaimer)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +130,7 @@ public final class WhoisHttpServer implements Runnable {
|
||||
|
||||
@Inject Clock clock;
|
||||
@Inject Response response;
|
||||
@Inject @Config("whoisDisclaimer") String disclaimer;
|
||||
@Inject @Config("whoisHttpExpires") Duration expires;
|
||||
@Inject @RequestPath String requestPath;
|
||||
@Inject WhoisHttpServer() {}
|
||||
@@ -159,7 +160,7 @@ public final class WhoisHttpServer implements Runnable {
|
||||
response.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN, CORS_ALLOW_ORIGIN);
|
||||
response.setHeader(X_CONTENT_TYPE_OPTIONS, X_CONTENT_NO_SNIFF);
|
||||
response.setContentType(PLAIN_TEXT_UTF_8);
|
||||
response.setPayload(whoisResponse.getPlainTextOutput(true));
|
||||
response.setPayload(whoisResponse.getPlainTextOutput(true, disclaimer));
|
||||
}
|
||||
|
||||
/** Removes {@code %xx} escape codes from request path components. */
|
||||
|
||||
@@ -22,13 +22,14 @@ public interface WhoisResponse {
|
||||
/**
|
||||
* Returns a plain text WHOIS response.
|
||||
*
|
||||
* @param preferUnicode if {@code false} will cause the output to be converted to ASCII
|
||||
* whenever possible; for example, converting IDN hostname labels to punycode. However
|
||||
* certain things (like a domain registrant name with accent marks) will be returned
|
||||
* "as is". If the WHOIS client has told us they're able to receive UTF-8 (such as with
|
||||
* HTTP) then this field should be set to {@code true}.
|
||||
* @param preferUnicode if {@code false} will cause the output to be converted to ASCII whenever
|
||||
* possible; for example, converting IDN hostname labels to punycode. However certain things
|
||||
* (like a domain registrant name with accent marks) will be returned "as is". If the WHOIS
|
||||
* client has told us they're able to receive UTF-8 (such as with HTTP) then this field should
|
||||
* be set to {@code true}.
|
||||
* @param disclaimer text to show at bottom of output
|
||||
*/
|
||||
String getPlainTextOutput(boolean preferUnicode);
|
||||
String getPlainTextOutput(boolean preferUnicode, String disclaimer);
|
||||
|
||||
/**
|
||||
* Returns the time at which this response was created.
|
||||
|
||||
@@ -17,7 +17,6 @@ package google.registry.whois;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
import static com.google.common.html.HtmlEscapers.htmlEscaper;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
@@ -26,13 +25,10 @@ import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.common.io.Resources;
|
||||
import google.registry.model.eppcommon.Address;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.util.Idn;
|
||||
import google.registry.xml.UtcDateTimeAdapter;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -42,9 +38,6 @@ import org.joda.time.DateTime;
|
||||
/** Base class for responses to WHOIS queries. */
|
||||
abstract class WhoisResponseImpl implements WhoisResponse {
|
||||
|
||||
/** Legal disclaimer that is appended to all WHOIS responses. */
|
||||
private static final String DISCLAIMER = load("disclaimer.txt");
|
||||
|
||||
/** Field name for ICANN problem reporting URL appended to all WHOIS responses. */
|
||||
private static final String ICANN_REPORTING_URL_FIELD =
|
||||
"URL of the ICANN WHOIS Data Problem Reporting System";
|
||||
@@ -166,9 +159,9 @@ abstract class WhoisResponseImpl implements WhoisResponse {
|
||||
}
|
||||
|
||||
/** Returns raw text that should be appended to the end of ALL WHOIS responses. */
|
||||
E emitFooter() {
|
||||
E emitFooter(String disclaimer) {
|
||||
emitField(ICANN_REPORTING_URL_FIELD, ICANN_REPORTING_URL);
|
||||
stringBuilder.append("\r\n").append(DISCLAIMER).append("\r\n");
|
||||
stringBuilder.append("\r\n").append(disclaimer).append("\r\n");
|
||||
return thisCastToDerived();
|
||||
}
|
||||
|
||||
@@ -199,16 +192,6 @@ abstract class WhoisResponseImpl implements WhoisResponse {
|
||||
/** An emitter that needs no special logic. */
|
||||
static class BasicEmitter extends Emitter<BasicEmitter> {}
|
||||
|
||||
/** Slurps UTF-8 file from jar, relative to this source file. */
|
||||
private static String load(String relativeFilename) {
|
||||
URL resource = Resources.getResource(WhoisResponseImpl.class, relativeFilename);
|
||||
try {
|
||||
return Resources.toString(resource, UTF_8).replaceAll("\r?\n", "\r\n").trim();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to slurp: " + relativeFilename, e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the registrar for this client id, or an empty registrar with null values. */
|
||||
static Registrar getRegistrar(@Nullable String clientId) {
|
||||
return Optional
|
||||
|
||||
@@ -18,6 +18,7 @@ import static google.registry.request.Action.Method.POST;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
|
||||
import com.google.common.net.MediaType;
|
||||
import google.registry.config.ConfigModule.Config;
|
||||
import google.registry.request.Action;
|
||||
import google.registry.request.Response;
|
||||
import google.registry.util.Clock;
|
||||
@@ -57,6 +58,9 @@ public class WhoisServer implements Runnable {
|
||||
@Inject Clock clock;
|
||||
@Inject Reader input;
|
||||
@Inject Response response;
|
||||
@Inject
|
||||
@Config("whoisDisclaimer")
|
||||
String disclaimer;
|
||||
@Inject WhoisServer() {}
|
||||
|
||||
@Override
|
||||
@@ -64,12 +68,13 @@ public class WhoisServer implements Runnable {
|
||||
String responseText;
|
||||
DateTime now = clock.nowUtc();
|
||||
try {
|
||||
responseText = new WhoisReader(input, now)
|
||||
.readCommand()
|
||||
.executeQuery(now)
|
||||
.getPlainTextOutput(PREFER_UNICODE);
|
||||
responseText =
|
||||
new WhoisReader(input, now)
|
||||
.readCommand()
|
||||
.executeQuery(now)
|
||||
.getPlainTextOutput(PREFER_UNICODE, disclaimer);
|
||||
} catch (WhoisException e) {
|
||||
responseText = e.getPlainTextOutput(PREFER_UNICODE);
|
||||
responseText = e.getPlainTextOutput(PREFER_UNICODE, disclaimer);
|
||||
} catch (Throwable t) {
|
||||
logger.severe(t, "WHOIS request crashed");
|
||||
responseText = "Internal Server Error";
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
WHOIS information is provided by Charleston Road Registry Inc. (CRR) solely for
|
||||
query-based, informational purposes. By querying our WHOIS database, you are
|
||||
agreeing to comply with these terms
|
||||
(http://www.registry.google/about/whois-disclaimer.html) so please read them
|
||||
carefully. Any information provided is "as is" without any guarantee of
|
||||
accuracy. You may not use such information to (a) allow, enable, or otherwise
|
||||
support the transmission of mass unsolicited, commercial advertising or
|
||||
solicitations; (b) enable high volume, automated, electronic processes that
|
||||
access the systems of CRR or any ICANN-Accredited Registrar, except as
|
||||
reasonably necessary to register domain names or modify existing registrations;
|
||||
or (c) engage in or support unlawful behavior. CRR reserves the right to
|
||||
restrict or deny your access to the Whois database, and may modify these terms
|
||||
at any time.
|
||||
Reference in New Issue
Block a user