use of org.apache.cloudstack.api.response.iam.IAMGroupResponse in project cloudstack by apache.
the class IAMApiServiceTest method addRemoveAccountToGroupTest.
@Test
public void addRemoveAccountToGroupTest() {
IAMGroup group = new IAMGroupVO("group1", "tester group1");
List<IAMGroup> groups = new ArrayList<IAMGroup>();
groups.add(group);
Long groupId = group.getId();
List<Long> acctIds = new ArrayList<Long>();
AccountVO acct1 = new AccountVO(100L);
acct1.setAccountName("account1");
AccountVO acct2 = new AccountVO(200L);
acct2.setAccountName("account2");
acctIds.add(acct1.getId());
acctIds.add(acct2.getId());
when(_accountDao.findById(acct1.getId())).thenReturn(acct1);
when(_accountDao.findById(acct2.getId())).thenReturn(acct2);
when(_iamSrv.addAccountsToGroup(acctIds, groupId)).thenReturn(group);
when(_iamSrv.listAccountsByGroup(groupId)).thenReturn(acctIds);
Pair<List<IAMGroup>, Integer> grpList = new Pair<List<IAMGroup>, Integer>(groups, 1);
when(_iamSrv.listIAMGroups(null, "group1", callerDomainPath, 0L, 20L)).thenReturn(grpList);
_aclSrv.addAccountsToGroup(acctIds, groupId);
ListResponse<IAMGroupResponse> grpResp = _aclSrv.listIAMGroups(null, "group1", callerDomainId, 0L, 20L);
assertTrue("No. of response items should be one", grpResp.getCount() == 1);
IAMGroupResponse resp = grpResp.getResponses().get(0);
Set<String> acctNames = resp.getAccountNameList();
assertEquals("There should be 2 accounts in the group", 2, acctNames.size());
assertTrue("account1 should be assigned to the group", acctNames.contains("account1"));
assertTrue("account2 should be assigned to the group", acctNames.contains("account2"));
// remove "account2" from group1
acctIds.remove(1);
List<Long> rmAccts = new ArrayList<Long>();
rmAccts.add(acct2.getId());
when(_iamSrv.removeAccountsFromGroup(rmAccts, groupId)).thenReturn(group);
_aclSrv.removeAccountsFromGroup(acctIds, groupId);
grpResp = _aclSrv.listIAMGroups(null, "group1", callerDomainId, 0L, 20L);
assertTrue("No. of response items should be one", grpResp.getCount() == 1);
resp = grpResp.getResponses().get(0);
acctNames = resp.getAccountNameList();
assertEquals("There should be 1 accounts in the group", 1, acctNames.size());
assertFalse("account2 should not belong to the group anymore", acctNames.contains("account2"));
}
use of org.apache.cloudstack.api.response.iam.IAMGroupResponse in project cloudstack by apache.
the class AddAccountToIAMGroupCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException {
CallContext.current().setEventDetails("IAM group Id: " + getId());
IAMGroup result = _iamApiSrv.addAccountsToGroup(accountIdList, id);
if (result != null) {
IAMGroupResponse response = _iamApiSrv.createIAMGroupResponse(result);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add accounts to iam group");
}
}
use of org.apache.cloudstack.api.response.iam.IAMGroupResponse in project cloudstack by apache.
the class AttachIAMPolicyToIAMGroupCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException {
CallContext.current().setEventDetails("IAM group Id: " + getId());
IAMGroup result = _iamApiSrv.attachIAMPoliciesToGroup(policyIdList, id);
if (result != null) {
IAMGroupResponse response = _iamApiSrv.createIAMGroupResponse(result);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add roles to iam group");
}
}
use of org.apache.cloudstack.api.response.iam.IAMGroupResponse in project cloudstack by apache.
the class CreateIAMGroupCmd method execute.
@Override
public void execute() {
IAMGroup grp = _entityMgr.findById(IAMGroup.class, getEntityId());
if (grp != null) {
IAMGroupResponse response = _iamApiSrv.createIAMGroupResponse(grp);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create iam group:" + name);
}
}
use of org.apache.cloudstack.api.response.iam.IAMGroupResponse in project cloudstack by apache.
the class RemoveIAMPolicyFromIAMGroupCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException {
CallContext.current().setEventDetails("IAM group Id: " + getId());
IAMGroup result = _iamApiSrv.removeIAMPoliciesFromGroup(policyIdList, id);
if (result != null) {
IAMGroupResponse response = _iamApiSrv.createIAMGroupResponse(result);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add roles to iam group");
}
}
Aggregations