use of com.sequenceiq.environment.tags.domain.AccountTag in project cloudbreak by hortonworks.
the class DefaultInternalAccountTagService method validate.
public void validate(List<AccountTag> accountTags) {
for (AccountTagResponse defaultTag : getDefaults().getResponses()) {
Optional<AccountTag> requestContainsUnmodifiableTag = accountTags.stream().filter(e -> e.getTagKey().equals(defaultTag.getKey())).findFirst();
if (requestContainsUnmodifiableTag.isPresent()) {
throw new BadRequestException(String.format("Tag with %s key exist as an unmodifiable tag.", defaultTag.getKey()));
}
}
for (AccountTag accountTag : accountTags) {
Pattern pattern = Pattern.compile(accountTagPattern);
Matcher keyMatcher = pattern.matcher(accountTag.getTagKey());
Matcher valueMatcher = pattern.matcher(accountTag.getTagValue());
if (!keyMatcher.matches()) {
throw new BadRequestException(String.format("The key '%s' can not start with microsoft or azure or aws or windows " + "or space and can contains only '-' and '_' and '{' and '}' characters.", accountTag.getTagKey()));
}
if (!valueMatcher.matches()) {
throw new BadRequestException(String.format("The value '%s' can not start with microsoft or azure or aws or windows " + "or space and can contains only '-' and '_' and '{' and '}' characters.", accountTag.getTagValue()));
}
if (isAccountTagContainsTemplate(accountTag.getTagKey()) && isAccountTagInvalid(accountTag.getTagKey())) {
throw new BadRequestException(String.format("The key '%s' of the tag contains invalid templates", accountTag.getTagKey()));
}
if (isAccountTagContainsTemplate(accountTag.getTagValue()) && isAccountTagInvalid(accountTag.getTagValue())) {
throw new BadRequestException(String.format("The value '%s' of the tag contains invalid templates", accountTag.getTagValue()));
}
}
}
Aggregations