dns_challenge_manual.go raw

   1  package dns01
   2  
   3  import (
   4  	"bufio"
   5  	"fmt"
   6  	"os"
   7  	"time"
   8  )
   9  
  10  const (
  11  	dnsTemplate = `%s %d IN TXT %q`
  12  )
  13  
  14  // DNSProviderManual is an implementation of the ChallengeProvider interface.
  15  // TODO(ldez): move this to providers/dns/manual
  16  //
  17  // Deprecated: Use the manual.DNSProvider instead.
  18  type DNSProviderManual struct{}
  19  
  20  // NewDNSProviderManual returns a DNSProviderManual instance.
  21  //
  22  // Deprecated: Use the manual.NewDNSProvider instead.
  23  func NewDNSProviderManual() (*DNSProviderManual, error) {
  24  	return &DNSProviderManual{}, nil
  25  }
  26  
  27  // Present prints instructions for manually creating the TXT record.
  28  func (*DNSProviderManual) Present(domain, token, keyAuth string) error {
  29  	info := GetChallengeInfo(domain, keyAuth)
  30  
  31  	authZone, err := FindZoneByFqdn(info.EffectiveFQDN)
  32  	if err != nil {
  33  		return fmt.Errorf("manual: could not find zone: %w", err)
  34  	}
  35  
  36  	fmt.Printf("lego: Please create the following TXT record in your %s zone:\n", authZone)
  37  	fmt.Printf(dnsTemplate+"\n", info.EffectiveFQDN, DefaultTTL, info.Value)
  38  	fmt.Printf("lego: Press 'Enter' when you are done\n")
  39  
  40  	_, err = bufio.NewReader(os.Stdin).ReadBytes('\n')
  41  	if err != nil {
  42  		return fmt.Errorf("manual: %w", err)
  43  	}
  44  
  45  	return nil
  46  }
  47  
  48  // CleanUp prints instructions for manually removing the TXT record.
  49  func (*DNSProviderManual) CleanUp(domain, token, keyAuth string) error {
  50  	info := GetChallengeInfo(domain, keyAuth)
  51  
  52  	authZone, err := FindZoneByFqdn(info.EffectiveFQDN)
  53  	if err != nil {
  54  		return fmt.Errorf("manual: could not find zone: %w", err)
  55  	}
  56  
  57  	fmt.Printf("lego: You can now remove this TXT record from your %s zone:\n", authZone)
  58  	fmt.Printf(dnsTemplate+"\n", info.EffectiveFQDN, DefaultTTL, "...")
  59  
  60  	return nil
  61  }
  62  
  63  // Sequential All DNS challenges for this provider will be resolved sequentially.
  64  // Returns the interval between each iteration.
  65  func (d *DNSProviderManual) Sequential() time.Duration {
  66  	return DefaultPropagationTimeout
  67  }
  68