switching gcloud to use json mode. Not backward compatible. (#24)

This commit is contained in:
Craig Peterson 2017-01-11 12:09:14 -07:00 committed by GitHub
parent 20bf7ef43b
commit ba94dc9777

View file

@ -6,7 +6,6 @@ import (
"fmt"
"strings"
"golang.org/x/oauth2"
gauth "golang.org/x/oauth2/google"
"google.golang.org/api/dns/v1"
@ -27,27 +26,23 @@ type gcloud struct {
// New creates a new gcloud provider
func New(cfg map[string]string, _ json.RawMessage) (providers.DNSServiceProvider, error) {
for _, key := range []string{"clientId", "clientSecret", "refreshToken", "project"} {
if cfg[key] == "" {
return nil, fmt.Errorf("%s required for google cloud provider", key)
}
raw, err := json.Marshal(cfg)
if err != nil {
return nil, err
}
ocfg := &oauth2.Config{
Endpoint: gauth.Endpoint,
ClientID: cfg["clientId"],
ClientSecret: cfg["clientSecret"],
config, err := gauth.JWTConfigFromJSON(raw, "https://www.googleapis.com/auth/ndev.clouddns.readwrite")
if err != nil {
return nil, err
}
tok := &oauth2.Token{
RefreshToken: cfg["refreshToken"],
}
client := ocfg.Client(context.Background(), tok)
dcli, err := dns.New(client)
ctx := context.Background()
hc := config.Client(ctx)
dcli, err := dns.New(hc)
if err != nil {
return nil, err
}
return &gcloud{
client: dcli,
project: cfg["project"],
project: cfg["project_id"],
}, nil
}