Created
August 19, 2023 15:34
-
-
Save bowencool/d0bce4bfb853c7ec1b1a4964e9371381 to your computer and use it in GitHub Desktop.
阿里云 aliyun certbot-renew-hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { DescribeDomainRecordsRequest, DescribeDomainRecordsResponseBodyDomainRecordsRecord, UpdateDomainRecordRequest } from '@alicloud/alidns20150109'; | |
import client from './client' | |
const { CERTBOT_VALIDATION, CERTBOT_REMAINING_CHALLENGES, CERTBOT_DOMAIN, CERTBOT_ALL_DOMAINS } = process.env | |
console.log({ CERTBOT_VALIDATION, CERTBOT_REMAINING_CHALLENGES, CERTBOT_DOMAIN }) | |
async function getConfiguredTXTRecord() { | |
const describeDomainRecordsRequest = new DescribeDomainRecordsRequest({}); | |
describeDomainRecordsRequest.domainName = CERTBOT_DOMAIN; | |
describeDomainRecordsRequest.type = "TXT"; | |
describeDomainRecordsRequest.RRKeyWord = "_acme-challenge"; | |
describeDomainRecordsRequest.status = "Enable"; | |
const response = await client.describeDomainRecords(describeDomainRecordsRequest) | |
const { domainRecords } = response.body; | |
return domainRecords?.record?.[0]; | |
} | |
async function update(record: DescribeDomainRecordsResponseBodyDomainRecordsRecord) { | |
const updateDomainRecordRequest = new UpdateDomainRecordRequest({}) | |
updateDomainRecordRequest.recordId = record.recordId; | |
updateDomainRecordRequest.RR = record.RR; | |
updateDomainRecordRequest.type = record.type; | |
updateDomainRecordRequest.value = CERTBOT_VALIDATION; | |
const response = await client.updateDomainRecord(updateDomainRecordRequest) | |
const { recordId } = response.body; | |
console.log(`Record ${recordId} updated`) | |
} | |
async function main() { | |
const record = await getConfiguredTXTRecord() | |
if (!record) { | |
return console.log('todo add TXT') | |
} | |
console.log(record) | |
await update(record) | |
} | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Alidns20150109 from '@alicloud/alidns20150109'; | |
import { Config } from '@alicloud/openapi-client'; | |
const config = new Config({ | |
accessKeyId: "xxx", | |
accessKeySecret: "xxx", | |
}); | |
// 访问的域名 | |
config.endpoint = `alidns.cn-hangzhou.aliyuncs.com`; | |
export default new Alidns20150109(config); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment