Search in sources :

Example 1 with SslCertResponse

use of com.cloud.api.response.SslCertResponse in project cosmic by MissionCriticalCloud.

the class UploadSslCertCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        final SslCertResponse response = _certService.uploadSslCert(this);
        setResponseObject(response);
        response.setResponseName(getCommandName());
    } catch (final Exception e) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) SslCertResponse(com.cloud.api.response.SslCertResponse) ServerApiException(com.cloud.api.ServerApiException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 2 with SslCertResponse

use of com.cloud.api.response.SslCertResponse in project cosmic by MissionCriticalCloud.

the class CertServiceImpl method listSslCerts.

@Override
public List<SslCertResponse> listSslCerts(final ListSslCertsCmd listSslCertCmd) {
    final CallContext ctx = CallContext.current();
    final Account caller = ctx.getCallingAccount();
    final Long certId = listSslCertCmd.getCertId();
    final Long accountId = listSslCertCmd.getAccountId();
    final Long lbRuleId = listSslCertCmd.getLbId();
    final Long projectId = listSslCertCmd.getProjectId();
    final List<SslCertResponse> certResponseList = new ArrayList<>();
    if (certId == null && accountId == null && lbRuleId == null && projectId == null) {
        throw new InvalidParameterValueException("Invalid parameters either certificate ID or Account ID or Loadbalancer ID or Project ID required");
    }
    List<LoadBalancerCertMapVO> certLbMap = null;
    SslCertVO certVO = null;
    if (certId != null) {
        certVO = _sslCertDao.findById(certId);
        if (certVO == null) {
            throw new InvalidParameterValueException("Invalid certificate id: " + certId);
        }
        _accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, certVO);
        certLbMap = _lbCertDao.listByCertId(certId);
        certResponseList.add(createCertResponse(certVO, certLbMap));
        return certResponseList;
    }
    if (lbRuleId != null) {
        final LoadBalancer lb = _entityMgr.findById(LoadBalancerVO.class, lbRuleId);
        if (lb == null) {
            throw new InvalidParameterValueException("Found no loadbalancer with id: " + lbRuleId);
        }
        _accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, lb);
        // get the cert id
        final LoadBalancerCertMapVO lbCertMapRule;
        lbCertMapRule = _lbCertDao.findByLbRuleId(lbRuleId);
        if (lbCertMapRule == null) {
            s_logger.debug("No certificate bound to loadbalancer id: " + lbRuleId);
            return certResponseList;
        }
        certVO = _sslCertDao.findById(lbCertMapRule.getCertId());
        certLbMap = _lbCertDao.listByCertId(lbCertMapRule.getCertId());
        certResponseList.add(createCertResponse(certVO, certLbMap));
        return certResponseList;
    }
    if (projectId != null) {
        final Project project = _projectMgr.getProject(projectId);
        if (project == null) {
            throw new InvalidParameterValueException("Found no project with id: " + projectId);
        }
        final List<SslCertVO> projectCertVOList = _sslCertDao.listByAccountId(project.getProjectAccountId());
        if (projectCertVOList == null || projectCertVOList.isEmpty()) {
            return certResponseList;
        }
        _accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, projectCertVOList.get(0));
        for (final SslCertVO cert : projectCertVOList) {
            certLbMap = _lbCertDao.listByCertId(cert.getId());
            certResponseList.add(createCertResponse(cert, certLbMap));
        }
        return certResponseList;
    }
    // reached here look by accountId
    final List<SslCertVO> certVOList = _sslCertDao.listByAccountId(accountId);
    if (certVOList == null || certVOList.isEmpty()) {
        return certResponseList;
    }
    _accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, certVOList.get(0));
    for (final SslCertVO cert : certVOList) {
        certLbMap = _lbCertDao.listByCertId(cert.getId());
        certResponseList.add(createCertResponse(cert, certLbMap));
    }
    return certResponseList;
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) LoadBalancerCertMapVO(com.cloud.network.dao.LoadBalancerCertMapVO) LoadBalancer(com.cloud.network.rules.LoadBalancer) CallContext(com.cloud.context.CallContext) Project(com.cloud.projects.Project) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) SslCertVO(com.cloud.network.dao.SslCertVO) SslCertResponse(com.cloud.api.response.SslCertResponse)

Example 3 with SslCertResponse

use of com.cloud.api.response.SslCertResponse in project cosmic by MissionCriticalCloud.

the class CertServiceImpl method createCertResponse.

public SslCertResponse createCertResponse(final SslCertVO cert, final List<LoadBalancerCertMapVO> lbCertMap) {
    final SslCertResponse response = new SslCertResponse();
    final Account account = _accountDao.findByIdIncludingRemoved(cert.getAccountId());
    if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
        // find the project
        final Project project = _projectMgr.findByProjectAccountIdIncludingRemoved(account.getId());
        if (project != null) {
            response.setProjectId(project.getUuid());
            response.setProjectName(project.getName());
        } else {
            response.setAccountName(account.getAccountName());
        }
    } else {
        response.setAccountName(account.getAccountName());
    }
    final DomainVO domain = _domainDao.findByIdIncludingRemoved(cert.getDomainId());
    response.setDomainId(domain.getUuid());
    response.setDomainName(domain.getName());
    response.setObjectName("sslcert");
    response.setId(cert.getUuid());
    response.setCertificate(cert.getCertificate());
    response.setFingerprint(cert.getFingerPrint());
    if (cert.getChain() != null) {
        response.setCertchain(cert.getChain());
    }
    if (lbCertMap != null && !lbCertMap.isEmpty()) {
        final List<String> lbIds = new ArrayList<>();
        for (final LoadBalancerCertMapVO mapVO : lbCertMap) {
            final LoadBalancer lb = _entityMgr.findById(LoadBalancerVO.class, mapVO.getLbId());
            if (lb != null) {
                lbIds.add(lb.getUuid());
            }
        }
        response.setLbIds(lbIds);
    }
    return response;
}
Also used : Account(com.cloud.user.Account) Project(com.cloud.projects.Project) DomainVO(com.cloud.domain.DomainVO) ArrayList(java.util.ArrayList) LoadBalancerCertMapVO(com.cloud.network.dao.LoadBalancerCertMapVO) LoadBalancer(com.cloud.network.rules.LoadBalancer) SslCertResponse(com.cloud.api.response.SslCertResponse)

Example 4 with SslCertResponse

use of com.cloud.api.response.SslCertResponse in project cosmic by MissionCriticalCloud.

the class ListSslCertsCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    try {
        final List<SslCertResponse> certResponseList = _certService.listSslCerts(this);
        final ListResponse<SslCertResponse> response = new ListResponse<>();
        response.setResponses(certResponseList);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (final Exception e) {
        throw new CloudRuntimeException(e);
    }
}
Also used : ListResponse(com.cloud.api.response.ListResponse) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SslCertResponse(com.cloud.api.response.SslCertResponse) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

SslCertResponse (com.cloud.api.response.SslCertResponse)4 LoadBalancerCertMapVO (com.cloud.network.dao.LoadBalancerCertMapVO)2 LoadBalancer (com.cloud.network.rules.LoadBalancer)2 Project (com.cloud.projects.Project)2 Account (com.cloud.user.Account)2 ArrayList (java.util.ArrayList)2 ServerApiException (com.cloud.api.ServerApiException)1 ListResponse (com.cloud.api.response.ListResponse)1 CallContext (com.cloud.context.CallContext)1 DomainVO (com.cloud.domain.DomainVO)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)1 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 SslCertVO (com.cloud.network.dao.SslCertVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)1