dnsrecord.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package compute
  15. import (
  16. "yunion.io/x/cloudmux/pkg/apis/compute"
  17. "yunion.io/x/cloudmux/pkg/cloudprovider"
  18. "yunion.io/x/pkg/util/regutils"
  19. "yunion.io/x/onecloud/pkg/apis"
  20. "yunion.io/x/onecloud/pkg/httperrors"
  21. )
  22. const (
  23. DNS_RECORDSET_STATUS_AVAILABLE = compute.DNS_RECORDSET_STATUS_AVAILABLE
  24. DNS_RECORDSET_STATUS_CREATING = apis.STATUS_CREATING
  25. )
  26. type DnsRecordCreateInput struct {
  27. apis.EnabledStatusStandaloneResourceCreateInput
  28. DnsZoneId string `json:"dns_zone_id"`
  29. DnsType string `json:"dns_type"`
  30. DnsValue string `json:"dns_value"`
  31. TTL int64 `json:"ttl"`
  32. MxPriority int64 `json:"mx_priority"`
  33. Proxied *bool `json:"proxied"`
  34. PolicyType string `json:"policy_type"`
  35. PolicyValue string `json:"policy_value"`
  36. }
  37. type DnsRecordUpdateInput struct {
  38. apis.EnabledStatusStandaloneResourceBaseUpdateInput
  39. DnsType string `json:"dns_type"`
  40. DnsValue string `json:"dns_value"`
  41. TTL *int64 `json:"ttl"`
  42. MxPriority *int64 `json:"mx_priority"`
  43. Proxied *bool `json:"proxied"`
  44. }
  45. type DnsRecordDetails struct {
  46. apis.EnabledStatusStandaloneResourceDetails
  47. SDnsRecord
  48. DnsZone string `json:"dns_zone"`
  49. }
  50. type DnsRecordListInput struct {
  51. apis.EnabledStatusStandaloneResourceListInput
  52. DnsZoneFilterListBase
  53. }
  54. type DnsRecordEnableInput struct {
  55. apis.PerformEnableInput
  56. }
  57. type DnsRecordDisableInput struct {
  58. apis.PerformDisableInput
  59. }
  60. func (record *SDnsRecord) ValidateDnsrecordValue() error {
  61. switch cloudprovider.TDnsType(record.DnsType) {
  62. case cloudprovider.DnsTypeMX:
  63. if record.MxPriority < 1 || record.MxPriority > 50 {
  64. return httperrors.NewOutOfRangeError("mx_priority range limited to [1,50]")
  65. }
  66. if !regutils.MatchDomainName(record.DnsValue) {
  67. return httperrors.NewInputParameterError("invalid domain %s for MX record", record.DnsValue)
  68. }
  69. case cloudprovider.DnsTypeA:
  70. if !regutils.MatchIP4Addr(record.DnsValue) {
  71. return httperrors.NewInputParameterError("invalid ipv4 %s for A record", record.DnsValue)
  72. }
  73. case cloudprovider.DnsTypeAAAA:
  74. if !regutils.MatchIP6Addr(record.DnsValue) {
  75. return httperrors.NewInputParameterError("invalid ipv6 %s for AAAA record", record.DnsValue)
  76. }
  77. case cloudprovider.DnsTypeCNAME:
  78. if !regutils.MatchDomainName(record.DnsValue) {
  79. return httperrors.NewInputParameterError("invalid domain %s for CNAME record", record.DnsValue)
  80. }
  81. }
  82. return nil
  83. }
  84. type SDnsResolveResult struct {
  85. DnsValue string `json:"dns_value"`
  86. TTL int64 `json:"ttl"`
  87. DnsName string `json:"dns_name"`
  88. }