github.com/timstclair/heapster@v0.20.0-alpha1/Godeps/_workspace/src/google.golang.org/appengine/internal/identity_vm.go (about)

     1  // Copyright 2011 Google Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache 2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build !appengine
     6  
     7  package internal
     8  
     9  import (
    10  	"net/http"
    11  	"os"
    12  
    13  	netcontext "golang.org/x/net/context"
    14  )
    15  
    16  // These functions are implementations of the wrapper functions
    17  // in ../appengine/identity.go. See that file for commentary.
    18  
    19  const (
    20  	hDefaultVersionHostname = "X-AppEngine-Default-Version-Hostname"
    21  	hRequestLogId           = "X-AppEngine-Request-Log-Id"
    22  	hDatacenter             = "X-AppEngine-Datacenter"
    23  )
    24  
    25  func ctxHeaders(ctx netcontext.Context) http.Header {
    26  	return fromContext(ctx).Request().Header
    27  }
    28  
    29  func DefaultVersionHostname(ctx netcontext.Context) string {
    30  	return ctxHeaders(ctx).Get(hDefaultVersionHostname)
    31  }
    32  
    33  func RequestID(ctx netcontext.Context) string {
    34  	return ctxHeaders(ctx).Get(hRequestLogId)
    35  }
    36  
    37  func Datacenter(ctx netcontext.Context) string {
    38  	return ctxHeaders(ctx).Get(hDatacenter)
    39  }
    40  
    41  func ServerSoftware() string {
    42  	// TODO(dsymonds): Remove fallback when we've verified this.
    43  	if s := os.Getenv("SERVER_SOFTWARE"); s != "" {
    44  		return s
    45  	}
    46  	return "Google App Engine/1.x.x"
    47  }
    48  
    49  // TODO(dsymonds): Remove the metadata fetches.
    50  
    51  func ModuleName(_ netcontext.Context) string {
    52  	if s := os.Getenv("GAE_MODULE_NAME"); s != "" {
    53  		return s
    54  	}
    55  	return string(mustGetMetadata("instance/attributes/gae_backend_name"))
    56  }
    57  
    58  func VersionID(_ netcontext.Context) string {
    59  	if s1, s2 := os.Getenv("GAE_MODULE_VERSION"), os.Getenv("GAE_MINOR_VERSION"); s1 != "" && s2 != "" {
    60  		return s1 + "." + s2
    61  	}
    62  	return string(mustGetMetadata("instance/attributes/gae_backend_version")) + "." + string(mustGetMetadata("instance/attributes/gae_backend_minor_version"))
    63  }
    64  
    65  func InstanceID() string {
    66  	if s := os.Getenv("GAE_MODULE_INSTANCE"); s != "" {
    67  		return s
    68  	}
    69  	return string(mustGetMetadata("instance/attributes/gae_backend_instance"))
    70  }
    71  
    72  func partitionlessAppID() string {
    73  	// gae_project has everything except the partition prefix.
    74  	appID := os.Getenv("GAE_LONG_APP_ID")
    75  	if appID == "" {
    76  		appID = string(mustGetMetadata("instance/attributes/gae_project"))
    77  	}
    78  	return appID
    79  }
    80  
    81  func fullyQualifiedAppID(_ netcontext.Context) string {
    82  	appID := partitionlessAppID()
    83  
    84  	part := os.Getenv("GAE_PARTITION")
    85  	if part == "" {
    86  		part = string(mustGetMetadata("instance/attributes/gae_partition"))
    87  	}
    88  
    89  	if part != "" {
    90  		appID = part + "~" + appID
    91  	}
    92  	return appID
    93  }
    94  
    95  func IsDevAppServer() bool {
    96  	return os.Getenv("RUN_WITH_DEVAPPSERVER") != ""
    97  }