mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
Inject RDAP help information in ConfigModule
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=140849879
This commit is contained in:
parent
3740171bbf
commit
c59b738b5b
57 changed files with 436 additions and 306 deletions
|
@ -13,6 +13,7 @@ java_library(
|
|||
"//java/com/google/common/collect",
|
||||
"//java/com/google/common/net",
|
||||
"//third_party/java/appengine:appengine-api",
|
||||
"//third_party/java/auto:auto_value",
|
||||
"//third_party/java/dagger",
|
||||
"//third_party/java/joda_money",
|
||||
"//third_party/java/joda_time",
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.net.URI;
|
|||
import java.net.URL;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Qualifier;
|
||||
import javax.inject.Singleton;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
import org.joda.time.DateTimeConstants;
|
||||
import org.joda.time.Duration;
|
||||
|
@ -921,4 +922,89 @@ public final class ConfigModule {
|
|||
// TODO(b/32875427): This will be moved into configuration in a text file in a future refactor.
|
||||
return "google.registry.flows.custom.CustomLogicFactory";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the help path for the RDAP terms of service.
|
||||
*
|
||||
* <p>Make sure that this path is equal to the key of the entry in the RDAP help map containing
|
||||
* the terms of service. The ICANN operational profile requires that the TOS be included in all
|
||||
* responses, and this string is used to find the TOS in the help map.
|
||||
*/
|
||||
@Provides
|
||||
@Config("rdapTosPath")
|
||||
public static String provideRdapTosPath() {
|
||||
return "/tos";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the help text to be used by RDAP.
|
||||
*
|
||||
* <p>Make sure that the map entry for the terms of service use the same key as specified in
|
||||
* rdapTosPath above.
|
||||
*/
|
||||
@Singleton
|
||||
@Provides
|
||||
@Config("rdapHelpMap")
|
||||
public static ImmutableMap<String, RdapNoticeDescriptor> provideRdapHelpMap() {
|
||||
return new ImmutableMap.Builder<String, RdapNoticeDescriptor>()
|
||||
.put("/", RdapNoticeDescriptor.builder()
|
||||
.setTitle("RDAP Help")
|
||||
.setDescription(ImmutableList.of(
|
||||
"RDAP Help Topics (use /help/topic for information)",
|
||||
"syntax",
|
||||
"tos (Terms of Service)"))
|
||||
.setLinkValueSuffix("help/")
|
||||
.build())
|
||||
.put("/index", RdapNoticeDescriptor.builder()
|
||||
.setTitle("RDAP Help")
|
||||
.setDescription(ImmutableList.of(
|
||||
"RDAP Help Topics (use /help/topic for information)",
|
||||
"syntax",
|
||||
"tos (Terms of Service)"))
|
||||
.setLinkValueSuffix("help/index")
|
||||
.build())
|
||||
.put("/syntax", RdapNoticeDescriptor.builder()
|
||||
.setTitle("RDAP Command Syntax")
|
||||
.setDescription(ImmutableList.of(
|
||||
"domain/XXXX",
|
||||
"nameserver/XXXX",
|
||||
"entity/XXXX",
|
||||
"domains?name=XXXX",
|
||||
"domains?nsLdhName=XXXX",
|
||||
"domains?nsIp=XXXX",
|
||||
"nameservers?name=XXXX",
|
||||
"nameservers?ip=XXXX",
|
||||
"entities?fn=XXXX",
|
||||
"entities?handle=XXXX",
|
||||
"help/XXXX"))
|
||||
.setLinkValueSuffix("help/syntax")
|
||||
.build())
|
||||
.put("/tos", RdapNoticeDescriptor.builder()
|
||||
.setTitle("RDAP Terms of Service")
|
||||
.setDescription(ImmutableList.of(
|
||||
"By querying our Domain Database, you are agreeing to comply with these terms so"
|
||||
+ " please read them carefully.",
|
||||
"Any information provided is 'as is' without any guarantee of accuracy.",
|
||||
"Please do not misuse the Domain Database. It is intended solely for"
|
||||
+ " query-based access.",
|
||||
"Don't use the Domain Database to allow, enable, or otherwise support the"
|
||||
+ " transmission of mass unsolicited, commercial advertising or"
|
||||
+ " solicitations.",
|
||||
"Don't access our Domain Database through the use of high volume, automated"
|
||||
+ " electronic processes that send queries or data to the systems of any"
|
||||
+ " ICANN-accredited registrar.",
|
||||
"You may only use the information contained in the Domain Database for lawful"
|
||||
+ " purposes.",
|
||||
"Do not compile, repackage, disseminate, or otherwise use the information"
|
||||
+ " contained in the Domain Database in its entirety, or in any substantial"
|
||||
+ " portion, without our prior written permission.",
|
||||
"We may retain certain details about queries to our Domain Database for the"
|
||||
+ " purposes of detecting and preventing misuse.",
|
||||
"We reserve the right to restrict or deny your access to the database if we"
|
||||
+ " suspect that you have failed to comply with these terms.",
|
||||
"We reserve the right to modify this agreement at any time."))
|
||||
.setLinkValueSuffix("help/tos")
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
50
java/google/registry/config/RdapNoticeDescriptor.java
Normal file
50
java/google/registry/config/RdapNoticeDescriptor.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
// Copyright 2016 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.config;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* AutoValue class describing an RDAP Notice object.
|
||||
*
|
||||
* <p>This is used for injecting RDAP help pages.
|
||||
*/
|
||||
@AutoValue
|
||||
public abstract class RdapNoticeDescriptor {
|
||||
public static Builder builder() {
|
||||
return new AutoValue_RdapNoticeDescriptor.Builder();
|
||||
}
|
||||
|
||||
@Nullable public abstract String getTitle();
|
||||
public abstract ImmutableList<String> getDescription();
|
||||
@Nullable public abstract String getTypeString();
|
||||
@Nullable public abstract String getLinkValueSuffix();
|
||||
@Nullable public abstract String getLinkHrefUrlString();
|
||||
|
||||
/** Builder class for {@link RdapNoticeDescriptor}. */
|
||||
@AutoValue.Builder
|
||||
public abstract static class Builder {
|
||||
public abstract Builder setTitle(@Nullable String title);
|
||||
public abstract Builder setDescription(Iterable<String> description);
|
||||
public abstract Builder setTypeString(@Nullable String typeString);
|
||||
public abstract Builder setLinkValueSuffix(@Nullable String linkValueSuffix);
|
||||
public abstract Builder setLinkHrefUrlString(@Nullable String linkHrefUrlString);
|
||||
|
||||
public abstract RdapNoticeDescriptor build();
|
||||
}
|
||||
}
|
||||
|
|
@ -68,6 +68,7 @@ public abstract class RdapActionBase implements Runnable {
|
|||
@Inject Response response;
|
||||
@Inject @RequestMethod Action.Method requestMethod;
|
||||
@Inject @RequestPath String requestPath;
|
||||
@Inject RdapJsonFormatter rdapJsonFormatter;
|
||||
@Inject @Config("rdapLinkBase") String rdapLinkBase;
|
||||
@Inject @Config("rdapWhoisServer") @Nullable String rdapWhoisServer;
|
||||
|
||||
|
@ -130,7 +131,7 @@ public abstract class RdapActionBase implements Runnable {
|
|||
try {
|
||||
if (requestMethod != Action.Method.HEAD) {
|
||||
response.setPayload(
|
||||
JSONValue.toJSONString(RdapJsonFormatter.makeError(status, title, description)));
|
||||
JSONValue.toJSONString(rdapJsonFormatter.makeError(status, title, description)));
|
||||
}
|
||||
response.setContentType(RESPONSE_MEDIA_TYPE);
|
||||
} catch (Exception ex) {
|
||||
|
|
|
@ -59,7 +59,7 @@ public class RdapDomainAction extends RdapActionBase {
|
|||
if (domainResource == null) {
|
||||
throw new NotFoundException(pathSearchString + " not found");
|
||||
}
|
||||
return RdapJsonFormatter.makeRdapJsonForDomain(
|
||||
return rdapJsonFormatter.makeRdapJsonForDomain(
|
||||
domainResource, true, rdapLinkBase, rdapWhoisServer, now, OutputDataType.FULL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ public class RdapDomainSearchAction extends RdapActionBase {
|
|||
}
|
||||
ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
|
||||
builder.put("domainSearchResults", results.jsonList());
|
||||
RdapJsonFormatter.addTopLevelEntries(
|
||||
rdapJsonFormatter.addTopLevelEntries(
|
||||
builder,
|
||||
BoilerplateType.DOMAIN,
|
||||
results.isTruncated()
|
||||
|
@ -296,7 +296,7 @@ public class RdapDomainSearchAction extends RdapActionBase {
|
|||
ImmutableList.Builder<ImmutableMap<String, Object>> jsonBuilder = new ImmutableList.Builder<>();
|
||||
for (DomainResource domain : domains) {
|
||||
jsonBuilder.add(
|
||||
RdapJsonFormatter.makeRdapJsonForDomain(
|
||||
rdapJsonFormatter.makeRdapJsonForDomain(
|
||||
domain, false, rdapLinkBase, rdapWhoisServer, now, outputDataType));
|
||||
}
|
||||
return RdapSearchResults.create(jsonBuilder.build(), isTruncated);
|
||||
|
|
|
@ -79,7 +79,7 @@ public class RdapEntityAction extends RdapActionBase {
|
|||
// As per Andy Newton on the regext mailing list, contacts by themselves have no role, since
|
||||
// they are global, and might have different roles for different domains.
|
||||
if ((contactResource != null) && now.isBefore(contactResource.getDeletionTime())) {
|
||||
return RdapJsonFormatter.makeRdapJsonForContact(
|
||||
return rdapJsonFormatter.makeRdapJsonForContact(
|
||||
contactResource,
|
||||
true,
|
||||
Optional.<DesignatedContact.Type>absent(),
|
||||
|
@ -95,7 +95,7 @@ public class RdapEntityAction extends RdapActionBase {
|
|||
Registrar registrar = Iterables.getOnlyElement(
|
||||
Registrar.loadByIanaIdentifierRange(ianaIdentifier, ianaIdentifier + 1, 1), null);
|
||||
if ((registrar != null) && registrar.isActiveAndPubliclyVisible()) {
|
||||
return RdapJsonFormatter.makeRdapJsonForRegistrar(
|
||||
return rdapJsonFormatter.makeRdapJsonForRegistrar(
|
||||
registrar, true, rdapLinkBase, rdapWhoisServer, now, OutputDataType.FULL);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
|
|
|
@ -101,7 +101,7 @@ public class RdapEntitySearchAction extends RdapActionBase {
|
|||
}
|
||||
ImmutableMap.Builder<String, Object> jsonBuilder = new ImmutableMap.Builder<>();
|
||||
jsonBuilder.put("entitySearchResults", results.jsonList());
|
||||
RdapJsonFormatter.addTopLevelEntries(
|
||||
rdapJsonFormatter.addTopLevelEntries(
|
||||
jsonBuilder,
|
||||
BoilerplateType.ENTITY,
|
||||
results.isTruncated()
|
||||
|
@ -243,7 +243,7 @@ public class RdapEntitySearchAction extends RdapActionBase {
|
|||
}
|
||||
// As per Andy Newton on the regext mailing list, contacts by themselves have no role, since
|
||||
// they are global, and might have different roles for different domains.
|
||||
jsonOutputList.add(RdapJsonFormatter.makeRdapJsonForContact(
|
||||
jsonOutputList.add(rdapJsonFormatter.makeRdapJsonForContact(
|
||||
contact,
|
||||
false,
|
||||
Optional.<DesignatedContact.Type>absent(),
|
||||
|
@ -257,7 +257,7 @@ public class RdapEntitySearchAction extends RdapActionBase {
|
|||
if (jsonOutputList.size() >= rdapResultSetMaxSize) {
|
||||
return RdapSearchResults.create(ImmutableList.copyOf(jsonOutputList), true);
|
||||
}
|
||||
jsonOutputList.add(RdapJsonFormatter.makeRdapJsonForRegistrar(
|
||||
jsonOutputList.add(rdapJsonFormatter.makeRdapJsonForRegistrar(
|
||||
registrar, false, rdapLinkBase, rdapWhoisServer, now, outputDataType));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,7 @@ import static google.registry.request.Action.Method.HEAD;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.rdap.RdapJsonFormatter.BoilerplateType;
|
||||
import google.registry.rdap.RdapJsonFormatter.MakeRdapJsonNoticeParameters;
|
||||
import google.registry.request.Action;
|
||||
import google.registry.request.HttpException.InternalServerErrorException;
|
||||
import google.registry.request.HttpException.NotFoundException;
|
||||
import google.registry.util.Clock;
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -35,85 +32,6 @@ public class RdapHelpAction extends RdapActionBase {
|
|||
|
||||
public static final String PATH = "/rdap/help";
|
||||
|
||||
/**
|
||||
* Path for the terms of service. The terms of service are also used to create the required
|
||||
* boilerplate notice, so we make it a publicly visible that we can use elsewhere to reference it.
|
||||
*/
|
||||
public static final String TERMS_OF_SERVICE_PATH = "/tos";
|
||||
|
||||
/**
|
||||
* Map from a relative path underneath the RDAP root path to the appropriate
|
||||
* {@link MakeRdapJsonNoticeParameters} object.
|
||||
*/
|
||||
private static final ImmutableMap<String, MakeRdapJsonNoticeParameters> HELP_MAP =
|
||||
ImmutableMap.of(
|
||||
"/",
|
||||
MakeRdapJsonNoticeParameters.builder()
|
||||
.title("RDAP Help")
|
||||
.description(ImmutableList.of(
|
||||
"RDAP Help Topics (use /help/topic for information)",
|
||||
"syntax",
|
||||
"tos (Terms of Service)"))
|
||||
.linkValueSuffix("help/")
|
||||
.linkHrefUrlString("https://www.registry.google/about/rdap/index.html")
|
||||
.build(),
|
||||
"/index",
|
||||
MakeRdapJsonNoticeParameters.builder()
|
||||
.title("RDAP Help")
|
||||
.description(ImmutableList.of(
|
||||
"RDAP Help Topics (use /help/topic for information)",
|
||||
"syntax",
|
||||
"tos (Terms of Service)"))
|
||||
.linkValueSuffix("help/index")
|
||||
.linkHrefUrlString("https://www.registry.google/about/rdap/index.html")
|
||||
.build(),
|
||||
"/syntax",
|
||||
MakeRdapJsonNoticeParameters.builder()
|
||||
.title("RDAP Command Syntax")
|
||||
.description(ImmutableList.of(
|
||||
"domain/XXXX",
|
||||
"nameserver/XXXX",
|
||||
"entity/XXXX",
|
||||
"domains?name=XXXX",
|
||||
"domains?nsLdhName=XXXX",
|
||||
"domains?nsIp=XXXX",
|
||||
"nameservers?name=XXXX",
|
||||
"nameservers?ip=XXXX",
|
||||
"entities?fn=XXXX",
|
||||
"entities?handle=XXXX",
|
||||
"help/XXXX"))
|
||||
.linkValueSuffix("help/syntax")
|
||||
.linkHrefUrlString("https://www.registry.google/about/rdap/syntax.html")
|
||||
.build(),
|
||||
TERMS_OF_SERVICE_PATH,
|
||||
MakeRdapJsonNoticeParameters.builder()
|
||||
.title("RDAP Terms of Service")
|
||||
.description(ImmutableList.of(
|
||||
"By querying our Domain Database, you are agreeing to comply with these terms so"
|
||||
+ " please read them carefully.",
|
||||
"Any information provided is 'as is' without any guarantee of accuracy.",
|
||||
"Please do not misuse the Domain Database. It is intended solely for"
|
||||
+ " query-based access.",
|
||||
"Don't use the Domain Database to allow, enable, or otherwise support the"
|
||||
+ " transmission of mass unsolicited, commercial advertising or"
|
||||
+ " solicitations.",
|
||||
"Don't access our Domain Database through the use of high volume, automated"
|
||||
+ " electronic processes that send queries or data to the systems of"
|
||||
+ " Charleston Road Registry or any ICANN-accredited registrar.",
|
||||
"You may only use the information contained in the Domain Database for lawful"
|
||||
+ " purposes.",
|
||||
"Do not compile, repackage, disseminate, or otherwise use the information"
|
||||
+ " contained in the Domain Database in its entirety, or in any substantial"
|
||||
+ " portion, without our prior written permission.",
|
||||
"We may retain certain details about queries to our Domain Database for the"
|
||||
+ " purposes of detecting and preventing misuse.",
|
||||
"We reserve the right to restrict or deny your access to the database if we"
|
||||
+ " suspect that you have failed to comply with these terms.",
|
||||
"We reserve the right to modify this agreement at any time."))
|
||||
.linkValueSuffix("help/tos")
|
||||
.linkHrefUrlString("https://www.registry.google/about/rdap/tos.html")
|
||||
.build());
|
||||
|
||||
@Inject Clock clock;
|
||||
@Inject RdapHelpAction() {}
|
||||
|
||||
|
@ -133,28 +51,12 @@ public class RdapHelpAction extends RdapActionBase {
|
|||
// We rely on addTopLevelEntries to notice if we are sending the TOS notice, and not add a
|
||||
// duplicate boilerplate entry.
|
||||
ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
|
||||
RdapJsonFormatter.addTopLevelEntries(
|
||||
rdapJsonFormatter.addTopLevelEntries(
|
||||
builder,
|
||||
BoilerplateType.OTHER,
|
||||
ImmutableList.of(getJsonHelpNotice(pathSearchString, rdapLinkBase)),
|
||||
ImmutableList.of(rdapJsonFormatter.getJsonHelpNotice(pathSearchString, rdapLinkBase)),
|
||||
ImmutableList.<ImmutableMap<String, Object>>of(),
|
||||
rdapLinkBase);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
static ImmutableMap<String, Object> getJsonHelpNotice(
|
||||
String pathSearchString, String rdapLinkBase) {
|
||||
if (pathSearchString.isEmpty()) {
|
||||
pathSearchString = "/";
|
||||
}
|
||||
if (!HELP_MAP.containsKey(pathSearchString)) {
|
||||
throw new NotFoundException("no help found for " + pathSearchString);
|
||||
}
|
||||
try {
|
||||
return RdapJsonFormatter.makeRdapJsonNotice(
|
||||
HELP_MAP.get(pathSearchString), rdapLinkBase);
|
||||
} catch (Exception e) {
|
||||
throw new InternalServerErrorException("unable to read help for " + pathSearchString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import static com.google.common.base.Strings.nullToEmpty;
|
|||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.util.DomainNameUtils.ACE_PREFIX;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.base.Optional;
|
||||
|
@ -30,6 +29,8 @@ import com.google.common.collect.Maps;
|
|||
import com.google.common.collect.Ordering;
|
||||
import com.google.common.net.InetAddresses;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.config.ConfigModule.Config;
|
||||
import google.registry.config.RdapNoticeDescriptor;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.contact.ContactPhoneNumber;
|
||||
import google.registry.model.contact.ContactResource;
|
||||
|
@ -44,6 +45,9 @@ import google.registry.model.registrar.Registrar;
|
|||
import google.registry.model.registrar.RegistrarAddress;
|
||||
import google.registry.model.registrar.RegistrarContact;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.request.HttpException.InternalServerErrorException;
|
||||
import google.registry.request.HttpException.NotFoundException;
|
||||
import google.registry.util.FormattingLogger;
|
||||
import google.registry.util.Idn;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
|
@ -53,6 +57,8 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
|
@ -66,8 +72,15 @@ import org.joda.time.DateTime;
|
|||
* @see <a href="https://tools.ietf.org/html/rfc7483">
|
||||
* RFC 7483: JSON Responses for the Registration Data Access Protocol (RDAP)</a>
|
||||
*/
|
||||
@Singleton
|
||||
public class RdapJsonFormatter {
|
||||
|
||||
@Inject @Config("rdapTosPath") String rdapTosPath;
|
||||
@Inject @Config("rdapHelpMap") ImmutableMap<String, RdapNoticeDescriptor> rdapHelpMap;
|
||||
@Inject RdapJsonFormatter() {}
|
||||
|
||||
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
||||
|
||||
/**
|
||||
* What type of data to generate. Summary data includes only information about the object itself,
|
||||
* while full data includes associated items (e.g. for domains, full data includes the hosts,
|
||||
|
@ -277,6 +290,26 @@ public class RdapJsonFormatter {
|
|||
return designatedContact.getType();
|
||||
}});
|
||||
|
||||
ImmutableMap<String, Object> getJsonTosNotice(String rdapLinkBase) {
|
||||
return getJsonHelpNotice(rdapTosPath, rdapLinkBase);
|
||||
}
|
||||
|
||||
ImmutableMap<String, Object> getJsonHelpNotice(
|
||||
String pathSearchString, String rdapLinkBase) {
|
||||
if (pathSearchString.isEmpty()) {
|
||||
pathSearchString = "/";
|
||||
}
|
||||
if (!rdapHelpMap.containsKey(pathSearchString)) {
|
||||
throw new NotFoundException("no help found for " + pathSearchString);
|
||||
}
|
||||
try {
|
||||
return RdapJsonFormatter.makeRdapJsonNotice(rdapHelpMap.get(pathSearchString), rdapLinkBase);
|
||||
} catch (Exception e) {
|
||||
logger.warningfmt(e, "Error reading RDAP help file: %s", pathSearchString);
|
||||
throw new InternalServerErrorException("unable to read help for " + pathSearchString);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the required top-level boilerplate. RFC 7483 specifies that the top-level object should
|
||||
* include an entry indicating the conformance level. The ICANN RDAP Profile document (dated 3
|
||||
|
@ -292,7 +325,7 @@ public class RdapJsonFormatter {
|
|||
* @param remarks a list of remarks to be inserted before the boilerplate notices.
|
||||
* @param rdapLinkBase the base for link URLs
|
||||
*/
|
||||
static void addTopLevelEntries(
|
||||
void addTopLevelEntries(
|
||||
ImmutableMap.Builder<String, Object> jsonBuilder,
|
||||
BoilerplateType boilerplateType,
|
||||
List<ImmutableMap<String, Object>> notices,
|
||||
|
@ -301,8 +334,7 @@ public class RdapJsonFormatter {
|
|||
jsonBuilder.put("rdapConformance", CONFORMANCE_LIST);
|
||||
ImmutableList.Builder<ImmutableMap<String, Object>> noticesBuilder =
|
||||
new ImmutableList.Builder<>();
|
||||
ImmutableMap<String, Object> tosNotice =
|
||||
RdapHelpAction.getJsonHelpNotice(RdapHelpAction.TERMS_OF_SERVICE_PATH, rdapLinkBase);
|
||||
ImmutableMap<String, Object> tosNotice = getJsonTosNotice(rdapLinkBase);
|
||||
boolean tosNoticeFound = false;
|
||||
if (!notices.isEmpty()) {
|
||||
noticesBuilder.addAll(notices);
|
||||
|
@ -337,31 +369,6 @@ public class RdapJsonFormatter {
|
|||
}
|
||||
}
|
||||
|
||||
/** AutoValue class to build parameters to {@link #makeRdapJsonNotice}. */
|
||||
@AutoValue
|
||||
abstract static class MakeRdapJsonNoticeParameters {
|
||||
static Builder builder() {
|
||||
return new AutoValue_RdapJsonFormatter_MakeRdapJsonNoticeParameters.Builder();
|
||||
}
|
||||
|
||||
@Nullable abstract String title();
|
||||
abstract ImmutableList<String> description();
|
||||
@Nullable abstract String typeString();
|
||||
@Nullable abstract String linkValueSuffix();
|
||||
@Nullable abstract String linkHrefUrlString();
|
||||
|
||||
@AutoValue.Builder
|
||||
abstract static class Builder {
|
||||
abstract Builder title(@Nullable String title);
|
||||
abstract Builder description(Iterable<String> description);
|
||||
abstract Builder typeString(@Nullable String typeString);
|
||||
abstract Builder linkValueSuffix(@Nullable String linkValueSuffix);
|
||||
abstract Builder linkHrefUrlString(@Nullable String linkHrefUrlString);
|
||||
|
||||
abstract MakeRdapJsonNoticeParameters build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a JSON object containing a notice or remark object, as defined by RFC 7483 § 4.3.
|
||||
* The object should then be inserted into a notices or remarks array. The builder fields are:
|
||||
|
@ -391,22 +398,22 @@ public class RdapJsonFormatter {
|
|||
* RFC 7483: JSON Responses for the Registration Data Access Protocol (RDAP)</a>
|
||||
*/
|
||||
static ImmutableMap<String, Object> makeRdapJsonNotice(
|
||||
MakeRdapJsonNoticeParameters parameters, @Nullable String linkBase) {
|
||||
RdapNoticeDescriptor parameters, @Nullable String linkBase) {
|
||||
ImmutableMap.Builder<String, Object> jsonBuilder = new ImmutableMap.Builder<>();
|
||||
if (parameters.title() != null) {
|
||||
jsonBuilder.put("title", parameters.title());
|
||||
if (parameters.getTitle() != null) {
|
||||
jsonBuilder.put("title", parameters.getTitle());
|
||||
}
|
||||
ImmutableList.Builder<String> descriptionBuilder = new ImmutableList.Builder<>();
|
||||
for (String line : parameters.description()) {
|
||||
for (String line : parameters.getDescription()) {
|
||||
descriptionBuilder.add(nullToEmpty(line));
|
||||
}
|
||||
jsonBuilder.put("description", descriptionBuilder.build());
|
||||
if (parameters.typeString() != null) {
|
||||
jsonBuilder.put("typeString", parameters.typeString());
|
||||
if (parameters.getTypeString() != null) {
|
||||
jsonBuilder.put("typeString", parameters.getTypeString());
|
||||
}
|
||||
String linkValueString =
|
||||
nullToEmpty(linkBase) + nullToEmpty(parameters.linkValueSuffix());
|
||||
if (parameters.linkHrefUrlString() == null) {
|
||||
nullToEmpty(linkBase) + nullToEmpty(parameters.getLinkValueSuffix());
|
||||
if (parameters.getLinkHrefUrlString() == null) {
|
||||
jsonBuilder.put("links", ImmutableList.of(ImmutableMap.of(
|
||||
"value", linkValueString,
|
||||
"rel", "self",
|
||||
|
@ -414,7 +421,7 @@ public class RdapJsonFormatter {
|
|||
"type", "application/rdap+json")));
|
||||
} else {
|
||||
URI htmlBaseURI = URI.create(nullToEmpty(linkBase));
|
||||
URI htmlUri = htmlBaseURI.resolve(parameters.linkHrefUrlString());
|
||||
URI htmlUri = htmlBaseURI.resolve(parameters.getLinkHrefUrlString());
|
||||
jsonBuilder.put("links", ImmutableList.of(ImmutableMap.of(
|
||||
"value", linkValueString,
|
||||
"rel", "alternate",
|
||||
|
@ -435,7 +442,7 @@ public class RdapJsonFormatter {
|
|||
* @param now the as-date
|
||||
* @param outputDataType whether to generate full or summary data
|
||||
*/
|
||||
static ImmutableMap<String, Object> makeRdapJsonForDomain(
|
||||
ImmutableMap<String, Object> makeRdapJsonForDomain(
|
||||
DomainResource domainResource,
|
||||
boolean isTopLevel,
|
||||
@Nullable String linkBase,
|
||||
|
@ -529,7 +536,7 @@ public class RdapJsonFormatter {
|
|||
* @param now the as-date
|
||||
* @param outputDataType whether to generate full or summary data
|
||||
*/
|
||||
static ImmutableMap<String, Object> makeRdapJsonForHost(
|
||||
ImmutableMap<String, Object> makeRdapJsonForHost(
|
||||
HostResource hostResource,
|
||||
boolean isTopLevel,
|
||||
@Nullable String linkBase,
|
||||
|
@ -612,7 +619,7 @@ public class RdapJsonFormatter {
|
|||
* @param now the as-date
|
||||
* @param outputDataType whether to generate full or summary data
|
||||
*/
|
||||
static ImmutableMap<String, Object> makeRdapJsonForContact(
|
||||
ImmutableMap<String, Object> makeRdapJsonForContact(
|
||||
ContactResource contactResource,
|
||||
boolean isTopLevel,
|
||||
Optional<DesignatedContact.Type> contactType,
|
||||
|
@ -701,7 +708,7 @@ public class RdapJsonFormatter {
|
|||
* @param now the as-date
|
||||
* @param outputDataType whether to generate full or summary data
|
||||
*/
|
||||
static ImmutableMap<String, Object> makeRdapJsonForRegistrar(
|
||||
ImmutableMap<String, Object> makeRdapJsonForRegistrar(
|
||||
Registrar registrar,
|
||||
boolean isTopLevel,
|
||||
@Nullable String linkBase,
|
||||
|
@ -1044,8 +1051,7 @@ public class RdapJsonFormatter {
|
|||
* @see <a href="https://tools.ietf.org/html/rfc7483">
|
||||
* RFC 7483: JSON Responses for the Registration Data Access Protocol (RDAP)</a>
|
||||
*/
|
||||
static ImmutableMap<String, Object> makeError(
|
||||
int status, String title, String description) {
|
||||
ImmutableMap<String, Object> makeError(int status, String title, String description) {
|
||||
return ImmutableMap.<String, Object>of(
|
||||
"rdapConformance", CONFORMANCE_LIST,
|
||||
"lang", "en",
|
||||
|
|
|
@ -59,7 +59,7 @@ public class RdapNameserverAction extends RdapActionBase {
|
|||
if (hostResource == null) {
|
||||
throw new NotFoundException(pathSearchString + " not found");
|
||||
}
|
||||
return RdapJsonFormatter.makeRdapJsonForHost(
|
||||
return rdapJsonFormatter.makeRdapJsonForHost(
|
||||
hostResource, true, rdapLinkBase, rdapWhoisServer, now, OutputDataType.FULL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ public class RdapNameserverSearchAction extends RdapActionBase {
|
|||
}
|
||||
ImmutableMap.Builder<String, Object> jsonBuilder = new ImmutableMap.Builder<>();
|
||||
jsonBuilder.put("nameserverSearchResults", results.jsonList());
|
||||
RdapJsonFormatter.addTopLevelEntries(
|
||||
rdapJsonFormatter.addTopLevelEntries(
|
||||
jsonBuilder,
|
||||
BoilerplateType.NAMESERVER,
|
||||
results.isTruncated()
|
||||
|
@ -127,7 +127,7 @@ public class RdapNameserverSearchAction extends RdapActionBase {
|
|||
}
|
||||
return RdapSearchResults.create(
|
||||
ImmutableList.of(
|
||||
RdapJsonFormatter.makeRdapJsonForHost(
|
||||
rdapJsonFormatter.makeRdapJsonForHost(
|
||||
hostResource, false, rdapLinkBase, rdapWhoisServer, now, OutputDataType.FULL)));
|
||||
// Handle queries with a wildcard, but no suffix. There are no pending deletes for hosts, so we
|
||||
// can call queryUndeleted.
|
||||
|
@ -186,7 +186,7 @@ public class RdapNameserverSearchAction extends RdapActionBase {
|
|||
new ImmutableList.Builder<>();
|
||||
for (HostResource host : Iterables.limit(hosts, rdapResultSetMaxSize)) {
|
||||
jsonListBuilder.add(
|
||||
RdapJsonFormatter.makeRdapJsonForHost(
|
||||
rdapJsonFormatter.makeRdapJsonForHost(
|
||||
host, false, rdapLinkBase, rdapWhoisServer, now, outputDataType));
|
||||
}
|
||||
ImmutableList<ImmutableMap<String, Object>> jsonList = jsonListBuilder.build();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue