Skip to content

Commit f0ecee7

Browse files
committed
handle copilot comments
1 parent 8f71ce6 commit f0ecee7

7 files changed

Lines changed: 38 additions & 9 deletions

File tree

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,8 +1423,10 @@ public class EventTypes {
14231423

14241424
// DNS Framework Events
14251425
entityEventDetails.put(EVENT_DNS_SERVER_ADD, DnsServer.class);
1426+
entityEventDetails.put(EVENT_DNS_SERVER_UPDATE, DnsServer.class);
14261427
entityEventDetails.put(EVENT_DNS_SERVER_DELETE, DnsServer.class);
14271428
entityEventDetails.put(EVENT_DNS_ZONE_CREATE, DnsZone.class);
1429+
entityEventDetails.put(EVENT_DNS_ZONE_UPDATE, DnsZone.class);
14281430
entityEventDetails.put(EVENT_DNS_ZONE_DELETE, DnsZone.class);
14291431
entityEventDetails.put(EVENT_DNS_RECORD_CREATE, DnsRecord.class);
14301432
entityEventDetails.put(EVENT_DNS_RECORD_DELETE, DnsRecord.class);

api/src/main/java/com/cloud/user/ResourceLimitService.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ public interface ResourceLimitService {
5757
"The default maximum number of GPU devices that can be used for a domain", false);
5858
static final ConfigKey<Long> DefaultMaxProjectGpus = new ConfigKey<>("Project Defaults",Long.class,"max.project.gpus","20",
5959
"The default maximum number of GPU devices that can be used for a project", false);
60-
ConfigKey<Long> DefaultMaxDnsAccounts = new ConfigKey<>("Account Defaults",Long.class, "max.account.dns_zones","10",
61-
"The default maximum number of DNS zones that can be created by an Account", true);
6260

6361
static final List<ResourceType> HostTagsSupportingTypes = List.of(ResourceType.user_vm, ResourceType.cpu, ResourceType.memory, ResourceType.gpu);
6462
static final List<ResourceType> StorageTagsSupportingTypes = List.of(ResourceType.volume, ResourceType.primary_storage);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public DnsZone.ZoneType getType() {
8888
return DnsZone.ZoneType.Public;
8989
}
9090
DnsZone.ZoneType zoneType = EnumUtils.getEnumIgnoreCase(DnsZone.ZoneType.class, type);
91-
if (type == null) {
91+
if (zoneType == null) {
9292
throw new IllegalArgumentException("Invalid type value, supported values are: " + Arrays.toString(DnsZone.ZoneType.values()));
9393
}
9494
return zoneType;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public class DeleteDnsZoneCmd extends BaseAsyncCmd {
5252
private Long id;
5353

5454
@Parameter(name = ApiConstants.UNMANAGE, type = CommandType.BOOLEAN, entityType = DnsZoneResponse.class,
55-
description = "If true, imports an existing DNS zone from the DNS provider into CloudStack; " +
56-
"if false, creates the DNS zone in the provider and registers it with CloudStack. Default: false")
55+
description = "If true, removes the DNS zone only from CloudStack; if false, removes it from " +
56+
"both CloudStack and the DNS provider. Default: false")
5757
private Boolean unmanage = false;
5858

5959
/////////////////////////////////////////////////////

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,15 @@ public Boolean isPublic() {
101101
public String getPublicDomainSuffix() {
102102
return publicDomainSuffix;
103103
}
104-
public String getNameServers() { return String.join(",", nameServers); }
104+
public String getNameServers() {
105+
if (nameServers == null) {
106+
return null;
107+
}
108+
return StringUtils.join(nameServers.stream()
109+
.filter(StringUtils::isNotBlank)
110+
.map(StringUtils::trim)
111+
.toArray(String[]::new), ",");
112+
}
105113

106114
@Override
107115
public long getEntityOwnerId() {

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@
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;
2426
import org.apache.cloudstack.api.BaseCmd;
2527
import org.apache.cloudstack.api.Parameter;
2628
import org.apache.cloudstack.api.ServerApiException;
2729
import org.apache.cloudstack.api.response.DnsZoneResponse;
28-
import org.apache.cloudstack.context.CallContext;
2930
import org.apache.cloudstack.dns.DnsZone;
3031

32+
import com.cloud.user.Account;
33+
3134
@APICommand(name = "updateDnsZone",
3235
description = "Updates a DNS Zone's metadata",
3336
responseObject = DnsZoneResponse.class,
@@ -41,6 +44,7 @@ public class UpdateDnsZoneCmd extends BaseCmd {
4144
//////////////// API Parameters /////////////////////
4245
/////////////////////////////////////////////////////
4346

47+
@ACL(accessType = SecurityChecker.AccessType.OperateEntry)
4448
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = DnsZoneResponse.class,
4549
required = true, description = "The ID of the DNS zone")
4650
private Long id;
@@ -82,6 +86,10 @@ public void execute() {
8286

8387
@Override
8488
public long getEntityOwnerId() {
85-
return CallContext.current().getCallingAccount().getId();
89+
DnsZone dnsZone = _entityMgr.findById(DnsZone.class, id);
90+
if (dnsZone != null) {
91+
return dnsZone.getAccountId();
92+
}
93+
return Account.ACCOUNT_ID_SYSTEM;
8694
}
8795
}

api/src/test/java/org/apache/cloudstack/api/command/user/dns/UpdateDnsZoneCmdTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@
2626
import org.apache.cloudstack.dns.DnsZone;
2727
import org.junit.Test;
2828

29+
import com.cloud.user.Account;
30+
2931
public class UpdateDnsZoneCmdTest extends BaseDnsCmdTest {
3032

3133
private UpdateDnsZoneCmd createCmd() throws Exception {
3234
UpdateDnsZoneCmd cmd = new UpdateDnsZoneCmd();
3335
setField(cmd, "dnsProviderManager", dnsProviderManager);
36+
setField(cmd, "_entityMgr", entityManager);
3437
setField(cmd, "id", ENTITY_ID);
3538
setField(cmd, "description", "Updated description");
3639
return cmd;
@@ -44,11 +47,21 @@ public void testAccessors() throws Exception {
4447
}
4548

4649
@Test
47-
public void testGetEntityOwnerId() throws Exception {
50+
public void testGetEntityOwnerIdWhenZoneExists() throws Exception {
4851
UpdateDnsZoneCmd cmd = createCmd();
52+
DnsZone mockZone = mock(DnsZone.class);
53+
when(mockZone.getAccountId()).thenReturn(ACCOUNT_ID);
54+
when(entityManager.findById(DnsZone.class, ENTITY_ID)).thenReturn(mockZone);
4955
assertEquals(ACCOUNT_ID, cmd.getEntityOwnerId());
5056
}
5157

58+
@Test
59+
public void testGetEntityOwnerIdWhenZoneNotFound() throws Exception {
60+
UpdateDnsZoneCmd cmd = createCmd();
61+
when(entityManager.findById(DnsZone.class, ENTITY_ID)).thenReturn(null);
62+
assertEquals(Account.ACCOUNT_ID_SYSTEM, cmd.getEntityOwnerId());
63+
}
64+
5265
@Test
5366
public void testExecuteSuccess() throws Exception {
5467
UpdateDnsZoneCmd cmd = createCmd();

0 commit comments

Comments
 (0)