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:
Justine Tunney 2016-07-21 11:18:06 -07:00
parent 2c9567e183
commit e82a40a2fb
34 changed files with 149 additions and 310 deletions

View file

@ -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