mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 08:27:14 +02:00
Simplify some of the RDAP Action classes
Overriding getter methods to change values is a bit overkill when these values are static (don't change based on internal state). Just setting them in the base class' constructor is simpler. Also, we can read the PATH of an Action based on the Annotation instead returning it manually for each Action. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=246135754
This commit is contained in:
parent
99aeedc598
commit
90c53152bf
21 changed files with 81 additions and 204 deletions
|
@ -18,6 +18,7 @@ import static com.google.common.base.Charsets.UTF_8;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.net.HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.request.Actions.getPathForAction;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
import static google.registry.util.DomainNameUtils.canonicalizeDomainName;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
||||
|
@ -106,14 +107,25 @@ public abstract class RdapActionBase implements Runnable {
|
|||
final RdapMetrics.RdapMetricInformation.Builder metricInformationBuilder =
|
||||
RdapMetrics.RdapMetricInformation.builder();
|
||||
|
||||
/** Returns a string like "domain name" or "nameserver", used for error strings. */
|
||||
abstract String getHumanReadableObjectTypeName();
|
||||
private final String humanReadableObjectTypeName;
|
||||
|
||||
/** Returns the endpoint type used for recording metrics. */
|
||||
abstract EndpointType getEndpointType();
|
||||
/** Returns a string like "domain name" or "nameserver", used for error strings. */
|
||||
final String getHumanReadableObjectTypeName() {
|
||||
return humanReadableObjectTypeName;
|
||||
}
|
||||
|
||||
/** The endpoint type used for recording metrics. */
|
||||
private final EndpointType endpointType;
|
||||
|
||||
/** Returns the servlet action path; used to extract the search string from the incoming path. */
|
||||
abstract String getActionPath();
|
||||
final String getActionPath() {
|
||||
return getPathForAction(getClass());
|
||||
}
|
||||
|
||||
RdapActionBase(String humanReadableObjectTypeName, EndpointType endpointType) {
|
||||
this.humanReadableObjectTypeName = humanReadableObjectTypeName;
|
||||
this.endpointType = endpointType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the actual search and returns an RDAP JSON object.
|
||||
|
@ -135,7 +147,7 @@ public abstract class RdapActionBase implements Runnable {
|
|||
metricInformationBuilder.setRegistrarSpecified(registrarParam.isPresent());
|
||||
metricInformationBuilder.setRole(getAuthorization().role());
|
||||
metricInformationBuilder.setRequestMethod(requestMethod);
|
||||
metricInformationBuilder.setEndpointType(getEndpointType());
|
||||
metricInformationBuilder.setEndpointType(endpointType);
|
||||
try {
|
||||
// Extract what we're searching for from the request path. Some RDAP commands use trailing
|
||||
// data in the path itself (e.g. /rdap/domain/mydomain.com), and some use the query string
|
||||
|
|
|
@ -32,29 +32,14 @@ import javax.inject.Inject;
|
|||
*/
|
||||
@Action(
|
||||
service = Action.Service.PUBAPI,
|
||||
path = RdapAutnumAction.PATH,
|
||||
path = "/rdap/autnum/",
|
||||
method = {GET, HEAD},
|
||||
isPrefix = true,
|
||||
auth = Auth.AUTH_PUBLIC_ANONYMOUS)
|
||||
public class RdapAutnumAction extends RdapActionBase {
|
||||
|
||||
public static final String PATH = "/rdap/autnum/";
|
||||
|
||||
@Inject RdapAutnumAction() {}
|
||||
|
||||
@Override
|
||||
public String getHumanReadableObjectTypeName() {
|
||||
return "autnum";
|
||||
}
|
||||
|
||||
@Override
|
||||
public EndpointType getEndpointType() {
|
||||
return EndpointType.AUTNUM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionPath() {
|
||||
return PATH;
|
||||
@Inject RdapAutnumAction() {
|
||||
super("authnum", EndpointType.AUTNUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -36,29 +36,14 @@ import org.joda.time.DateTime;
|
|||
/** RDAP (new WHOIS) action for domain requests. */
|
||||
@Action(
|
||||
service = Action.Service.PUBAPI,
|
||||
path = RdapDomainAction.PATH,
|
||||
path = "/rdap/domain/",
|
||||
method = {GET, HEAD},
|
||||
isPrefix = true,
|
||||
auth = Auth.AUTH_PUBLIC)
|
||||
public class RdapDomainAction extends RdapActionBase {
|
||||
|
||||
public static final String PATH = "/rdap/domain/";
|
||||
|
||||
@Inject public RdapDomainAction() {}
|
||||
|
||||
@Override
|
||||
public String getHumanReadableObjectTypeName() {
|
||||
return "domain name";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionPath() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EndpointType getEndpointType() {
|
||||
return EndpointType.DOMAIN;
|
||||
@Inject public RdapDomainAction() {
|
||||
super("domain name", EndpointType.DOMAIN);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -68,13 +68,11 @@ import org.joda.time.DateTime;
|
|||
*/
|
||||
@Action(
|
||||
service = Action.Service.PUBAPI,
|
||||
path = RdapDomainSearchAction.PATH,
|
||||
path = "/rdap/domains",
|
||||
method = {GET, HEAD},
|
||||
auth = Auth.AUTH_PUBLIC)
|
||||
public class RdapDomainSearchAction extends RdapSearchActionBase {
|
||||
|
||||
static final String PATH = "/rdap/domains";
|
||||
|
||||
static final int RESULT_SET_SIZE_SCALING_FACTOR = 30;
|
||||
|
||||
@NonFinalForTesting
|
||||
|
@ -85,21 +83,8 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
|
|||
@Inject @Parameter("name") Optional<String> nameParam;
|
||||
@Inject @Parameter("nsLdhName") Optional<String> nsLdhNameParam;
|
||||
@Inject @Parameter("nsIp") Optional<String> nsIpParam;
|
||||
@Inject public RdapDomainSearchAction() {}
|
||||
|
||||
@Override
|
||||
public String getHumanReadableObjectTypeName() {
|
||||
return "domain search";
|
||||
}
|
||||
|
||||
@Override
|
||||
public EndpointType getEndpointType() {
|
||||
return EndpointType.DOMAINS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionPath() {
|
||||
return PATH;
|
||||
@Inject public RdapDomainSearchAction() {
|
||||
super("domain search", EndpointType.DOMAINS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,31 +47,16 @@ import org.joda.time.DateTime;
|
|||
*/
|
||||
@Action(
|
||||
service = Action.Service.PUBAPI,
|
||||
path = RdapEntityAction.PATH,
|
||||
path = "/rdap/entity/",
|
||||
method = {GET, HEAD},
|
||||
isPrefix = true,
|
||||
auth = Auth.AUTH_PUBLIC)
|
||||
public class RdapEntityAction extends RdapActionBase {
|
||||
|
||||
public static final String PATH = "/rdap/entity/";
|
||||
|
||||
private static final Pattern ROID_PATTERN = Pattern.compile("[-_.a-zA-Z0-9]+");
|
||||
|
||||
@Inject public RdapEntityAction() {}
|
||||
|
||||
@Override
|
||||
public String getHumanReadableObjectTypeName() {
|
||||
return "entity";
|
||||
}
|
||||
|
||||
@Override
|
||||
public EndpointType getEndpointType() {
|
||||
return EndpointType.ENTITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionPath() {
|
||||
return PATH;
|
||||
@Inject public RdapEntityAction() {
|
||||
super("entity", EndpointType.ENTITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -76,17 +76,17 @@ import org.joda.time.DateTime;
|
|||
*/
|
||||
@Action(
|
||||
service = Action.Service.PUBAPI,
|
||||
path = RdapEntitySearchAction.PATH,
|
||||
path = "/rdap/entities",
|
||||
method = {GET, HEAD},
|
||||
auth = Auth.AUTH_PUBLIC)
|
||||
public class RdapEntitySearchAction extends RdapSearchActionBase {
|
||||
|
||||
public static final String PATH = "/rdap/entities";
|
||||
|
||||
@Inject @Parameter("fn") Optional<String> fnParam;
|
||||
@Inject @Parameter("handle") Optional<String> handleParam;
|
||||
@Inject @Parameter("subtype") Optional<String> subtypeParam;
|
||||
@Inject public RdapEntitySearchAction() {}
|
||||
@Inject public RdapEntitySearchAction() {
|
||||
super("entity search", EndpointType.ENTITIES);
|
||||
}
|
||||
|
||||
private enum QueryType {
|
||||
FULL_NAME,
|
||||
|
@ -108,21 +108,6 @@ public class RdapEntitySearchAction extends RdapSearchActionBase {
|
|||
private static final String CONTACT_CURSOR_PREFIX = "c:";
|
||||
private static final String REGISTRAR_CURSOR_PREFIX = "r:";
|
||||
|
||||
@Override
|
||||
public String getHumanReadableObjectTypeName() {
|
||||
return "entity search";
|
||||
}
|
||||
|
||||
@Override
|
||||
public EndpointType getEndpointType() {
|
||||
return EndpointType.ENTITIES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionPath() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
/** Parses the parameters and calls the appropriate search function. */
|
||||
@Override
|
||||
public ImmutableMap<String, Object> getJsonObjectForResource(
|
||||
|
|
|
@ -28,29 +28,14 @@ import javax.inject.Inject;
|
|||
/** RDAP (new WHOIS) action for help requests. */
|
||||
@Action(
|
||||
service = Action.Service.PUBAPI,
|
||||
path = RdapHelpAction.PATH,
|
||||
path = "/rdap/help",
|
||||
method = {GET, HEAD},
|
||||
isPrefix = true,
|
||||
auth = Auth.AUTH_PUBLIC_ANONYMOUS)
|
||||
public class RdapHelpAction extends RdapActionBase {
|
||||
|
||||
public static final String PATH = "/rdap/help";
|
||||
|
||||
@Inject public RdapHelpAction() {}
|
||||
|
||||
@Override
|
||||
public String getHumanReadableObjectTypeName() {
|
||||
return "help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public EndpointType getEndpointType() {
|
||||
return EndpointType.HELP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionPath() {
|
||||
return PATH;
|
||||
@Inject public RdapHelpAction() {
|
||||
super("help", EndpointType.HELP);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,29 +32,14 @@ import javax.inject.Inject;
|
|||
*/
|
||||
@Action(
|
||||
service = Action.Service.PUBAPI,
|
||||
path = RdapIpAction.PATH,
|
||||
path = "/rdap/ip/",
|
||||
method = {GET, HEAD},
|
||||
isPrefix = true,
|
||||
auth = Auth.AUTH_PUBLIC_ANONYMOUS)
|
||||
public class RdapIpAction extends RdapActionBase {
|
||||
|
||||
public static final String PATH = "/rdap/ip/";
|
||||
|
||||
@Inject RdapIpAction() {}
|
||||
|
||||
@Override
|
||||
public String getHumanReadableObjectTypeName() {
|
||||
return "ip";
|
||||
}
|
||||
|
||||
@Override
|
||||
public EndpointType getEndpointType() {
|
||||
return EndpointType.IP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionPath() {
|
||||
return PATH;
|
||||
@Inject RdapIpAction() {
|
||||
super("ip", EndpointType.IP);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -36,29 +36,14 @@ import org.joda.time.DateTime;
|
|||
/** RDAP (new WHOIS) action for nameserver requests. */
|
||||
@Action(
|
||||
service = Action.Service.PUBAPI,
|
||||
path = RdapNameserverAction.PATH,
|
||||
path = "/rdap/nameserver/",
|
||||
method = {GET, HEAD},
|
||||
isPrefix = true,
|
||||
auth = Auth.AUTH_PUBLIC_ANONYMOUS)
|
||||
public class RdapNameserverAction extends RdapActionBase {
|
||||
|
||||
public static final String PATH = "/rdap/nameserver/";
|
||||
|
||||
@Inject public RdapNameserverAction() {}
|
||||
|
||||
@Override
|
||||
public String getHumanReadableObjectTypeName() {
|
||||
return "nameserver";
|
||||
}
|
||||
|
||||
@Override
|
||||
public EndpointType getEndpointType() {
|
||||
return EndpointType.NAMESERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionPath() {
|
||||
return PATH;
|
||||
@Inject public RdapNameserverAction() {
|
||||
super("nameserver", EndpointType.NAMESERVER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -58,7 +58,7 @@ import org.joda.time.DateTime;
|
|||
*/
|
||||
@Action(
|
||||
service = Action.Service.PUBAPI,
|
||||
path = RdapNameserverSearchAction.PATH,
|
||||
path = "/rdap/nameservers",
|
||||
method = {GET, HEAD},
|
||||
auth = Auth.AUTH_PUBLIC_ANONYMOUS)
|
||||
public class RdapNameserverSearchAction extends RdapSearchActionBase {
|
||||
|
@ -67,21 +67,8 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase {
|
|||
|
||||
@Inject @Parameter("name") Optional<String> nameParam;
|
||||
@Inject @Parameter("ip") Optional<String> ipParam;
|
||||
@Inject public RdapNameserverSearchAction() {}
|
||||
|
||||
@Override
|
||||
public String getHumanReadableObjectTypeName() {
|
||||
return "nameserver search";
|
||||
}
|
||||
|
||||
@Override
|
||||
public EndpointType getEndpointType() {
|
||||
return EndpointType.NAMESERVERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionPath() {
|
||||
return PATH;
|
||||
@Inject public RdapNameserverSearchAction() {
|
||||
super("nameserver search", EndpointType.NAMESERVERS);
|
||||
}
|
||||
|
||||
private enum CursorType {
|
||||
|
|
|
@ -19,6 +19,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableListMultimap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.rdap.RdapMetrics.EndpointType;
|
||||
import google.registry.request.Parameter;
|
||||
import google.registry.request.ParameterMap;
|
||||
import google.registry.request.RequestUrl;
|
||||
|
@ -44,6 +45,10 @@ public abstract class RdapSearchActionBase extends RdapActionBase {
|
|||
|
||||
protected Optional<String> cursorString;
|
||||
|
||||
RdapSearchActionBase(String humanReadableObjectTypeName, EndpointType endpointType) {
|
||||
super(humanReadableObjectTypeName, endpointType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes the cursor token passed in the HTTP request.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue