use of com.cloud.storage.datastore.db.ImageStoreDetailVO in project cosmic by MissionCriticalCloud.
the class ImageStoreHelper method createImageStore.
public ImageStoreVO createImageStore(final Map<String, Object> params, final Map<String, String> details) {
ImageStoreVO store = imageStoreDao.findByName((String) params.get("name"));
if (store != null) {
return store;
}
store = new ImageStoreVO();
store.setProtocol((String) params.get("protocol"));
store.setProviderName((String) params.get("providerName"));
store.setScope((ScopeType) params.get("scope"));
store.setDataCenterId((Long) params.get("zoneId"));
final String uuid = (String) params.get("uuid");
if (uuid != null) {
store.setUuid(uuid);
} else {
store.setUuid(UUID.randomUUID().toString());
}
store.setUrl((String) params.get("url"));
store.setName((String) params.get("name"));
if (store.getName() == null) {
store.setName(store.getUuid());
}
store.setRole((DataStoreRole) params.get("role"));
if ("cifs".equalsIgnoreCase((String) params.get("protocol")) && details != null) {
final String user = details.get("user");
String password = details.get("password");
final String domain = details.get("domain");
String updatedPath = (String) params.get("url");
if (user == null || password == null) {
final String errMsg = "Missing cifs user and password details. Add them as details parameter.";
throw new InvalidParameterValueException(errMsg);
} else {
try {
password = DBEncryptionUtil.encrypt(URLEncoder.encode(password, "UTF-8"));
details.put("password", password);
updatedPath += "?user=" + user + "&password=" + password + "&domain=" + domain;
} catch (final UnsupportedEncodingException e) {
throw new CloudRuntimeException("Error while generating the cifs url. " + e.getMessage());
}
store.setUrl(updatedPath);
}
}
store = imageStoreDao.persist(store);
// persist details
if (details != null) {
final Iterator<String> keyIter = details.keySet().iterator();
while (keyIter.hasNext()) {
final String key = keyIter.next().toString();
final ImageStoreDetailVO detail = new ImageStoreDetailVO();
detail.setStoreId(store.getId());
detail.setName(key);
String value = details.get(key);
// encrypt swift key or s3 secret key
if (key.equals(ApiConstants.KEY)) {
value = DBEncryptionUtil.encrypt(value);
}
detail.setValue(value);
imageStoreDetailsDao.persist(detail);
}
}
return store;
}
use of com.cloud.storage.datastore.db.ImageStoreDetailVO in project cosmic by MissionCriticalCloud.
the class ImageStoreDetailsDaoImpl method getDetails.
@Override
public Map<String, String> getDetails(final long storeId) {
final SearchCriteria<ImageStoreDetailVO> sc = storeSearch.create();
sc.setParameters("store", storeId);
final List<ImageStoreDetailVO> details = listBy(sc);
final Map<String, String> detailsMap = new HashMap<>();
for (final ImageStoreDetailVO detail : details) {
final String name = detail.getName();
String value = detail.getValue();
if (name.equals(ApiConstants.KEY)) {
value = DBEncryptionUtil.decrypt(value);
}
detailsMap.put(name, value);
}
return detailsMap;
}
use of com.cloud.storage.datastore.db.ImageStoreDetailVO in project cosmic by MissionCriticalCloud.
the class ImageStoreDetailsDaoImpl method deleteDetails.
@Override
public void deleteDetails(final long storeId) {
final SearchCriteria<ImageStoreDetailVO> sc = storeSearch.create();
sc.setParameters("store", storeId);
final List<ImageStoreDetailVO> results = search(sc, null);
for (final ImageStoreDetailVO result : results) {
remove(result.getId());
}
}
use of com.cloud.storage.datastore.db.ImageStoreDetailVO in project cosmic by MissionCriticalCloud.
the class ImageStoreDetailsDaoImpl method update.
@Override
public void update(final long storeId, final Map<String, String> details) {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
final SearchCriteria<ImageStoreDetailVO> sc = storeSearch.create();
sc.setParameters("store", storeId);
txn.start();
expunge(sc);
for (final Map.Entry<String, String> entry : details.entrySet()) {
final ImageStoreDetailVO detail = new ImageStoreDetailVO(storeId, entry.getKey(), entry.getValue());
persist(detail);
}
txn.commit();
}
Aggregations