@@ -55,10 +55,12 @@ type DNSProvider struct {
55
55
// Project name must be passed in the environment variable: GCE_PROJECT.
56
56
// A Service Account file can be passed in the environment variable: GCE_SERVICE_ACCOUNT_FILE
57
57
func NewDNSProvider () (* DNSProvider , error ) {
58
+ // Use a service account file if specified via environment variable.
58
59
if saFile , ok := os .LookupEnv ("GCE_SERVICE_ACCOUNT_FILE" ); ok {
59
60
return NewDNSProviderServiceAccount (saFile )
60
61
}
61
62
63
+ // Use default credentials.
62
64
project := os .Getenv ("GCE_PROJECT" )
63
65
return NewDNSProviderCredentials (project )
64
66
}
@@ -94,15 +96,20 @@ func NewDNSProviderServiceAccount(saFile string) (*DNSProvider, error) {
94
96
return nil , fmt .Errorf ("googlecloud: unable to read Service Account file: %v" , err )
95
97
}
96
98
97
- // read project id from service account file
98
- var datJSON struct {
99
- ProjectID string `json:"project_id"`
100
- }
101
- err = json .Unmarshal (dat , & datJSON )
102
- if err != nil || datJSON .ProjectID == "" {
103
- return nil , fmt .Errorf ("googlecloud: project ID not found in Google Cloud Service Account file" )
99
+ // If GCE_PROJECT is non-empty it overrides the project in the service
100
+ // account file.
101
+ project := os .Getenv ("GCE_PROJECT" )
102
+ if project != "" {
103
+ // read project id from service account file
104
+ var datJSON struct {
105
+ ProjectID string `json:"project_id"`
106
+ }
107
+ err = json .Unmarshal (dat , & datJSON )
108
+ if err != nil || datJSON .ProjectID == "" {
109
+ return nil , fmt .Errorf ("googlecloud: project ID not found in Google Cloud Service Account file" )
110
+ }
111
+ project = datJSON .ProjectID
104
112
}
105
- project := datJSON .ProjectID
106
113
107
114
conf , err := google .JWTConfigFromJSON (dat , dns .NdevClouddnsReadwriteScope )
108
115
if err != nil {
0 commit comments