Search in sources :

Example 1 with Crn

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());
}
Also used : Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Test(org.junit.jupiter.api.Test)

Example 2 with Crn

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);
}
Also used : Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Test(org.junit.jupiter.api.Test)

Example 3 with Crn

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();
}
Also used : Crn(com.sequenceiq.cloudbreak.auth.crn.Crn)

Example 4 with Crn

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;
}
Also used : Crn(com.sequenceiq.cloudbreak.auth.crn.Crn)

Example 5 with Crn

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;
}
Also used : Crn(com.sequenceiq.cloudbreak.auth.crn.Crn)

Aggregations

Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)55 Test (org.junit.Test)15 CrnParseException (com.sequenceiq.cloudbreak.auth.crn.CrnParseException)6 DatabaseConfig (com.sequenceiq.redbeams.domain.DatabaseConfig)6 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)6 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)4 Actor (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Actor)3 MachineUser (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.MachineUser)3 CheckPermissionByResourceCrn (com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)3 ResourceCrn (com.sequenceiq.authorization.annotation.ResourceCrn)3 Test (org.junit.jupiter.api.Test)3 SDXSvcAdminProto (com.cloudera.thunderhead.service.sdxsvcadmin.SDXSvcAdminProto)2 User (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.User)2 CrnUser (com.sequenceiq.cloudbreak.auth.CrnUser)2 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)2 CloudbreakUser (com.sequenceiq.cloudbreak.common.user.CloudbreakUser)2 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)2 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)2 NotFoundException (com.sequenceiq.redbeams.exception.NotFoundException)2 Optional (java.util.Optional)2