Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ repos:
exclude: >
(?x)
^scripts/vm/systemvm/id_rsa\.cloud$|
^server/src/test/java/org/apache/cloudstack/network/ssl/CertServiceTest.java$|
^server/src/test/java/com/cloud/keystore/KeystoreTest\.java$|
^server/src/test/resources/certs/dsa_self_signed\.key$|
^server/src/test/resources/certs/non_root\.key$|
Expand All @@ -57,7 +58,8 @@ repos:
^server/src/test/resources/certs/rsa_self_signed\.key$|
^services/console-proxy/rdpconsole/src/test/doc/rdp-key\.pem$|
^systemvm/agent/certs/localhost\.key$|
^systemvm/agent/certs/realhostip\.key$
^systemvm/agent/certs/realhostip\.key$|
^test/integration/smoke/test_ssl_offloading.py$
- id: end-of-file-fixer
exclude: \.vhd$
- id: fix-byte-order-marker
Expand All @@ -75,7 +77,7 @@ repos:
name: run codespell
description: Check spelling with codespell
args: [--ignore-words=.github/linters/codespell.txt]
exclude: ^systemvm/agent/noVNC/|^ui/package\.json$|^ui/package-lock\.json$|^ui/public/js/less\.min\.js$|^ui/public/locales/.*[^n].*\.json$
exclude: ^systemvm/agent/noVNC/|^ui/package\.json$|^ui/package-lock\.json$|^ui/public/js/less\.min\.js$|^ui/public/locales/.*[^n].*\.json$|^server/src/test/java/org/apache/cloudstack/network/ssl/CertServiceTest.java$|^test/integration/smoke/test_ssl_offloading.py$
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
Expand Down
6 changes: 5 additions & 1 deletion api/src/main/java/com/cloud/agent/api/to/LoadBalancerTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public LoadBalancerTO(String uuid, String srcIp, int srcPort, String protocol, S
this.destinations = new DestinationTO[destinations.size()];
this.stickinessPolicies = null;
this.sslCert = null;
this.lbProtocol = null;
this.lbProtocol = protocol;
int i = 0;
for (LbDestination destination : destinations) {
this.destinations[i++] = new DestinationTO(destination.getIpAddress(), destination.getDestinationPortStart(), destination.isRevoked(), false);
Expand Down Expand Up @@ -205,6 +205,10 @@ public LbSslCert getSslCert() {
return this.sslCert;
}

public void setLbSslCert(LbSslCert sslCert) {
this.sslCert = sslCert;
}

public String getSrcIpVlan() {
return srcIpVlan;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ LoadBalancer createPublicLoadBalancerRule(String xId, String name, String descri

boolean applyLoadBalancerConfig(long lbRuleId) throws ResourceUnavailableException;

boolean assignCertToLoadBalancer(long lbRuleId, Long certId);
boolean assignCertToLoadBalancer(long lbRuleId, Long certId, boolean isForced);

boolean removeCertFromLoadBalancer(long lbRuleId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.cloudstack.api.response.FirewallRuleResponse;
import org.apache.cloudstack.api.response.SslCertResponse;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.commons.lang3.BooleanUtils;

import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
Expand Down Expand Up @@ -57,11 +58,17 @@ public class AssignCertToLoadBalancerCmd extends BaseAsyncCmd {
description = "the ID of the certificate")
Long certId;

@Parameter(name = ApiConstants.FORCED,
type = CommandType.BOOLEAN,
since = "4.22",
description = "Force assign the certificate. If there is a certificate assigned to the LB, it will be removed at first.")
private Boolean forced;

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,
ResourceAllocationException, NetworkRuleConflictException {
//To change body of implemented methods use File | Settings | File Templates.
if (_lbService.assignCertToLoadBalancer(getLbRuleId(), getCertId())) {
if (_lbService.assignCertToLoadBalancer(getLbRuleId(), getCertId(), isForced())) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
} else {
Expand Down Expand Up @@ -95,4 +102,19 @@ public Long getCertId() {
public Long getLbRuleId() {
return lbRuleId;
}

public boolean isForced() {
return BooleanUtils.toBoolean(forced);
}

@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
}

@Override
public Long getSyncObjId() {
LoadBalancer lb = _entityMgr.findById(LoadBalancer.class, getLbRuleId());
return (lb != null)? lb.getNetworkId(): null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.cloudstack.api.response.NetworkResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.commons.lang3.StringUtils;

import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
Expand Down Expand Up @@ -112,7 +113,7 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements L
+ "rule will be created for. Required when public Ip address is not associated with any Guest network yet (VPC case)")
private Long networkId;

@Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, description = "The protocol for the LB such as tcp, udp or tcp-proxy.")
@Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, description = "The protocol for the LB such as tcp, udp, tcp-proxy or ssl.")
private String lbProtocol;

@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the rule to the end user or not", since = "4.4", authorized = {RoleType.Admin})
Expand Down Expand Up @@ -253,7 +254,7 @@ public List<String> getSourceCidrList() {
}

public String getLbProtocol() {
return lbProtocol;
return StringUtils.trim(StringUtils.lowerCase(lbProtocol));
}

/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,15 @@ public long getEntityOwnerId() {
public Long getLbRuleId() {
return this.lbRuleId;
}

@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
}

@Override
public Long getSyncObjId() {
LoadBalancer lb = _entityMgr.findById(LoadBalancer.class, getLbRuleId());
return (lb != null)? lb.getNetworkId(): null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) {
final String[] statRules = allRules[LoadBalancerConfigurator.STATS];

final LoadBalancerRule loadBalancerRule = new LoadBalancerRule(configuration, tmpCfgFilePath, tmpCfgFileName, addRules, removeRules, statRules, routerIp);
final LoadBalancerRule.SslCertEntry[] sslCerts = cfgtr.generateSslCertEntries(command);
loadBalancerRule.setSslCerts(sslCerts);

final List<LoadBalancerRule> rules = new LinkedList<LoadBalancerRule>();
rules.add(loadBalancerRule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,61 @@ public class LoadBalancerRule {
private String[] configuration;
private String tmpCfgFilePath;
private String tmpCfgFileName;
private SslCertEntry[] sslCerts;

private String[] addRules;
private String[] removeRules;
private String[] statRules;

private String routerIp;

public static class SslCertEntry {
private String name;
private String cert;
private String key;
private String chain;
private String password;

public SslCertEntry(String name, String cert, String key, String chain, String password) {
this.name = name;
this.cert = cert;
this.key = key;
this.chain = chain;
this.password = password;
}

public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setCert(String cert) {
this.cert = cert;
}
public String getCert() {
return cert;
}
public void setKey(String key) {
this.key = key;
}
public String getKey() {
return key;
}
public void setChain(String chain) {
this.chain = chain;
}
public String getChain() {
return chain;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
}

public LoadBalancerRule() {
// Empty constructor for (de)serialization
}
Expand Down Expand Up @@ -101,4 +149,12 @@ public String getRouterIp() {
public void setRouterIp(final String routerIp) {
this.routerIp = routerIp;
}

public SslCertEntry[] getSslCerts() {
return sslCerts;
}

public void setSslCerts(final SslCertEntry[] sslCerts) {
this.sslCerts = sslCerts;
}
}
Loading
Loading