use of com.emc.storageos.ecs.api.ECSApi in project coprhd-controller by CoprHD.
the class ECSObjectStorageDevice method doUpdateBucketACL.
@Override
public BiosCommandResult doUpdateBucketACL(StorageSystem storageObj, Bucket bucket, ObjectDeviceInputOutput objectArgs, BucketACLUpdateParams param, String taskId) throws ControllerException {
List<BucketACE> aclToAdd = objectArgs.getBucketAclToAdd();
List<BucketACE> aclToModify = objectArgs.getBucketAclToModify();
List<BucketACE> aclToDelete = objectArgs.getBucketAclToDelete();
// Get existing Acl for the Bucket
List<BucketACE> aclsToProcess = objectArgs.getExistingBucketAcl();
aclsToProcess.addAll(aclToAdd);
// Process ACLs to modify
for (BucketACE existingAce : aclsToProcess) {
String domainOfExistingAce = existingAce.getDomain();
if (domainOfExistingAce == null) {
domainOfExistingAce = "";
}
for (BucketACE aceToModify : aclToModify) {
String domainOfmodifiedAce = aceToModify.getDomain();
if (domainOfmodifiedAce == null) {
domainOfmodifiedAce = "";
}
if (aceToModify.getUser() != null && existingAce.getUser() != null) {
if (domainOfExistingAce.concat(existingAce.getUser()).equalsIgnoreCase(domainOfmodifiedAce.concat(aceToModify.getUser()))) {
existingAce.setPermissions(aceToModify.getPermissions());
}
}
if (aceToModify.getGroup() != null && existingAce.getGroup() != null) {
if (domainOfExistingAce.concat(existingAce.getGroup()).equalsIgnoreCase(domainOfmodifiedAce.concat(aceToModify.getGroup()))) {
existingAce.setPermissions(aceToModify.getPermissions());
}
}
if (aceToModify.getCustomGroup() != null && existingAce.getCustomGroup() != null) {
if (domainOfExistingAce.concat(existingAce.getCustomGroup()).equalsIgnoreCase(domainOfmodifiedAce.concat(aceToModify.getCustomGroup()))) {
existingAce.setPermissions(aceToModify.getPermissions());
}
}
}
}
// Process ACLs to delete
for (BucketACE aceToDelete : aclToDelete) {
String domainOfDeleteAce = aceToDelete.getDomain();
if (domainOfDeleteAce == null) {
domainOfDeleteAce = "";
}
for (Iterator<BucketACE> iterator = aclsToProcess.iterator(); iterator.hasNext(); ) {
BucketACE existingAcl = iterator.next();
String domainOfExistingAce = existingAcl.getDomain();
if (domainOfExistingAce == null) {
domainOfExistingAce = "";
}
if (aceToDelete.getUser() != null && existingAcl.getUser() != null) {
if (domainOfDeleteAce.concat(aceToDelete.getUser()).equalsIgnoreCase(domainOfExistingAce.concat(existingAcl.getUser()))) {
iterator.remove();
}
}
if (aceToDelete.getGroup() != null && existingAcl.getGroup() != null) {
if (domainOfDeleteAce.concat(aceToDelete.getGroup()).equalsIgnoreCase(domainOfExistingAce.concat(existingAcl.getGroup()))) {
iterator.remove();
}
}
if (aceToDelete.getCustomGroup() != null && existingAcl.getCustomGroup() != null) {
if (domainOfDeleteAce.concat(aceToDelete.getCustomGroup()).equalsIgnoreCase(domainOfExistingAce.concat(existingAcl.getCustomGroup()))) {
iterator.remove();
}
}
}
}
ECSApi objectAPI = getAPI(storageObj);
try {
String payload = toJsonString(objectArgs, aclsToProcess);
objectAPI.updateBucketACL(objectArgs.getName(), payload);
updateBucketACLInDB(param, objectArgs, bucket);
} catch (ECSException e) {
_log.error("ACL Update for Bucket : {} failed.", objectArgs.getName(), e);
completeTask(bucket.getId(), taskId, e);
return BiosCommandResult.createErrorResult(e);
}
completeTask(bucket.getId(), taskId, "Successfully updated Bucket ACL.");
return BiosCommandResult.createSuccessfulResult();
}
use of com.emc.storageos.ecs.api.ECSApi in project coprhd-controller by CoprHD.
the class ECSObjectStorageDevice method doSyncBucketACL.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.volumecontroller.ObjectStorageDevice#doSyncBucketACL(com.emc.storageos.db.client.model.StorageSystem,
* com.emc.storageos.db.client.model.Bucket, com.emc.storageos.volumecontroller.ObjectDeviceInputOutput, java.lang.String)
*
* Gets the ACl for the bucket from ECS and persist in coprhd DB.
*/
@Override
public BiosCommandResult doSyncBucketACL(StorageSystem storageObj, Bucket bucket, ObjectDeviceInputOutput objectArgs, String taskId) throws ControllerException {
ECSApi objectAPI = getAPI(storageObj);
try {
String aclResponse = objectAPI.getBucketAclFromECS(objectArgs.getName(), objectArgs.getNamespace());
_log.info("aclResponse {} " + aclResponse);
ECSBucketACL bucketACl = new Gson().fromJson(SecurityUtils.sanitizeJsonString(aclResponse), ECSBucketACL.class);
ECSBucketACL.Acl acl = bucketACl.getAcl();
List<ECSBucketACL.UserAcl> user_acl = acl.getUseAcl();
List<ECSBucketACL.GroupAcl> group_acl = acl.getGroupAcl();
List<ECSBucketACL.CustomGroupAcl> customgroup_acl = acl.getCustomgroupAcl();
List<BucketACE> aclToAdd = Lists.newArrayList();
final String _VERSION = "acl_supported";
final String DELIMETER = "@";
for (ECSBucketACL.UserAcl userAce : user_acl) {
String userWithDomain = userAce.getUser();
String[] usrDomain = userWithDomain.split(DELIMETER);
BucketACE bucketAce = new BucketACE();
if (usrDomain.length > 1) {
bucketAce.setDomain(usrDomain[1]);
bucketAce.setUser(usrDomain[0]);
} else if (usrDomain.length == 1) {
// username without domain
bucketAce.setUser(usrDomain[0]);
}
String[] permArray = userAce.getPermission();
String permissions = formatPermissions(permArray);
bucketAce.setPermissions(permissions);
aclToAdd.add(bucketAce);
}
for (ECSBucketACL.GroupAcl groupAce : group_acl) {
String groupWithDomain = groupAce.getGroup();
String[] grpDomain = groupWithDomain.split(DELIMETER);
BucketACE bucketAce = new BucketACE();
if (grpDomain.length > 1) {
bucketAce.setDomain(grpDomain[1]);
bucketAce.setGroup(grpDomain[0]);
} else if (grpDomain.length == 1) {
// group without domain
bucketAce.setGroup(grpDomain[0]);
}
String[] permArray = groupAce.getPermission();
String permissions = formatPermissions(permArray);
bucketAce.setPermissions(permissions);
aclToAdd.add(bucketAce);
}
for (ECSBucketACL.CustomGroupAcl customGroupAce : customgroup_acl) {
String customGroupWithDomain = customGroupAce.getCustomgroup();
String[] grpDomain = customGroupWithDomain.split(DELIMETER);
BucketACE bucketAce = new BucketACE();
if (grpDomain.length > 1) {
bucketAce.setDomain(grpDomain[1]);
bucketAce.setCustomGroup(grpDomain[0]);
} else if (grpDomain.length == 1) {
// custom group without domain
bucketAce.setCustomGroup(grpDomain[0]);
}
String[] permArray = customGroupAce.getPermission();
String permissions = formatPermissions(permArray);
bucketAce.setPermissions(permissions);
aclToAdd.add(bucketAce);
}
BucketACLUpdateParams param = new BucketACLUpdateParams();
BucketACL aclForAddition = new BucketACL();
aclForAddition.setBucketACL(aclToAdd);
param.setAclToAdd(aclForAddition);
updateBucketACLInDB(param, objectArgs, bucket);
bucket.setVersion(_VERSION);
_dbClient.updateObject(bucket);
} catch (ECSException e) {
_log.error("Sync ACL for Bucket : {} failed.", objectArgs.getName(), e);
completeTask(bucket.getId(), taskId, e);
return BiosCommandResult.createErrorResult(e);
}
completeTask(bucket.getId(), taskId, "Bucket ACL Sync Successful.");
return BiosCommandResult.createSuccessfulResult();
}
use of com.emc.storageos.ecs.api.ECSApi in project coprhd-controller by CoprHD.
the class ECSObjectStorageDevice method doAddUserSecretKey.
@Override
public ObjectUserSecretKey doAddUserSecretKey(StorageSystem storageObj, String userId, String secretKey) throws InternalException {
ECSApi ecsApi = getAPI(storageObj);
ObjectUserSecretKey secretKeyRes = new ObjectUserSecretKey();
try {
UserSecretKeysAddCommandResult cmdRes = ecsApi.addUserSecretKey(userId, secretKey);
// secretKeyRes.setSecret_key_1(cmdRes.getSecret_key()); //for security reason hiding the secrete key
secretKeyRes.setSecret_key_1_expiry_timestamp(cmdRes.getKey_expiry_timestamp());
return secretKeyRes;
} catch (Exception e) {
_log.error("ECSObjectStorageDevice:doAddUserSecretKey failed");
throw e;
}
}
use of com.emc.storageos.ecs.api.ECSApi in project coprhd-controller by CoprHD.
the class ECSObjectStorageDevice method getAPI.
private ECSApi getAPI(StorageSystem storageObj) throws ControllerException {
ECSApi objectAPI = null;
URI deviceURI = null;
try {
deviceURI = new URI("https", null, storageObj.getIpAddress(), storageObj.getPortNumber(), "/", null, null);
} catch (URISyntaxException e) {
throw ECSException.exceptions.invalidReturnParameters(storageObj.getId());
}
if (storageObj.getUsername() != null && !storageObj.getUsername().isEmpty()) {
objectAPI = ecsApiFactory.getRESTClient(deviceURI, storageObj.getUsername(), storageObj.getPassword());
} else {
objectAPI = ecsApiFactory.getRESTClient(deviceURI);
}
return objectAPI;
}
use of com.emc.storageos.ecs.api.ECSApi in project coprhd-controller by CoprHD.
the class ECSObjectStorageDevice method doDeleteBucketACL.
@Override
public BiosCommandResult doDeleteBucketACL(StorageSystem storageObj, Bucket bucket, ObjectDeviceInputOutput objectArgs, String taskId) throws ControllerException {
ECSApi objectAPI = getAPI(storageObj);
BucketACLUpdateParams param = new BucketACLUpdateParams();
BucketACL aclForDeletion = new BucketACL();
aclForDeletion.setBucketACL(objectArgs.getBucketAclToDelete());
param.setAclToDelete(aclForDeletion);
try {
String payload = "{\"bucket\":\"" + objectArgs.getName() + "\",\"namespace\":\"" + objectArgs.getNamespace() + "\",\"acl\":{}}\"";
objectAPI.updateBucketACL(objectArgs.getName(), payload);
updateBucketACLInDB(param, objectArgs, bucket);
} catch (ECSException e) {
_log.error("Delete ACL for Bucket : {} failed.", objectArgs.getName(), e);
completeTask(bucket.getId(), taskId, e);
return BiosCommandResult.createErrorResult(e);
}
completeTask(bucket.getId(), taskId, "Successfully updated Bucket ACL.");
return BiosCommandResult.createSuccessfulResult();
}
Aggregations