aboutsummaryrefslogtreecommitdiff
path: root/vendor/google.golang.org/appengine/internal/identity_vm.go
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net> 2019-09-05 21:39:32 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net> 2019-09-05 21:53:12 -0700
commitb94160df725a52af53f113bf27de7a7b8723174c (patch)
tree9e86b227d4683f26da9b393410df1bedc2e95074 /vendor/google.golang.org/appengine/internal/identity_vm.go
parent456ebaf423ce2122bf8faa36da464c5d90361204 (diff)
downloadv2-b94160df725a52af53f113bf27de7a7b8723174c.tar.gz
v2-b94160df725a52af53f113bf27de7a7b8723174c.tar.zst
v2-b94160df725a52af53f113bf27de7a7b8723174c.zip
Update dependencies
Diffstat (limited to 'vendor/google.golang.org/appengine/internal/identity_vm.go')
-rw-r--r--vendor/google.golang.org/appengine/internal/identity_vm.go43
1 files changed, 38 insertions, 5 deletions
diff --git a/vendor/google.golang.org/appengine/internal/identity_vm.go b/vendor/google.golang.org/appengine/internal/identity_vm.go
index d5fa75be..5d806726 100644
--- a/vendor/google.golang.org/appengine/internal/identity_vm.go
+++ b/vendor/google.golang.org/appengine/internal/identity_vm.go
@@ -7,8 +7,10 @@
package internal
import (
+ "log"
"net/http"
"os"
+ "strings"
netcontext "golang.org/x/net/context"
)
@@ -39,7 +41,21 @@ func RequestID(ctx netcontext.Context) string {
}
func Datacenter(ctx netcontext.Context) string {
- return ctxHeaders(ctx).Get(hDatacenter)
+ if dc := ctxHeaders(ctx).Get(hDatacenter); dc != "" {
+ return dc
+ }
+ // If the header isn't set, read zone from the metadata service.
+ // It has the format projects/[NUMERIC_PROJECT_ID]/zones/[ZONE]
+ zone, err := getMetadata("instance/zone")
+ if err != nil {
+ log.Printf("Datacenter: %v", err)
+ return ""
+ }
+ parts := strings.Split(string(zone), "/")
+ if len(parts) == 0 {
+ return ""
+ }
+ return parts[len(parts)-1]
}
func ServerSoftware() string {
@@ -47,6 +63,9 @@ func ServerSoftware() string {
if s := os.Getenv("SERVER_SOFTWARE"); s != "" {
return s
}
+ if s := os.Getenv("GAE_ENV"); s != "" {
+ return s
+ }
return "Google App Engine/1.x.x"
}
@@ -56,6 +75,9 @@ func ModuleName(_ netcontext.Context) string {
if s := os.Getenv("GAE_MODULE_NAME"); s != "" {
return s
}
+ if s := os.Getenv("GAE_SERVICE"); s != "" {
+ return s
+ }
return string(mustGetMetadata("instance/attributes/gae_backend_name"))
}
@@ -63,6 +85,9 @@ func VersionID(_ netcontext.Context) string {
if s1, s2 := os.Getenv("GAE_MODULE_VERSION"), os.Getenv("GAE_MINOR_VERSION"); s1 != "" && s2 != "" {
return s1 + "." + s2
}
+ if s1, s2 := os.Getenv("GAE_VERSION"), os.Getenv("GAE_DEPLOYMENT_ID"); s1 != "" && s2 != "" {
+ return s1 + "." + s2
+ }
return string(mustGetMetadata("instance/attributes/gae_backend_version")) + "." + string(mustGetMetadata("instance/attributes/gae_backend_minor_version"))
}
@@ -70,19 +95,27 @@ func InstanceID() string {
if s := os.Getenv("GAE_MODULE_INSTANCE"); s != "" {
return s
}
+ if s := os.Getenv("GAE_INSTANCE"); s != "" {
+ return s
+ }
return string(mustGetMetadata("instance/attributes/gae_backend_instance"))
}
func partitionlessAppID() string {
// gae_project has everything except the partition prefix.
- appID := os.Getenv("GAE_LONG_APP_ID")
- if appID == "" {
- appID = string(mustGetMetadata("instance/attributes/gae_project"))
+ if appID := os.Getenv("GAE_LONG_APP_ID"); appID != "" {
+ return appID
}
- return appID
+ if project := os.Getenv("GOOGLE_CLOUD_PROJECT"); project != "" {
+ return project
+ }
+ return string(mustGetMetadata("instance/attributes/gae_project"))
}
func fullyQualifiedAppID(_ netcontext.Context) string {
+ if s := os.Getenv("GAE_APPLICATION"); s != "" {
+ return s
+ }
appID := partitionlessAppID()
part := os.Getenv("GAE_PARTITION")