Add a command-line tool suitable for tech support usage

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=213634869
This commit is contained in:
mcilwain 2018-09-19 08:50:54 -07:00 committed by Ben McIlwain
parent e258eee582
commit 399cde1291
5 changed files with 196 additions and 0 deletions

View file

@ -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");
}
}

View file

@ -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<String> 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<String, Class<? extends Command>> 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);
}
}
}

View file

@ -45,6 +45,7 @@ public final class RegistryTool {
.put("create_registrar", CreateRegistrarCommand.class) .put("create_registrar", CreateRegistrarCommand.class)
.put("create_registrar_groups", CreateRegistrarGroupsCommand.class) .put("create_registrar_groups", CreateRegistrarGroupsCommand.class)
.put("create_reserved_list", CreateReservedListCommand.class) .put("create_reserved_list", CreateReservedListCommand.class)
.put("create_sandbox_tld", CreateSandboxTldCommand.class)
.put("create_tld", CreateTldCommand.class) .put("create_tld", CreateTldCommand.class)
.put("curl", CurlCommand.class) .put("curl", CurlCommand.class)
.put("delete_domain", DeleteDomainCommand.class) .put("delete_domain", DeleteDomainCommand.class)
@ -113,6 +114,7 @@ public final class RegistryTool {
.put("update_premium_list", UpdatePremiumListCommand.class) .put("update_premium_list", UpdatePremiumListCommand.class)
.put("update_registrar", UpdateRegistrarCommand.class) .put("update_registrar", UpdateRegistrarCommand.class)
.put("update_reserved_list", UpdateReservedListCommand.class) .put("update_reserved_list", UpdateReservedListCommand.class)
.put("update_sandbox_tld", UpdateSandboxTldCommand.class)
.put("update_server_locks", UpdateServerLocksCommand.class) .put("update_server_locks", UpdateServerLocksCommand.class)
.put("update_smd", UpdateSmdCommand.class) .put("update_smd", UpdateSmdCommand.class)
.put("update_tld", UpdateTldCommand.class) .put("update_tld", UpdateTldCommand.class)

View file

@ -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");
}
}

View file

@ -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();
}
}