iwantmyname.go raw
1 // Package iwantmyname implements a DNS provider for solving the DNS-01 challenge using iwantmyname.
2 package iwantmyname
3
4 import (
5 "errors"
6 "fmt"
7 "net/http"
8 "time"
9
10 "github.com/go-acme/lego/v4/challenge"
11 "github.com/go-acme/lego/v4/platform/config/env"
12 )
13
14 // Environment variables names.
15 const (
16 envNamespace = "IWANTMYNAME_"
17
18 EnvUsername = envNamespace + "USERNAME"
19 EnvPassword = envNamespace + "PASSWORD"
20
21 EnvTTL = envNamespace + "TTL"
22 EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
23 EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
24 EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
25 )
26
27 var _ challenge.ProviderTimeout = (*DNSProvider)(nil)
28
29 // Config is used to configure the creation of the DNSProvider.
30 type Config struct {
31 Username string
32 Password string
33 PropagationTimeout time.Duration
34 PollingInterval time.Duration
35 TTL int
36 HTTPClient *http.Client
37 }
38
39 // NewDefaultConfig returns a default configuration for the DNSProvider.
40 func NewDefaultConfig() *Config {
41 return &Config{}
42 }
43
44 // DNSProvider implements the challenge.Provider interface.
45 type DNSProvider struct {
46 config *Config
47 }
48
49 // NewDNSProvider returns a DNSProvider instance configured for iwantmyname.
50 // Credentials must be passed in the environment variables: IWANTMYNAME_USERNAME, IWANTMYNAME_PASSWORD.
51 func NewDNSProvider() (*DNSProvider, error) {
52 values, err := env.Get(EnvUsername, EnvPassword)
53 if err != nil {
54 return nil, fmt.Errorf("iwantmyname: %w", err)
55 }
56
57 config := NewDefaultConfig()
58 config.Username = values[EnvUsername]
59 config.Password = values[EnvPassword]
60
61 return NewDNSProviderConfig(config)
62 }
63
64 // NewDNSProviderConfig return a DNSProvider instance configured for iwantmyname.
65 func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
66 return nil, errors.New("iwantmyname: the iwantmyname API has shut down https://github.com/go-acme/lego/issues/2563")
67 }
68
69 // Timeout returns the timeout and interval to use when checking for DNS propagation.
70 // Adjusting here to cope with spikes in propagation times.
71 func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
72 return d.config.PropagationTimeout, d.config.PollingInterval
73 }
74
75 // Present creates a TXT record using the specified parameters.
76 func (d *DNSProvider) Present(domain, _, keyAuth string) error {
77 return nil
78 }
79
80 // CleanUp removes the TXT record matching the specified parameters.
81 func (d *DNSProvider) CleanUp(domain, _, keyAuth string) error {
82 return nil
83 }
84