mirror of
https://github.com/google/nomulus.git
synced 2025-05-17 09:57:17 +02:00
Automatically create mailing lists for registrars
This improves one of our gTech processes so they no longer have to remember to create Google Groups for a registrar after creating that registrar. The ConfirmingCommand.verify() method is renamed to be more general purpose, so that it can do anything that follows naturally after a successful execution, such as creating Google Groups groups. Minor refactoring is done around RegistryToolEnvironment handling for tests to make it more bullet-proof and general case. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=117494277
This commit is contained in:
parent
5174c1c63f
commit
2293be4079
6 changed files with 135 additions and 5 deletions
|
@ -19,16 +19,22 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Strings.emptyToNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
import static com.google.domain.registry.model.registrar.Registrar.State.ACTIVE;
|
||||
import static com.google.domain.registry.tools.RegistryToolEnvironment.PRODUCTION;
|
||||
import static com.google.domain.registry.tools.RegistryToolEnvironment.SANDBOX;
|
||||
import static com.google.domain.registry.tools.RegistryToolEnvironment.UNITTEST;
|
||||
import static com.google.domain.registry.util.RegistrarUtils.normalizeClientId;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.domain.registry.model.registrar.Registrar;
|
||||
import com.google.domain.registry.tools.Command.GtechCommand;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -37,12 +43,29 @@ import javax.annotation.Nullable;
|
|||
|
||||
/** Command to create a Registrar. */
|
||||
@Parameters(separators = " =", commandDescription = "Create new registrar account(s)")
|
||||
final class CreateRegistrarCommand extends CreateOrUpdateRegistrarCommand implements GtechCommand {
|
||||
final class CreateRegistrarCommand extends CreateOrUpdateRegistrarCommand
|
||||
implements GtechCommand, ServerSideCommand {
|
||||
|
||||
private static final ImmutableSet<RegistryToolEnvironment> ENVIRONMENTS_ALLOWING_GROUP_CREATION =
|
||||
ImmutableSet.of(PRODUCTION, SANDBOX, UNITTEST);
|
||||
|
||||
// Allows test cases to be cleaner.
|
||||
@VisibleForTesting
|
||||
static boolean requireAddress = true;
|
||||
|
||||
@Parameter(
|
||||
names = "--create_groups",
|
||||
description = "Whether the Google Groups for this registrar should be created",
|
||||
arity = 1)
|
||||
boolean createGoogleGroups = true;
|
||||
|
||||
private Connection connection;
|
||||
|
||||
@Override
|
||||
public void setConnection(Connection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initRegistrarCommand() throws Exception {
|
||||
checkArgument(mainParameters.size() == 1, "Must specify exactly one client identifier.");
|
||||
|
@ -85,4 +108,24 @@ final class CreateRegistrarCommand extends CreateOrUpdateRegistrarCommand implem
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String postExecute() throws Exception {
|
||||
if (!createGoogleGroups) {
|
||||
return "";
|
||||
}
|
||||
// Allow prod and sandbox because they actually have Groups, and UNITTEST for testing.
|
||||
if (!ENVIRONMENTS_ALLOWING_GROUP_CREATION.contains(RegistryToolEnvironment.get())) {
|
||||
return "\nSkipping registrar groups creation because only production and sandbox support it.";
|
||||
}
|
||||
try {
|
||||
// We know it is safe to use the only main parameter here because initRegistrarCommand has
|
||||
// already verified that there is only one, and getOldRegistrar has already verified that a
|
||||
// registrar with this clientIdentifier doesn't already exist.
|
||||
CreateRegistrarGroupsCommand.executeOnServer(connection, getOnlyElement(mainParameters));
|
||||
} catch (Exception e) {
|
||||
return "\nRegistrar created, but groups creation failed with error:\n" + e;
|
||||
}
|
||||
return "\nRegistrar groups created successfully.";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue