-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: start switching to libdns, update go
Updates go to 1.19. It's not the latest, but was the most compatible version I could bump up to while requiring the least changes. quic-go had to be updated a few versions (again, not the latest) and required minor changes. This PR updates all tests to work for the certmagic changes, and they are now all passing, except for the plugin count test. Next up is to change all of the DNS providers in tmpim/dnsproviders to use libdns. Eventually each provider should just become minimal glue that takes `credentials ...string`, and all the environment variables lego supported, and returns the configured libdns provider. A temporary Cloudflare provider has been added in `caskettls/dnsproviders.go` to show what that would look like. The Cloudflare provider update already has a breaking change; legacy auth tokens are no longer supported.
- Loading branch information
Showing
19 changed files
with
317 additions
and
435 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ Casketfile.* | |
!casketfile/ | ||
casket/go.mod | ||
casket/go.sum | ||
caskethttp/browse/tempTemplate* | ||
|
||
og_static/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package caskettls | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/caddyserver/certmagic" | ||
"github.com/libdns/cloudflare" | ||
"github.com/tmpim/casket/caskettls/env" | ||
"strings" | ||
) | ||
|
||
const tokenErr = "cloudflare: email and API tokens are no longer supported in Casket, please use Scoped Tokens only. " + | ||
"More info: https://pkg.go.dev/github.com/libdns/cloudflare#readme-authenticating" | ||
|
||
func init() { | ||
RegisterDNSProvider("cloudflare", func(credentials ...string) (certmagic.ACMEDNSProvider, error) { | ||
switch len(credentials) { | ||
case 0: | ||
values, err := env.GetWithFallback([]string{ | ||
"CLOUDFLARE_ZONE_API_TOKEN", | ||
"CF_ZONE_API_TOKEN", | ||
"CLOUDFLARE_DNS_API_TOKEN", | ||
"CF_DNS_API_TOKEN", | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("cloudflare: %v", err) | ||
} | ||
|
||
return &cloudflare.Provider{APIToken: values["CLOUDFLARE_ZONE_API_TOKEN"]}, nil | ||
case 1: | ||
return &cloudflare.Provider{APIToken: credentials[0]}, nil | ||
case 2: | ||
if strings.Contains(credentials[0], "@") { | ||
return nil, errors.New(tokenErr) | ||
} | ||
|
||
switch credentials[0] { | ||
case "zonetoken": | ||
return &cloudflare.Provider{APIToken: credentials[1]}, nil | ||
default: | ||
return nil, errors.New(tokenErr) | ||
} | ||
default: | ||
return nil, errors.New("invalid credentials length") | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package env | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"strings" | ||
) | ||
|
||
// Utilities for getting environment variables, to be used by the DNS providers in tmpim/dnsproviders. These utility | ||
// functions are based on lego's config/env/env.go, which is licensed under the MIT license. See | ||
// https://github.com/go-acme/lego/blob/master/LICENSE for more details. | ||
|
||
// GetWithFallback Get environment variable values. | ||
// The first name in each group is use as key in the result map. | ||
// | ||
// case 1: | ||
// | ||
// // LEGO_ONE="ONE" | ||
// // LEGO_TWO="TWO" | ||
// env.GetWithFallback([]string{"LEGO_ONE", "LEGO_TWO"}) | ||
// // => "LEGO_ONE" = "ONE" | ||
// | ||
// case 2: | ||
// | ||
// // LEGO_ONE="" | ||
// // LEGO_TWO="TWO" | ||
// env.GetWithFallback([]string{"LEGO_ONE", "LEGO_TWO"}) | ||
// // => "LEGO_ONE" = "TWO" | ||
// | ||
// case 3: | ||
// | ||
// // LEGO_ONE="" | ||
// // LEGO_TWO="" | ||
// env.GetWithFallback([]string{"LEGO_ONE", "LEGO_TWO"}) | ||
// // => error | ||
func GetWithFallback(groups ...[]string) (map[string]string, error) { | ||
values := map[string]string{} | ||
|
||
var missingEnvVars []string | ||
for _, names := range groups { | ||
if len(names) == 0 { | ||
return nil, errors.New("undefined environment variable names") | ||
} | ||
|
||
value, envVar := getOneWithFallback(names[0], names[1:]...) | ||
if len(value) == 0 { | ||
missingEnvVars = append(missingEnvVars, envVar) | ||
continue | ||
} | ||
values[envVar] = value | ||
} | ||
|
||
if len(missingEnvVars) > 0 { | ||
return nil, fmt.Errorf("some credentials information are missing: %s", strings.Join(missingEnvVars, ",")) | ||
} | ||
|
||
return values, nil | ||
} | ||
|
||
func getOneWithFallback(main string, names ...string) (string, string) { | ||
value := GetOrFile(main) | ||
if len(value) > 0 { | ||
return value, main | ||
} | ||
|
||
for _, name := range names { | ||
value := GetOrFile(name) | ||
if len(value) > 0 { | ||
return value, main | ||
} | ||
} | ||
|
||
return "", main | ||
} | ||
|
||
// GetOrFile Attempts to resolve 'key' as an environment variable. | ||
// Failing that, it will check to see if '<key>_FILE' exists. | ||
// If so, it will attempt to read from the referenced file to populate a value. | ||
func GetOrFile(envVar string) string { | ||
envVarValue := os.Getenv(envVar) | ||
if envVarValue != "" { | ||
return envVarValue | ||
} | ||
|
||
fileVar := envVar + "_FILE" | ||
fileVarValue := os.Getenv(fileVar) | ||
if fileVarValue == "" { | ||
return envVarValue | ||
} | ||
|
||
fileContents, err := ioutil.ReadFile(fileVarValue) | ||
if err != nil { | ||
log.Printf("Failed to read the file %s (defined by env var %s): %s", fileVarValue, fileVar, err) | ||
return "" | ||
} | ||
|
||
return strings.TrimSuffix(string(fileContents), "\n") | ||
} |
Oops, something went wrong.