mirror of
https://github.com/go-acme/lego.git
synced 2025-06-06 18:46:15 +02:00
Use GCE_PROJECT for project always, if specified (#750)
This commit is contained in:
parent
43401f2475
commit
c938de68f2
@ -55,10 +55,12 @@ type DNSProvider struct {
|
|||||||
// Project name must be passed in the environment variable: GCE_PROJECT.
|
// Project name must be passed in the environment variable: GCE_PROJECT.
|
||||||
// A Service Account file can be passed in the environment variable: GCE_SERVICE_ACCOUNT_FILE
|
// A Service Account file can be passed in the environment variable: GCE_SERVICE_ACCOUNT_FILE
|
||||||
func NewDNSProvider() (*DNSProvider, error) {
|
func NewDNSProvider() (*DNSProvider, error) {
|
||||||
|
// Use a service account file if specified via environment variable.
|
||||||
if saFile, ok := os.LookupEnv("GCE_SERVICE_ACCOUNT_FILE"); ok {
|
if saFile, ok := os.LookupEnv("GCE_SERVICE_ACCOUNT_FILE"); ok {
|
||||||
return NewDNSProviderServiceAccount(saFile)
|
return NewDNSProviderServiceAccount(saFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use default credentials.
|
||||||
project := os.Getenv("GCE_PROJECT")
|
project := os.Getenv("GCE_PROJECT")
|
||||||
return NewDNSProviderCredentials(project)
|
return NewDNSProviderCredentials(project)
|
||||||
}
|
}
|
||||||
@ -94,6 +96,10 @@ func NewDNSProviderServiceAccount(saFile string) (*DNSProvider, error) {
|
|||||||
return nil, fmt.Errorf("googlecloud: unable to read Service Account file: %v", err)
|
return nil, fmt.Errorf("googlecloud: unable to read Service Account file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If GCE_PROJECT is non-empty it overrides the project in the service
|
||||||
|
// account file.
|
||||||
|
project := os.Getenv("GCE_PROJECT")
|
||||||
|
if project != "" {
|
||||||
// read project id from service account file
|
// read project id from service account file
|
||||||
var datJSON struct {
|
var datJSON struct {
|
||||||
ProjectID string `json:"project_id"`
|
ProjectID string `json:"project_id"`
|
||||||
@ -102,7 +108,8 @@ func NewDNSProviderServiceAccount(saFile string) (*DNSProvider, error) {
|
|||||||
if err != nil || datJSON.ProjectID == "" {
|
if err != nil || datJSON.ProjectID == "" {
|
||||||
return nil, fmt.Errorf("googlecloud: project ID not found in Google Cloud Service Account file")
|
return nil, fmt.Errorf("googlecloud: project ID not found in Google Cloud Service Account file")
|
||||||
}
|
}
|
||||||
project := datJSON.ProjectID
|
project = datJSON.ProjectID
|
||||||
|
}
|
||||||
|
|
||||||
conf, err := google.JWTConfigFromJSON(dat, dns.NdevClouddnsReadwriteScope)
|
conf, err := google.JWTConfigFromJSON(dat, dns.NdevClouddnsReadwriteScope)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user