diff --git a/java/google/registry/tools/RegistryTool.java b/java/google/registry/tools/RegistryTool.java index f3f24211b..1188c7992 100644 --- a/java/google/registry/tools/RegistryTool.java +++ b/java/google/registry/tools/RegistryTool.java @@ -107,6 +107,7 @@ public final class RegistryTool { .put("uniform_rapid_suspension", UniformRapidSuspensionCommand.class) .put("unlock_domain", UnlockDomainCommand.class) .put("unrenew_domain", UnrenewDomainCommand.class) + .put("update_allocation_tokens", UpdateAllocationTokensCommand.class) .put("update_cursors", UpdateCursorsCommand.class) .put("update_domain", UpdateDomainCommand.class) .put("update_kms_keyring", UpdateKmsKeyringCommand.class) diff --git a/java/google/registry/tools/UpdateAllocationTokensCommand.java b/java/google/registry/tools/UpdateAllocationTokensCommand.java new file mode 100644 index 000000000..8bbafe799 --- /dev/null +++ b/java/google/registry/tools/UpdateAllocationTokensCommand.java @@ -0,0 +1,174 @@ +// Copyright 2019 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 static com.google.common.collect.ImmutableList.toImmutableList; +import static com.google.common.collect.ImmutableMap.toImmutableMap; +import static com.google.common.collect.ImmutableSet.toImmutableSet; +import static com.google.common.collect.Iterables.partition; +import static com.google.common.collect.Streams.stream; +import static google.registry.model.ofy.ObjectifyService.ofy; + +import com.beust.jcommander.Parameter; +import com.beust.jcommander.Parameters; +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSortedMap; +import com.googlecode.objectify.Key; +import google.registry.model.domain.token.AllocationToken; +import google.registry.model.domain.token.AllocationToken.TokenStatus; +import google.registry.tools.params.TransitionListParameter.TokenStatusTransitions; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import org.joda.time.DateTime; + +/** Command to update existing {@link AllocationToken}s. */ +@Parameters( + separators = " =", + commandDescription = + "Updates AllocationTokens with the given prefix, modifying some subset of their allowed" + + " client IDs, allowed TLDs, discount fraction, or status transitions") +public final class UpdateAllocationTokensCommand extends ConfirmingCommand + implements CommandWithRemoteApi { + + @Parameter( + names = {"-p", "--prefix"}, + description = + "Update all allocation tokens with this prefix; otherwise use '--tokens' to specify" + + " exact tokens(s) to update") + private String prefix; + + @Parameter( + names = {"--tokens"}, + description = + "Comma-separated list of tokens to update; otherwise use '--prefix' to update all tokens" + + " with a given prefix") + private List tokens; + + @Parameter( + names = {"--dry_run"}, + description = "Do not actually update the tokens; defaults to false") + private boolean dryRun; + + @Parameter( + names = {"--allowed_client_ids"}, + description = + "Comma-separated list of allowed client IDs. Use the empty string to clear the" + + " existing list.") + private List allowedClientIds; + + @Parameter( + names = {"--allowed_tlds"}, + description = + "Comma-separated list of allowed TLDs. Use the empty string to clear the" + + " existing list.") + private List allowedTlds; + + @Parameter( + names = {"--discount_fraction"}, + description = + "A discount off the base price for the first year between 0.0 and 1.0. Default is 0.0," + + " i.e. no discount.") + private Double discountFraction; + + @Parameter( + names = "--token_status_transitions", + converter = TokenStatusTransitions.class, + validateWith = TokenStatusTransitions.class, + description = + "Comma-delimited list of token status transitions effective on specific dates, of the" + + " form