Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mouday committed Jul 25, 2024
1 parent 88441b7 commit cdf0ebb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion domain_admin/api/issue_certificate_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def deploy_cert_to_oss():
:return:
"""
issue_certificate_id = request.json['issue_certificate_id']
dns_id = request.json.get['dns_id']
dns_id = request.json['dns_id']

ret = issue_certificate_service.deploy_cert_to_oss(
issue_certificate_id=issue_certificate_id,
Expand Down
4 changes: 4 additions & 0 deletions domain_admin/service/issue_certificate_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ def deploy_cert_to_oss(issue_certificate_id, dns_id):
domain = issue_certificate_row.domains[0]

oss_info = aliyun_oss_api.cname_to_oss_info(domain)
if not oss_info:
raise AppException('dns 未设置')

logger.info("oss_info: %s", oss_info)

aliyun_oss_api.put_bucket_cname(
access_key_id=dns_row.access_key,
Expand Down
17 changes: 12 additions & 5 deletions domain_admin/utils/open_api/aliyun_oss_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from oss2.credentials import EnvironmentVariableCredentialsProvider, StaticCredentialsProvider

# https://next.api.aliyun.com/product/Oss
from domain_admin.utils import domain_util
from domain_admin.utils import domain_util, dns_util

ENDPOINT_OPTIONS = [
{
Expand Down Expand Up @@ -75,10 +75,17 @@ def cname_to_oss_info(cname):
:param cname:
:return: zaiting oss-cn-beijing.aliyuncs.com
"""
return {
'bucket_name': cname.split('.')[0],
'endpoint': 'https://' + domain_util.get_domain_parent(cname).strip('.')
}
lst = dns_util.query_domain_cname(cname)

if lst and len(lst) > 0:
domain = lst[0]

return {
'bucket_name': domain.split('.')[0],
'endpoint': 'https://' + domain_util.get_domain_parent(domain).strip('.')
}
else:
return None


def put_bucket_cname(
Expand Down
16 changes: 16 additions & 0 deletions tests/utils/test_aliyun_oss_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
"""
@File : test_aliyun_oss_api.py
@Date : 2024-07-25
"""
import unittest

from domain_admin.utils.open_api import aliyun_oss_api


class AliyunOSSApiTest(unittest.TestCase):

def test_cname_to_oss_info(self):
domain = 'cdn.baidu.com'
oss_info = aliyun_oss_api.cname_to_oss_info(domain)
print(oss_info)

0 comments on commit cdf0ebb

Please sign in to comment.