Skip to content

Instantly share code, notes, and snippets.

@wuyanxin
Created January 24, 2025 08:51
Show Gist options
  • Save wuyanxin/fe87de79e9dd39c3821be49ce30f06d3 to your computer and use it in GitHub Desktop.
Save wuyanxin/fe87de79e9dd39c3821be49ce30f06d3 to your computer and use it in GitHub Desktop.
自动更新域名证书并上传七牛云脚本
# 1. certbot 更新证书
# 2. 上传证书到七牛云
# 3. 部署证书到域名
import os.path
import subprocess
import qiniu # pip install qiniu
from qiniu import DomainManager
domain = 'dyxzs.cn'
ssl_dir = f'/etc/letsencrypt/live/{domain}/'
res = subprocess.run(["certbot", "renew", "--force-renewal", '-d', domain])
print(res)
# upload ssl cert to qiniu
access_key = 'xxx'
secret_key = 'sss'
pri_path = os.path.join(ssl_dir, 'privkey.pem')
cert_path = os.path.join(ssl_dir, 'fullchain.pem')
auth = qiniu.Auth(access_key=access_key, secret_key=secret_key)
domain_manager = DomainManager(auth)
with open(pri_path, 'r') as f:
privatekey_str = f.read()
with open(cert_path, 'r') as f:
ca_str = f.read()
ret, info = domain_manager.create_sslcert(
domain, domain, privatekey_str, ca_str)
print(ret)
ret, info = domain_manager.put_httpsconf(domain, ret['certID'], True)
print(ret)
print(info)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment