Skip to content

Commit

Permalink
新增 添加dns记录接口
Browse files Browse the repository at this point in the history
  • Loading branch information
mouday committed Jun 21, 2024
1 parent 6f5059a commit 26edb9a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
37 changes: 37 additions & 0 deletions domain_admin/api/dns_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
from domain_admin.enums.dns_type_enum import DnsTypeEnum
from domain_admin.log import logger
from domain_admin.model.dns_model import DnsModel
from domain_admin.model.issue_certificate_model import IssueCertificateModel
from domain_admin.service import issue_certificate_service
from domain_admin.utils.acme_util.challenge_type import ChallengeType
from domain_admin.utils.open_api import aliyun_domain_api
from domain_admin.utils.open_api.aliyun_domain_api import RecordTypeEnum


def add_dns():
Expand Down Expand Up @@ -110,3 +115,35 @@ def get_dns_list():
'list': rows,
'total': total,
}


def add_dns_domain_record():
"""
添加dns记录
:return:
"""
dns_id = request.json['dns_id']
issue_certificate_id = request.json['issue_certificate_id']

dns_row = DnsModel.get_by_id(dns_id)

# 获取验证方式
challenge_list = issue_certificate_service.get_certificate_challenges(issue_certificate_id)

for challenge_row in challenge_list:
challenge_json = challenge_row['challenge'].to_json()
if challenge_json['type'] == ChallengeType.DNS01:

if challenge_row['sub_domain'] and challenge_row['sub_domain'] != 'www':
record_key = '_acme-challenge.' + challenge_row['sub_domain']
else:
record_key = '_acme-challenge'

aliyun_domain_api.add_domain_record(
access_key_id=dns_row.access_key,
access_key_secret=dns_row.secret_key,
domain_name=challenge_row['domain'],
record_type=RecordTypeEnum.TXT,
record_key=record_key,
record_value=challenge_row['validation']
)
3 changes: 2 additions & 1 deletion domain_admin/model/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import print_function, unicode_literals, absolute_import, division

from domain_admin.log import logger
from domain_admin.model import base_model, domain_icp_model, tag_model, certificate_model, deploy_cert_model
from domain_admin.model import base_model, domain_icp_model, tag_model, certificate_model, deploy_cert_model, dns_model
from domain_admin.model import (
address_model,
log_operation_model,
Expand Down Expand Up @@ -47,6 +47,7 @@
(tag_model.TagModel, None),
(certificate_model.CertificateModel, None),
(deploy_cert_model.DeployCertModel, None),
(dns_model.DnsModel, None),
]


Expand Down
1 change: 1 addition & 0 deletions domain_admin/model/issue_certificate_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class IssueCertificateModel(BaseModel):
expire_time = DateTimeField(default=None, null=True)

# 部署机器
# @since 1.6.33 部署机器 && 部署dns账户
deploy_host_id = IntegerField(default=0)

# 验证文件部署目录
Expand Down

0 comments on commit 26edb9a

Please sign in to comment.