Disallow combing CONSOLE_USER_EMAIL dimension with some other dimensions
@@ -3,7 +3,9 @@ package com.yahoo.vespa.flags;
import javax.annotation.concurrent.Immutable;
import java.time.Instant;
+import java.util.EnumSet;
import java.util.List;
+import java.util.Set;
/**
* @author hakonhall
@@ -26,7 +28,6 @@ public class FlagDefinition {
String description,
String modificationEffect,
FetchVector.Dimension... dimensions) {
- validate(owners, createdAt, expiresAt);
this.unboundFlag = unboundFlag;
this.owners = owners;
this.createdAt = createdAt;
@@ -34,6 +35,7 @@ public class FlagDefinition {
this.description = description;
this.modificationEffect = modificationEffect;
this.dimensions = List.of(dimensions);
+ validate(owners, createdAt, expiresAt, this.dimensions);
}
public UnboundFlag<?, ?, ?> getUnboundFlag() {
@@ -58,13 +60,14 @@ public class FlagDefinition {
public Instant getExpiresAt() { return expiresAt; }
- private static void validate(List<String> owners, Instant createdAt, Instant expiresAt) {
+ private static void validate(List<String> owners, Instant createdAt, Instant expiresAt, List<FetchVector.Dimension> dimensions) {
if (expiresAt.isBefore(createdAt)) {
throw new IllegalArgumentException(
String.format(
"Flag cannot expire before its creation date (createdAt='%s', expiresAt='%s')",
createdAt, expiresAt));
}
+
if (owners == PermanentFlags.OWNERS) {
if (!createdAt.equals(PermanentFlags.CREATED_AT) || !expiresAt.equals(PermanentFlags.EXPIRES_AT)) {
throw new IllegalArgumentException("Invalid creation or expiration date for permanent flag");
@@ -72,5 +75,15 @@ public class FlagDefinition {
} else if (owners.isEmpty()) {
throw new IllegalArgumentException("Owner(s) must be specified");
}
+
+ if (dimensions.contains(FetchVector.Dimension.CONSOLE_USER_EMAIL)) {
+ Set<FetchVector.Dimension> disallowedCombinations = EnumSet.allOf(FetchVector.Dimension.class);
+ disallowedCombinations.remove(FetchVector.Dimension.CONSOLE_USER_EMAIL);
+ disallowedCombinations.remove(FetchVector.Dimension.APPLICATION_ID);
+ disallowedCombinations.remove(FetchVector.Dimension.TENANT_ID);
+ disallowedCombinations.retainAll(dimensions);
+ if (!disallowedCombinations.isEmpty())
+ throw new IllegalArgumentException("Dimension " + FetchVector.Dimension.CONSOLE_USER_EMAIL + " cannot be combined with " + disallowedCombinations);
+ }
}
}
