Skip to content

Commit 1fe79bd

Browse files
committed
fixes related to acl, dao
1 parent add7763 commit 1fe79bd

File tree

15 files changed

+126
-293
lines changed

15 files changed

+126
-293
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/dns/AddDnsServerCmd.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@
2828
import org.apache.cloudstack.api.ServerApiException;
2929
import org.apache.cloudstack.api.response.DnsServerResponse;
3030
import org.apache.cloudstack.context.CallContext;
31+
import org.apache.cloudstack.dns.DnsProviderType;
3132
import org.apache.cloudstack.dns.DnsServer;
3233
import org.apache.commons.lang3.BooleanUtils;
3334

35+
import com.cloud.exception.InvalidParameterValueException;
36+
import com.cloud.utils.EnumUtils;
37+
3438
@APICommand(name = "addDnsServer",
3539
description = "Adds a new external DNS server",
3640
responseObject = DnsServerResponse.class,
@@ -51,8 +55,8 @@ public class AddDnsServerCmd extends BaseCmd {
5155
@Parameter(name = ApiConstants.URL, type = CommandType.STRING, required = true, description = "API URL of the provider")
5256
private String url;
5357

54-
@Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, required = true, description = "Provider type (e.g., PowerDNS)")
55-
private String provider;
58+
@Parameter(name = ApiConstants.PROVIDER_TYPE, type = CommandType.STRING, required = true, description = "Provider type (e.g., PowerDNS)")
59+
private String providerType;
5660

5761
@Parameter(name = ApiConstants.DNS_USER_NAME, type = CommandType.STRING,
5862
description = "Username or email associated with the external DNS provider account (used for authentication)")
@@ -82,8 +86,9 @@ public class AddDnsServerCmd extends BaseCmd {
8286
/////////////////////////////////////////////////////
8387

8488
public String getName() { return name; }
89+
8590
public String getUrl() { return url; }
86-
public String getProvider() { return provider; }
91+
8792
public String getCredentials() {
8893
return credentials;
8994
}
@@ -104,6 +109,15 @@ public List<String> getNameServers() {
104109
return nameServers;
105110
}
106111

112+
public DnsProviderType getProviderType() {
113+
DnsProviderType dnsProviderType = EnumUtils.getEnumIgnoreCase(DnsProviderType.class, providerType, DnsProviderType.PowerDNS);
114+
if (dnsProviderType == null) {
115+
throw new InvalidParameterValueException(String.format("Invalid value passed for provider type, valid values are: %s",
116+
EnumUtils.listValues(DnsProviderType.values())));
117+
}
118+
return dnsProviderType;
119+
}
120+
107121
@Override
108122
public long getEntityOwnerId() {
109123
return CallContext.current().getCallingAccount().getId();

api/src/main/java/org/apache/cloudstack/api/command/user/dns/AssociateDnsZoneToNetworkCmd.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package org.apache.cloudstack.api.command.user.dns;
1919

2020
import org.apache.cloudstack.acl.RoleType;
21+
import org.apache.cloudstack.acl.SecurityChecker;
22+
import org.apache.cloudstack.api.ACL;
2123
import org.apache.cloudstack.api.APICommand;
2224
import org.apache.cloudstack.api.ApiConstants;
2325
import org.apache.cloudstack.api.ApiErrorCode;
@@ -27,12 +29,14 @@
2729
import org.apache.cloudstack.api.response.DnsZoneNetworkMapResponse;
2830
import org.apache.cloudstack.api.response.DnsZoneResponse;
2931
import org.apache.cloudstack.api.response.NetworkResponse;
32+
import org.apache.cloudstack.dns.DnsZone;
3033

3134
import com.cloud.exception.ConcurrentOperationException;
3235
import com.cloud.exception.InsufficientCapacityException;
3336
import com.cloud.exception.NetworkRuleConflictException;
3437
import com.cloud.exception.ResourceAllocationException;
3538
import com.cloud.exception.ResourceUnavailableException;
39+
import com.cloud.user.Account;
3640

3741
@APICommand(name = "associateDnsZoneToNetwork",
3842
description = "Associates a DNS Zone with a Network for VM auto-registration",
@@ -47,6 +51,7 @@ public class AssociateDnsZoneToNetworkCmd extends BaseCmd {
4751
required = true, description = "The ID of the DNS zone")
4852
private Long dnsZoneId;
4953

54+
@ACL(accessType = SecurityChecker.AccessType.OperateEntry)
5055
@Parameter(name = ApiConstants.NETWORK_ID, type = CommandType.UUID, entityType = NetworkResponse.class,
5156
required = true, description = "The ID of the network")
5257
private Long networkId;
@@ -68,7 +73,11 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
6873

6974
@Override
7075
public long getEntityOwnerId() {
71-
return dnsProviderManager.getDnsZone(dnsZoneId).getAccountId();
76+
DnsZone zone = _entityMgr.findById(DnsZone.class, dnsZoneId);
77+
if (zone != null) {
78+
return zone.getAccountId();
79+
}
80+
return Account.ACCOUNT_ID_SYSTEM;
7281
}
7382

7483
public Long getDnsZoneId() {

api/src/main/java/org/apache/cloudstack/api/command/user/dns/DeleteDnsZoneCmd.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ public void execute() {
8080

8181
@Override
8282
public long getEntityOwnerId() {
83-
// Look up the Zone to find the Account Owner
84-
DnsZone zone = dnsProviderManager.getDnsZone(id);
83+
DnsZone zone = _entityMgr.findById(DnsZone.class, id);
8584
if (zone != null) {
8685
return zone.getAccountId();
8786
}

api/src/main/java/org/apache/cloudstack/api/command/user/dns/DisassociateDnsZoneFromNetworkCmd.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import org.apache.cloudstack.api.BaseCmd;
2727
import org.apache.cloudstack.api.Parameter;
2828
import org.apache.cloudstack.api.ServerApiException;
29-
import org.apache.cloudstack.api.response.DnsZoneNetworkMapResponse;
29+
import org.apache.cloudstack.api.response.DnsZoneResponse;
30+
import org.apache.cloudstack.api.response.NetworkResponse;
3031
import org.apache.cloudstack.api.response.SuccessResponse;
3132

3233
import com.cloud.exception.ConcurrentOperationException;
@@ -44,10 +45,14 @@
4445
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
4546
public class DisassociateDnsZoneFromNetworkCmd extends BaseCmd {
4647

48+
@Parameter(name = ApiConstants.DNS_ZONE_ID, type = CommandType.UUID, entityType = DnsZoneResponse.class,
49+
required = true, description = "The ID of the DNS zone")
50+
private Long dnsZoneId;
51+
4752
@ACL(accessType = SecurityChecker.AccessType.OperateEntry)
48-
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = DnsZoneNetworkMapResponse.class,
49-
required = true, description = "The ID of the DNS zone to network mapping")
50-
private Long id;
53+
@Parameter(name = ApiConstants.NETWORK_ID, type = CommandType.UUID, entityType = NetworkResponse.class,
54+
required = true, description = "The ID of the network")
55+
private Long networkId;
5156

5257
@Override
5358
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
@@ -69,5 +74,11 @@ public long getEntityOwnerId() {
6974
return Account.ACCOUNT_ID_SYSTEM;
7075
}
7176

72-
public Long getId() { return id; }
77+
public Long getDnsZoneId() {
78+
return dnsZoneId;
79+
}
80+
81+
public void setDnsZoneId(Long dnsZoneId) {
82+
this.dnsZoneId = dnsZoneId;
83+
}
7384
}

api/src/main/java/org/apache/cloudstack/api/command/user/dns/ListDnsServersCmd.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424
import org.apache.cloudstack.api.Parameter;
2525
import org.apache.cloudstack.api.response.DnsServerResponse;
2626
import org.apache.cloudstack.api.response.ListResponse;
27+
import org.apache.cloudstack.dns.DnsProviderType;
2728
import org.apache.cloudstack.dns.DnsServer;
2829

30+
import com.cloud.exception.InvalidParameterValueException;
31+
import com.cloud.utils.EnumUtils;
32+
2933
@APICommand(name = "listDnsServers",
3034
description = "Lists DNS servers owned by the account.",
3135
responseObject = DnsServerResponse.class,
@@ -43,9 +47,9 @@ public class ListDnsServersCmd extends BaseListAccountResourcesCmd {
4347
description = "the ID of the DNS server")
4448
private Long id;
4549

46-
@Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING,
50+
@Parameter(name = ApiConstants.PROVIDER_TYPE, type = CommandType.STRING,
4751
description = "filter by provider type (e.g. PowerDNS, Cloudflare)")
48-
private String provider;
52+
private String providerType;
4953

5054
/////////////////////////////////////////////////////
5155
/////////////////// Accessors ///////////////////////
@@ -55,8 +59,13 @@ public Long getId() {
5559
return id;
5660
}
5761

58-
public String getProvider() {
59-
return provider;
62+
public DnsProviderType getProviderType() {
63+
DnsProviderType dnsProviderType = EnumUtils.getEnumIgnoreCase(DnsProviderType.class, providerType, DnsProviderType.PowerDNS);
64+
if (dnsProviderType == null) {
65+
throw new InvalidParameterValueException(String.format("Invalid value passed for provider type, valid values are: %s",
66+
EnumUtils.listValues(DnsProviderType.values())));
67+
}
68+
return dnsProviderType;
6069
}
6170

6271
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/command/user/dns/ListDnsZonesCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.apache.cloudstack.acl.RoleType;
2121
import org.apache.cloudstack.api.APICommand;
2222
import org.apache.cloudstack.api.ApiConstants;
23-
import org.apache.cloudstack.api.BaseListAccountResourcesCmd;
23+
import org.apache.cloudstack.api.BaseListCmd;
2424
import org.apache.cloudstack.api.Parameter;
2525
import org.apache.cloudstack.api.response.DnsServerResponse;
2626
import org.apache.cloudstack.api.response.DnsZoneResponse;
@@ -33,7 +33,7 @@
3333
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
3434
since = "4.23.0",
3535
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
36-
public class ListDnsZonesCmd extends BaseListAccountResourcesCmd {
36+
public class ListDnsZonesCmd extends BaseListCmd {
3737

3838
/////////////////////////////////////////////////////
3939
//////////////// API parameters /////////////////////

api/src/main/java/org/apache/cloudstack/api/command/user/dns/RegisterDnsRecordForVmCmd.java

Lines changed: 0 additions & 80 deletions
This file was deleted.

api/src/main/java/org/apache/cloudstack/api/command/user/dns/RemoveDnsRecordForVmCmd.java

Lines changed: 0 additions & 83 deletions
This file was deleted.

api/src/main/java/org/apache/cloudstack/dns/DnsProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.cloud.utils.component.Adapter;
2525

2626
public interface DnsProvider extends Adapter {
27+
2728
DnsProviderType getProviderType();
2829

2930
// Validates connectivity to the server

0 commit comments

Comments
 (0)