use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Account in project cloudbreak by hortonworks.
the class MockUserManagementService method listUsers.
@Override
public void listUsers(ListUsersRequest request, StreamObserver<ListUsersResponse> responseObserver) {
LOGGER.info("List users for account: {}", request.getAccountId());
Builder userBuilder = ListUsersResponse.newBuilder();
if (request.getUserIdOrCrnCount() == 0) {
if (isNotEmpty(request.getAccountId())) {
ofNullable(accountUsers.get(request.getAccountId())).orElse(Set.of()).stream().map(userName -> createUser(request.getAccountId(), userName)).forEach(userBuilder::addUser);
for (int i = 0; i < MOCK_USER_COUNT; i++) {
User user = createUser(request.getAccountId(), "fakeMockUser" + i);
userBuilder.addUser(user);
}
}
responseObserver.onNext(userBuilder.build());
} else {
String userIdOrCrn = request.getUserIdOrCrn(0);
String[] splittedCrn = userIdOrCrn.split(":");
String userName = splittedCrn[6];
String accountId = splittedCrn[4];
responseObserver.onNext(userBuilder.addUser(createUser(accountId, userName)).build());
}
responseObserver.onCompleted();
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Account in project cloudbreak by hortonworks.
the class MockUserManagementServiceTest method getAccountTestIncludesFixedEntitlements.
@Test
void getAccountTestIncludesFixedEntitlements() {
ReflectionTestUtils.setField(underTest, "cbLicense", VALID_LICENSE);
underTest.initializeWorkloadPasswordPolicy();
GetAccountRequest req = GetAccountRequest.getDefaultInstance();
StreamRecorder<GetAccountResponse> observer = StreamRecorder.create();
underTest.getAccount(req, observer);
assertThat(observer.getValues().size()).isEqualTo(1);
GetAccountResponse res = observer.getValues().get(0);
assertThat(res.hasAccount()).isTrue();
Account account = res.getAccount();
List<String> entitlements = account.getEntitlementsList().stream().map(Entitlement::getEntitlementName).collect(Collectors.toList());
assertThat(entitlements).contains("CDP_AZURE", "CDP_GCP", "CDP_AUTOMATIC_USERSYNC_POLLER", "CLOUDERA_INTERNAL_ACCOUNT", "DATAHUB_AZURE_AUTOSCALING", "DATAHUB_AWS_AUTOSCALING", "DATAHUB_GCP_AUTOSCALING", "LOCAL_DEV", "DATAHUB_FLOW_SCALING", "DATAHUB_STREAMING_SCALING", "CDP_CM_ADMIN_CREDENTIALS");
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Account in project cloudbreak by hortonworks.
the class MockUserManagementServiceTest method getAccountTestIncludesConditionalEntitlement.
@ParameterizedTest(name = "{0}")
@MethodSource("conditionalEntitlementDataProvider")
void getAccountTestIncludesConditionalEntitlement(String testCaseName, String conditionFieldName, boolean condition, String entitlementName, boolean entitlementPresentExpected) {
ReflectionTestUtils.setField(underTest, "cbLicense", VALID_LICENSE);
underTest.initializeWorkloadPasswordPolicy();
ReflectionTestUtils.setField(underTest, conditionFieldName, condition);
GetAccountRequest req = GetAccountRequest.getDefaultInstance();
StreamRecorder<GetAccountResponse> observer = StreamRecorder.create();
underTest.getAccount(req, observer);
assertThat(observer.getValues().size()).isEqualTo(1);
GetAccountResponse res = observer.getValues().get(0);
assertThat(res.hasAccount()).isTrue();
Account account = res.getAccount();
List<String> entitlements = account.getEntitlementsList().stream().map(Entitlement::getEntitlementName).collect(Collectors.toList());
if (entitlementPresentExpected) {
assertThat(entitlements).contains(entitlementName);
} else {
assertThat(entitlements).doesNotContain(entitlementName);
}
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Account in project cloudbreak by hortonworks.
the class ClusterHostServiceRunner method decoratePillarWithClouderaManagerLicense.
public Optional<String> decoratePillarWithClouderaManagerLicense(Long stackId, Map<String, SaltPillarProperties> servicePillar) {
String accountId = Crn.safeFromString(stackService.get(stackId).getResourceCrn()).getAccountId();
Account account = umsClient.getAccountDetails(accountId, MDCUtils.getRequestId(), regionAwareInternalCrnGeneratorFactory);
Optional<String> licenseOpt = Optional.ofNullable(account.getClouderaManagerLicenseKey());
if (licenseOpt.isPresent() && isNotEmpty(licenseOpt.get())) {
String license = licenseOpt.get();
servicePillar.put("cloudera-manager-license", new SaltPillarProperties("/cloudera-manager/license.sls", singletonMap("cloudera-manager", singletonMap("license", license))));
}
return licenseOpt;
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Account in project cloudbreak by hortonworks.
the class UmsClient method createGroup.
/**
* Create new user group if it does not exist.
*
* @param requestId the request ID for the request
* @param accountId the account ID
* @param groupName the newly created group name
* @return the new or existing user group.
*/
public Group createGroup(String requestId, String accountId, String groupName) {
checkNotNull(requestId, "requestId should not be null.");
checkNotNull(groupName, "groupName should not be null.");
validateAccountIdWithWarning(accountId);
try {
CreateGroupResponse createGroupResponse = newStub(requestId).createGroup(CreateGroupRequest.newBuilder().setAccountId(accountId).setGroupName(groupName).build());
LOGGER.info("New user group has been created: \nId: {} \nCrn: {} \nName: {}.", createGroupResponse.getGroup().getGroupId(), createGroupResponse.getGroup().getCrn(), createGroupResponse.getGroup().getGroupName());
return createGroupResponse.getGroup();
} catch (StatusRuntimeException e) {
if (e.getStatus().getCode().equals(io.grpc.Status.ALREADY_EXISTS.getCode())) {
Group existingGroup = listGroups(requestId, accountId, List.of(groupName)).stream().filter(foundGroup -> foundGroup.getGroupName().equals(groupName)).findAny().orElse(null);
LOGGER.info("User group already exists: \nId: {} \nCrn: {} \nName: {}.", existingGroup.getGroupId(), existingGroup.getCrn(), existingGroup.getGroupName());
return existingGroup;
} else {
throw e;
}
}
}
Aggregations