mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 21:49:52 +00:00
34 lines
602 B
Go
34 lines
602 B
Go
package applicant
|
|
|
|
import (
|
|
"certimate/internal/domain"
|
|
"encoding/json"
|
|
"os"
|
|
|
|
cf "github.com/go-acme/lego/v4/providers/dns/cloudflare"
|
|
)
|
|
|
|
type cloudflare struct {
|
|
option *ApplyOption
|
|
}
|
|
|
|
func NewCloudflare(option *ApplyOption) Applicant {
|
|
return &cloudflare{
|
|
option: option,
|
|
}
|
|
}
|
|
|
|
func (c *cloudflare) Apply() (*Certificate, error) {
|
|
access := &domain.CloudflareAccess{}
|
|
json.Unmarshal([]byte(c.option.Access), access)
|
|
|
|
os.Setenv("CLOUDFLARE_DNS_API_TOKEN", access.DnsApiToken)
|
|
|
|
provider, err := cf.NewDNSProvider()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return apply(c.option, provider)
|
|
}
|