Skip to content

Commit

Permalink
优化代码备注
Browse files Browse the repository at this point in the history
  • Loading branch information
mouday committed Feb 3, 2024
1 parent 6d7ec34 commit a8be266
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& pip install --no-cache-dir -r requirements/production.txt \
&& apk del .build-deps

CMD gunicorn --bind '0.0.0.0:8000' 'domain_admin.main:app' --timeout 120
CMD gunicorn --bind '0.0.0.0:8000' --timeout 120 --worker-class gevent 'domain_admin.main:app'
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

# 运行开发环境
dev:
source venv/bin/activate && gunicorn --bind '0.0.0.0:5000' --reload 'domain_admin.main:app' --timeout 120
source venv/bin/activate && gunicorn --bind '0.0.0.0:5000' --timeout 120 --worker-class gevent --reload 'domain_admin.main:app'

# 运行生产环境
pro:
source venv/bin/activate && gunicorn --bind '0.0.0.0:8000' 'domain_admin.main:app' --timeout 120
source venv/bin/activate && gunicorn --bind '0.0.0.0:8000' --worker-class gevent --timeout 120 'domain_admin.main:app'

# 发布 make release
.PHONY: release
Expand Down
3 changes: 3 additions & 0 deletions doc/source/manual/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ $ pip install gunicorn domain-admin

# 启动运行
$ gunicorn --bind '127.0.0.1:8000' 'domain_admin.main:app'

# 开启异步处理,增加并发
$ gunicorn --bind '127.0.0.1:8000' --worker-class gevent 'domain_admin.main:app'
```

windows 安装
Expand Down
3 changes: 2 additions & 1 deletion domain_admin/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals, absolute_import, division


from flask import request, make_response, send_file
from flask_cors import CORS
from werkzeug.middleware.proxy_fix import ProxyFix

from domain_admin import compat
from domain_admin.log import logger
from domain_admin.config import TEMP_DIR
from domain_admin.model.base_model import db
from domain_admin.model.database import init_database
Expand Down Expand Up @@ -83,6 +83,7 @@ def init_app(flask_app):
:param flask_app:
:return:
"""
logger.info('init_app')

# 注册路由
register.register_app_routers(flask_app, api_map.routes)
Expand Down
4 changes: 3 additions & 1 deletion domain_admin/router/api_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
whois_api, address_api,
domain_info_api, prometheus_api,
log_operation_api, group_user_api,
log_async_task_api, issue_certificate_api, host_api, monitor_api, log_monitor_api)
log_async_task_api, issue_certificate_api,
host_api, monitor_api, log_monitor_api
)
from domain_admin.api import domain_api
from domain_admin.api import group_api
from domain_admin.api import auth_api
Expand Down
8 changes: 3 additions & 5 deletions domain_admin/utils/datetime_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_timestamp_with_microsecond(datetime_obj):
ref: https://stackoverflow.com/questions/50650704/attributeerror-datetime-datetime-object-has-no-attribute-timestamp
:param datetime_obj:
:return: float
:return: int
"""
if sys.version_info[0] < 3 or sys.version_info[1] < 4:
# python version < 3.3
Expand Down Expand Up @@ -207,16 +207,14 @@ def get_diff_time_with_microsecond(start_date, end_date):
获取两个时间对象的时间差秒数
:param start_date:
:param end_date:
:return:
:return: int
"""
print('get_diff_time_with_microsecond', start_date, end_date)

if start_date and end_date \
and isinstance(start_date, datetime) \
and isinstance(end_date, datetime):
return get_timestamp_with_microsecond(end_date) - get_timestamp_with_microsecond(start_date)
else:
return 0.0
return 0


def is_less_than(source_date, target_date):
Expand Down
61 changes: 61 additions & 0 deletions domain_admin/utils/open_api/aliyun_oss_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
"""
@File : aliyun_oss_api.py
@Date : 2024-02-02
@Author : Peng Shiyu
OSS Python SDK适用于Python 2.6、2.7、3.3、3.4、3.5、3.6、3.7、3.8及以上版本。
https://help.aliyun.com/zh/oss/developer-reference/map-custom-domain-names-4?spm=a2c4g.11186623.0.i6
"""
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider, StaticCredentialsProvider


def create_bucket_cname_token():
# 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
auth = oss2.ProviderAuth(StaticCredentialsProvider(access_key_id="", access_key_secret="", security_token=""))

# yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
# 填写Bucket名称,例如examplebucket。
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')

# 填写自定义域名。
test_domain = 'www.example.com'
# 创建CnameToken。
result = bucket.create_bucket_cname_token(test_domain)
# 打印绑定的Cname名称。
print(result.cname)
# 打印OSS返回的CnameToken。
print(result.token)
# 打印CnameToken的过期时间。
print(result.expire_time)


def put_bucket_cname():
# 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
auth = oss2.ProviderAuth(StaticCredentialsProvider(access_key_id="", access_key_secret="", security_token=""))

# yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
# 填写Bucket名称,例如examplebucket。
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')

# 填写自定义域名。
test_domain = 'www.example.com'
# 填写旧版证书ID。
previous_cert_id = '001'
certificate = '''-----BEGIN CERTIFICATE-----
MIIDWzCCAkOgA******KTgnwyOGU9cv+mxA=
-----END CERTIFICATE-----'''
# 设置证书私钥。
private_key = '''-----BEGIN PRIVATE KEY-----
MIIEvQIBADAN******1i2t41Q/SC3HUGC5mJjpO8=
-----END PRIVATE KEY-----
'''

cert = oss2.models.CertInfo(certificate=certificate, private_key=private_key)
# 通过force=True设置强制覆盖旧版证书。
# 通过delete_certificate选择是否删除证书。设置为delete_certificate=True表示删除证书,设置为delete_certificate=False表示不删除证书。
# cert = oss2.models.CertInfo(certificate=certificate, private_key=private_key, force=True, delete_certificate=False)
input = oss2.models.PutBucketCnameRequest(test_domain, cert)
bucket.put_bucket_cname(input)
2 changes: 2 additions & 0 deletions requirements/production.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ acme
fabric
dnspython
openpyxl
psycopg2

0 comments on commit a8be266

Please sign in to comment.