跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • upyun 没提供 https 证书更新的 API 不如自己写一个(以及日志下载)
未分類
22 4 月 2020

upyun 没提供 https 证书更新的 API 不如自己写一个(以及日志下载)

upyun 没提供 https 证书更新的 API 不如自己写一个(以及日志下载)

資深大佬 : cy97cool 61

https://github.com/zjuchenyuan/EasyLogin/blob/master/examples/upyun/upyun.py

基于我的 EasyLogin 写的,其实就是封装了一下 requests 和 Beautifulsoup,提供了 cookie 保存和内容缓存机制

这个 upyun.py 会登录 console.upyun.com ,提供规则刷新和 https 证书更新功能,用法如

# 这里的 @会被替换成*, 刷新 https://py3.io/*.html 的缓存 python3 upyun.py purge https://py3.io/@.html  # 查看所有证书,只显示当前正在使用的自有证书+正在使用的已经过期的证书 python3 upyun.py https list  # 更新所有 30 天之内过期的证书 python3 upyun.py https renew 

更新证书除了需要在 config.py 中提供登录的USERNAME和PASSWORD之外,还需要提供一个 api_func(domain_name)函数,这个函数需要返回证书信息

 {"certificate":"-----BEGIN CERTIFICATE-----n...",    "private_key":"-----BEGIN RSA PRIVATE KEY-----n..."} 

我是使用函数计算用 dns 验证自动更新证书: https://py3.io/Nginx/#https_1

这个函数就是这个样子:(注意到传入的域名可能是子域名 需要判断后缀)

def renew_api(domain):     namedict = {       'py3.io': 'py3io_ATxx',      }     for k, v in namedict.items():         if domain.endswith(k):             return get_from_oss(v)     return False  import requests sess = requests.session() def get_from_oss(name):     crt = sess.get("https://OSSNAME.oss-cn-REGION.aliyuncs.com/{name}.crt".format(name=name), headers={"Referer":"Referer_STRING"})     key = sess.get("https://OSSNAME.oss-cn-REGION.aliyuncs.com/{name}.key".format(name=name), headers={"Referer":"Referer_STRING"})     return {"certificate": crt.text, "private_key": key.text} 

另外 upyun 真的会在 30 天删访问日志,然而法律要求至少保留六个月┑( ̄Д  ̄)┍ 所以需要自己下载日志咯: https://github.com/zjuchenyuan/EasyLogin/blob/master/examples/upyun/downloadlogs.py

从 config.py 读取 mydomains,调用 upyun 提供的 openapi 获取日志并下载

大佬有話說 (0)

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具