1
0
mirror of https://github.com/google/nomulus synced 2026-02-11 15:21:28 +00:00

Add defaultPromoTokens to Registry (#1850)

* Add defaultPromoTokens to Registry

* Remove flyway files from this PR

* Fix merge conflicts

* Add back flyway file

* Add more info to error messages

* Change to a list

* Fix javadoc

* Change error message

* Add note to field declaration
This commit is contained in:
sarahcaseybot
2022-12-06 12:22:43 -05:00
committed by GitHub
parent 9bf1bf47dd
commit 342ae7a5de
6 changed files with 232 additions and 0 deletions

View File

@@ -30,6 +30,7 @@ import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
@@ -45,11 +46,14 @@ import google.registry.model.UnsafeSerializable;
import google.registry.model.common.TimedTransitionProperty;
import google.registry.model.domain.fee.BaseFee.FeeType;
import google.registry.model.domain.fee.Fee;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.tld.label.PremiumList;
import google.registry.model.tld.label.ReservedList;
import google.registry.persistence.VKey;
import google.registry.persistence.converter.JodaMoneyType;
import google.registry.util.Idn;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@@ -451,6 +455,18 @@ public class Registry extends ImmutableObject implements Buildable, UnsafeSerial
/** An allowlist of hosts allowed to be used on domains on this TLD (ignored if empty). */
@Nullable Set<String> allowedFullyQualifiedHostNames;
/**
* References to allocation tokens that can be used on the TLD if no other token is passed in on a
* domain create.
*
* <p>Ordering is important for this field as it will determine which token is used if multiple
* tokens in the list are valid for a specific registration. It is crucial that modifications to
* this field only modify the entire list contents. Modifications to a single token in the list
* (ex: add a token to the list or remove a token from the list) should not be allowed without
* resetting the entire list contents.
*/
List<VKey<AllocationToken>> defaultPromoTokens;
public String getTldStr() {
return tldStr;
}
@@ -639,6 +655,10 @@ public class Registry extends ImmutableObject implements Buildable, UnsafeSerial
return nullToEmptyImmutableCopy(allowedFullyQualifiedHostNames);
}
public ImmutableList<VKey<AllocationToken>> getDefaultPromoTokens() {
return nullToEmptyImmutableCopy(defaultPromoTokens);
}
@Override
public Builder asBuilder() {
return new Builder(clone(this));
@@ -900,6 +920,28 @@ public class Registry extends ImmutableObject implements Buildable, UnsafeSerial
return this;
}
public Builder setDefaultPromoTokens(ImmutableList<VKey<AllocationToken>> promoTokens) {
tm().transact(
() -> {
for (VKey<AllocationToken> tokenKey : promoTokens) {
AllocationToken token = tm().loadByKey(tokenKey);
checkArgument(
token.getTokenType().equals(TokenType.DEFAULT_PROMO),
String.format(
"Token %s has an invalid token type of %s. DefaultPromoTokens must be of"
+ " the type DEFAULT_PROMO",
token.getToken(), token.getTokenType()));
checkArgument(
token.getAllowedTlds().contains(getInstance().tldStr),
String.format(
"The token %s is not valid for this TLD. The valid TLDs for it are %s",
token.getToken(), token.getAllowedTlds()));
}
getInstance().defaultPromoTokens = promoTokens;
});
return this;
}
@Override
public Registry build() {
final Registry instance = getInstance();

View File

@@ -0,0 +1,33 @@
// Copyright 2022 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.persistence.converter;
import google.registry.model.domain.token.AllocationToken;
import google.registry.persistence.VKey;
import javax.persistence.Converter;
@Converter(autoApply = true)
public class AllocationTokenListConverter extends StringListConverterBase<VKey<AllocationToken>> {
@Override
String toString(VKey<AllocationToken> element) {
return element.getKey().toString();
}
@Override
VKey<AllocationToken> fromString(String value) {
return VKey.create(AllocationToken.class, value);
}
}

View File

@@ -78,6 +78,7 @@
<class>google.registry.model.domain.RegistryLock</class>
<!-- Customized type converters -->
<class>google.registry.persistence.converter.AllocationTokenListConverter</class>
<class>google.registry.persistence.converter.AllocationTokenStatusTransitionConverter</class>
<class>google.registry.persistence.converter.BillingCostTransitionConverter</class>
<class>google.registry.persistence.converter.BillingEventFlagSetConverter</class>