|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.apache.cloudstack.api.command.user.dns; |
| 19 | + |
| 20 | +import javax.inject.Inject; |
| 21 | + |
| 22 | +import org.apache.cloudstack.api.APICommand; |
| 23 | +import org.apache.cloudstack.api.ApiConstants; |
| 24 | +import org.apache.cloudstack.api.ApiErrorCode; |
| 25 | +import org.apache.cloudstack.api.BaseCmd; |
| 26 | +import org.apache.cloudstack.api.Parameter; |
| 27 | +import org.apache.cloudstack.api.ServerApiException; |
| 28 | +import org.apache.cloudstack.api.response.DnsServerResponse; |
| 29 | +import org.apache.cloudstack.context.CallContext; |
| 30 | +import org.apache.cloudstack.dns.DnsProviderManager; |
| 31 | +import org.apache.cloudstack.dns.DnsServer; |
| 32 | +import org.apache.commons.lang3.BooleanUtils; |
| 33 | + |
| 34 | +@APICommand(name = "updateDnsServer", description = "Update DNS server", |
| 35 | + responseObject = DnsServerResponse.class, requestHasSensitiveInfo = true) |
| 36 | +public class UpdateDnsServerCmd extends BaseCmd { |
| 37 | + |
| 38 | + @Inject |
| 39 | + DnsProviderManager dnsProviderManager; |
| 40 | + |
| 41 | + ///////////////////////////////////////////////////// |
| 42 | + //////////////// API parameters ///////////////////// |
| 43 | + ///////////////////////////////////////////////////// |
| 44 | + |
| 45 | + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = DnsServerResponse.class, |
| 46 | + required = true, description = "The ID of the DNS server to update") |
| 47 | + private Long id; |
| 48 | + |
| 49 | + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "Name of the DNS server") |
| 50 | + private String name; |
| 51 | + |
| 52 | + @Parameter(name = ApiConstants.URL, type = CommandType.STRING, description = "API URL of the provider") |
| 53 | + private String url; |
| 54 | + |
| 55 | + @Parameter(name = ApiConstants.CREDENTIALS, type = CommandType.STRING, required = false, description = "API Key or Credentials for the external provider") |
| 56 | + private String credentials; |
| 57 | + |
| 58 | + @Parameter(name = ApiConstants.PORT, type = CommandType.INTEGER, description = "Port number of the external DNS server") |
| 59 | + private Integer port; |
| 60 | + |
| 61 | + @Parameter(name = ApiConstants.IS_PUBLIC, type = CommandType.BOOLEAN, description = "Whether the DNS server is publicly accessible by other accounts") |
| 62 | + private Boolean isPublic; |
| 63 | + |
| 64 | + @Parameter(name = ApiConstants.PUBLIC_DOMAIN_SUFFIX, type = CommandType.STRING, description = "The domain suffix used for public access (e.g. public.example.com)") |
| 65 | + private String publicDomainSuffix; |
| 66 | + |
| 67 | + @Parameter(name = ApiConstants.NAME_SERVERS, type = CommandType.STRING, description = "Comma separated list of name servers") |
| 68 | + private String nameServers; |
| 69 | + |
| 70 | + ///////////////////////////////////////////////////// |
| 71 | + /////////////////// Accessors /////////////////////// |
| 72 | + ///////////////////////////////////////////////////// |
| 73 | + |
| 74 | + public Long getId() { return id; } |
| 75 | + public String getName() { return name; } |
| 76 | + public String getUrl() { return url; } |
| 77 | + public String getCredentials() { |
| 78 | + return credentials; |
| 79 | + } |
| 80 | + public Integer getPort() { |
| 81 | + return port; |
| 82 | + } |
| 83 | + public Boolean isPublic() { |
| 84 | + return BooleanUtils.isTrue(isPublic); |
| 85 | + } |
| 86 | + public String getPublicDomainSuffix() { |
| 87 | + return publicDomainSuffix; |
| 88 | + } |
| 89 | + public String getNameServers() { return nameServers; } |
| 90 | + |
| 91 | + @Override |
| 92 | + public long getEntityOwnerId() { |
| 93 | + return CallContext.current().getCallingAccount().getId(); |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public void execute() { |
| 98 | + try { |
| 99 | + DnsServer server = dnsProviderManager.updateDnsServer(this); |
| 100 | + if (server != null) { |
| 101 | + DnsServerResponse response = dnsProviderManager.createDnsServerResponse(server); |
| 102 | + response.setResponseName(getCommandName()); |
| 103 | + setResponseObject(response); |
| 104 | + } else { |
| 105 | + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update DNS server"); |
| 106 | + } |
| 107 | + } catch (Exception ex) { |
| 108 | + logger.error("Failed to add update server", ex); |
| 109 | + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); |
| 110 | + } |
| 111 | + } |
| 112 | +} |
0 commit comments