forked from toolshed/abra
WIP: domain listing with Gandi
Rethinking the interface already.
This commit is contained in:
28
pkg/dns/common.go
Normal file
28
pkg/dns/common.go
Normal file
@ -0,0 +1,28 @@
|
||||
package dns
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// NewToken constructs a new DNS provider token.
|
||||
func NewToken(provider, providerTokenEnvVar string) (string, error) {
|
||||
if token, present := os.LookupEnv(providerTokenEnvVar); present {
|
||||
return token, nil
|
||||
}
|
||||
|
||||
logrus.Debugf("no %s in environment, asking via stdin", providerTokenEnvVar)
|
||||
|
||||
var token string
|
||||
prompt := &survey.Input{
|
||||
Message: fmt.Sprintf("%s API token?", provider),
|
||||
}
|
||||
if err := survey.AskOne(prompt, &token); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return token, nil
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package gandi
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/libdns/gandi"
|
||||
"github.com/libdns/libdns"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func getToken() (string, error) {
|
||||
if token, present := os.LookupEnv("GANDI_TOKEN"); present {
|
||||
return token, nil
|
||||
}
|
||||
|
||||
logrus.Debugf("no GANDI_TOKEN in environment, asking via stdin")
|
||||
|
||||
var token string
|
||||
prompt := &survey.Input{
|
||||
Message: "Gandi API token?",
|
||||
}
|
||||
if err := survey.AskOne(prompt, &token); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func getProvider() (gandi.Provider, error) {
|
||||
token, err := getToken()
|
||||
if err != nil {
|
||||
return gandi.Provider{}, err
|
||||
}
|
||||
return gandi.Provider{APIToken: token}, nil
|
||||
}
|
||||
|
||||
func ListDomains() ([]libdns.Record, error) {
|
||||
return []libdns.Record{}, nil
|
||||
}
|
||||
|
||||
func RemoveDomain() (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func AddDomain() (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func UpdateDomain() (bool, error) {
|
||||
return false, nil
|
||||
}
|
15
pkg/dns/gandi/gandi.go
Normal file
15
pkg/dns/gandi/gandi.go
Normal file
@ -0,0 +1,15 @@
|
||||
package gandi
|
||||
|
||||
import (
|
||||
"coopcloud.tech/abra/pkg/dns"
|
||||
"github.com/libdns/gandi"
|
||||
)
|
||||
|
||||
// New constructs a new DNs provider.
|
||||
func New() (gandi.Provider, error) {
|
||||
token, err := dns.NewToken("Gandi", "GANDI_TOKEN")
|
||||
if err != nil {
|
||||
return gandi.Provider{}, err
|
||||
}
|
||||
return gandi.Provider{APIToken: token}, nil
|
||||
}
|
Reference in New Issue
Block a user