sing/common/acme/config.go
2022-04-30 17:33:31 +08:00

37 lines
938 B
Go

package acme
import (
"os"
"github.com/go-acme/lego/v4/challenge"
"github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/acme/cloudflare"
E "github.com/sagernet/sing/common/exceptions"
)
type Settings struct {
Enabled bool `json:"enabled"`
DataDirectory string `json:"data_directory"`
Email string `json:"email"`
DNSProvider string `json:"dns_provider"`
DNSEnv *common.JSONMap `json:"dns_env"`
}
func (s *Settings) SetupEnvironment() error {
for envName, envValue := range s.DNSEnv.Data {
err := os.Setenv(envName, envValue.(string))
if err != nil {
return err
}
}
return nil
}
func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
switch name {
case "cloudflare":
return cloudflare.NewDNSProvider()
}
// return dns.NewDNSChallengeProviderByName(name)
return nil, E.New("unsupported dns provider ", name)
}