use of com.sequenceiq.cloudbreak.auth.crn.Crn in project cloudbreak by hortonworks.
the class ResourceRoleCrnGeneratorTest method testGetResourceRoleCrn.
@Test
public void testGetResourceRoleCrn() {
Crn testRole1 = underTest.getResourceRoleCrn(TEST_ROLE_1);
Crn testRole2 = underTest.getResourceRoleCrn(TEST_ROLE_2);
assertEquals(ACCOUNT_ID, testRole1.getAccountId());
assertEquals(TEST_ROLE_1, testRole1.getResource());
assertEquals(Crn.ResourceType.RESOURCE_ROLE, testRole1.getResourceType());
assertEquals(ACCOUNT_ID, testRole2.getAccountId());
assertEquals(TEST_ROLE_2, testRole2.getResource());
assertEquals(Crn.ResourceType.RESOURCE_ROLE, testRole2.getResourceType());
}
use of com.sequenceiq.cloudbreak.auth.crn.Crn in project cloudbreak by hortonworks.
the class RoleCrnGeneratorTest method testGetExistingRoles.
@Test
public void testGetExistingRoles() {
Crn testRole1 = ThreadBasedUserCrnProvider.doAs(ACTOR, () -> underTest.getRoleCrn(TEST_ROLE_1, "altus"));
Crn testRole2 = ThreadBasedUserCrnProvider.doAs(ACTOR, () -> underTest.getRoleCrn(TEST_ROLE_2, "altus"));
existingRoleAssertions(testRole1, testRole2, Crn.ResourceType.ROLE);
testRole1 = ThreadBasedUserCrnProvider.doAs(ACTOR, () -> underTest.getResourceRoleCrn(TEST_ROLE_1, "altus"));
testRole2 = ThreadBasedUserCrnProvider.doAs(ACTOR, () -> underTest.getResourceRoleCrn(TEST_ROLE_2, "altus"));
existingRoleAssertions(testRole1, testRole2, Crn.ResourceType.RESOURCE_ROLE);
}
use of com.sequenceiq.cloudbreak.auth.crn.Crn in project cloudbreak by hortonworks.
the class InternalCrnModifier method getAccountIdModifiedCrn.
private String getAccountIdModifiedCrn(String userCrnString, String accountId) {
MDCBuilder.addTenant(accountId);
Crn userCrn = Crn.fromString(userCrnString);
Crn newUserCrn = Crn.copyWithDifferentAccountId(userCrn, accountId);
LOGGER.debug("Changing internal CRN to {}", newUserCrn);
createNewUser(newUserCrn);
return newUserCrn.toString();
}
use of com.sequenceiq.cloudbreak.auth.crn.Crn in project cloudbreak by hortonworks.
the class GcpLabelUtil method transformLabelKeyOrValue.
public String transformLabelKeyOrValue(String value) {
// GCP labels have strict rules https://cloud.google.com/compute/docs/labeling-resources
LOGGER.debug("Transforming tag key/value for GCP.");
if (Crn.isCrn(value)) {
try {
Crn crn = Crn.fromString(value);
value = crn == null ? value : crn.getResource();
} catch (Exception e) {
LOGGER.debug("Ignoring CRN ({}) parse error during tag value generation : {}", value, e.getMessage());
}
}
String sanitized = value.split("@")[0].toLowerCase().replaceAll("[^\\w]", "-");
String shortenedValue = StringUtils.right(sanitized, GCP_MAX_TAG_LEN);
LOGGER.debug("GCP label element has been transformed from '{}' to '{}'", value, shortenedValue);
return shortenedValue;
}
use of com.sequenceiq.cloudbreak.auth.crn.Crn in project cloudbreak by hortonworks.
the class FluentConfigService method getEnvironmentRegion.
private String getEnvironmentRegion(TelemetryClusterDetails clusterDetails) {
String environmentRegion = null;
if (clusterDetails != null && StringUtils.isNotBlank(clusterDetails.getCrn())) {
Crn crn = Crn.fromString(clusterDetails.getCrn());
if (crn != null && crn.getRegion() != null) {
environmentRegion = crn.getRegion().getName();
LOGGER.debug("Found environment region for telemetry: {}", environmentRegion);
} else {
LOGGER.debug("CRN is not filled correctly for telemetry cluster details");
}
}
return environmentRegion;
}
Aggregations