forked from TrueCloudLab/lego
Adding output of which envvars are missing in Cloudflare and Azure (#537)
* Adding output of which envvars are missing in Cloudflare dns provider * go fmt, duh * Fixing & adding test(s) * Adding azure missing env vars checking * Fixing test * Doh, fixing up expected output
This commit is contained in:
parent
5922ca9269
commit
8e9c5ac3e6
4 changed files with 27 additions and 6 deletions
|
@ -28,7 +28,7 @@ type DNSProvider struct {
|
|||
tenantId string
|
||||
resourceGroup string
|
||||
|
||||
context context.Context
|
||||
context context.Context
|
||||
}
|
||||
|
||||
// NewDNSProvider returns a DNSProvider instance configured for azure.
|
||||
|
@ -47,7 +47,13 @@ func NewDNSProvider() (*DNSProvider, error) {
|
|||
// DNSProvider instance configured for azure.
|
||||
func NewDNSProviderCredentials(clientId, clientSecret, subscriptionId, tenantId, resourceGroup string) (*DNSProvider, error) {
|
||||
if clientId == "" || clientSecret == "" || subscriptionId == "" || tenantId == "" || resourceGroup == "" {
|
||||
return nil, fmt.Errorf("Azure configuration missing")
|
||||
missingEnvVars := []string{}
|
||||
for _, envVar := range []string{"AZURE_CLIENT_ID", "AZURE_CLIENT_SECRET", "AZURE_SUBSCRIPTION_ID", "AZURE_TENANT_ID", "AZURE_RESOURCE_GROUP"} {
|
||||
if os.Getenv(envVar) == "" {
|
||||
missingEnvVars = append(missingEnvVars, envVar)
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("Azure configuration missing: %s", strings.Join(missingEnvVars, ","))
|
||||
}
|
||||
|
||||
return &DNSProvider{
|
||||
|
@ -57,7 +63,7 @@ func NewDNSProviderCredentials(clientId, clientSecret, subscriptionId, tenantId,
|
|||
tenantId: tenantId,
|
||||
resourceGroup: resourceGroup,
|
||||
// TODO: A timeout can be added here for cancellation purposes.
|
||||
context: context.Background(),
|
||||
context: context.Background(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ func TestNewDNSProviderValidEnv(t *testing.T) {
|
|||
func TestNewDNSProviderMissingCredErr(t *testing.T) {
|
||||
os.Setenv("AZURE_SUBSCRIPTION_ID", "")
|
||||
_, err := NewDNSProvider()
|
||||
assert.EqualError(t, err, "Azure configuration missing")
|
||||
assert.EqualError(t, err, "Azure configuration missing: AZURE_CLIENT_ID,AZURE_CLIENT_SECRET,AZURE_SUBSCRIPTION_ID,AZURE_TENANT_ID,AZURE_RESOURCE_GROUP")
|
||||
restoreAzureEnv()
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/xenolf/lego/acme"
|
||||
|
@ -37,7 +38,14 @@ func NewDNSProvider() (*DNSProvider, error) {
|
|||
// DNSProvider instance configured for cloudflare.
|
||||
func NewDNSProviderCredentials(email, key string) (*DNSProvider, error) {
|
||||
if email == "" || key == "" {
|
||||
return nil, fmt.Errorf("CloudFlare credentials missing")
|
||||
missingEnvVars := []string{}
|
||||
if email == "" {
|
||||
missingEnvVars = append(missingEnvVars, "CLOUDFLARE_EMAIL")
|
||||
}
|
||||
if key == "" {
|
||||
missingEnvVars = append(missingEnvVars, "CLOUDFLARE_API_KEY")
|
||||
}
|
||||
return nil, fmt.Errorf("CloudFlare credentials missing: %s", strings.Join(missingEnvVars, ","))
|
||||
}
|
||||
|
||||
return &DNSProvider{
|
||||
|
|
|
@ -49,10 +49,17 @@ func TestNewDNSProviderMissingCredErr(t *testing.T) {
|
|||
os.Setenv("CLOUDFLARE_EMAIL", "")
|
||||
os.Setenv("CLOUDFLARE_API_KEY", "")
|
||||
_, err := NewDNSProvider()
|
||||
assert.EqualError(t, err, "CloudFlare credentials missing")
|
||||
assert.EqualError(t, err, "CloudFlare credentials missing: CLOUDFLARE_EMAIL,CLOUDFLARE_API_KEY")
|
||||
restoreCloudFlareEnv()
|
||||
}
|
||||
|
||||
func TestNewDNSProviderMissingCredErrSingle(t *testing.T){
|
||||
os.Setenv("CLOUDFLARE_EMAIL", "awesome@possum.com")
|
||||
_, err:= NewDNSProvider()
|
||||
assert.EqualError(t, err, "CloudFlare credentials missing: CLOUDFLARE_API_KEY")
|
||||
restoreCloudFlareEnv()
|
||||
}
|
||||
|
||||
func TestCloudFlarePresent(t *testing.T) {
|
||||
if !cflareLiveTest {
|
||||
t.Skip("skipping live test")
|
||||
|
|
Loading…
Reference in a new issue