mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 00:47:11 +02:00
Display created domain name in get_allocation_token command
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=240212479
This commit is contained in:
parent
73f527ccc8
commit
5ef4c4edf1
2 changed files with 82 additions and 16 deletions
|
@ -23,8 +23,11 @@ import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.googlecode.objectify.Key;
|
import com.googlecode.objectify.Key;
|
||||||
|
import google.registry.model.domain.DomainBase;
|
||||||
import google.registry.model.domain.token.AllocationToken;
|
import google.registry.model.domain.token.AllocationToken;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/** Command to show allocation tokens. */
|
/** Command to show allocation tokens. */
|
||||||
@Parameters(separators = " =", commandDescription = "Show allocation token(s)")
|
@Parameters(separators = " =", commandDescription = "Show allocation token(s)")
|
||||||
|
@ -41,17 +44,49 @@ final class GetAllocationTokenCommand implements CommandWithRemoteApi {
|
||||||
public void run() {
|
public void run() {
|
||||||
ImmutableMap.Builder<String, AllocationToken> builder = new ImmutableMap.Builder<>();
|
ImmutableMap.Builder<String, AllocationToken> builder = new ImmutableMap.Builder<>();
|
||||||
for (List<String> tokens : Lists.partition(mainParameters, BATCH_SIZE)) {
|
for (List<String> tokens : Lists.partition(mainParameters, BATCH_SIZE)) {
|
||||||
ImmutableList<Key<AllocationToken>> keys =
|
ImmutableList<Key<AllocationToken>> tokenKeys =
|
||||||
tokens.stream().map(t -> Key.create(AllocationToken.class, t)).collect(toImmutableList());
|
tokens.stream().map(t -> Key.create(AllocationToken.class, t)).collect(toImmutableList());
|
||||||
ofy().load().keys(keys).forEach((k, v) -> builder.put(k.getName(), v));
|
ofy().load().keys(tokenKeys).forEach((k, v) -> builder.put(k.getName(), v));
|
||||||
}
|
}
|
||||||
ImmutableMap<String, AllocationToken> loadedTokens = builder.build();
|
ImmutableMap<String, AllocationToken> loadedTokens = builder.build();
|
||||||
|
ImmutableMap<Key<DomainBase>, DomainBase> domains = loadRedeemedDomains(loadedTokens.values());
|
||||||
|
|
||||||
for (String token : mainParameters) {
|
for (String token : mainParameters) {
|
||||||
System.out.println(
|
if (loadedTokens.containsKey(token)) {
|
||||||
loadedTokens.containsKey(token)
|
AllocationToken loadedToken = loadedTokens.get(token);
|
||||||
? loadedTokens.get(token)
|
System.out.println(loadedToken.toString());
|
||||||
: String.format("Token %s does not exist.", token));
|
if (loadedToken.getRedemptionHistoryEntry() == null) {
|
||||||
|
System.out.printf("Token %s was not redeemed.\n", token);
|
||||||
|
} else {
|
||||||
|
DomainBase domain =
|
||||||
|
domains.get(loadedToken.getRedemptionHistoryEntry().<DomainBase>getParent());
|
||||||
|
if (domain == null) {
|
||||||
|
System.out.printf("ERROR: Token %s was redeemed but domain can't be loaded.\n", token);
|
||||||
|
} else {
|
||||||
|
System.out.printf(
|
||||||
|
"Token %s was redeemed to create domain %s at %s.\n",
|
||||||
|
token, domain.getFullyQualifiedDomainName(), domain.getCreationTime());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.printf("ERROR: Token %s does not exist.\n", token);
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ImmutableMap<Key<DomainBase>, DomainBase> loadRedeemedDomains(
|
||||||
|
Collection<AllocationToken> tokens) {
|
||||||
|
ImmutableList<Key<DomainBase>> domainKeys =
|
||||||
|
tokens.stream()
|
||||||
|
.map(AllocationToken::getRedemptionHistoryEntry)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.map(Key::<DomainBase>getParent)
|
||||||
|
.collect(toImmutableList());
|
||||||
|
ImmutableMap.Builder<Key<DomainBase>, DomainBase> domainsBuilder = new ImmutableMap.Builder<>();
|
||||||
|
for (List<Key<DomainBase>> keys : Lists.partition(domainKeys, BATCH_SIZE)) {
|
||||||
|
domainsBuilder.putAll(ofy().load().keys(keys));
|
||||||
|
}
|
||||||
|
return domainsBuilder.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,17 @@
|
||||||
|
|
||||||
package google.registry.tools;
|
package google.registry.tools;
|
||||||
|
|
||||||
|
import static google.registry.testing.DatastoreHelper.createHistoryEntryForEppResource;
|
||||||
|
import static google.registry.testing.DatastoreHelper.createTld;
|
||||||
|
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
|
||||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||||
import static google.registry.testing.DatastoreHelper.persistSimpleResources;
|
import static google.registry.testing.DatastoreHelper.persistSimpleResources;
|
||||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||||
|
|
||||||
import com.beust.jcommander.ParameterException;
|
import com.beust.jcommander.ParameterException;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.googlecode.objectify.Key;
|
||||||
|
import google.registry.model.domain.DomainBase;
|
||||||
import google.registry.model.domain.token.AllocationToken;
|
import google.registry.model.domain.token.AllocationToken;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -33,20 +38,43 @@ public class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocation
|
||||||
persistResource(
|
persistResource(
|
||||||
new AllocationToken.Builder().setToken("foo").setDomainName("foo.bar").build());
|
new AllocationToken.Builder().setToken("foo").setDomainName("foo.bar").build());
|
||||||
runCommand("foo");
|
runCommand("foo");
|
||||||
assertInStdout(token.toHydratedString());
|
assertInStdout(token.toString(), "Token foo was not redeemed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_multipleTokens() throws Exception {
|
public void testSuccess_multipleTokens() throws Exception {
|
||||||
ImmutableList<AllocationToken> tokens = persistSimpleResources(
|
ImmutableList<AllocationToken> tokens =
|
||||||
ImmutableList.of(
|
persistSimpleResources(
|
||||||
new AllocationToken.Builder()
|
ImmutableList.of(
|
||||||
.setToken("fee")
|
new AllocationToken.Builder()
|
||||||
.setCreationTimeForTest(DateTime.parse("2015-04-07T22:19:17.044Z"))
|
.setToken("fee")
|
||||||
.build(),
|
.setCreationTimeForTest(DateTime.parse("2015-04-07T22:19:17.044Z"))
|
||||||
new AllocationToken.Builder().setToken("fii").setDomainName("bar.baz").build()));
|
.build(),
|
||||||
|
new AllocationToken.Builder().setToken("fii").setDomainName("bar.baz").build()));
|
||||||
runCommand("fee", "fii");
|
runCommand("fee", "fii");
|
||||||
assertInStdout(tokens.get(0).toHydratedString(), tokens.get(1).toHydratedString());
|
assertInStdout(
|
||||||
|
tokens.get(0).toString(),
|
||||||
|
"Token fee was not redeemed.",
|
||||||
|
tokens.get(1).toString(),
|
||||||
|
"Token fii was not redeemed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSuccess_redeemedToken() throws Exception {
|
||||||
|
createTld("tld");
|
||||||
|
DomainBase domain =
|
||||||
|
persistActiveDomain("fqqdn.tld", DateTime.parse("2016-04-07T22:19:17.044Z"));
|
||||||
|
AllocationToken token =
|
||||||
|
persistResource(
|
||||||
|
new AllocationToken.Builder()
|
||||||
|
.setToken("foo")
|
||||||
|
.setDomainName("fqqdn.tld")
|
||||||
|
.setRedemptionHistoryEntry(Key.create(createHistoryEntryForEppResource(domain)))
|
||||||
|
.build());
|
||||||
|
runCommand("foo");
|
||||||
|
assertInStdout(
|
||||||
|
token.toString(),
|
||||||
|
"Token foo was redeemed to create domain fqqdn.tld at 2016-04-07T22:19:17.044Z.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -55,7 +83,10 @@ public class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocation
|
||||||
persistResource(
|
persistResource(
|
||||||
new AllocationToken.Builder().setToken("foo").setDomainName("foo.bar").build());
|
new AllocationToken.Builder().setToken("foo").setDomainName("foo.bar").build());
|
||||||
runCommand("foo", "bar");
|
runCommand("foo", "bar");
|
||||||
assertInStdout(token.toHydratedString(), "Token bar does not exist.");
|
assertInStdout(
|
||||||
|
token.toString(),
|
||||||
|
"Token foo was not redeemed.",
|
||||||
|
"ERROR: Token bar does not exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue