Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ CALL `cloud`.`IDEMPOTENT_CHANGE_COLUMN`('router_health_check', 'check_result', '
-- Increase length of scripts_version column to 128 due to md5sum to sha512sum change
CALL `cloud`.`IDEMPOTENT_CHANGE_COLUMN`('cloud.domain_router', 'scripts_version', 'scripts_version', 'VARCHAR(128)');

-- Add uuid column to ldap_configuration table
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.ldap_configuration', 'uuid', 'VARCHAR(40) NOT NULL');

-- Populate uuid for existing rows where uuid is NULL or empty
UPDATE `cloud`.`ldap_configuration` SET uuid = UUID() WHERE uuid IS NULL OR uuid = '';

-- Add the column cross_zone_instance_creation to cloud.backup_repository. if enabled it means that new Instance can be created on all Zones from Backups on this Repository.
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.backup_repository', 'cross_zone_instance_creation', 'TINYINT(1) DEFAULT NULL COMMENT ''Backup Repository can be used for disaster recovery on another zone''');
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public class LdapDeleteConfigurationCmd extends BaseCmd {
@Inject
private LdapManager _ldapManager;

@Parameter(name = ApiConstants.ID, type = CommandType.UUID, required = false, entityType = LdapConfigurationResponse.class, description = "ID of the LDAP configuration")
private Long id;

@Parameter(name = ApiConstants.HOST_NAME, type = CommandType.STRING, required = true, description = "Hostname")
@Parameter(name = ApiConstants.HOST_NAME, type = CommandType.STRING, description = "Hostname")
private String hostname;

@Parameter(name = ApiConstants.PORT, type = CommandType.INTEGER, required = false, description = "port")
Expand Down Expand Up @@ -71,6 +73,10 @@ public Long getDomainId() {
return domainId;
}

public Long getId() {
return id;
}

@Override
public void execute() throws ServerApiException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public class LdapListConfigurationCmd extends BaseListCmd {
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = false, entityType = DomainResponse.class, description = "linked domain")
private Long domainId;

@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = LdapConfigurationResponse.class, description = "list ldap configuration by ID")
private Long id;

@Parameter(name = ApiConstants.LIST_ALL, type = CommandType.BOOLEAN, description = "If set to true, "
+ " and no domainid specified, list all LDAP configurations irrespective of the linked domain", since = "4.13.2")
private Boolean listAll;
Expand Down Expand Up @@ -120,6 +123,10 @@ public void setDomainId(final Long domainId) {
this.domainId = domainId;
}

public Long getId() {
return id;
}

public boolean listAll() {
return listAll != null && listAll;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@

import com.cloud.serializer.Param;
import org.apache.cloudstack.api.EntityReference;
import org.apache.cloudstack.ldap.LdapConfiguration;
import org.apache.cloudstack.ldap.LdapConfigurationVO;

@EntityReference(value = LdapConfiguration.class)
@EntityReference(value = LdapConfigurationVO.class)
public class LdapConfigurationResponse extends BaseResponse {
@SerializedName("id")
@Param(description = "the ID of the LDAP configuration")
private String id;

@SerializedName(ApiConstants.HOST_NAME)
@Param(description = "name of the host running the ldap server")
private String hostname;
Expand All @@ -53,9 +57,18 @@ public LdapConfigurationResponse(final String hostname, final int port) {
setPort(port);
}

public LdapConfigurationResponse(final String hostname, final int port, final String domainId) {
public LdapConfigurationResponse(final String hostname, final int port, final String domainId, final String id) {
this(hostname, port);
setDomainId(domainId);
setId(id);
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getHostname() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,40 @@
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;

import java.util.UUID;

@Entity
@Table(name = "ldap_configuration")
public class LdapConfigurationVO implements InternalIdentity {
@Column(name = "hostname")
private String hostname;

public class LdapConfigurationVO implements Identity, InternalIdentity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@Column(name = "hostname")
private String hostname;

@Column(name = "uuid")
private String uuid;

@Column(name = "port")
private int port;

@Column(name = "domain_id")
private Long domainId;

public LdapConfigurationVO() {
this.uuid = UUID.randomUUID().toString();
}

public LdapConfigurationVO(final String hostname, final int port, final Long domainId) {
this.hostname = hostname;
this.port = port;
this.domainId = domainId;
this.uuid = UUID.randomUUID().toString();
}

public String getHostname() {
Expand All @@ -60,6 +68,10 @@ public long getId() {
return id;
}

public String getUuid() {
return uuid;
}

public int getPort() {
return port;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.cloudstack.ldap.dao.LdapConfigurationDao;
import org.apache.cloudstack.ldap.dao.LdapTrustMapDao;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import com.cloud.domain.DomainVO;
Expand Down Expand Up @@ -240,7 +241,7 @@ public LdapConfigurationResponse createLdapConfigurationResponse(final LdapConfi
domainUuid = domain.getUuid();
}
}
return new LdapConfigurationResponse(configuration.getHostname(), configuration.getPort(), domainUuid);
return new LdapConfigurationResponse(configuration.getHostname(), configuration.getPort(), domainUuid, configuration.getUuid());
}

@Override
Expand All @@ -257,6 +258,19 @@ public LdapUserResponse createLdapUserResponse(final LdapUser user) {

@Override
public LdapConfigurationResponse deleteConfiguration(final LdapDeleteConfigurationCmd cmd) throws InvalidParameterValueException {
Long id = cmd.getId();
String hostname = cmd.getHostname();
if (id == null && StringUtils.isEmpty(hostname)) {
throw new InvalidParameterValueException("Either id or hostname must be specified");
}
if (id != null) {
final LdapConfigurationVO config = _ldapConfigurationDao.findById(cmd.getId());
if (config != null) {
_ldapConfigurationDao.remove(config.getId());
return createLdapConfigurationResponse(config);
}
throw new InvalidParameterValueException("Cannot find configuration with id " + id);
}
return deleteConfigurationInternal(cmd.getHostname(), cmd.getPort(), cmd.getDomainId());
}

Expand Down Expand Up @@ -377,7 +391,8 @@ public Pair<List<? extends LdapConfigurationVO>, Integer> listConfigurations(fin
final int port = cmd.getPort();
final Long domainId = cmd.getDomainId();
final boolean listAll = cmd.listAll();
final Pair<List<LdapConfigurationVO>, Integer> result = _ldapConfigurationDao.searchConfigurations(hostname, port, domainId, listAll);
final Long id = cmd.getId();
final Pair<List<LdapConfigurationVO>, Integer> result = _ldapConfigurationDao.searchConfigurations(id, hostname, port, domainId, listAll);
return new Pair<List<? extends LdapConfigurationVO>, Integer>(result.first(), result.second());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ public interface LdapConfigurationDao extends GenericDao<LdapConfigurationVO, Lo

Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(String hostname, int port, Long domainId);

Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(String hostname, int port, Long domainId, boolean listAll);
Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(Long id, String hostname, int port, Long domainId, boolean listAll);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public LdapConfigurationDaoImpl() {
listGlobalConfigurationsSearch.done();

listDomainConfigurationsSearch = createSearchBuilder();
listDomainConfigurationsSearch.and("id", listDomainConfigurationsSearch.entity().getId(), SearchCriteria.Op.EQ);
listDomainConfigurationsSearch.and("hostname", listDomainConfigurationsSearch.entity().getHostname(), Op.EQ);
listDomainConfigurationsSearch.and("port", listDomainConfigurationsSearch.entity().getPort(), Op.EQ);
listDomainConfigurationsSearch.and("domain_id", listDomainConfigurationsSearch.entity().getDomainId(), Op.EQ);
Expand All @@ -63,31 +64,35 @@ public LdapConfigurationVO findByHostname(final String hostname) {

@Override
public LdapConfigurationVO find(String hostname, int port, Long domainId) {
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, false);
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(null, hostname, port, domainId, false);
return findOneBy(sc);
}

@Override
public LdapConfigurationVO find(String hostname, int port, Long domainId, boolean listAll) {
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, listAll);
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(null, hostname, port, domainId, listAll);
return findOneBy(sc);
}

@Override
public Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(final String hostname, final int port, final Long domainId) {
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, false);
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(null, hostname, port, domainId, false);
return searchAndCount(sc, null);
}

@Override
public Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(final String hostname, final int port, final Long domainId, final boolean listAll) {
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, listAll);
public Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(final Long id, final String hostname, final int port, final Long domainId, final boolean listAll) {
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(id, hostname, port, domainId, listAll);
return searchAndCount(sc, null);
}

private SearchCriteria<LdapConfigurationVO> getSearchCriteria(String hostname, int port, Long domainId,boolean listAll) {
private SearchCriteria<LdapConfigurationVO> getSearchCriteria(Long id, String hostname, int port, Long domainId,boolean listAll) {
SearchCriteria<LdapConfigurationVO> sc;
if (domainId != null) {
if (id != null) {
// If id is present, ignore all other parameters
sc = listDomainConfigurationsSearch.create();
sc.setParameters("id", id);
} else if (domainId != null) {
// If domainid is present, ignore listall
sc = listDomainConfigurationsSearch.create();
sc.setParameters("domain_id", domainId);
Expand Down
2 changes: 1 addition & 1 deletion ui/src/config/section/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default {
permission: ['listLdapConfigurations'],
searchFilters: ['domainid', 'hostname', 'port'],
columns: ['hostname', 'port', 'domainid'],
details: ['hostname', 'port', 'domainid'],
details: ['id', 'hostname', 'port', 'domainid'],
actions: [
{
api: 'addLdapConfiguration',
Expand Down
5 changes: 0 additions & 5 deletions ui/src/views/AutogenView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1078,8 +1078,6 @@ export default {
}
if (this.$route.path.startsWith('/vmsnapshot/')) {
params.vmsnapshotid = this.$route.params.id
} else if (this.$route.path.startsWith('/ldapsetting/')) {
params.hostname = this.$route.params.id
}
if (this.$route.path.startsWith('/tungstenpolicy/')) {
params.policyuuid = this.$route.params.id
Expand Down Expand Up @@ -1192,9 +1190,6 @@ export default {
this.items[idx][key] = func(this.items[idx])
}
}
if (this.$route.path.startsWith('/ldapsetting')) {
this.items[idx].id = this.items[idx].hostname
}
}
if (this.items.length > 0) {
if (!this.showAction || this.dataView) {
Expand Down
12 changes: 6 additions & 6 deletions ui/tests/unit/views/AutogenView.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,12 +652,12 @@ describe('Views > AutogenView.vue', () => {
testapinamecase1response: {
count: 0,
testapinamecase1: [{
id: 'test-id-1',
id: 'uuid1',
name: 'test-name-1'
}]
}
})
await router.push({ name: 'testRouter13', params: { id: 'test-id' } })
await router.push({ name: 'testRouter13', params: { id: 'uuid1' } })
await flushPromises()

expect(mockAxios).toHaveBeenCalled()
Expand All @@ -668,8 +668,7 @@ describe('Views > AutogenView.vue', () => {
command: 'testApiNameCase1',
response: 'json',
listall: true,
id: 'test-id',
hostname: 'test-id',
id: 'uuid1',
page: 1,
pagesize: 20
})
Expand Down Expand Up @@ -777,6 +776,7 @@ describe('Views > AutogenView.vue', () => {
testapinamecase1response: {
count: 1,
testapinamecase1: [{
id: 'uuid1',
name: 'test-name-value',
hostname: 'test-hostname-value'
}]
Expand All @@ -786,13 +786,13 @@ describe('Views > AutogenView.vue', () => {
await flushPromises()

expect(wrapper.vm.items).toEqual([{
id: 'test-hostname-value',
id: 'uuid1',
name: 'test-name-value',
hostname: 'test-hostname-value',
key: 0
}])
expect(wrapper.vm.resource).toEqual({
id: 'test-hostname-value',
id: 'uuid1',
name: 'test-name-value',
hostname: 'test-hostname-value',
key: 0
Expand Down
Loading