diff --git a/java/google/registry/tools/AllocateDomainCommand.java b/java/google/registry/tools/AllocateDomainCommand.java index 5509a75c1..dc0356359 100644 --- a/java/google/registry/tools/AllocateDomainCommand.java +++ b/java/google/registry/tools/AllocateDomainCommand.java @@ -97,7 +97,7 @@ final class AllocateDomainCommand extends MutatingEppToolCommand { } @Override - void initMutatingEppToolCommand() { + protected void initMutatingEppToolCommand() { checkArgument(superuser, "This command MUST be run as --superuser."); setSoyTemplate(DomainAllocateSoyInfo.getInstance(), DomainAllocateSoyInfo.CREATE); ofy().transactNewReadOnly(new VoidWork() { diff --git a/java/google/registry/tools/CreateAnchorTenantCommand.java b/java/google/registry/tools/CreateAnchorTenantCommand.java index 14e25a5c5..9d6bc7178 100644 --- a/java/google/registry/tools/CreateAnchorTenantCommand.java +++ b/java/google/registry/tools/CreateAnchorTenantCommand.java @@ -77,7 +77,7 @@ final class CreateAnchorTenantCommand extends MutatingEppToolCommand implements PasswordGenerator passwordGenerator; @Override - void initMutatingEppToolCommand() { + protected void initMutatingEppToolCommand() { checkArgument(superuser, "This command must be run as a superuser."); String tld = findTldForNameOrThrow(InternetDomainName.from(domainName)).toString(); if (isNullOrEmpty(password)) { diff --git a/java/google/registry/tools/CreateContactCommand.java b/java/google/registry/tools/CreateContactCommand.java index 3e44ec20f..308583c0e 100644 --- a/java/google/registry/tools/CreateContactCommand.java +++ b/java/google/registry/tools/CreateContactCommand.java @@ -111,7 +111,7 @@ final class CreateContactCommand extends MutatingEppToolCommand implements Gtech private static final int PASSWORD_LENGTH = 16; @Override - void initMutatingEppToolCommand() { + protected void initMutatingEppToolCommand() { if (isNullOrEmpty(password)) { password = passwordGenerator.createPassword(PASSWORD_LENGTH); } diff --git a/java/google/registry/tools/DeleteDomainCommand.java b/java/google/registry/tools/DeleteDomainCommand.java index 4f9fe87e6..ba48c1c58 100644 --- a/java/google/registry/tools/DeleteDomainCommand.java +++ b/java/google/registry/tools/DeleteDomainCommand.java @@ -51,7 +51,7 @@ final class DeleteDomainCommand extends MutatingEppToolCommand implements GtechC private boolean requestedByRegistrar = false; @Override - void initMutatingEppToolCommand() { + protected void initMutatingEppToolCommand() { setSoyTemplate(DeleteDomainSoyInfo.getInstance(), DeleteDomainSoyInfo.DELETEDOMAIN); addSoyRecord(clientIdentifier, new SoyMapData( "domainName", domainName, diff --git a/java/google/registry/tools/ExecuteEppCommand.java b/java/google/registry/tools/ExecuteEppCommand.java index 492d68642..73b46ebe3 100644 --- a/java/google/registry/tools/ExecuteEppCommand.java +++ b/java/google/registry/tools/ExecuteEppCommand.java @@ -47,7 +47,7 @@ final class ExecuteEppCommand extends MutatingEppToolCommand { private static InputStream stdin = System.in; @Override - void initMutatingEppToolCommand() throws IOException { + protected void initMutatingEppToolCommand() throws IOException { if (mainParameters.isEmpty()) { addXmlCommand( clientIdentifier, CharStreams.toString(new InputStreamReader(stdin, UTF_8))); diff --git a/java/google/registry/tools/MutatingEppToolCommand.java b/java/google/registry/tools/MutatingEppToolCommand.java index 0d56709c5..4b0a338c5 100644 --- a/java/google/registry/tools/MutatingEppToolCommand.java +++ b/java/google/registry/tools/MutatingEppToolCommand.java @@ -17,10 +17,10 @@ package google.registry.tools; import com.beust.jcommander.Parameter; /** - * A command to execute an epp command that intends to mutate objects + * A command to execute an epp command that intends to mutate objects * (i.e. enables a dry run option). */ -abstract class MutatingEppToolCommand extends EppToolCommand { +public abstract class MutatingEppToolCommand extends EppToolCommand { @Parameter( names = {"-d", "--dry_run"}, @@ -37,5 +37,5 @@ abstract class MutatingEppToolCommand extends EppToolCommand { initMutatingEppToolCommand(); } - abstract void initMutatingEppToolCommand() throws Exception; + protected abstract void initMutatingEppToolCommand() throws Exception; } diff --git a/java/google/registry/tools/RegistryTool.java b/java/google/registry/tools/RegistryTool.java index 23080dc6c..f03647bd1 100644 --- a/java/google/registry/tools/RegistryTool.java +++ b/java/google/registry/tools/RegistryTool.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSortedMap; import google.registry.tools.javascrap.LoadAndResaveCommand; +import google.registry.tools.javascrap.RemoveIpAddressCommand; /** Container class to create and run remote commands against a datastore instance. */ public final class RegistryTool { @@ -61,6 +62,7 @@ public final class RegistryTool { .put("load_snapshot", LoadSnapshotCommand.class) .put("make_billing_tables", MakeBillingTablesCommand.class) .put("pending_escrow", PendingEscrowCommand.class) + .put("remove_ip_address", RemoveIpAddressCommand.class) .put("resave_environment_entities", ResaveEnvironmentEntitiesCommand.class) .put("send_escrow_report_to_icann", SendEscrowReportToIcannCommand.class) .put("update_application_status", UpdateApplicationStatusCommand.class) diff --git a/java/google/registry/tools/UpdateServerLocksCommand.java b/java/google/registry/tools/UpdateServerLocksCommand.java index e980a0582..219fc5ffa 100644 --- a/java/google/registry/tools/UpdateServerLocksCommand.java +++ b/java/google/registry/tools/UpdateServerLocksCommand.java @@ -94,7 +94,7 @@ final class UpdateServerLocksCommand extends MutatingEppToolCommand implements G } @Override - void initMutatingEppToolCommand() { + protected void initMutatingEppToolCommand() { checkArgument( requestedByRegistrar || !isNullOrEmpty(reason), "A reason must be provided when a change is not requested by a registrar."); diff --git a/java/google/registry/tools/javascrap/RemoveIpAddressCommand.java b/java/google/registry/tools/javascrap/RemoveIpAddressCommand.java new file mode 100644 index 000000000..144d811a1 --- /dev/null +++ b/java/google/registry/tools/javascrap/RemoveIpAddressCommand.java @@ -0,0 +1,85 @@ +// Copyright 2016 The Domain Registry 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.tools.javascrap; + +import static google.registry.model.ofy.ObjectifyService.ofy; +import static java.nio.charset.StandardCharsets.UTF_8; + +import com.google.template.soy.data.SoyMapData; + +import com.beust.jcommander.Parameter; +import com.beust.jcommander.Parameters; + +import google.registry.model.host.HostResource; +import google.registry.tools.MutatingEppToolCommand; +import google.registry.tools.params.PathParameter; +import google.registry.tools.soy.RemoveIpAddressSoyInfo; + +import java.net.Inet6Address; +import java.net.InetAddress; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +/** + * Command to remove external IP Addresses from HostResources identified by text file listing + * resource ids, one per line. + * + *
Written for b/23757755 so we can clean up records with IP addresses that should always be + * resolved by hostname. + * + *
The JSON file should contain a list of objects each of which has a "roid" attribute.
+ */
+@Parameters(separators = " =", commandDescription = "Remove all IP Addresses.")
+public class RemoveIpAddressCommand extends MutatingEppToolCommand {
+ public static String registrarId = "CharlestonRoad";
+
+ @Parameter(names = "--roids_file",
+ description = "Text file containing a list of HostResource roids to remove",
+ required = true,
+ validateWith = PathParameter.InputFile.class)
+ private Path roidsFilePath;
+
+ @Override
+ protected void initMutatingEppToolCommand() throws Exception {
+ List