use of com.sequenceiq.environment.api.v1.tags.model.response.AccountTagResponse 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()));
}
}
}
use of com.sequenceiq.environment.api.v1.tags.model.response.AccountTagResponse in project cloudbreak by hortonworks.
the class AccountTagToAccountTagResponsesConverter method convert.
public AccountTagResponse convert(AccountTag source) {
AccountTagResponse response = new AccountTagResponse();
response.setKey(source.getTagKey());
response.setValue(source.getTagValue());
response.setAccountId(source.getAccountId());
response.setResourceCrn(source.getResourceCrn());
response.setStatus(AccountTagStatus.USER_MANAGED);
return response;
}
use of com.sequenceiq.environment.api.v1.tags.model.response.AccountTagResponse in project cloudbreak by hortonworks.
the class AccountTagService method list.
public Map<String, String> list() {
try {
String accountId = ThreadBasedUserCrnProvider.getAccountId();
AccountTagResponses list = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> accountTagEndpoint.listInAccount(accountId));
return list.getResponses().stream().collect(Collectors.toMap(AccountTagResponse::getKey, AccountTagResponse::getValue));
} catch (ClientErrorException e) {
try (Response response = e.getResponse()) {
if (Response.Status.NOT_FOUND.getStatusCode() == response.getStatus()) {
throw new BadRequestException(String.format("Account tag not found"), e);
}
String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e);
throw new CloudbreakServiceException(String.format("Failed to get account tag: %s", errorMessage), e);
}
}
}
Aggregations