mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Decrypt zone, cluster, storage details for configuration values (#10237)
Co-authored-by: dahn <daan.hoogland@gmail.com> Co-authored-by: Bryan Lima <42067040+BryanMLima@users.noreply.github.com>
This commit is contained in:
parent
0d5047b8b7
commit
60af31c9c0
@ -19,8 +19,9 @@ package com.cloud.dc;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
import org.apache.cloudstack.resourcedetail.ResourceDetailsDao;
|
||||||
|
|
||||||
public interface ClusterDetailsDao extends GenericDao<ClusterDetailsVO, Long> {
|
public interface ClusterDetailsDao extends GenericDao<ClusterDetailsVO, Long>, ResourceDetailsDao<ClusterDetailsVO> {
|
||||||
Map<String, String> findDetails(long clusterId);
|
Map<String, String> findDetails(long clusterId);
|
||||||
|
|
||||||
void persist(long clusterId, Map<String, String> details);
|
void persist(long clusterId, Map<String, String> details);
|
||||||
|
|||||||
@ -26,12 +26,13 @@ import org.apache.cloudstack.framework.config.ConfigKey.Scope;
|
|||||||
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
|
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
|
||||||
|
|
||||||
import com.cloud.utils.crypt.DBEncryptionUtil;
|
import com.cloud.utils.crypt.DBEncryptionUtil;
|
||||||
import com.cloud.utils.db.GenericDaoBase;
|
|
||||||
import com.cloud.utils.db.SearchBuilder;
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
import com.cloud.utils.db.SearchCriteria;
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
import com.cloud.utils.db.TransactionLegacy;
|
import com.cloud.utils.db.TransactionLegacy;
|
||||||
|
import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase;
|
||||||
|
|
||||||
|
public class ClusterDetailsDaoImpl extends ResourceDetailsDaoBase<ClusterDetailsVO> implements ClusterDetailsDao, ScopedConfigStorage {
|
||||||
|
|
||||||
public class ClusterDetailsDaoImpl extends GenericDaoBase<ClusterDetailsVO, Long> implements ClusterDetailsDao, ScopedConfigStorage {
|
|
||||||
protected final SearchBuilder<ClusterDetailsVO> ClusterSearch;
|
protected final SearchBuilder<ClusterDetailsVO> ClusterSearch;
|
||||||
protected final SearchBuilder<ClusterDetailsVO> DetailSearch;
|
protected final SearchBuilder<ClusterDetailsVO> DetailSearch;
|
||||||
|
|
||||||
@ -42,11 +43,11 @@ public class ClusterDetailsDaoImpl extends GenericDaoBase<ClusterDetailsVO, Long
|
|||||||
|
|
||||||
protected ClusterDetailsDaoImpl() {
|
protected ClusterDetailsDaoImpl() {
|
||||||
ClusterSearch = createSearchBuilder();
|
ClusterSearch = createSearchBuilder();
|
||||||
ClusterSearch.and("clusterId", ClusterSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
|
ClusterSearch.and("clusterId", ClusterSearch.entity().getResourceId(), SearchCriteria.Op.EQ);
|
||||||
ClusterSearch.done();
|
ClusterSearch.done();
|
||||||
|
|
||||||
DetailSearch = createSearchBuilder();
|
DetailSearch = createSearchBuilder();
|
||||||
DetailSearch.and("clusterId", DetailSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
|
DetailSearch.and("clusterId", DetailSearch.entity().getResourceId(), SearchCriteria.Op.EQ);
|
||||||
DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ);
|
DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ);
|
||||||
DetailSearch.done();
|
DetailSearch.done();
|
||||||
}
|
}
|
||||||
@ -66,6 +67,11 @@ public class ClusterDetailsDaoImpl extends GenericDaoBase<ClusterDetailsVO, Long
|
|||||||
return detail;
|
return detail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addDetail(long resourceId, String key, String value, boolean display) {
|
||||||
|
super.addDetail(new ClusterDetailsVO(resourceId, key, value));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> findDetails(long clusterId) {
|
public Map<String, String> findDetails(long clusterId) {
|
||||||
SearchCriteria<ClusterDetailsVO> sc = ClusterSearch.create();
|
SearchCriteria<ClusterDetailsVO> sc = ClusterSearch.create();
|
||||||
@ -138,7 +144,7 @@ public class ClusterDetailsDaoImpl extends GenericDaoBase<ClusterDetailsVO, Long
|
|||||||
@Override
|
@Override
|
||||||
public String getConfigValue(long id, ConfigKey<?> key) {
|
public String getConfigValue(long id, ConfigKey<?> key) {
|
||||||
ClusterDetailsVO vo = findDetail(id, key.key());
|
ClusterDetailsVO vo = findDetail(id, key.key());
|
||||||
return vo == null ? null : vo.getValue();
|
return vo == null ? null : getActualValue(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -23,11 +23,11 @@ import javax.persistence.GenerationType;
|
|||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import org.apache.cloudstack.api.InternalIdentity;
|
import org.apache.cloudstack.api.ResourceDetail;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "cluster_details")
|
@Table(name = "cluster_details")
|
||||||
public class ClusterDetailsVO implements InternalIdentity {
|
public class ClusterDetailsVO implements ResourceDetail {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@ -35,7 +35,7 @@ public class ClusterDetailsVO implements InternalIdentity {
|
|||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
@Column(name = "cluster_id")
|
@Column(name = "cluster_id")
|
||||||
private long clusterId;
|
private long resourceId;
|
||||||
|
|
||||||
@Column(name = "name")
|
@Column(name = "name")
|
||||||
private String name;
|
private String name;
|
||||||
@ -47,13 +47,14 @@ public class ClusterDetailsVO implements InternalIdentity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ClusterDetailsVO(long clusterId, String name, String value) {
|
public ClusterDetailsVO(long clusterId, String name, String value) {
|
||||||
this.clusterId = clusterId;
|
this.resourceId = clusterId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getClusterId() {
|
@Override
|
||||||
return clusterId;
|
public long getResourceId() {
|
||||||
|
return resourceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -64,6 +65,11 @@ public class ClusterDetailsVO implements InternalIdentity {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDisplay() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public void setValue(String value) {
|
public void setValue(String value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,6 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package com.cloud.dc.dao;
|
package com.cloud.dc.dao;
|
||||||
|
|
||||||
import org.apache.cloudstack.api.ResourceDetail;
|
|
||||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||||
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
|
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
|
||||||
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
|
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
|
||||||
@ -45,8 +44,8 @@ public class DataCenterDetailsDaoImpl extends ResourceDetailsDaoBase<DataCenterD
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getConfigValue(long id, ConfigKey<?> key) {
|
public String getConfigValue(long id, ConfigKey<?> key) {
|
||||||
ResourceDetail vo = findDetail(id, key.key());
|
DataCenterDetailVO vo = findDetail(id, key.key());
|
||||||
return vo == null ? null : vo.getValue();
|
return vo == null ? null : getActualValue(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -23,18 +23,18 @@ import javax.persistence.GenerationType;
|
|||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import org.apache.cloudstack.api.InternalIdentity;
|
import org.apache.cloudstack.api.ResourceDetail;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "domain_details")
|
@Table(name = "domain_details")
|
||||||
public class DomainDetailVO implements InternalIdentity {
|
public class DomainDetailVO implements ResourceDetail {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "id")
|
@Column(name = "id")
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
@Column(name = "domain_id")
|
@Column(name = "domain_id")
|
||||||
private long domainId;
|
private long resourceId;
|
||||||
|
|
||||||
@Column(name = "name")
|
@Column(name = "name")
|
||||||
private String name;
|
private String name;
|
||||||
@ -46,13 +46,14 @@ public class DomainDetailVO implements InternalIdentity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DomainDetailVO(long domainId, String name, String value) {
|
public DomainDetailVO(long domainId, String name, String value) {
|
||||||
this.domainId = domainId;
|
this.resourceId = domainId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getDomainId() {
|
@Override
|
||||||
return domainId;
|
public long getResourceId() {
|
||||||
|
return resourceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -63,6 +64,11 @@ public class DomainDetailVO implements InternalIdentity {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDisplay() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public void setValue(String value) {
|
public void setValue(String value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,8 +20,9 @@ import java.util.Map;
|
|||||||
|
|
||||||
import com.cloud.domain.DomainDetailVO;
|
import com.cloud.domain.DomainDetailVO;
|
||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
import org.apache.cloudstack.resourcedetail.ResourceDetailsDao;
|
||||||
|
|
||||||
public interface DomainDetailsDao extends GenericDao<DomainDetailVO, Long> {
|
public interface DomainDetailsDao extends GenericDao<DomainDetailVO, Long>, ResourceDetailsDao<DomainDetailVO> {
|
||||||
Map<String, String> findDetails(long domainId);
|
Map<String, String> findDetails(long domainId);
|
||||||
|
|
||||||
void persist(long domainId, Map<String, String> details);
|
void persist(long domainId, Map<String, String> details);
|
||||||
@ -31,6 +32,4 @@ public interface DomainDetailsDao extends GenericDao<DomainDetailVO, Long> {
|
|||||||
void deleteDetails(long domainId);
|
void deleteDetails(long domainId);
|
||||||
|
|
||||||
void update(long domainId, Map<String, String> details);
|
void update(long domainId, Map<String, String> details);
|
||||||
|
|
||||||
String getActualValue(DomainDetailVO domainDetailVO);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,8 +24,6 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import com.cloud.domain.DomainDetailVO;
|
import com.cloud.domain.DomainDetailVO;
|
||||||
import com.cloud.domain.DomainVO;
|
import com.cloud.domain.DomainVO;
|
||||||
import com.cloud.utils.crypt.DBEncryptionUtil;
|
|
||||||
import com.cloud.utils.db.GenericDaoBase;
|
|
||||||
import com.cloud.utils.db.QueryBuilder;
|
import com.cloud.utils.db.QueryBuilder;
|
||||||
import com.cloud.utils.db.SearchBuilder;
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
import com.cloud.utils.db.SearchCriteria;
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
@ -35,9 +33,9 @@ import org.apache.cloudstack.framework.config.ConfigKey;
|
|||||||
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
|
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
|
||||||
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
|
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
|
||||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase;
|
||||||
|
|
||||||
public class DomainDetailsDaoImpl extends GenericDaoBase<DomainDetailVO, Long> implements DomainDetailsDao, ScopedConfigStorage {
|
public class DomainDetailsDaoImpl extends ResourceDetailsDaoBase<DomainDetailVO> implements DomainDetailsDao, ScopedConfigStorage {
|
||||||
protected final SearchBuilder<DomainDetailVO> domainSearch;
|
protected final SearchBuilder<DomainDetailVO> domainSearch;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -47,14 +45,14 @@ public class DomainDetailsDaoImpl extends GenericDaoBase<DomainDetailVO, Long> i
|
|||||||
|
|
||||||
protected DomainDetailsDaoImpl() {
|
protected DomainDetailsDaoImpl() {
|
||||||
domainSearch = createSearchBuilder();
|
domainSearch = createSearchBuilder();
|
||||||
domainSearch.and("domainId", domainSearch.entity().getDomainId(), Op.EQ);
|
domainSearch.and("domainId", domainSearch.entity().getResourceId(), Op.EQ);
|
||||||
domainSearch.done();
|
domainSearch.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> findDetails(long domainId) {
|
public Map<String, String> findDetails(long domainId) {
|
||||||
QueryBuilder<DomainDetailVO> sc = QueryBuilder.create(DomainDetailVO.class);
|
QueryBuilder<DomainDetailVO> sc = QueryBuilder.create(DomainDetailVO.class);
|
||||||
sc.and(sc.entity().getDomainId(), Op.EQ, domainId);
|
sc.and(sc.entity().getResourceId(), Op.EQ, domainId);
|
||||||
List<DomainDetailVO> results = sc.list();
|
List<DomainDetailVO> results = sc.list();
|
||||||
Map<String, String> details = new HashMap<String, String>(results.size());
|
Map<String, String> details = new HashMap<String, String>(results.size());
|
||||||
for (DomainDetailVO r : results) {
|
for (DomainDetailVO r : results) {
|
||||||
@ -80,11 +78,16 @@ public class DomainDetailsDaoImpl extends GenericDaoBase<DomainDetailVO, Long> i
|
|||||||
@Override
|
@Override
|
||||||
public DomainDetailVO findDetail(long domainId, String name) {
|
public DomainDetailVO findDetail(long domainId, String name) {
|
||||||
QueryBuilder<DomainDetailVO> sc = QueryBuilder.create(DomainDetailVO.class);
|
QueryBuilder<DomainDetailVO> sc = QueryBuilder.create(DomainDetailVO.class);
|
||||||
sc.and(sc.entity().getDomainId(), Op.EQ, domainId);
|
sc.and(sc.entity().getResourceId(), Op.EQ, domainId);
|
||||||
sc.and(sc.entity().getName(), Op.EQ, name);
|
sc.and(sc.entity().getName(), Op.EQ, name);
|
||||||
return sc.find();
|
return sc.find();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addDetail(long resourceId, String key, String value, boolean display) {
|
||||||
|
super.addDetail(new DomainDetailVO(resourceId, key, value));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteDetails(long domainId) {
|
public void deleteDetails(long domainId) {
|
||||||
SearchCriteria<DomainDetailVO> sc = domainSearch.create();
|
SearchCriteria<DomainDetailVO> sc = domainSearch.create();
|
||||||
@ -129,13 +132,4 @@ public class DomainDetailsDaoImpl extends GenericDaoBase<DomainDetailVO, Long> i
|
|||||||
}
|
}
|
||||||
return vo == null ? null : getActualValue(vo);
|
return vo == null ? null : getActualValue(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getActualValue(DomainDetailVO domainDetailVO) {
|
|
||||||
ConfigurationVO configurationVO = _configDao.findByName(domainDetailVO.getName());
|
|
||||||
if (configurationVO != null && configurationVO.isEncrypted()) {
|
|
||||||
return DBEncryptionUtil.decrypt(domainDetailVO.getValue());
|
|
||||||
}
|
|
||||||
return domainDetailVO.getValue();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,7 +45,7 @@ public class StoragePoolDetailsDaoImpl extends ResourceDetailsDaoBase<StoragePoo
|
|||||||
@Override
|
@Override
|
||||||
public String getConfigValue(long id, ConfigKey<?> key) {
|
public String getConfigValue(long id, ConfigKey<?> key) {
|
||||||
StoragePoolDetailVO vo = findDetail(id, key.key());
|
StoragePoolDetailVO vo = findDetail(id, key.key());
|
||||||
return vo == null ? null : vo.getValue();
|
return vo == null ? null : getActualValue(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -23,18 +23,18 @@ import javax.persistence.GenerationType;
|
|||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import org.apache.cloudstack.api.InternalIdentity;
|
import org.apache.cloudstack.api.ResourceDetail;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "account_details")
|
@Table(name = "account_details")
|
||||||
public class AccountDetailVO implements InternalIdentity {
|
public class AccountDetailVO implements ResourceDetail {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "id")
|
@Column(name = "id")
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
@Column(name = "account_id")
|
@Column(name = "account_id")
|
||||||
private long accountId;
|
private long resourceId;
|
||||||
|
|
||||||
@Column(name = "name")
|
@Column(name = "name")
|
||||||
private String name;
|
private String name;
|
||||||
@ -46,13 +46,14 @@ public class AccountDetailVO implements InternalIdentity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AccountDetailVO(long accountId, String name, String value) {
|
public AccountDetailVO(long accountId, String name, String value) {
|
||||||
this.accountId = accountId;
|
this.resourceId = accountId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getAccountId() {
|
@Override
|
||||||
return accountId;
|
public long getResourceId() {
|
||||||
|
return resourceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -63,6 +64,11 @@ public class AccountDetailVO implements InternalIdentity {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDisplay() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public void setValue(String value) {
|
public void setValue(String value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,8 +19,9 @@ package com.cloud.user;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
import org.apache.cloudstack.resourcedetail.ResourceDetailsDao;
|
||||||
|
|
||||||
public interface AccountDetailsDao extends GenericDao<AccountDetailVO, Long> {
|
public interface AccountDetailsDao extends GenericDao<AccountDetailVO, Long>, ResourceDetailsDao<AccountDetailVO> {
|
||||||
Map<String, String> findDetails(long accountId);
|
Map<String, String> findDetails(long accountId);
|
||||||
|
|
||||||
void persist(long accountId, Map<String, String> details);
|
void persist(long accountId, Map<String, String> details);
|
||||||
@ -34,6 +35,4 @@ public interface AccountDetailsDao extends GenericDao<AccountDetailVO, Long> {
|
|||||||
* they will get created
|
* they will get created
|
||||||
*/
|
*/
|
||||||
void update(long accountId, Map<String, String> details);
|
void update(long accountId, Map<String, String> details);
|
||||||
|
|
||||||
String getActualValue(AccountDetailVO accountDetailVO);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,6 @@ import java.util.Optional;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import com.cloud.utils.crypt.DBEncryptionUtil;
|
|
||||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||||
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
|
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
|
||||||
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
|
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
|
||||||
@ -34,16 +33,15 @@ import com.cloud.domain.dao.DomainDetailsDao;
|
|||||||
import com.cloud.domain.dao.DomainDao;
|
import com.cloud.domain.dao.DomainDao;
|
||||||
import com.cloud.user.dao.AccountDao;
|
import com.cloud.user.dao.AccountDao;
|
||||||
|
|
||||||
import com.cloud.utils.db.GenericDaoBase;
|
|
||||||
import com.cloud.utils.db.QueryBuilder;
|
import com.cloud.utils.db.QueryBuilder;
|
||||||
import com.cloud.utils.db.SearchBuilder;
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
import com.cloud.utils.db.SearchCriteria;
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
import com.cloud.utils.db.SearchCriteria.Op;
|
import com.cloud.utils.db.SearchCriteria.Op;
|
||||||
import com.cloud.utils.db.TransactionLegacy;
|
import com.cloud.utils.db.TransactionLegacy;
|
||||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase;
|
||||||
|
|
||||||
public class AccountDetailsDaoImpl extends GenericDaoBase<AccountDetailVO, Long> implements AccountDetailsDao, ScopedConfigStorage {
|
public class AccountDetailsDaoImpl extends ResourceDetailsDaoBase<AccountDetailVO> implements AccountDetailsDao, ScopedConfigStorage {
|
||||||
protected final SearchBuilder<AccountDetailVO> accountSearch;
|
protected final SearchBuilder<AccountDetailVO> accountSearch;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -57,14 +55,14 @@ public class AccountDetailsDaoImpl extends GenericDaoBase<AccountDetailVO, Long>
|
|||||||
|
|
||||||
protected AccountDetailsDaoImpl() {
|
protected AccountDetailsDaoImpl() {
|
||||||
accountSearch = createSearchBuilder();
|
accountSearch = createSearchBuilder();
|
||||||
accountSearch.and("accountId", accountSearch.entity().getAccountId(), Op.EQ);
|
accountSearch.and("accountId", accountSearch.entity().getResourceId(), Op.EQ);
|
||||||
accountSearch.done();
|
accountSearch.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> findDetails(long accountId) {
|
public Map<String, String> findDetails(long accountId) {
|
||||||
QueryBuilder<AccountDetailVO> sc = QueryBuilder.create(AccountDetailVO.class);
|
QueryBuilder<AccountDetailVO> sc = QueryBuilder.create(AccountDetailVO.class);
|
||||||
sc.and(sc.entity().getAccountId(), Op.EQ, accountId);
|
sc.and(sc.entity().getResourceId(), Op.EQ, accountId);
|
||||||
List<AccountDetailVO> results = sc.list();
|
List<AccountDetailVO> results = sc.list();
|
||||||
Map<String, String> details = new HashMap<String, String>(results.size());
|
Map<String, String> details = new HashMap<String, String>(results.size());
|
||||||
for (AccountDetailVO r : results) {
|
for (AccountDetailVO r : results) {
|
||||||
@ -90,11 +88,16 @@ public class AccountDetailsDaoImpl extends GenericDaoBase<AccountDetailVO, Long>
|
|||||||
@Override
|
@Override
|
||||||
public AccountDetailVO findDetail(long accountId, String name) {
|
public AccountDetailVO findDetail(long accountId, String name) {
|
||||||
QueryBuilder<AccountDetailVO> sc = QueryBuilder.create(AccountDetailVO.class);
|
QueryBuilder<AccountDetailVO> sc = QueryBuilder.create(AccountDetailVO.class);
|
||||||
sc.and(sc.entity().getAccountId(), Op.EQ, accountId);
|
sc.and(sc.entity().getResourceId(), Op.EQ, accountId);
|
||||||
sc.and(sc.entity().getName(), Op.EQ, name);
|
sc.and(sc.entity().getName(), Op.EQ, name);
|
||||||
return sc.find();
|
return sc.find();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addDetail(long resourceId, String key, String value, boolean display) {
|
||||||
|
super.addDetail(new AccountDetailVO(resourceId, key, value));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteDetails(long accountId) {
|
public void deleteDetails(long accountId) {
|
||||||
SearchCriteria<AccountDetailVO> sc = accountSearch.create();
|
SearchCriteria<AccountDetailVO> sc = accountSearch.create();
|
||||||
@ -154,13 +157,4 @@ public class AccountDetailsDaoImpl extends GenericDaoBase<AccountDetailVO, Long>
|
|||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getActualValue(AccountDetailVO accountDetailVO) {
|
|
||||||
ConfigurationVO configurationVO = _configDao.findByName(accountDetailVO.getName());
|
|
||||||
if (configurationVO != null && configurationVO.isEncrypted()) {
|
|
||||||
return DBEncryptionUtil.decrypt(accountDetailVO.getValue());
|
|
||||||
}
|
|
||||||
return accountDetailVO.getValue();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,4 +97,6 @@ public interface ResourceDetailsDao<R extends ResourceDetail> extends GenericDao
|
|||||||
public void addDetail(long resourceId, String key, String value, boolean display);
|
public void addDetail(long resourceId, String key, String value, boolean display);
|
||||||
|
|
||||||
public List<Long> findResourceIdsByNameAndValueIn(String name, Object[] values);
|
public List<Long> findResourceIdsByNameAndValueIn(String name, Object[] values);
|
||||||
|
|
||||||
|
String getActualValue(ResourceDetail resourceDetail);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.cloud.utils.crypt.DBEncryptionUtil;
|
||||||
import org.apache.cloudstack.api.ResourceDetail;
|
import org.apache.cloudstack.api.ResourceDetail;
|
||||||
|
|
||||||
import com.cloud.utils.db.GenericDaoBase;
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
@ -28,8 +29,16 @@ import com.cloud.utils.db.SearchBuilder;
|
|||||||
import com.cloud.utils.db.SearchCriteria;
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
import com.cloud.utils.db.TransactionLegacy;
|
import com.cloud.utils.db.TransactionLegacy;
|
||||||
import com.cloud.utils.db.SearchCriteria.Op;
|
import com.cloud.utils.db.SearchCriteria.Op;
|
||||||
|
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||||
|
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
public abstract class ResourceDetailsDaoBase<R extends ResourceDetail> extends GenericDaoBase<R, Long> implements ResourceDetailsDao<R> {
|
public abstract class ResourceDetailsDaoBase<R extends ResourceDetail> extends GenericDaoBase<R, Long> implements ResourceDetailsDao<R> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ConfigurationDao configDao;
|
||||||
|
|
||||||
private SearchBuilder<R> AllFieldsSearch;
|
private SearchBuilder<R> AllFieldsSearch;
|
||||||
|
|
||||||
public ResourceDetailsDaoBase() {
|
public ResourceDetailsDaoBase() {
|
||||||
@ -201,4 +210,13 @@ public abstract class ResourceDetailsDaoBase<R extends ResourceDetail> extends G
|
|||||||
|
|
||||||
return customSearch(sc, null);
|
return customSearch(sc, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getActualValue(ResourceDetail resourceDetail) {
|
||||||
|
ConfigurationVO configurationVO = configDao.findByName(resourceDetail.getName());
|
||||||
|
if (configurationVO != null && configurationVO.isEncrypted()) {
|
||||||
|
return DBEncryptionUtil.decrypt(resourceDetail.getValue());
|
||||||
|
}
|
||||||
|
return resourceDetail.getValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,6 @@ import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase;
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class ImageStoreDetailsDaoImpl extends ResourceDetailsDaoBase<ImageStoreDetailVO> implements ImageStoreDetailsDao, ScopedConfigStorage {
|
public class ImageStoreDetailsDaoImpl extends ResourceDetailsDaoBase<ImageStoreDetailVO> implements ImageStoreDetailsDao, ScopedConfigStorage {
|
||||||
|
|
||||||
protected final SearchBuilder<ImageStoreDetailVO> storeSearch;
|
protected final SearchBuilder<ImageStoreDetailVO> storeSearch;
|
||||||
|
|
||||||
public ImageStoreDetailsDaoImpl() {
|
public ImageStoreDetailsDaoImpl() {
|
||||||
@ -108,12 +107,11 @@ public class ImageStoreDetailsDaoImpl extends ResourceDetailsDaoBase<ImageStoreD
|
|||||||
@Override
|
@Override
|
||||||
public String getConfigValue(long id, ConfigKey<?> key) {
|
public String getConfigValue(long id, ConfigKey<?> key) {
|
||||||
ImageStoreDetailVO vo = findDetail(id, key.key());
|
ImageStoreDetailVO vo = findDetail(id, key.key());
|
||||||
return vo == null ? null : vo.getValue();
|
return vo == null ? null : getActualValue(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addDetail(long resourceId, String key, String value, boolean display) {
|
public void addDetail(long resourceId, String key, String value, boolean display) {
|
||||||
super.addDetail(new ImageStoreDetailVO(resourceId, key, value, display));
|
super.addDetail(new ImageStoreDetailVO(resourceId, key, value, display));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user