diff --git a/java/google/registry/tools/CreateSandboxTldCommand.java b/java/google/registry/tools/CreateSandboxTldCommand.java new file mode 100644 index 000000000..e25e62f69 --- /dev/null +++ b/java/google/registry/tools/CreateSandboxTldCommand.java @@ -0,0 +1,32 @@ +// Copyright 2017 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 static com.google.common.base.Preconditions.checkArgument; + +import com.beust.jcommander.Parameters; +import google.registry.config.RegistryEnvironment; + +/** Command to create a TLD in sandbox, separated out for gTech use. */ +@Parameters(separators = " =", commandDescription = "Create new sandbox TLD(s)") +final class CreateSandboxTldCommand extends CreateTldCommand { + + @Override + void assertAllowedEnvironment() { + checkArgument( + RegistryEnvironment.get() == RegistryEnvironment.SANDBOX, + "This command can only be run in the sandbox environment"); + } +} diff --git a/java/google/registry/tools/GtechTool.java b/java/google/registry/tools/GtechTool.java new file mode 100644 index 000000000..82b9d2157 --- /dev/null +++ b/java/google/registry/tools/GtechTool.java @@ -0,0 +1,85 @@ +// Copyright 2017 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.annotations.VisibleForTesting; +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; + +/** Command line interface with a subset of commands that are safe for tech support to run. */ +public final class GtechTool { + + /** Names of commands from {@link RegistryTool#COMMAND_MAP} to include in GtechTool. */ + @VisibleForTesting + static final ImmutableSet COMMAND_SET = ImmutableSet.of( + "canonicalize_labels", + "check_domain", + "check_domain_claims", + "convert_idn", + "count_domains", + "create_anchor_tenant", + "create_contact", + "create_domain", + "create_host", + "create_registrar", + "create_registrar_groups", + "create_sandbox_tld", + "delete_domain", + "domain_application_info", + "generate_applications_report", + "generate_auction_data", + "generate_dns_report", + "get_application", + "get_application_ids", + "get_applied_labels", + "get_claims_list", + "get_contact", + "get_domain", + "get_history_entries", + "get_host", + "get_registrar", + "get_routing_map", + "get_schema", + "get_schema_tree", + "get_tld", + "hash_certificate", + "list_registrars", + "list_tlds", + "lock_domain", + "registrar_contact", + "setup_ote", + "uniform_rapid_suspension", + "unlock_domain", + "update_domain", + "update_registrar", + "update_sandbox_tld", + "update_server_locks", + "validate_login_credentials", + "verify_ote", + "whois_query"); + + @VisibleForTesting + static final ImmutableMap> COMMAND_MAP = + ImmutableMap.copyOf(Maps.filterKeys(RegistryTool.COMMAND_MAP, Predicates.in(COMMAND_SET))); + + public static void main(String[] args) throws Exception { + RegistryToolEnvironment.parseFromArgs(args).setup(); + try (RegistryCli cli = new RegistryCli("gtech_tool", COMMAND_MAP)) { + cli.run(args); + } + } +} diff --git a/java/google/registry/tools/RegistryTool.java b/java/google/registry/tools/RegistryTool.java index d5f33c4d4..a16b59433 100644 --- a/java/google/registry/tools/RegistryTool.java +++ b/java/google/registry/tools/RegistryTool.java @@ -45,6 +45,7 @@ public final class RegistryTool { .put("create_registrar", CreateRegistrarCommand.class) .put("create_registrar_groups", CreateRegistrarGroupsCommand.class) .put("create_reserved_list", CreateReservedListCommand.class) + .put("create_sandbox_tld", CreateSandboxTldCommand.class) .put("create_tld", CreateTldCommand.class) .put("curl", CurlCommand.class) .put("delete_domain", DeleteDomainCommand.class) @@ -113,6 +114,7 @@ public final class RegistryTool { .put("update_premium_list", UpdatePremiumListCommand.class) .put("update_registrar", UpdateRegistrarCommand.class) .put("update_reserved_list", UpdateReservedListCommand.class) + .put("update_sandbox_tld", UpdateSandboxTldCommand.class) .put("update_server_locks", UpdateServerLocksCommand.class) .put("update_smd", UpdateSmdCommand.class) .put("update_tld", UpdateTldCommand.class) diff --git a/java/google/registry/tools/UpdateSandboxTldCommand.java b/java/google/registry/tools/UpdateSandboxTldCommand.java new file mode 100644 index 000000000..59412ebcc --- /dev/null +++ b/java/google/registry/tools/UpdateSandboxTldCommand.java @@ -0,0 +1,32 @@ +// Copyright 2017 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 static com.google.common.base.Preconditions.checkArgument; + +import com.beust.jcommander.Parameters; +import google.registry.config.RegistryEnvironment; + +/** Command to update a TLD in sandbox, separated out for gTech use. */ +@Parameters(separators = " =", commandDescription = "Update new sandbox TLD(s)") +final class UpdateSandboxTldCommand extends UpdateTldCommand { + + @Override + void assertAllowedEnvironment() { + checkArgument( + RegistryEnvironment.get() == RegistryEnvironment.SANDBOX, + "This command can only be run in the sandbox environment"); + } +} diff --git a/javatests/google/registry/tools/GtechToolTest.java b/javatests/google/registry/tools/GtechToolTest.java new file mode 100644 index 000000000..90683073f --- /dev/null +++ b/javatests/google/registry/tools/GtechToolTest.java @@ -0,0 +1,45 @@ +// Copyright 2017 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 static com.google.common.truth.Truth.assertThat; + +import com.google.common.collect.Sets; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Unit tests for {@link GtechTool}. */ +@RunWith(JUnit4.class) +public class GtechToolTest { + + @Before + public void init() { + RegistryToolEnvironment.UNITTEST.setup(); + } + + @Test + public void test_commandMap_namesAreInAlphabeticalOrder() { + assertThat(GtechTool.COMMAND_MAP.keySet()).isStrictlyOrdered(); + } + + @Test + public void test_commandSet_namesAreSubsetOfRegistryToolCommands() { + assertThat(Sets.difference(GtechTool.COMMAND_SET, RegistryTool.COMMAND_MAP.keySet())) + .named("commands in GtechTool.COMMAND_SET but not in RegistryTool.COMMAND_MAP") + .isEmpty(); + } +}