Delete all Limited Release Program (LRP) code

We never used it and don't have any plans to use it going forward. All
conceivable parts of its functionality that we might use going forward have
already been subsumed into allocation tokens, which are a simpler way of
handling the same use case that are also standards-compliant.

Also gets rid of the hideous ANCHOR_ prefix on anchor tenant EPP authcodes
that was only ever necessary because of overloading the authcode for
anchor tenant creation. Going forward it'll be based on allocation tokens,
so there's no risk of conflicts.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=209418194
This commit is contained in:
mcilwain 2018-08-20 08:03:41 -07:00 committed by jianglai
parent f7bc17fbe8
commit 7b87ba41c7
34 changed files with 12 additions and 1601 deletions

View file

@ -18,8 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;
import static google.registry.model.registry.Registries.findTldForNameOrThrow;
import static google.registry.pricing.PricingEngineProxy.getDomainCreateCost;
import static google.registry.util.TokenUtils.TokenType.ANCHOR_TENANT;
import static google.registry.util.TokenUtils.createToken;
import static google.registry.util.StringGenerator.DEFAULT_PASSWORD_LENGTH;
import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.Parameter;
@ -80,7 +79,7 @@ final class CreateAnchorTenantCommand extends MutatingEppToolCommand {
checkArgument(superuser, "This command must be run as a superuser.");
findTldForNameOrThrow(InternetDomainName.from(domainName)); // Check that the tld exists.
if (isNullOrEmpty(password)) {
password = createToken(ANCHOR_TENANT, passwordGenerator);
password = passwordGenerator.createString(DEFAULT_PASSWORD_LENGTH);
}
Money cost = null;

View file

@ -1,202 +0,0 @@
// 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 static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Sets.difference;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.Registries.assertTldsExist;
import static google.registry.util.TokenUtils.TokenType.LRP;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.appengine.tools.remoteapi.RemoteApiException;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.Files;
import com.google.common.io.LineReader;
import com.googlecode.objectify.Key;
import google.registry.model.domain.LrpTokenEntity;
import google.registry.tools.Command.RemoteApiCommand;
import google.registry.tools.params.KeyValueMapParameter.StringToIntegerMap;
import google.registry.tools.params.KeyValueMapParameter.StringToStringMap;
import google.registry.tools.params.PathParameter;
import google.registry.util.NonFinalForTesting;
import google.registry.util.Retrier;
import google.registry.util.StringGenerator;
import google.registry.util.TokenUtils;
import java.io.StringReader;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import javax.inject.Inject;
/**
* Command to create one or more LRP tokens, given assignee(s) as either a parameter or a text file.
*/
@NonFinalForTesting
@Parameters(
separators = " =",
commandDescription = "Create an LRP token for a given assignee (using -a) or import a text"
+ " file of assignees for bulk token creation (using -i). Assignee/token pairs are printed"
+ " to stdout, and should be piped to a file for distribution to assignees or for cleanup"
+ " in the event of a command interruption.")
public class CreateLrpTokensCommand implements RemoteApiCommand {
@Parameter(
names = {"-a", "--assignee"},
description = "LRP token assignee")
private String assignee;
@Parameter(
names = {"-t", "--tlds"},
description = "Comma-delimited list of TLDs that the tokens to create will be valid on",
required = true)
private List<String> tlds;
@Parameter(
names = {"-i", "--input"},
description = "Filename containing a list of assignees, newline-delimited",
validateWith = PathParameter.InputFile.class)
private Path assigneesFile;
@Parameter(
names = {"-m", "--metadata"},
description = "Token metadata key-value pairs (formatted as key=value[,key=value...]). Used"
+ " only in conjunction with -a/--assignee when creating a single token.",
converter = StringToStringMap.class,
validateWith = StringToStringMap.class)
private ImmutableMap<String, String> metadata;
@Parameter(
names = {"-c", "--metadata_columns"},
description = "Token metadata columns (formatted as key=index[,key=index...], columns are"
+ " zero-indexed). Used only in conjunction with -i/--input to map additional fields in"
+ " the CSV file to metadata stored on the LRP token. The index corresponds to the column"
+ " number in the CSV file (where the assignee is assigned column 0).",
converter = StringToIntegerMap.class,
validateWith = StringToIntegerMap.class)
private ImmutableMap<String, Integer> metadataColumns;
@Inject StringGenerator stringGenerator;
@Inject Retrier retrier;
private static final int BATCH_SIZE = 20;
// Ensures that all of the double quotes to the right of a comma are balanced. In a well-formed
// CSV line, there can be no leading double quote preceding the comma.
private static final String COMMA_EXCEPT_WHEN_QUOTED_REGEX =
",(?=([^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)";
@Override
public void run() throws Exception {
checkArgument(
(assignee == null) == (assigneesFile != null),
"Exactly one of either assignee or filename must be specified.");
checkArgument(
(assigneesFile == null) || (metadata == null),
"Metadata cannot be specified along with a filename.");
checkArgument(
(assignee == null) || (metadataColumns == null),
"Metadata columns cannot be specified along with an assignee.");
ImmutableSet<String> validTlds = ImmutableSet.copyOf(assertTldsExist(tlds));
LineReader reader = new LineReader(
(assigneesFile != null)
? Files.newReader(assigneesFile.toFile(), UTF_8)
: new StringReader(assignee));
String line = null;
do {
ImmutableSet.Builder<LrpTokenEntity> tokensToSaveBuilder = new ImmutableSet.Builder<>();
for (String token : generateTokens(BATCH_SIZE)) {
line = reader.readLine();
if (!isNullOrEmpty(line)) {
ImmutableList<String> values =
ImmutableList.copyOf(
Splitter.onPattern(COMMA_EXCEPT_WHEN_QUOTED_REGEX)
// Results should not be surrounded in double quotes.
.trimResults(CharMatcher.is('\"'))
.split(line));
LrpTokenEntity.Builder tokenBuilder = new LrpTokenEntity.Builder()
.setAssignee(values.get(0))
.setToken(token)
.setValidTlds(validTlds);
if (metadata != null) {
tokenBuilder.setMetadata(metadata);
} else if (metadataColumns != null) {
ImmutableMap.Builder<String, String> metadataBuilder = ImmutableMap.builder();
for (ImmutableMap.Entry<String, Integer> entry : metadataColumns.entrySet()) {
checkArgument(
values.size() > entry.getValue(),
"Entry for %s does not have a value for %s (index %s)",
values.get(0),
entry.getKey(),
entry.getValue());
metadataBuilder.put(entry.getKey(), values.get(entry.getValue()));
}
tokenBuilder.setMetadata(metadataBuilder.build());
}
tokensToSaveBuilder.add(tokenBuilder.build());
}
}
final ImmutableSet<LrpTokenEntity> tokensToSave = tokensToSaveBuilder.build();
// Wrap in a retrier to deal with transient 404 errors (thrown as RemoteApiExceptions).
retrier.callWithRetry(() -> saveTokens(tokensToSave), RemoteApiException.class);
} while (line != null);
}
@VisibleForTesting
void saveTokens(final ImmutableSet<LrpTokenEntity> tokens) {
Collection<LrpTokenEntity> savedTokens =
ofy().transact(() -> ofy().save().entities(tokens).now().values());
for (LrpTokenEntity token : savedTokens) {
System.out.printf("%s,%s%n", token.getAssignee(), token.getToken());
}
}
/**
* This function generates at MOST {@code count} tokens, after filtering out any token strings
* that already exist.
*
* <p>Note that in the incredibly rare case that all generated tokens already exist, this function
* may return an empty set.
*/
private ImmutableSet<String> generateTokens(int count) {
final ImmutableSet<String> candidates =
ImmutableSet.copyOf(TokenUtils.createTokens(LRP, stringGenerator, count));
ImmutableSet<Key<LrpTokenEntity>> existingTokenKeys =
candidates
.stream()
.map(input -> Key.create(LrpTokenEntity.class, input))
.collect(toImmutableSet());
ImmutableSet<String> existingTokenStrings =
ofy()
.load()
.keys(existingTokenKeys)
.values()
.stream()
.map(LrpTokenEntity::getToken)
.collect(toImmutableSet());
return ImmutableSet.copyOf(difference(candidates, existingTokenStrings));
}
}

View file

@ -32,7 +32,6 @@ import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState;
import google.registry.model.registry.Registry.TldType;
import google.registry.model.registry.label.PremiumList;
import google.registry.tools.params.OptionalIntervalParameter;
import google.registry.tools.params.OptionalStringParameter;
import google.registry.tools.params.TransitionListParameter.BillingCostTransitions;
import google.registry.tools.params.TransitionListParameter.TldStateTransitions;
@ -46,7 +45,6 @@ import javax.inject.Named;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.joda.time.Interval;
/** Shared base class for commands to create or update a TLD. */
abstract class CreateOrUpdateTldCommand extends MutatingCommand {
@ -242,15 +240,6 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand {
)
Integer numDnsPublishShards;
@Nullable
@Parameter(
names = "--lrp_period",
description =
"LRP period (in ISO-8601 format, e.g. 2004-06-09T12:30:00Z/2004-07-10T13:30:00Z",
converter = OptionalIntervalParameter.class,
validateWith = OptionalIntervalParameter.class)
private Optional<Interval> lrpPeriod;
/** Returns the existing registry (for update) or null (for creates). */
@Nullable
abstract Registry getOldRegistry(String tld);
@ -358,7 +347,6 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand {
Optional.ofNullable(claimsPeriodEnd).ifPresent(builder::setClaimsPeriodEnd);
Optional.ofNullable(domainCreateRestricted).ifPresent(builder::setDomainCreateRestricted);
Optional.ofNullable(numDnsPublishShards).ifPresent(builder::setNumDnsPublishLocks);
Optional.ofNullable(lrpPeriod).ifPresent(p -> builder.setLrpPeriod(p.orElse(null)));
if (premiumListName != null) {
if (premiumListName.isPresent()) {

View file

@ -19,6 +19,7 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Queues.newArrayDeque;
import static com.google.common.collect.Sets.difference;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.StringGenerator.DEFAULT_PASSWORD_LENGTH;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.beust.jcommander.Parameter;
@ -73,7 +74,7 @@ public class GenerateAllocationTokensCommand implements RemoteApiCommand {
names = {"-l", "--length"},
description = "The length of each token, exclusive of the prefix (if specified); defaults to 16"
)
private int tokenLength = 16;
private int tokenLength = DEFAULT_PASSWORD_LENGTH;
@Parameter(
names = {"--dry_run"},

View file

@ -1,79 +0,0 @@
// 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 static google.registry.model.ofy.ObjectifyService.ofy;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import google.registry.model.domain.LrpTokenEntity;
import google.registry.tools.Command.RemoteApiCommand;
/** Command to show token information for LRP participants. */
@Parameters(
separators = " =",
commandDescription = "Show token information for LRP participants by matching on a "
+ "known token or a unique ID (assignee).")
public final class GetLrpTokenCommand implements RemoteApiCommand {
@Parameter(
names = {"-t", "--token"},
description = "LRP access token (auth code) to check")
private String tokenString;
@Parameter(
names = {"-a", "--assignee"},
description = "LRP token assignee")
private String assignee;
@Parameter(
names = {"-h", "--history"},
description = "Return expanded history entry (including domain application)")
private boolean includeHistory = false;
@Override
public void run() {
checkArgument(
(tokenString == null) == (assignee != null),
"Exactly one of either token or assignee must be specified.");
ImmutableSet.Builder<LrpTokenEntity> tokensBuilder = new ImmutableSet.Builder<>();
if (tokenString != null) {
LrpTokenEntity token =
ofy().load().key(Key.create(LrpTokenEntity.class, tokenString)).now();
if (token != null) {
tokensBuilder.add(token);
}
} else {
tokensBuilder.addAll(ofy().load().type(LrpTokenEntity.class).filter("assignee", assignee));
}
ImmutableSet<LrpTokenEntity> tokens = tokensBuilder.build();
if (!tokens.isEmpty()) {
for (LrpTokenEntity token : tokens) {
System.out.println(token);
if (includeHistory && token.getRedemptionHistoryEntry() != null) {
System.out.println(
ofy().load().key(token.getRedemptionHistoryEntry()).now().toHydratedString());
}
}
} else {
System.out.println("Token not found.");
}
}
}

View file

@ -41,7 +41,6 @@ public final class RegistryTool {
.put("create_contact", CreateContactCommand.class)
.put("create_domain", CreateDomainCommand.class)
.put("create_host", CreateHostCommand.class)
.put("create_lrp_tokens", CreateLrpTokensCommand.class)
.put("create_premium_list", CreatePremiumListCommand.class)
.put("create_registrar", CreateRegistrarCommand.class)
.put("create_registrar_groups", CreateRegistrarGroupsCommand.class)
@ -74,7 +73,6 @@ public final class RegistryTool {
.put("get_history_entries", GetHistoryEntriesCommand.class)
.put("get_host", GetHostCommand.class)
.put("get_keyring_secret", GetKeyringSecretCommand.class)
.put("get_lrp_token", GetLrpTokenCommand.class)
.put("get_registrar", GetRegistrarCommand.class)
.put("get_resource_by_key", GetResourceByKeyCommand.class)
.put("get_routing_map", GetRoutingMapCommand.class)

View file

@ -80,7 +80,6 @@ interface RegistryToolComponent {
void inject(CreateCdnsTld command);
void inject(CreateContactCommand command);
void inject(CreateDomainCommand command);
void inject(CreateLrpTokensCommand command);
void inject(CreateTldCommand command);
void inject(DeployInvoicingPipelineCommand command);
void inject(DeploySpec11PipelineCommand command);