Add validation to ROID suffixes

I could've sworn we were already doing this, but apparently not? Anyway,
ROID suffixes have a number of requirements on them that weren't being
enforced, so this enforces them. All existing production data is compliant
with these requirements; the only existing bad data we have is in alpha and
sandbox.

ROID suffixes are now required to match the regex ^[A-Z0-9_]{1,8}$

See also https://tools.ietf.org/html/rfc5730

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=173400001
This commit is contained in:
mcilwain 2017-10-25 08:19:47 -07:00 committed by jianglai
parent 2f539d6008
commit 7951799595
4 changed files with 39 additions and 8 deletions

View file

@ -68,6 +68,7 @@ import java.util.Collection;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
@ -852,7 +853,13 @@ public class Registry extends ImmutableObject implements Buildable {
return this;
}
private static final Pattern ROID_SUFFIX_PATTERN = Pattern.compile("^[A-Z0-9_]{1,8}$");
public Builder setRoidSuffix(String roidSuffix) {
checkArgument(
ROID_SUFFIX_PATTERN.matcher(roidSuffix).matches(),
"ROID suffix must be in format %s",
ROID_SUFFIX_PATTERN.pattern());
getInstance().roidSuffix = roidSuffix;
return this;
}