Add Google Cloud DNS plugin (#3011)

Signed-off-by: Palash Nigam <npalash25@gmail.com>

Closes: #2822
This commit is contained in:
Palash Nigam 2019-08-18 02:29:09 +05:30 committed by Yong Tang
parent bde393096f
commit 194b0f95b4
13 changed files with 825 additions and 0 deletions

32
plugin/clouddns/gcp.go Normal file
View file

@ -0,0 +1,32 @@
package clouddns
import gcp "google.golang.org/api/dns/v1"
type gcpDNS interface {
zoneExists(projectName, hostedZoneName string) error
listRRSets(projectName, hostedZoneName string) (*gcp.ResourceRecordSetsListResponse, error)
}
type gcpClient struct {
*gcp.Service
}
// zoneExists is a wrapper method around `gcp.Service.ManagedZones.Get`
// it checks if the provided zone name for a given project exists.
func (c gcpClient) zoneExists(projectName, hostedZoneName string) error {
_, err := c.ManagedZones.Get(projectName, hostedZoneName).Do()
if err != nil {
return err
}
return nil
}
// listRRSets is a wrapper method around `gcp.Service.ResourceRecordSets.List`
// it fetches and returns the record sets for a hosted zone.
func (c gcpClient) listRRSets(projectName, hostedZoneName string) (*gcp.ResourceRecordSetsListResponse, error) {
rr, err := c.ResourceRecordSets.List(projectName, hostedZoneName).Do()
if err != nil {
return nil, err
}
return rr, nil
}