mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 00:47:11 +02:00
Add a throw-away tool to remove IP addresses of external hosts
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=121279715
This commit is contained in:
parent
b672643194
commit
05803bbc33
10 changed files with 129 additions and 9 deletions
|
@ -97,7 +97,7 @@ final class AllocateDomainCommand extends MutatingEppToolCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void initMutatingEppToolCommand() {
|
protected void initMutatingEppToolCommand() {
|
||||||
checkArgument(superuser, "This command MUST be run as --superuser.");
|
checkArgument(superuser, "This command MUST be run as --superuser.");
|
||||||
setSoyTemplate(DomainAllocateSoyInfo.getInstance(), DomainAllocateSoyInfo.CREATE);
|
setSoyTemplate(DomainAllocateSoyInfo.getInstance(), DomainAllocateSoyInfo.CREATE);
|
||||||
ofy().transactNewReadOnly(new VoidWork() {
|
ofy().transactNewReadOnly(new VoidWork() {
|
||||||
|
|
|
@ -77,7 +77,7 @@ final class CreateAnchorTenantCommand extends MutatingEppToolCommand implements
|
||||||
PasswordGenerator passwordGenerator;
|
PasswordGenerator passwordGenerator;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void initMutatingEppToolCommand() {
|
protected void initMutatingEppToolCommand() {
|
||||||
checkArgument(superuser, "This command must be run as a superuser.");
|
checkArgument(superuser, "This command must be run as a superuser.");
|
||||||
String tld = findTldForNameOrThrow(InternetDomainName.from(domainName)).toString();
|
String tld = findTldForNameOrThrow(InternetDomainName.from(domainName)).toString();
|
||||||
if (isNullOrEmpty(password)) {
|
if (isNullOrEmpty(password)) {
|
||||||
|
|
|
@ -111,7 +111,7 @@ final class CreateContactCommand extends MutatingEppToolCommand implements Gtech
|
||||||
private static final int PASSWORD_LENGTH = 16;
|
private static final int PASSWORD_LENGTH = 16;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void initMutatingEppToolCommand() {
|
protected void initMutatingEppToolCommand() {
|
||||||
if (isNullOrEmpty(password)) {
|
if (isNullOrEmpty(password)) {
|
||||||
password = passwordGenerator.createPassword(PASSWORD_LENGTH);
|
password = passwordGenerator.createPassword(PASSWORD_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ final class DeleteDomainCommand extends MutatingEppToolCommand implements GtechC
|
||||||
private boolean requestedByRegistrar = false;
|
private boolean requestedByRegistrar = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void initMutatingEppToolCommand() {
|
protected void initMutatingEppToolCommand() {
|
||||||
setSoyTemplate(DeleteDomainSoyInfo.getInstance(), DeleteDomainSoyInfo.DELETEDOMAIN);
|
setSoyTemplate(DeleteDomainSoyInfo.getInstance(), DeleteDomainSoyInfo.DELETEDOMAIN);
|
||||||
addSoyRecord(clientIdentifier, new SoyMapData(
|
addSoyRecord(clientIdentifier, new SoyMapData(
|
||||||
"domainName", domainName,
|
"domainName", domainName,
|
||||||
|
|
|
@ -47,7 +47,7 @@ final class ExecuteEppCommand extends MutatingEppToolCommand {
|
||||||
private static InputStream stdin = System.in;
|
private static InputStream stdin = System.in;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void initMutatingEppToolCommand() throws IOException {
|
protected void initMutatingEppToolCommand() throws IOException {
|
||||||
if (mainParameters.isEmpty()) {
|
if (mainParameters.isEmpty()) {
|
||||||
addXmlCommand(
|
addXmlCommand(
|
||||||
clientIdentifier, CharStreams.toString(new InputStreamReader(stdin, UTF_8)));
|
clientIdentifier, CharStreams.toString(new InputStreamReader(stdin, UTF_8)));
|
||||||
|
|
|
@ -20,7 +20,7 @@ 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).
|
* (i.e. enables a dry run option).
|
||||||
*/
|
*/
|
||||||
abstract class MutatingEppToolCommand extends EppToolCommand {
|
public abstract class MutatingEppToolCommand extends EppToolCommand {
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = {"-d", "--dry_run"},
|
names = {"-d", "--dry_run"},
|
||||||
|
@ -37,5 +37,5 @@ abstract class MutatingEppToolCommand extends EppToolCommand {
|
||||||
initMutatingEppToolCommand();
|
initMutatingEppToolCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract void initMutatingEppToolCommand() throws Exception;
|
protected abstract void initMutatingEppToolCommand() throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSortedMap;
|
import com.google.common.collect.ImmutableSortedMap;
|
||||||
|
|
||||||
import google.registry.tools.javascrap.LoadAndResaveCommand;
|
import google.registry.tools.javascrap.LoadAndResaveCommand;
|
||||||
|
import google.registry.tools.javascrap.RemoveIpAddressCommand;
|
||||||
|
|
||||||
/** Container class to create and run remote commands against a datastore instance. */
|
/** Container class to create and run remote commands against a datastore instance. */
|
||||||
public final class RegistryTool {
|
public final class RegistryTool {
|
||||||
|
@ -61,6 +62,7 @@ public final class RegistryTool {
|
||||||
.put("load_snapshot", LoadSnapshotCommand.class)
|
.put("load_snapshot", LoadSnapshotCommand.class)
|
||||||
.put("make_billing_tables", MakeBillingTablesCommand.class)
|
.put("make_billing_tables", MakeBillingTablesCommand.class)
|
||||||
.put("pending_escrow", PendingEscrowCommand.class)
|
.put("pending_escrow", PendingEscrowCommand.class)
|
||||||
|
.put("remove_ip_address", RemoveIpAddressCommand.class)
|
||||||
.put("resave_environment_entities", ResaveEnvironmentEntitiesCommand.class)
|
.put("resave_environment_entities", ResaveEnvironmentEntitiesCommand.class)
|
||||||
.put("send_escrow_report_to_icann", SendEscrowReportToIcannCommand.class)
|
.put("send_escrow_report_to_icann", SendEscrowReportToIcannCommand.class)
|
||||||
.put("update_application_status", UpdateApplicationStatusCommand.class)
|
.put("update_application_status", UpdateApplicationStatusCommand.class)
|
||||||
|
|
|
@ -94,7 +94,7 @@ final class UpdateServerLocksCommand extends MutatingEppToolCommand implements G
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void initMutatingEppToolCommand() {
|
protected void initMutatingEppToolCommand() {
|
||||||
checkArgument(
|
checkArgument(
|
||||||
requestedByRegistrar || !isNullOrEmpty(reason),
|
requestedByRegistrar || !isNullOrEmpty(reason),
|
||||||
"A reason must be provided when a change is not requested by a registrar.");
|
"A reason must be provided when a change is not requested by a registrar.");
|
||||||
|
|
|
@ -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.
|
||||||
|
*
|
||||||
|
* <p>Written for b/23757755 so we can clean up records with IP addresses that should always be
|
||||||
|
* resolved by hostname.
|
||||||
|
*
|
||||||
|
* <p>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<String> roids = Files.readAllLines(roidsFilePath, UTF_8);
|
||||||
|
|
||||||
|
for (String roid : roids) {
|
||||||
|
// Look up the HostResource from its roid.
|
||||||
|
HostResource host = ofy().load().type(HostResource.class).id(roid).now();
|
||||||
|
if (host == null) {
|
||||||
|
System.err.printf("Record for %s not found.\n", roid);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<SoyMapData> ipAddresses = new ArrayList<SoyMapData>();
|
||||||
|
for (InetAddress address : host.getInetAddresses()) {
|
||||||
|
SoyMapData dataMap = new SoyMapData(
|
||||||
|
"address", address.getHostAddress(),
|
||||||
|
"version", address instanceof Inet6Address ? "v6" : "v4");
|
||||||
|
ipAddresses.add(dataMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build and execute the EPP command.
|
||||||
|
setSoyTemplate(
|
||||||
|
RemoveIpAddressSoyInfo.getInstance(), RemoveIpAddressSoyInfo.REMOVE_IP_ADDRESS);
|
||||||
|
addSoyRecord(registrarId, new SoyMapData(
|
||||||
|
"name", host.getFullyQualifiedHostName(),
|
||||||
|
"ipAddresses", ipAddresses,
|
||||||
|
"requestedByRegistrar", registrarId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
java/google/registry/tools/soy/RemoveIpAddress.soy
Normal file
33
java/google/registry/tools/soy/RemoveIpAddress.soy
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
{namespace domain.registry.tools autoescape="strict"}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to remove IP addresses.
|
||||||
|
*/
|
||||||
|
{template .remove_ip_address}
|
||||||
|
{@param name: string}
|
||||||
|
{@param ipAddresses: list<map<string, string>>}
|
||||||
|
{@param requestedByRegistrar: string}
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||||
|
<command>
|
||||||
|
<update>
|
||||||
|
<host:update
|
||||||
|
xmlns:host="urn:ietf:params:xml:ns:host-1.0">
|
||||||
|
<host:name>{$name}</host:name>
|
||||||
|
{foreach $ip in $ipAddresses}
|
||||||
|
<host:rem>
|
||||||
|
<host:addr ip="{$ip['type']}">{$ip['address']}</host:addr>
|
||||||
|
</host:rem>
|
||||||
|
{/foreach}
|
||||||
|
</host:update>
|
||||||
|
</update>
|
||||||
|
<extension>
|
||||||
|
<metadata:metadata xmlns:metadata="urn:google:params:xml:ns:metadata-1.0">
|
||||||
|
<metadata:reason>External IP address removed by registry administrator.</metadata:reason>
|
||||||
|
<metadata:requestedByRegistrar>{$requestedByRegistrar}</metadata:requestedByRegistrar>
|
||||||
|
</metadata:metadata>
|
||||||
|
</extension>
|
||||||
|
<clTRID>ABC-12345</clTRID>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
{/template}
|
Loading…
Add table
Add a link
Reference in a new issue