Add currentPackageToken on create flow (#1751)

* Add currentPackageToken on create flow

* Change to Truth8 assertion

* Add check for specified renewal behavior
This commit is contained in:
sarahcaseybot
2022-08-23 14:47:41 -04:00
committed by GitHub
parent 6dd96c247a
commit 8b02f76ae9
6 changed files with 50 additions and 1 deletions
@@ -390,6 +390,11 @@ public final class DomainCreateFlow implements TransactionalFlow {
.addGracePeriod(
GracePeriod.forBillingEvent(GracePeriodStatus.ADD, repoId, createBillingEvent))
.build();
if (allocationToken.isPresent()
&& allocationToken.get().getTokenType().equals(TokenType.PACKAGE)) {
domain =
domain.asBuilder().setCurrentPackageToken(allocationToken.get().createVKey()).build();
}
DomainHistory domainHistory =
buildDomainHistory(domain, registry, now, period, registry.getAddGracePeriodLength());
if (reservationTypes.contains(NAME_COLLISION)) {
@@ -105,6 +105,7 @@ public class AllocationToken extends BackupGroupRoot implements Buildable {
/** Single-use tokens are invalid after use. Infinite-use tokens, predictably, are not. */
public enum TokenType {
PACKAGE,
SINGLE_USE,
UNLIMITED_USE
}
@@ -274,6 +275,10 @@ public class AllocationToken extends BackupGroupRoot implements Buildable {
public AllocationToken build() {
checkArgumentNotNull(getInstance().tokenType, "Token type must be specified");
checkArgument(!Strings.isNullOrEmpty(getInstance().token), "Token must not be null or empty");
checkArgument(
!getInstance().tokenType.equals(TokenType.PACKAGE)
|| getInstance().renewalPriceBehavior.equals(RenewalPriceBehavior.SPECIFIED),
"Package tokens must have renewalPriceBehavior set to SPECIFIED");
checkArgument(
getInstance().domainName == null || TokenType.SINGLE_USE.equals(getInstance().tokenType),
"Domain name can only be specified for SINGLE_USE tokens");