diff --git a/java/google/registry/tools/AppEngineConnection.java b/java/google/registry/tools/AppEngineConnection.java index d15be6f21..cf4393a02 100644 --- a/java/google/registry/tools/AppEngineConnection.java +++ b/java/google/registry/tools/AppEngineConnection.java @@ -19,7 +19,6 @@ import static com.google.common.base.Suppliers.memoize; import static com.google.common.net.HttpHeaders.X_REQUESTED_WITH; import static com.google.common.net.MediaType.JSON_UTF_8; import static google.registry.security.JsonHttp.JSON_SAFETY_PREFIX; -import static google.registry.security.XsrfTokenManager.X_CSRF_TOKEN; import static java.nio.charset.StandardCharsets.UTF_8; import com.google.api.client.http.ByteArrayContent; @@ -37,7 +36,7 @@ import com.google.common.net.MediaType; import com.google.re2j.Matcher; import com.google.re2j.Pattern; import google.registry.security.XsrfTokenManager; -import google.registry.tools.ServerSideCommand.Connection; +import google.registry.tools.CommandWithConnection.Connection; import java.io.IOException; import java.io.InputStreamReader; import java.util.Map; @@ -95,7 +94,6 @@ class AppEngineConnection implements Connection { : requestFactory.buildGetRequest(url); HttpHeaders headers = request.getHeaders(); headers.setCacheControl("no-cache"); - headers.put(X_CSRF_TOKEN, ImmutableList.of(xsrfToken.get())); headers.put(X_REQUESTED_WITH, ImmutableList.of("RegistryTool")); request.setHeaders(headers); request.setFollowRedirects(false); diff --git a/java/google/registry/tools/CheckSnapshotCommand.java b/java/google/registry/tools/CheckSnapshotCommand.java index 9645d3c45..1234f9eea 100644 --- a/java/google/registry/tools/CheckSnapshotCommand.java +++ b/java/google/registry/tools/CheckSnapshotCommand.java @@ -20,7 +20,6 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Streams; import google.registry.export.DatastoreBackupInfo; import google.registry.export.DatastoreBackupService; -import google.registry.tools.Command.RemoteApiCommand; import javax.inject.Inject; /** diff --git a/java/google/registry/tools/Command.java b/java/google/registry/tools/Command.java index dcfe97f58..dbf549ecb 100644 --- a/java/google/registry/tools/Command.java +++ b/java/google/registry/tools/Command.java @@ -19,12 +19,4 @@ public interface Command { /** Performs the command. */ void run() throws Exception; - - /** - * Marker interface for commands that use the remote api. - * - *

Just implementing this is sufficient to use the remote api; {@link RegistryTool} will - * install it as needed. - */ - interface RemoteApiCommand extends Command {} } diff --git a/java/google/registry/tools/CommandWithConnection.java b/java/google/registry/tools/CommandWithConnection.java new file mode 100644 index 000000000..010afce8f --- /dev/null +++ b/java/google/registry/tools/CommandWithConnection.java @@ -0,0 +1,43 @@ +// Copyright 2018 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.tools; + +import com.google.common.net.MediaType; +import java.io.IOException; +import java.util.Map; +import javax.annotation.Nullable; + +/** A command that can send HTTP requests to a backend module. */ +interface CommandWithConnection extends Command { + + /** An http connection to AppEngine. */ + interface Connection { + + void prefetchXsrfToken(); + + /** Send a POST request. TODO(mmuller): change to sendPostRequest() */ + String send( + String endpoint, Map params, MediaType contentType, @Nullable byte[] payload) + throws IOException; + + String sendGetRequest(String endpoint, Map params) throws IOException; + + Map sendJson(String endpoint, Map object) throws IOException; + + String getServerUrl(); + } + + void setConnection(Connection connection); +} diff --git a/java/google/registry/tools/CountDomainsCommand.java b/java/google/registry/tools/CountDomainsCommand.java index b79b2e456..7c3532f0c 100644 --- a/java/google/registry/tools/CountDomainsCommand.java +++ b/java/google/registry/tools/CountDomainsCommand.java @@ -21,7 +21,6 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.google.common.collect.Iterators; import google.registry.model.domain.DomainResource; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.util.Clock; import java.util.List; import javax.inject.Inject; diff --git a/java/google/registry/tools/CreateDomainCommand.java b/java/google/registry/tools/CreateDomainCommand.java index 5b0ee91a6..17dcbf400 100644 --- a/java/google/registry/tools/CreateDomainCommand.java +++ b/java/google/registry/tools/CreateDomainCommand.java @@ -24,7 +24,6 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.google.template.soy.data.SoyMapData; import google.registry.model.pricing.PremiumPricingEngine.DomainPrices; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.soy.DomainCreateSoyInfo; import google.registry.util.StringGenerator; import javax.inject.Inject; diff --git a/java/google/registry/tools/CurlCommand.java b/java/google/registry/tools/CurlCommand.java index 090f13fcc..046a808c7 100644 --- a/java/google/registry/tools/CurlCommand.java +++ b/java/google/registry/tools/CurlCommand.java @@ -25,7 +25,7 @@ import com.google.common.net.MediaType; import java.util.List; @Parameters(separators = " =", commandDescription = "Send an HTTP command to the nomulus server.") -class CurlCommand implements ServerSideCommand { +class CurlCommand implements CommandWithConnection { private Connection connection; // HTTP Methods that are acceptable for use as values for --method. diff --git a/java/google/registry/tools/DeletePremiumListCommand.java b/java/google/registry/tools/DeletePremiumListCommand.java index c7e3e3191..99e38da15 100644 --- a/java/google/registry/tools/DeletePremiumListCommand.java +++ b/java/google/registry/tools/DeletePremiumListCommand.java @@ -23,7 +23,6 @@ import com.beust.jcommander.Parameters; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableSet; import google.registry.model.registry.label.PremiumList; -import google.registry.tools.Command.RemoteApiCommand; import javax.annotation.Nullable; /** diff --git a/java/google/registry/tools/DeleteTldCommand.java b/java/google/registry/tools/DeleteTldCommand.java index b6c3741b5..072ff60e1 100644 --- a/java/google/registry/tools/DeleteTldCommand.java +++ b/java/google/registry/tools/DeleteTldCommand.java @@ -23,7 +23,6 @@ import google.registry.model.domain.DomainResource; import google.registry.model.registrar.Registrar; import google.registry.model.registry.Registry; import google.registry.model.registry.Registry.TldType; -import google.registry.tools.Command.RemoteApiCommand; /** * Command to delete the {@link Registry} associated with the specified TLD in Datastore. diff --git a/java/google/registry/tools/EncryptEscrowDepositCommand.java b/java/google/registry/tools/EncryptEscrowDepositCommand.java index 9f07692ad..84c5bcf40 100644 --- a/java/google/registry/tools/EncryptEscrowDepositCommand.java +++ b/java/google/registry/tools/EncryptEscrowDepositCommand.java @@ -18,7 +18,6 @@ import static google.registry.util.DomainNameUtils.canonicalizeDomainName; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.PathParameter; import java.nio.file.Path; import java.nio.file.Paths; diff --git a/java/google/registry/tools/GenerateAllocationTokensCommand.java b/java/google/registry/tools/GenerateAllocationTokensCommand.java index 386c93a70..5e013e514 100644 --- a/java/google/registry/tools/GenerateAllocationTokensCommand.java +++ b/java/google/registry/tools/GenerateAllocationTokensCommand.java @@ -32,7 +32,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.io.Files; import com.googlecode.objectify.Key; import google.registry.model.domain.token.AllocationToken; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.util.NonFinalForTesting; import google.registry.util.Retrier; import google.registry.util.StringGenerator; diff --git a/java/google/registry/tools/GenerateApplicationsReportCommand.java b/java/google/registry/tools/GenerateApplicationsReportCommand.java index b4a882862..03b4a53b9 100644 --- a/java/google/registry/tools/GenerateApplicationsReportCommand.java +++ b/java/google/registry/tools/GenerateApplicationsReportCommand.java @@ -36,7 +36,6 @@ import google.registry.model.smd.SignedMark; import google.registry.model.smd.SignedMarkRevocationList; import google.registry.model.tmch.ClaimsListShard; import google.registry.tmch.TmchXmlSignature; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.PathParameter; import google.registry.util.Clock; import google.registry.util.Idn; diff --git a/java/google/registry/tools/GenerateAuctionDataCommand.java b/java/google/registry/tools/GenerateAuctionDataCommand.java index 917cfbb12..dddcc8cf1 100644 --- a/java/google/registry/tools/GenerateAuctionDataCommand.java +++ b/java/google/registry/tools/GenerateAuctionDataCommand.java @@ -47,7 +47,6 @@ import google.registry.model.eppcommon.PhoneNumber; import google.registry.model.registrar.Registrar; import google.registry.model.registrar.RegistrarAddress; import google.registry.model.registrar.RegistrarContact; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.PathParameter; import java.nio.file.Files; import java.nio.file.Path; diff --git a/java/google/registry/tools/GenerateDnsReportCommand.java b/java/google/registry/tools/GenerateDnsReportCommand.java index 70868e239..9bb96303d 100644 --- a/java/google/registry/tools/GenerateDnsReportCommand.java +++ b/java/google/registry/tools/GenerateDnsReportCommand.java @@ -27,7 +27,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import google.registry.model.domain.DomainResource; import google.registry.model.host.HostResource; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.PathParameter; import google.registry.util.Clock; import java.net.InetAddress; diff --git a/java/google/registry/tools/GenerateEscrowDepositCommand.java b/java/google/registry/tools/GenerateEscrowDepositCommand.java index 5d69c0a41..ceaa34ea6 100644 --- a/java/google/registry/tools/GenerateEscrowDepositCommand.java +++ b/java/google/registry/tools/GenerateEscrowDepositCommand.java @@ -30,7 +30,6 @@ import com.google.appengine.api.taskqueue.Queue; import com.google.appengine.api.taskqueue.TaskOptions; import google.registry.model.rde.RdeMode; import google.registry.rde.RdeStagingAction; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.DateTimeParameter; import google.registry.util.AppEngineServiceUtils; import java.util.List; diff --git a/java/google/registry/tools/GenerateLordnCommand.java b/java/google/registry/tools/GenerateLordnCommand.java index 406603d5c..360bba353 100644 --- a/java/google/registry/tools/GenerateLordnCommand.java +++ b/java/google/registry/tools/GenerateLordnCommand.java @@ -23,7 +23,6 @@ import com.beust.jcommander.Parameters; import com.google.common.collect.ImmutableList; import google.registry.model.domain.DomainResource; import google.registry.tmch.LordnTask; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.PathParameter; import java.io.IOException; import java.nio.file.Files; diff --git a/java/google/registry/tools/GetApplicationIdsCommand.java b/java/google/registry/tools/GetApplicationIdsCommand.java index 26f4b7c28..5f4fafc0f 100644 --- a/java/google/registry/tools/GetApplicationIdsCommand.java +++ b/java/google/registry/tools/GetApplicationIdsCommand.java @@ -24,7 +24,6 @@ import com.beust.jcommander.Parameters; import com.google.common.collect.ImmutableList; import com.google.common.net.InternetDomainName; import google.registry.model.domain.DomainApplication; -import google.registry.tools.Command.RemoteApiCommand; import java.util.List; import org.joda.time.DateTime; diff --git a/java/google/registry/tools/GetAppliedLabelsCommand.java b/java/google/registry/tools/GetAppliedLabelsCommand.java index 144dbf6dd..a42453abd 100644 --- a/java/google/registry/tools/GetAppliedLabelsCommand.java +++ b/java/google/registry/tools/GetAppliedLabelsCommand.java @@ -26,7 +26,6 @@ import com.beust.jcommander.internal.Sets; import com.google.common.base.Ascii; import google.registry.model.domain.DomainApplication; import google.registry.model.domain.launch.ApplicationStatus; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.PathParameter; import google.registry.util.Idn; import java.nio.file.Files; diff --git a/java/google/registry/tools/GetClaimsListCommand.java b/java/google/registry/tools/GetClaimsListCommand.java index 08946ef8a..61c5d649f 100644 --- a/java/google/registry/tools/GetClaimsListCommand.java +++ b/java/google/registry/tools/GetClaimsListCommand.java @@ -22,7 +22,6 @@ import com.beust.jcommander.Parameters; import com.google.common.base.Joiner; import com.google.common.io.Files; import google.registry.model.tmch.ClaimsListShard; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.PathParameter; import java.nio.file.Path; import java.nio.file.Paths; diff --git a/java/google/registry/tools/GetEppResourceCommand.java b/java/google/registry/tools/GetEppResourceCommand.java index 162fa3e38..6df3f6f08 100644 --- a/java/google/registry/tools/GetEppResourceCommand.java +++ b/java/google/registry/tools/GetEppResourceCommand.java @@ -21,7 +21,6 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.googlecode.objectify.Key; import google.registry.model.EppResource; -import google.registry.tools.Command.RemoteApiCommand; import javax.annotation.Nullable; import org.joda.time.DateTime; diff --git a/java/google/registry/tools/GetHistoryEntriesCommand.java b/java/google/registry/tools/GetHistoryEntriesCommand.java index c15d14877..d4277058c 100644 --- a/java/google/registry/tools/GetHistoryEntriesCommand.java +++ b/java/google/registry/tools/GetHistoryEntriesCommand.java @@ -26,7 +26,6 @@ import com.beust.jcommander.Parameters; import com.googlecode.objectify.Key; import google.registry.model.EppResource; import google.registry.model.reporting.HistoryEntry; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.CommandUtilities.ResourceType; import google.registry.xml.XmlTransformer; import org.joda.time.DateTime; diff --git a/java/google/registry/tools/GetKeyringSecretCommand.java b/java/google/registry/tools/GetKeyringSecretCommand.java index fcf100150..adb3d954e 100644 --- a/java/google/registry/tools/GetKeyringSecretCommand.java +++ b/java/google/registry/tools/GetKeyringSecretCommand.java @@ -18,7 +18,6 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import google.registry.keyring.api.KeySerializer; import google.registry.keyring.api.Keyring; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.KeyringKeyName; import google.registry.tools.params.PathParameter; import java.io.FileOutputStream; diff --git a/java/google/registry/tools/GetRegistrarCommand.java b/java/google/registry/tools/GetRegistrarCommand.java index f7687b5a0..56eba1053 100644 --- a/java/google/registry/tools/GetRegistrarCommand.java +++ b/java/google/registry/tools/GetRegistrarCommand.java @@ -19,7 +19,6 @@ import static google.registry.util.PreconditionsUtils.checkArgumentPresent; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import google.registry.model.registrar.Registrar; -import google.registry.tools.Command.RemoteApiCommand; import java.util.List; /** Command to show a registrar record. */ diff --git a/java/google/registry/tools/GetResourceByKeyCommand.java b/java/google/registry/tools/GetResourceByKeyCommand.java index 6eb3fc48b..d3903ff32 100644 --- a/java/google/registry/tools/GetResourceByKeyCommand.java +++ b/java/google/registry/tools/GetResourceByKeyCommand.java @@ -21,7 +21,6 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.googlecode.objectify.Key; import google.registry.model.EppResource; -import google.registry.tools.Command.RemoteApiCommand; import java.util.List; /** diff --git a/java/google/registry/tools/GetTldCommand.java b/java/google/registry/tools/GetTldCommand.java index e8c7ac64a..d9db16161 100644 --- a/java/google/registry/tools/GetTldCommand.java +++ b/java/google/registry/tools/GetTldCommand.java @@ -19,7 +19,6 @@ import static google.registry.model.registry.Registries.assertTldsExist; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import google.registry.model.registry.Registry; -import google.registry.tools.Command.RemoteApiCommand; import java.util.List; /** Command to show a TLD record. */ diff --git a/java/google/registry/tools/GhostrydeCommand.java b/java/google/registry/tools/GhostrydeCommand.java index 4f7f30302..9d9d2511e 100644 --- a/java/google/registry/tools/GhostrydeCommand.java +++ b/java/google/registry/tools/GhostrydeCommand.java @@ -22,7 +22,6 @@ import com.beust.jcommander.Parameters; import com.google.common.io.ByteStreams; import google.registry.keyring.api.KeyModule.Key; import google.registry.rde.Ghostryde; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.PathParameter; import java.io.IOException; import java.io.InputStream; diff --git a/java/google/registry/tools/ListCursorsCommand.java b/java/google/registry/tools/ListCursorsCommand.java index 822243167..57067a10c 100644 --- a/java/google/registry/tools/ListCursorsCommand.java +++ b/java/google/registry/tools/ListCursorsCommand.java @@ -26,7 +26,6 @@ import google.registry.model.common.Cursor.CursorType; import google.registry.model.registry.Registries; import google.registry.model.registry.Registry; import google.registry.model.registry.Registry.TldType; -import google.registry.tools.Command.RemoteApiCommand; import java.util.Map; import java.util.Optional; diff --git a/java/google/registry/tools/ListObjectsCommand.java b/java/google/registry/tools/ListObjectsCommand.java index bd96cb75d..c5d66b077 100644 --- a/java/google/registry/tools/ListObjectsCommand.java +++ b/java/google/registry/tools/ListObjectsCommand.java @@ -23,7 +23,6 @@ import com.beust.jcommander.Parameter; import com.google.common.base.VerifyException; import com.google.common.collect.ImmutableMap; import com.google.common.net.MediaType; -import google.registry.tools.Command.RemoteApiCommand; import java.util.List; import java.util.Map; import javax.annotation.Nullable; diff --git a/java/google/registry/tools/MutatingCommand.java b/java/google/registry/tools/MutatingCommand.java index 7650f9d63..b37cc4b17 100644 --- a/java/google/registry/tools/MutatingCommand.java +++ b/java/google/registry/tools/MutatingCommand.java @@ -31,7 +31,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; import google.registry.model.ImmutableObject; -import google.registry.tools.Command.RemoteApiCommand; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashMap; diff --git a/java/google/registry/tools/PendingEscrowCommand.java b/java/google/registry/tools/PendingEscrowCommand.java index b269460a4..39e3480f0 100644 --- a/java/google/registry/tools/PendingEscrowCommand.java +++ b/java/google/registry/tools/PendingEscrowCommand.java @@ -21,7 +21,6 @@ import com.google.common.collect.ComparisonChain; import com.google.common.collect.Ordering; import google.registry.rde.PendingDeposit; import google.registry.rde.PendingDepositChecker; -import google.registry.tools.Command.RemoteApiCommand; import javax.inject.Inject; /** Command to show what escrow deposits are pending generation on the server. */ diff --git a/java/google/registry/tools/RegistryCli.java b/java/google/registry/tools/RegistryCli.java index d74871a9d..82755b40c 100644 --- a/java/google/registry/tools/RegistryCli.java +++ b/java/google/registry/tools/RegistryCli.java @@ -29,7 +29,6 @@ import com.beust.jcommander.ParametersDelegate; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import google.registry.model.ofy.ObjectifyService; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.ParameterFactory; import java.security.Security; import java.util.Map; @@ -59,6 +58,8 @@ final class RegistryCli implements AutoCloseable, CommandRunner { @ParametersDelegate private LoggingParameters loggingParams = new LoggingParameters(); + RegistryToolComponent component; + // These are created lazily on first use. private AppEngineConnection connection; private RemoteApiInstaller installer; @@ -76,6 +77,10 @@ final class RegistryCli implements AutoCloseable, CommandRunner { this.commands = commands; Security.addProvider(new BouncyCastleProvider()); + + component = DaggerRegistryToolComponent.builder() + .flagsModule(new AppEngineConnectionFlags.FlagsModule(appEngineConnectionFlags)) + .build(); } // The > wildcard looks a little funny, but is needed so that @@ -165,48 +170,43 @@ final class RegistryCli implements AutoCloseable, CommandRunner { } } - private void runCommand(Command command) throws Exception { - // Create the main component and use it to inject the command class. - RegistryToolComponent component = DaggerRegistryToolComponent.builder() - .flagsModule(new AppEngineConnectionFlags.FlagsModule(appEngineConnectionFlags)) - .build(); - injectReflectively(RegistryToolComponent.class, component, command); - - if (!(command instanceof RemoteApiCommand)) { - // TODO(mmuller): this should be in the try/catch LoginRequiredException in case future - // commands use our credential. - command.run(); - return; - } - + private AppEngineConnection getConnection() { // Get the App Engine connection, advise the user if they are not currently logged in.. if (connection == null) { connection = component.appEngineConnection(); } + return connection; + } - if (command instanceof ServerSideCommand) { - ((ServerSideCommand) command).setConnection(connection); + private void runCommand(Command command) throws Exception { + injectReflectively(RegistryToolComponent.class, component, command); + + if (command instanceof CommandWithConnection) { + ((CommandWithConnection) command).setConnection(getConnection()); } // RemoteApiCommands need to have the remote api installed to work. - if (installer == null) { - installer = new RemoteApiInstaller(); - RemoteApiOptions options = new RemoteApiOptions(); - options.server(connection.getServer().getHost(), connection.getServer().getPort()); - if (connection.isLocalhost()) { - // Use dev credentials for localhost. - options.useDevelopmentServerCredential(); - } else { - options.useApplicationDefaultCredential(); + if (command instanceof RemoteApiCommand) { + if (installer == null) { + installer = new RemoteApiInstaller(); + RemoteApiOptions options = new RemoteApiOptions(); + options.server( + getConnection().getServer().getHost(), getConnection().getServer().getPort()); + if (getConnection().isLocalhost()) { + // Use dev credentials for localhost. + options.useDevelopmentServerCredential(); + } else { + options.useApplicationDefaultCredential(); + } + installer.install(options); } - installer.install(options); - } - // Ensure that all entity classes are loaded before command code runs. - ObjectifyService.initOfy(); - // Make sure we start the command with a clean cache, so that any previous command won't - // interfere with this one. - ofy().clearSessionCache(); + // Ensure that all entity classes are loaded before command code runs. + ObjectifyService.initOfy(); + // Make sure we start the command with a clean cache, so that any previous command won't + // interfere with this one. + ofy().clearSessionCache(); + } command.run(); } diff --git a/java/google/registry/tools/RemoteApiCommand.java b/java/google/registry/tools/RemoteApiCommand.java new file mode 100644 index 000000000..6e7982086 --- /dev/null +++ b/java/google/registry/tools/RemoteApiCommand.java @@ -0,0 +1,23 @@ +// Copyright 2018 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. + +/** + * Marker interface for commands that use the remote api. + * + *

Just implementing this is sufficient to use the remote api; {@link RegistryTool} will + * install it as needed. + */ +package google.registry.tools; + +interface RemoteApiCommand extends Command {} diff --git a/java/google/registry/tools/ResaveEnvironmentEntitiesCommand.java b/java/google/registry/tools/ResaveEnvironmentEntitiesCommand.java index d83568021..1ba31b19c 100644 --- a/java/google/registry/tools/ResaveEnvironmentEntitiesCommand.java +++ b/java/google/registry/tools/ResaveEnvironmentEntitiesCommand.java @@ -23,7 +23,6 @@ import com.googlecode.objectify.Key; import google.registry.model.registrar.Registrar; import google.registry.model.registrar.RegistrarContact; import google.registry.model.registry.Registry; -import google.registry.tools.Command.RemoteApiCommand; /** * Command to re-save all environment entities to ensure that they have valid commit logs. diff --git a/java/google/registry/tools/SendEscrowReportToIcannCommand.java b/java/google/registry/tools/SendEscrowReportToIcannCommand.java index 6a901d642..0aaeb01c2 100644 --- a/java/google/registry/tools/SendEscrowReportToIcannCommand.java +++ b/java/google/registry/tools/SendEscrowReportToIcannCommand.java @@ -17,7 +17,6 @@ package google.registry.tools; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import google.registry.rde.RdeReporter; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.PathParameter; import java.nio.file.Files; import java.nio.file.Path; diff --git a/java/google/registry/tools/ServerSideCommand.java b/java/google/registry/tools/ServerSideCommand.java index 1e514bf43..95142df25 100644 --- a/java/google/registry/tools/ServerSideCommand.java +++ b/java/google/registry/tools/ServerSideCommand.java @@ -14,31 +14,6 @@ package google.registry.tools; -import com.google.common.net.MediaType; -import google.registry.tools.Command.RemoteApiCommand; -import java.io.IOException; -import java.util.Map; -import javax.annotation.Nullable; - /** A command that executes on the server. */ -interface ServerSideCommand extends RemoteApiCommand { - - /** An http connection to AppEngine. */ - interface Connection { - - void prefetchXsrfToken(); - - /** Send a POST request. TODO(mmuller): change to sendPostRequest() */ - String send( - String endpoint, Map params, MediaType contentType, @Nullable byte[] payload) - throws IOException; - - String sendGetRequest(String endpoint, Map params) throws IOException; - - Map sendJson(String endpoint, Map object) throws IOException; - - String getServerUrl(); - } - - void setConnection(Connection connection); +interface ServerSideCommand extends CommandWithConnection, RemoteApiCommand { } diff --git a/java/google/registry/tools/SetupOteCommand.java b/java/google/registry/tools/SetupOteCommand.java index a7d6cfa5d..304928929 100644 --- a/java/google/registry/tools/SetupOteCommand.java +++ b/java/google/registry/tools/SetupOteCommand.java @@ -26,7 +26,6 @@ import com.google.re2j.Pattern; import google.registry.config.RegistryEnvironment; import google.registry.model.registrar.Registrar; import google.registry.model.registry.Registry.TldState; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.PathParameter; import google.registry.util.StringGenerator; import java.nio.file.Path; diff --git a/java/google/registry/tools/UpdateClaimsNoticeCommand.java b/java/google/registry/tools/UpdateClaimsNoticeCommand.java index 621dd51a7..8c0ae0c92 100644 --- a/java/google/registry/tools/UpdateClaimsNoticeCommand.java +++ b/java/google/registry/tools/UpdateClaimsNoticeCommand.java @@ -25,7 +25,6 @@ import google.registry.model.domain.DomainApplication; import google.registry.model.domain.launch.LaunchNotice; import google.registry.model.domain.launch.LaunchNotice.InvalidChecksumException; import google.registry.model.reporting.HistoryEntry; -import google.registry.tools.Command.RemoteApiCommand; import org.joda.time.DateTime; /** Command to update the claims notice on a domain application. */ diff --git a/java/google/registry/tools/UpdateKmsKeyringCommand.java b/java/google/registry/tools/UpdateKmsKeyringCommand.java index 4d57cf55a..c3bba76cc 100644 --- a/java/google/registry/tools/UpdateKmsKeyringCommand.java +++ b/java/google/registry/tools/UpdateKmsKeyringCommand.java @@ -21,7 +21,6 @@ import static google.registry.keyring.api.KeySerializer.deserializeString; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import google.registry.keyring.kms.KmsUpdater; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.KeyringKeyName; import google.registry.tools.params.PathParameter; import java.nio.file.Files; diff --git a/java/google/registry/tools/UpdateSmdCommand.java b/java/google/registry/tools/UpdateSmdCommand.java index 4b723f611..9c139670f 100644 --- a/java/google/registry/tools/UpdateSmdCommand.java +++ b/java/google/registry/tools/UpdateSmdCommand.java @@ -30,7 +30,6 @@ import google.registry.model.domain.DomainApplication; import google.registry.model.reporting.HistoryEntry; import google.registry.model.smd.EncodedSignedMark; import google.registry.model.smd.SignedMark; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.PathParameter; import java.nio.file.Files; import java.nio.file.Path; diff --git a/java/google/registry/tools/UploadClaimsListCommand.java b/java/google/registry/tools/UploadClaimsListCommand.java index 0f0ac66bb..248ae838d 100644 --- a/java/google/registry/tools/UploadClaimsListCommand.java +++ b/java/google/registry/tools/UploadClaimsListCommand.java @@ -23,7 +23,6 @@ import com.google.common.base.Joiner; import com.google.common.io.Files; import google.registry.model.tmch.ClaimsListShard; import google.registry.tmch.ClaimsListParser; -import google.registry.tools.Command.RemoteApiCommand; import java.io.File; import java.io.IOException; import java.util.ArrayList; diff --git a/java/google/registry/tools/ValidateLoginCredentialsCommand.java b/java/google/registry/tools/ValidateLoginCredentialsCommand.java index 9b6eacf17..20117e3fe 100644 --- a/java/google/registry/tools/ValidateLoginCredentialsCommand.java +++ b/java/google/registry/tools/ValidateLoginCredentialsCommand.java @@ -26,7 +26,6 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import google.registry.flows.TlsCredentials; import google.registry.model.registrar.Registrar; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.PathParameter; import java.nio.file.Files; import java.nio.file.Path; diff --git a/java/google/registry/tools/WhoisQueryCommand.java b/java/google/registry/tools/WhoisQueryCommand.java index 027d4bac4..b3744f5db 100644 --- a/java/google/registry/tools/WhoisQueryCommand.java +++ b/java/google/registry/tools/WhoisQueryCommand.java @@ -17,7 +17,6 @@ package google.registry.tools; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.google.common.base.Joiner; -import google.registry.tools.Command.RemoteApiCommand; import google.registry.whois.Whois; import java.util.List; import javax.inject.Inject; diff --git a/javatests/google/registry/tools/CreateOrUpdatePremiumListCommandTestCase.java b/javatests/google/registry/tools/CreateOrUpdatePremiumListCommandTestCase.java index 99650729f..a4b8ba84e 100644 --- a/javatests/google/registry/tools/CreateOrUpdatePremiumListCommandTestCase.java +++ b/javatests/google/registry/tools/CreateOrUpdatePremiumListCommandTestCase.java @@ -23,7 +23,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.io.Files; import com.google.common.net.MediaType; import google.registry.testing.UriParameters; -import google.registry.tools.ServerSideCommand.Connection; +import google.registry.tools.CommandWithConnection.Connection; import java.io.File; import java.nio.charset.StandardCharsets; import org.mockito.ArgumentCaptor; diff --git a/javatests/google/registry/tools/CreatePremiumListCommandTest.java b/javatests/google/registry/tools/CreatePremiumListCommandTest.java index 58ac07c4d..9c1ecada6 100644 --- a/javatests/google/registry/tools/CreatePremiumListCommandTest.java +++ b/javatests/google/registry/tools/CreatePremiumListCommandTest.java @@ -28,7 +28,7 @@ import com.beust.jcommander.ParameterException; import com.google.common.base.VerifyException; import com.google.common.collect.ImmutableMap; import com.google.common.net.MediaType; -import google.registry.tools.ServerSideCommand.Connection; +import google.registry.tools.CommandWithConnection.Connection; import google.registry.tools.server.CreatePremiumListAction; import org.junit.Before; import org.junit.Test; diff --git a/javatests/google/registry/tools/CreateRegistrarCommandTest.java b/javatests/google/registry/tools/CreateRegistrarCommandTest.java index a389b0f70..c1ef74c3f 100644 --- a/javatests/google/registry/tools/CreateRegistrarCommandTest.java +++ b/javatests/google/registry/tools/CreateRegistrarCommandTest.java @@ -34,7 +34,7 @@ import com.google.common.collect.Range; import com.google.common.net.MediaType; import google.registry.model.registrar.Registrar; import google.registry.testing.CertificateSamples; -import google.registry.tools.ServerSideCommand.Connection; +import google.registry.tools.CommandWithConnection.Connection; import java.io.IOException; import java.util.Optional; import org.joda.money.CurrencyUnit; diff --git a/javatests/google/registry/tools/CreateRegistrarGroupsCommandTest.java b/javatests/google/registry/tools/CreateRegistrarGroupsCommandTest.java index a49e6e043..ee5757d1e 100644 --- a/javatests/google/registry/tools/CreateRegistrarGroupsCommandTest.java +++ b/javatests/google/registry/tools/CreateRegistrarGroupsCommandTest.java @@ -21,7 +21,7 @@ import static org.mockito.Mockito.verify; import com.google.common.collect.ImmutableMap; import com.google.common.net.MediaType; -import google.registry.tools.ServerSideCommand.Connection; +import google.registry.tools.CommandWithConnection.Connection; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; diff --git a/javatests/google/registry/tools/CurlCommandTest.java b/javatests/google/registry/tools/CurlCommandTest.java index 0685c031f..35baa0057 100644 --- a/javatests/google/registry/tools/CurlCommandTest.java +++ b/javatests/google/registry/tools/CurlCommandTest.java @@ -22,7 +22,7 @@ import static org.mockito.Mockito.verify; import com.google.common.collect.ImmutableMap; import com.google.common.net.MediaType; -import google.registry.tools.ServerSideCommand.Connection; +import google.registry.tools.CommandWithConnection.Connection; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; diff --git a/javatests/google/registry/tools/EppToolVerifier.java b/javatests/google/registry/tools/EppToolVerifier.java index f2b95917a..7e912c148 100644 --- a/javatests/google/registry/tools/EppToolVerifier.java +++ b/javatests/google/registry/tools/EppToolVerifier.java @@ -28,7 +28,7 @@ import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.net.MediaType; -import google.registry.tools.ServerSideCommand.Connection; +import google.registry.tools.CommandWithConnection.Connection; import google.registry.tools.server.ToolsTestData; import java.net.URLDecoder; import java.util.Map; diff --git a/javatests/google/registry/tools/ListObjectsCommandTestCase.java b/javatests/google/registry/tools/ListObjectsCommandTestCase.java index 3f31fe9f4..02df59698 100644 --- a/javatests/google/registry/tools/ListObjectsCommandTestCase.java +++ b/javatests/google/registry/tools/ListObjectsCommandTestCase.java @@ -28,7 +28,7 @@ import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.net.MediaType; -import google.registry.tools.ServerSideCommand.Connection; +import google.registry.tools.CommandWithConnection.Connection; import java.util.Optional; import org.junit.Before; import org.junit.Test; diff --git a/javatests/google/registry/tools/LoadTestCommandTest.java b/javatests/google/registry/tools/LoadTestCommandTest.java index 211c357e0..a4a496563 100644 --- a/javatests/google/registry/tools/LoadTestCommandTest.java +++ b/javatests/google/registry/tools/LoadTestCommandTest.java @@ -24,7 +24,7 @@ import static org.mockito.Mockito.verifyZeroInteractions; import com.google.common.collect.ImmutableMap; import com.google.common.net.MediaType; import google.registry.model.registrar.Registrar; -import google.registry.tools.ServerSideCommand.Connection; +import google.registry.tools.CommandWithConnection.Connection; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/javatests/google/registry/tools/UpdatePremiumListCommandTest.java b/javatests/google/registry/tools/UpdatePremiumListCommandTest.java index bc85f0ab7..d8858547a 100644 --- a/javatests/google/registry/tools/UpdatePremiumListCommandTest.java +++ b/javatests/google/registry/tools/UpdatePremiumListCommandTest.java @@ -23,7 +23,7 @@ import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableMap; import com.google.common.net.MediaType; -import google.registry.tools.ServerSideCommand.Connection; +import google.registry.tools.CommandWithConnection.Connection; import google.registry.tools.server.UpdatePremiumListAction; import org.junit.Before; import org.junit.Test; diff --git a/javatests/google/registry/tools/VerifyOteCommandTest.java b/javatests/google/registry/tools/VerifyOteCommandTest.java index b2831bbdb..5c6c2ccc9 100644 --- a/javatests/google/registry/tools/VerifyOteCommandTest.java +++ b/javatests/google/registry/tools/VerifyOteCommandTest.java @@ -27,7 +27,7 @@ import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import google.registry.model.registrar.Registrar; -import google.registry.tools.ServerSideCommand.Connection; +import google.registry.tools.CommandWithConnection.Connection; import org.junit.Before; import org.junit.Test; import org.mockito.Mock;