Skip to content

Commit

Permalink
Fix credential lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrsagen committed Mar 24, 2019
1 parent 8fa6229 commit d577fd6
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func main() {
cleanup := flag.Bool("cleanup", false, "Sets cleanup mode (to be used in --manual-cleanup-hook)")
verbose := flag.Bool("verbose", false, "Enables verbose output")
renewPath := flag.String("renew-path", "/etc/letsencrypt/renewal/", "Let's Encrypt renew folder path")
useRenewCreds := flag.Bool("use-renew-creds", true, "Try to read Cloudflare credentials from Let's Encrypt renew config?")
saveRenewCreds := flag.Bool("save-renew-creds", false, "Save Cloudflare credentials to Let's Encrypt renew config?")
onlySaveRenewCreds := flag.Bool("only-save-renew-creds", false, "Do nothing other than save Cloudflare credentials to Let's Encrypt renew config?")
flag.Parse()
Expand Down Expand Up @@ -53,22 +54,24 @@ func main() {
// Get renewal file path
renewDomain := domain
var renewFilePath string
for {
renewFilePath = path.Join(*renewPath, renewDomain+".conf")
if _, err := os.Stat(renewFilePath); err == nil {
break
}
tldPos := strings.LastIndexByte(renewDomain, '.')
sldPos := strings.IndexByte(renewDomain, '.')
if sldPos == tldPos || sldPos == -1 {
fmt.Println("[error] Certbot renewal file not found")
return
if *saveRenewCreds || (*useRenewCreds && (cfAPIEmail == "" || cfAPIKey == "")) {
for {
renewFilePath = path.Join(*renewPath, renewDomain+".conf")
if _, err := os.Stat(renewFilePath); err == nil {
break
}
tldPos := strings.LastIndexByte(renewDomain, '.')
sldPos := strings.IndexByte(renewDomain, '.')
if sldPos == tldPos || sldPos == -1 {
fmt.Println("[error] Certbot renewal file not found")
return
}
renewDomain = renewDomain[sldPos+1:]
}
renewDomain = renewDomain[sldPos+1:]
}

// Load API email and/or key from renewal file
if cfAPIEmail == "" || cfAPIKey == "" {
if *useRenewCreds && (cfAPIEmail == "" || cfAPIKey == "") {
file, err := ini.Load(renewFilePath)
if err != nil {
fmt.Printf("[error] Failed to load file \"%s\"\n%v\n", renewFilePath, err)
Expand Down

0 comments on commit d577fd6

Please sign in to comment.