store = imageStoreDao.persist(store);
return store;
}
public ImageStoreVO createImageStore(Map<String, Object> params, 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"));
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) {
String user = details.get("user");
String password = details.get("password");
String domain = details.get("domain");
String updatedPath = (String) params.get("url");
if (user == null || password == null) {
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 (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) {
Iterator<String> keyIter = details.keySet().iterator();
while (keyIter.hasNext()) {
String key = keyIter.next().toString();
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) || key.equals(ApiConstants.S3_SECRET_KEY)) {
value = DBEncryptionUtil.encrypt(value);