diff options
author | Håkon Hallingstad <hakon@yahooinc.com> | 2023-01-13 14:55:22 +0100 |
---|---|---|
committer | Håkon Hallingstad <hakon@yahooinc.com> | 2023-01-13 14:55:22 +0100 |
commit | b45d75179d6c12025ace97c71fdca251146a8e42 (patch) | |
tree | 3771bc82d1e4b20f2e8cdf1833de76ce3bd84871 /config-provisioning | |
parent | 697182201491bf75fdd8e5a630208ae8b374b4fd (diff) |
Move from spec.CloudAccount.isEnclave(Zone) to enclave()
Diffstat (limited to 'config-provisioning')
-rw-r--r-- | config-provisioning/src/main/java/com/yahoo/config/provision/CloudAccount.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/CloudAccount.java b/config-provisioning/src/main/java/com/yahoo/config/provision/CloudAccount.java index 974e5203e76..677803f9394 100644 --- a/config-provisioning/src/main/java/com/yahoo/config/provision/CloudAccount.java +++ b/config-provisioning/src/main/java/com/yahoo/config/provision/CloudAccount.java @@ -2,6 +2,7 @@ package com.yahoo.config.provision; import ai.vespa.validation.PatternedStringWrapper; +import ai.vespa.validation.Validation; import java.util.regex.Pattern; @@ -14,11 +15,25 @@ public class CloudAccount extends PatternedStringWrapper<CloudAccount> { private static final String EMPTY = ""; private static final String AWS_ACCOUNT_ID = "[0-9]{12}"; + private static final Pattern AWS_ACCOUNT_ID_PATTERN = Pattern.compile(AWS_ACCOUNT_ID); private static final String GCP_PROJECT_ID = "[a-z][a-z0-9-]{4,28}[a-z0-9]"; + private static final Pattern GCP_PROJECT_ID_PATTERN = Pattern.compile(GCP_PROJECT_ID); /** Empty value. When this is used, either implicitly or explicitly, the zone will use its default account */ public static final CloudAccount empty = new CloudAccount("", EMPTY, "cloud account"); + /** Verifies accountId is a valid AWS account ID and return it unaltered, or throw an IllegalArgumentException. */ + public static String requireAwsAccountId(String accountId) { + Validation.requireMatch(accountId, "AWS account ID", AWS_ACCOUNT_ID_PATTERN); + return accountId; + } + + /** Verifies accountId is a valid GCP project ID and return it unaltered, or throw an IllegalArgumentException. */ + public static String requireGcpProjectId(String projectId) { + Validation.requireMatch(projectId, "GCP project ID", GCP_PROJECT_ID_PATTERN); + return projectId; + } + private CloudAccount(String value, String regex, String description) { super(value, Pattern.compile("^(" + regex + ")$"), description); } @@ -34,6 +49,18 @@ public class CloudAccount extends PatternedStringWrapper<CloudAccount> { !equals(zone.cloud().account()); } + /** Verifies this account is a valid AWS account ID and return this, or throw an IllegalArgumentException. */ + public CloudAccount requireAwsAccountId() { + requireAwsAccountId(value()); + return this; + } + + /** Verifies this account is a valid GCP project ID and return this, or throw an IllegalArgumentException. */ + public CloudAccount requireGcpProjectId() { + requireGcpProjectId(value()); + return this; + } + public static CloudAccount from(String cloudAccount) { return switch (cloudAccount) { // Tenants are allowed to specify "default" in services.xml. |