1
0
mirror of https://github.com/go-acme/lego.git synced 2025-11-29 16:57:53 +02:00

chore: use custom API client constructor for sakuracloud (#2587)

This commit is contained in:
Ludovic Fernandez
2025-07-17 17:38:48 +02:00
committed by GitHub
parent 0eac4b3dda
commit 7d82b83bfd

View File

@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"strings"
"time"
"github.com/go-acme/lego/v4/challenge"
@@ -13,6 +14,7 @@ import (
"github.com/go-acme/lego/v4/providers/dns/internal/useragent"
client "github.com/sacloud/api-client-go"
"github.com/sacloud/iaas-api-go"
"github.com/sacloud/iaas-api-go/defaults"
"github.com/sacloud/iaas-api-go/helper/api"
)
@@ -104,7 +106,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
}
return &DNSProvider{
client: iaas.NewDNSOp(api.NewCallerWithOptions(api.MergeOptions(defaultOption, options))),
client: iaas.NewDNSOp(newCallerWithOptions(api.MergeOptions(defaultOption, options))),
config: config,
}, nil
}
@@ -138,3 +140,37 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
return d.config.PropagationTimeout, d.config.PollingInterval
}
// Extracted from https://github.com/sacloud/iaas-api-go/blob/af06b3ccc2c38625d2dc684ad39590d0ae13eed3/helper/api/caller.go#L36-L81
// Trace and fake are removed.
// Related to https://github.com/sacloud/iaas-api-go/issues/376.
func newCallerWithOptions(opts *api.CallerOptions) iaas.APICaller {
return newCaller(opts)
}
func newCaller(opts *api.CallerOptions) iaas.APICaller {
if opts.UserAgent == "" {
opts.UserAgent = iaas.DefaultUserAgent
}
caller := iaas.NewClientWithOptions(opts.Options)
defaults.DefaultStatePollingTimeout = 72 * time.Hour
if opts.DefaultZone != "" {
iaas.APIDefaultZone = opts.DefaultZone
}
if len(opts.Zones) > 0 {
iaas.SakuraCloudZones = opts.Zones
}
if opts.APIRootURL != "" {
if strings.HasSuffix(opts.APIRootURL, "/") {
opts.APIRootURL = strings.TrimRight(opts.APIRootURL, "/")
}
iaas.SakuraCloudAPIRoot = opts.APIRootURL
}
return caller
}