mirror of https://github.com/apache/cloudstack.git
handle copilot comments
This commit is contained in:
parent
8f71ce6f40
commit
f0ecee7540
|
|
@ -1423,8 +1423,10 @@ public class EventTypes {
|
|||
|
||||
// DNS Framework Events
|
||||
entityEventDetails.put(EVENT_DNS_SERVER_ADD, DnsServer.class);
|
||||
entityEventDetails.put(EVENT_DNS_SERVER_UPDATE, DnsServer.class);
|
||||
entityEventDetails.put(EVENT_DNS_SERVER_DELETE, DnsServer.class);
|
||||
entityEventDetails.put(EVENT_DNS_ZONE_CREATE, DnsZone.class);
|
||||
entityEventDetails.put(EVENT_DNS_ZONE_UPDATE, DnsZone.class);
|
||||
entityEventDetails.put(EVENT_DNS_ZONE_DELETE, DnsZone.class);
|
||||
entityEventDetails.put(EVENT_DNS_RECORD_CREATE, DnsRecord.class);
|
||||
entityEventDetails.put(EVENT_DNS_RECORD_DELETE, DnsRecord.class);
|
||||
|
|
|
|||
|
|
@ -57,8 +57,6 @@ public interface ResourceLimitService {
|
|||
"The default maximum number of GPU devices that can be used for a domain", false);
|
||||
static final ConfigKey<Long> DefaultMaxProjectGpus = new ConfigKey<>("Project Defaults",Long.class,"max.project.gpus","20",
|
||||
"The default maximum number of GPU devices that can be used for a project", false);
|
||||
ConfigKey<Long> DefaultMaxDnsAccounts = new ConfigKey<>("Account Defaults",Long.class, "max.account.dns_zones","10",
|
||||
"The default maximum number of DNS zones that can be created by an Account", true);
|
||||
|
||||
static final List<ResourceType> HostTagsSupportingTypes = List.of(ResourceType.user_vm, ResourceType.cpu, ResourceType.memory, ResourceType.gpu);
|
||||
static final List<ResourceType> StorageTagsSupportingTypes = List.of(ResourceType.volume, ResourceType.primary_storage);
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ public class CreateDnsZoneCmd extends BaseAsyncCreateCmd {
|
|||
return DnsZone.ZoneType.Public;
|
||||
}
|
||||
DnsZone.ZoneType zoneType = EnumUtils.getEnumIgnoreCase(DnsZone.ZoneType.class, type);
|
||||
if (type == null) {
|
||||
if (zoneType == null) {
|
||||
throw new IllegalArgumentException("Invalid type value, supported values are: " + Arrays.toString(DnsZone.ZoneType.values()));
|
||||
}
|
||||
return zoneType;
|
||||
|
|
|
|||
|
|
@ -52,8 +52,8 @@ public class DeleteDnsZoneCmd extends BaseAsyncCmd {
|
|||
private Long id;
|
||||
|
||||
@Parameter(name = ApiConstants.UNMANAGE, type = CommandType.BOOLEAN, entityType = DnsZoneResponse.class,
|
||||
description = "If true, imports an existing DNS zone from the DNS provider into CloudStack; " +
|
||||
"if false, creates the DNS zone in the provider and registers it with CloudStack. Default: false")
|
||||
description = "If true, removes the DNS zone only from CloudStack; if false, removes it from " +
|
||||
"both CloudStack and the DNS provider. Default: false")
|
||||
private Boolean unmanage = false;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -101,7 +101,15 @@ public class UpdateDnsServerCmd extends BaseCmd {
|
|||
public String getPublicDomainSuffix() {
|
||||
return publicDomainSuffix;
|
||||
}
|
||||
public String getNameServers() { return String.join(",", nameServers); }
|
||||
public String getNameServers() {
|
||||
if (nameServers == null) {
|
||||
return null;
|
||||
}
|
||||
return StringUtils.join(nameServers.stream()
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.map(StringUtils::trim)
|
||||
.toArray(String[]::new), ",");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
package org.apache.cloudstack.api.command.user.dns;
|
||||
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.acl.SecurityChecker;
|
||||
import org.apache.cloudstack.api.ACL;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
|
|
@ -25,9 +27,10 @@ import org.apache.cloudstack.api.BaseCmd;
|
|||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.DnsZoneResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.dns.DnsZone;
|
||||
|
||||
import com.cloud.user.Account;
|
||||
|
||||
@APICommand(name = "updateDnsZone",
|
||||
description = "Updates a DNS Zone's metadata",
|
||||
responseObject = DnsZoneResponse.class,
|
||||
|
|
@ -41,6 +44,7 @@ public class UpdateDnsZoneCmd extends BaseCmd {
|
|||
//////////////// API Parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@ACL(accessType = SecurityChecker.AccessType.OperateEntry)
|
||||
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = DnsZoneResponse.class,
|
||||
required = true, description = "The ID of the DNS zone")
|
||||
private Long id;
|
||||
|
|
@ -82,6 +86,10 @@ public class UpdateDnsZoneCmd extends BaseCmd {
|
|||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return CallContext.current().getCallingAccount().getId();
|
||||
DnsZone dnsZone = _entityMgr.findById(DnsZone.class, id);
|
||||
if (dnsZone != null) {
|
||||
return dnsZone.getAccountId();
|
||||
}
|
||||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,11 +26,14 @@ import org.apache.cloudstack.api.response.DnsZoneResponse;
|
|||
import org.apache.cloudstack.dns.DnsZone;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.cloud.user.Account;
|
||||
|
||||
public class UpdateDnsZoneCmdTest extends BaseDnsCmdTest {
|
||||
|
||||
private UpdateDnsZoneCmd createCmd() throws Exception {
|
||||
UpdateDnsZoneCmd cmd = new UpdateDnsZoneCmd();
|
||||
setField(cmd, "dnsProviderManager", dnsProviderManager);
|
||||
setField(cmd, "_entityMgr", entityManager);
|
||||
setField(cmd, "id", ENTITY_ID);
|
||||
setField(cmd, "description", "Updated description");
|
||||
return cmd;
|
||||
|
|
@ -44,11 +47,21 @@ public class UpdateDnsZoneCmdTest extends BaseDnsCmdTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetEntityOwnerId() throws Exception {
|
||||
public void testGetEntityOwnerIdWhenZoneExists() throws Exception {
|
||||
UpdateDnsZoneCmd cmd = createCmd();
|
||||
DnsZone mockZone = mock(DnsZone.class);
|
||||
when(mockZone.getAccountId()).thenReturn(ACCOUNT_ID);
|
||||
when(entityManager.findById(DnsZone.class, ENTITY_ID)).thenReturn(mockZone);
|
||||
assertEquals(ACCOUNT_ID, cmd.getEntityOwnerId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEntityOwnerIdWhenZoneNotFound() throws Exception {
|
||||
UpdateDnsZoneCmd cmd = createCmd();
|
||||
when(entityManager.findById(DnsZone.class, ENTITY_ID)).thenReturn(null);
|
||||
assertEquals(Account.ACCOUNT_ID_SYSTEM, cmd.getEntityOwnerId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteSuccess() throws Exception {
|
||||
UpdateDnsZoneCmd cmd = createCmd();
|
||||
|
|
|
|||
Loading…
Reference in New Issue