Skip to content

Commit d0ae4d9

Browse files
committed
CLOUDSTACK-5920:Add interface to ControlledEntity to return IAM
entity type.
1 parent b8413b9 commit d0ae4d9

62 files changed

Lines changed: 778 additions & 318 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/src/com/cloud/network/NetworkProfile.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.net.URI;
2020

21+
import org.apache.cloudstack.acl.IAMEntityType;
22+
2123
import com.cloud.network.Networks.BroadcastDomainType;
2224
import com.cloud.network.Networks.Mode;
2325
import com.cloud.network.Networks.TrafficType;
@@ -275,4 +277,9 @@ public String getIp6Gateway() {
275277
public String getIp6Cidr() {
276278
return ip6Cidr;
277279
}
280+
281+
@Override
282+
public IAMEntityType getEntityType() {
283+
return IAMEntityType.Network;
284+
}
278285
}

api/src/com/cloud/network/vpc/StaticRouteProfile.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// under the License.
1717
package com.cloud.network.vpc;
1818

19+
import org.apache.cloudstack.acl.IAMEntityType;
20+
1921
public class StaticRouteProfile implements StaticRoute {
2022
private long id;
2123
private String uuid;
@@ -31,18 +33,18 @@ public class StaticRouteProfile implements StaticRoute {
3133
String ipAddress;
3234

3335
public StaticRouteProfile(StaticRoute staticRoute, VpcGateway gateway) {
34-
this.id = staticRoute.getId();
35-
this.uuid = staticRoute.getUuid();
36-
this.targetCidr = staticRoute.getCidr();
37-
this.accountId = staticRoute.getAccountId();
38-
this.domainId = staticRoute.getDomainId();
39-
this.gatewayId = staticRoute.getVpcGatewayId();
40-
this.state = staticRoute.getState();
41-
this.vpcId = staticRoute.getVpcId();
42-
this.vlanTag = gateway.getBroadcastUri();
36+
id = staticRoute.getId();
37+
uuid = staticRoute.getUuid();
38+
targetCidr = staticRoute.getCidr();
39+
accountId = staticRoute.getAccountId();
40+
domainId = staticRoute.getDomainId();
41+
gatewayId = staticRoute.getVpcGatewayId();
42+
state = staticRoute.getState();
43+
vpcId = staticRoute.getVpcId();
44+
vlanTag = gateway.getBroadcastUri();
4345
this.gateway = gateway.getGateway();
44-
this.netmask = gateway.getNetmask();
45-
this.ipAddress = gateway.getIp4Address();
46+
netmask = gateway.getNetmask();
47+
ipAddress = gateway.getIp4Address();
4648
}
4749

4850
@Override
@@ -101,4 +103,8 @@ public String getNetmask() {
101103
return netmask;
102104
}
103105

106+
@Override
107+
public IAMEntityType getEntityType() {
108+
return IAMEntityType.StaticRoute;
109+
}
104110
}

api/src/org/apache/cloudstack/acl/ControlledEntity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ public enum ACLType {
2929
Account, Domain
3030
}
3131

32+
IAMEntityType getEntityType();
3233
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.apache.cloudstack.acl;
2+
3+
public enum IAMEntityType {
4+
// currently supported entity, to be added one by one after we support acl on the entity
5+
VirtualMachine,
6+
Volume,
7+
ResourceTag,
8+
Account,
9+
AffinityGroup,
10+
AutoScalePolicy,
11+
AutoScaleVmGroup,
12+
AutoScaleVmProfile,
13+
Condition,
14+
Vpc,
15+
VpcGateway,
16+
PrivateGateway,
17+
VpnUser,
18+
VMSnapshot,
19+
VirtualMachineTemplate,
20+
UserIpv6Address,
21+
StaticRoute,
22+
SSHKeyPair,
23+
Snapshot,
24+
Site2SiteVpnGateway,
25+
Site2SiteVpnConnection,
26+
Site2SiteCustomerGateway,
27+
SecurityGroup,
28+
RemoteAccessVpn,
29+
PublicIpAddress,
30+
ProjectInvitation,
31+
NicSecondaryIp,
32+
NicIpAlias,
33+
Network,
34+
IpAddress,
35+
InstanceGroup,
36+
GlobalLoadBalancerRule,
37+
FirewallRule,
38+
PortForwardingRule,
39+
Event,
40+
AsyncJob,
41+
IAMPolicy,
42+
IAMGroup,
43+
MonitorService,
44+
SSLCert
45+
}

api/src/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import java.util.ArrayList;
2121
import java.util.List;
2222

23+
import org.apache.log4j.Logger;
24+
25+
import org.apache.cloudstack.acl.IAMEntityType;
2326
import org.apache.cloudstack.acl.RoleType;
2427
import org.apache.cloudstack.api.APICommand;
2528
import org.apache.cloudstack.api.ApiCommandJobType;
@@ -32,7 +35,6 @@
3235
import org.apache.cloudstack.api.response.FirewallResponse;
3336
import org.apache.cloudstack.api.response.NetworkResponse;
3437
import org.apache.cloudstack.context.CallContext;
35-
import org.apache.log4j.Logger;
3638

3739
import com.cloud.event.EventTypes;
3840
import com.cloud.exception.InvalidParameterValueException;
@@ -275,7 +277,7 @@ public String getEventType() {
275277
@Override
276278
public String getEventDescription() {
277279
Network network = _networkService.getNetwork(networkId);
278-
return ("Creating firewall rule for network: " + network + " for protocol:" + this.getProtocol());
280+
return ("Creating firewall rule for network: " + network + " for protocol:" + getProtocol());
279281
}
280282

281283
@Override
@@ -354,4 +356,9 @@ public boolean isDisplay() {
354356
}
355357
}
356358

359+
@Override
360+
public IAMEntityType getEntityType() {
361+
return IAMEntityType.FirewallRule;
362+
}
363+
357364
}

api/src/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22+
import org.apache.log4j.Logger;
23+
24+
import org.apache.cloudstack.acl.IAMEntityType;
2225
import org.apache.cloudstack.acl.RoleType;
2326
import org.apache.cloudstack.api.APICommand;
2427
import org.apache.cloudstack.api.ApiCommandJobType;
@@ -31,7 +34,6 @@
3134
import org.apache.cloudstack.api.response.FirewallResponse;
3235
import org.apache.cloudstack.api.response.IPAddressResponse;
3336
import org.apache.cloudstack.context.CallContext;
34-
import org.apache.log4j.Logger;
3537

3638
import com.cloud.event.EventTypes;
3739
import com.cloud.exception.InvalidParameterValueException;
@@ -266,7 +268,7 @@ public String getEventType() {
266268
@Override
267269
public String getEventDescription() {
268270
IpAddress ip = _networkService.getIp(ipAddressId);
269-
return ("Creating firewall rule for Ip: " + ip.getAddress() + " for protocol:" + this.getProtocol());
271+
return ("Creating firewall rule for Ip: " + ip.getAddress() + " for protocol:" + getProtocol());
270272
}
271273

272274
@Override
@@ -346,4 +348,10 @@ public boolean isDisplay() {
346348
return true;
347349
}
348350
}
351+
352+
@Override
353+
public IAMEntityType getEntityType() {
354+
return IAMEntityType.FirewallRule;
355+
}
356+
349357
}

api/src/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import java.util.List;
2020

21+
import org.apache.log4j.Logger;
22+
23+
import org.apache.cloudstack.acl.IAMEntityType;
2124
import org.apache.cloudstack.acl.RoleType;
2225
import org.apache.cloudstack.api.APICommand;
2326
import org.apache.cloudstack.api.ApiCommandJobType;
@@ -32,7 +35,6 @@
3235
import org.apache.cloudstack.api.response.NetworkResponse;
3336
import org.apache.cloudstack.api.response.UserVmResponse;
3437
import org.apache.cloudstack.context.CallContext;
35-
import org.apache.log4j.Logger;
3638

3739
import com.cloud.event.EventTypes;
3840
import com.cloud.exception.InvalidParameterValueException;
@@ -428,4 +430,10 @@ public boolean isDisplay() {
428430
return true;
429431
}
430432
}
433+
434+
@Override
435+
public IAMEntityType getEntityType() {
436+
return IAMEntityType.FirewallRule;
437+
}
438+
431439
}

api/src/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import java.util.List;
2020

21+
import org.apache.log4j.Logger;
22+
23+
import org.apache.cloudstack.acl.IAMEntityType;
2124
import org.apache.cloudstack.api.APICommand;
2225
import org.apache.cloudstack.api.ApiCommandJobType;
2326
import org.apache.cloudstack.api.ApiConstants;
@@ -30,7 +33,6 @@
3033
import org.apache.cloudstack.api.response.IPAddressResponse;
3134
import org.apache.cloudstack.api.response.IpForwardingRuleResponse;
3235
import org.apache.cloudstack.context.CallContext;
33-
import org.apache.log4j.Logger;
3436

3537
import com.cloud.event.EventTypes;
3638
import com.cloud.exception.InvalidParameterValueException;
@@ -126,7 +128,7 @@ public void execute() throws ResourceUnavailableException {
126128
StaticNatRule staticNatRule = _rulesService.buildStaticNatRule(rule, false);
127129
IpForwardingRuleResponse fwResponse = _responseGenerator.createIpForwardingRuleResponse(staticNatRule);
128130
fwResponse.setResponseName(getCommandName());
129-
this.setResponseObject(fwResponse);
131+
setResponseObject(fwResponse);
130132
} finally {
131133
if (!result || rule == null) {
132134

@@ -152,8 +154,8 @@ public void create() {
152154

153155
try {
154156
StaticNatRule rule = _rulesService.createStaticNatRule(this, getOpenFirewall());
155-
this.setEntityId(rule.getId());
156-
this.setEntityUuid(rule.getUuid());
157+
setEntityId(rule.getId());
158+
setEntityUuid(rule.getUuid());
157159
} catch (NetworkRuleConflictException e) {
158160
s_logger.info("Unable to create Static Nat Rule due to ", e);
159161
throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
@@ -179,7 +181,7 @@ public String getEventType() {
179181
@Override
180182
public String getEventDescription() {
181183
IpAddress ip = _networkService.getIp(ipAddressId);
182-
return ("Applying an ipforwarding 1:1 NAT rule for Ip: " + ip.getAddress() + " with virtual machine:" + this.getVirtualMachineId());
184+
return ("Applying an ipforwarding 1:1 NAT rule for Ip: " + ip.getAddress() + " with virtual machine:" + getVirtualMachineId());
183185
}
184186

185187
private long getVirtualMachineId() {
@@ -321,4 +323,10 @@ public TrafficType getTrafficType() {
321323
public boolean isDisplay() {
322324
return true;
323325
}
326+
327+
@Override
328+
public IAMEntityType getEntityType() {
329+
return IAMEntityType.FirewallRule;
330+
}
331+
324332
}

engine/components-api/src/com/cloud/network/addr/PublicIp.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.util.Date;
2020

21+
import org.apache.cloudstack.acl.IAMEntityType;
22+
2123
import com.cloud.dc.VlanVO;
2224
import com.cloud.network.PublicIpAddress;
2325
import com.cloud.network.dao.IPAddressVO;
@@ -236,4 +238,9 @@ public Long getIpMacAddress() {
236238
public boolean isDisplay() {
237239
return _addr.isDisplay();
238240
}
241+
242+
@Override
243+
public IAMEntityType getEntityType() {
244+
return IAMEntityType.PublicIpAddress;
245+
}
239246
}

engine/components-api/src/com/cloud/network/rules/StaticNatRuleImpl.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.util.List;
2020

21+
import org.apache.cloudstack.acl.IAMEntityType;
22+
2123
public class StaticNatRuleImpl implements StaticNatRule {
2224
long id;
2325
String xid;
@@ -34,19 +36,19 @@ public class StaticNatRuleImpl implements StaticNatRule {
3436
boolean forDisplay;
3537

3638
public StaticNatRuleImpl(FirewallRuleVO rule, String dstIp) {
37-
this.id = rule.getId();
38-
this.xid = rule.getXid();
39-
this.uuid = rule.getUuid();
40-
this.protocol = rule.getProtocol();
41-
this.portStart = rule.getSourcePortStart();
42-
this.portEnd = rule.getSourcePortEnd();
43-
this.state = rule.getState();
44-
this.accountId = rule.getAccountId();
45-
this.domainId = rule.getDomainId();
46-
this.networkId = rule.getNetworkId();
47-
this.sourceIpAddressId = rule.getSourceIpAddressId();
48-
this.destIpAddress = dstIp;
49-
this.forDisplay = rule.isDisplay();
39+
id = rule.getId();
40+
xid = rule.getXid();
41+
uuid = rule.getUuid();
42+
protocol = rule.getProtocol();
43+
portStart = rule.getSourcePortStart();
44+
portEnd = rule.getSourcePortEnd();
45+
state = rule.getState();
46+
accountId = rule.getAccountId();
47+
domainId = rule.getDomainId();
48+
networkId = rule.getNetworkId();
49+
sourceIpAddressId = rule.getSourceIpAddressId();
50+
destIpAddress = dstIp;
51+
forDisplay = rule.isDisplay();
5052
}
5153

5254
@Override
@@ -148,4 +150,9 @@ public TrafficType getTrafficType() {
148150
public boolean isDisplay() {
149151
return forDisplay;
150152
}
153+
154+
@Override
155+
public IAMEntityType getEntityType() {
156+
return IAMEntityType.FirewallRule;
157+
}
151158
}

0 commit comments

Comments
 (0)