DNSimpleProvider: Check valid credentials

This commit is contained in:
Simone Carletti 2016-01-26 12:25:51 +01:00
parent 3f4b078329
commit bcfce0809a
2 changed files with 16 additions and 2 deletions

View file

@ -1,6 +1,8 @@
package acme package acme
import ( import (
"fmt"
"github.com/weppos/go-dnsimple/dnsimple" "github.com/weppos/go-dnsimple/dnsimple"
) )
@ -12,7 +14,15 @@ type DNSProviderDNSimple struct {
// NewDNSProviderDNSimple returns a DNSProviderDNSimple instance with a configured dnsimple client. // NewDNSProviderDNSimple returns a DNSProviderDNSimple instance with a configured dnsimple client.
// Authentication is either done using the passed credentials. // Authentication is either done using the passed credentials.
func NewDNSProviderDNSimple(dnsimpleEmail, dnsimpleApiKey string) (*DNSProviderDNSimple, error) { func NewDNSProviderDNSimple(dnsimpleEmail, dnsimpleApiKey string) (*DNSProviderDNSimple, error) {
return nil, nil if dnsimpleEmail == "" || dnsimpleApiKey == "" {
return nil, fmt.Errorf("DNSimple credentials missing")
}
c := &DNSProviderDNSimple{
client: dnsimple.NewClient(dnsimpleApiKey, dnsimpleEmail),
}
return c, nil
} }
// Present creates a TXT record to fulfil the dns-01 challenge. // Present creates a TXT record to fulfil the dns-01 challenge.

View file

@ -6,8 +6,12 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestNewDNSProviderDNSimpleValid(t *testing.T) { func TestNewDNSProviderDNSimpleValid(t *testing.T) {
_, err := NewDNSProviderDNSimple("example@example.com", "123") _, err := NewDNSProviderDNSimple("example@example.com", "123")
assert.NoError(t, err) assert.NoError(t, err)
} }
func TestNewDNSProviderDNSimpleMissingCredErr(t *testing.T) {
_, err := NewDNSProviderDNSimple("", "")
assert.EqualError(t, err, "DNSimple credentials missing")
}