All checks were successful
continuous-integration/drone/push Build is passing
Rethinking the interface already.
29 lines
589 B
Go
29 lines
589 B
Go
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
|
|
}
|