From 26edb9a7178688f4a789e87284106fcf338b083e Mon Sep 17 00:00:00 2001 From: pengshiyu <1940607002@qq.com> Date: Fri, 21 Jun 2024 19:05:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E6=B7=BB=E5=8A=A0dns?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain_admin/api/dns_api.py | 37 +++++++++++++++++++ domain_admin/model/database.py | 3 +- domain_admin/model/issue_certificate_model.py | 1 + 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/domain_admin/api/dns_api.py b/domain_admin/api/dns_api.py index 817ed50e4f..363a463830 100644 --- a/domain_admin/api/dns_api.py +++ b/domain_admin/api/dns_api.py @@ -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(): @@ -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'] + ) diff --git a/domain_admin/model/database.py b/domain_admin/model/database.py index 91f24a4c1b..4a3f25bda8 100644 --- a/domain_admin/model/database.py +++ b/domain_admin/model/database.py @@ -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, @@ -47,6 +47,7 @@ (tag_model.TagModel, None), (certificate_model.CertificateModel, None), (deploy_cert_model.DeployCertModel, None), + (dns_model.DnsModel, None), ] diff --git a/domain_admin/model/issue_certificate_model.py b/domain_admin/model/issue_certificate_model.py index f2b764b0ee..5ba8ca6e09 100644 --- a/domain_admin/model/issue_certificate_model.py +++ b/domain_admin/model/issue_certificate_model.py @@ -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) # 验证文件部署目录