From d2f6f9e057896ffa9aa8e23e15fa11a9a787bdc1 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 15 Aug 2014 22:06:13 -0700 Subject: [PATCH] serverinit: in the GCE env, set the BaseURL based on the IP address for now. Change-Id: I3be51c52ac78e6f6d7cf373cbc358ac1244526c4 --- pkg/serverinit/env.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pkg/serverinit/env.go b/pkg/serverinit/env.go index db5ae2d40..0982e77d3 100644 --- a/pkg/serverinit/env.go +++ b/pkg/serverinit/env.go @@ -17,7 +17,6 @@ limitations under the License. package serverinit import ( - "errors" "fmt" "strings" @@ -36,13 +35,13 @@ func DefaultEnvConfig() (*Config, error) { auth := "none" user, _ := gce.InstanceAttributeValue("camlistore-username") pass, _ := gce.InstanceAttributeValue("camlistore-password") - confBucket, _ := gce.InstanceAttributeValue("camlistore-config-bucket") - blobBucket, _ := gce.InstanceAttributeValue("camlistore-blob-bucket") - if confBucket == "" { - return nil, errors.New("VM instance metadata key 'camlistore-config-bucket' not set.") + confBucket, err := gce.InstanceAttributeValue("camlistore-config-bucket") + if confBucket == "" || err != nil { + return nil, fmt.Errorf("VM instance metadata key 'camlistore-config-bucket' not set: %v", err) } - if blobBucket == "" { - return nil, errors.New("VM instance metadata key 'camlistore-blob-bucket' not set.") + blobBucket, err := gce.InstanceAttributeValue("camlistore-blob-bucket") + if blobBucket == "" || err != nil { + return nil, fmt.Errorf("VM instance metadata key 'camlistore-blob-bucket' not set: %v", err) } if user != "" && pass != "" { auth = "userpass:" + user + ":" + pass @@ -56,8 +55,15 @@ func DefaultEnvConfig() (*Config, error) { return nil, err } + ipOrHost, _ := gce.ExternalIP() + host, _ := gce.InstanceAttributeValue("camlistore-hostname") + if host != "" { + ipOrHost = host + } + return genLowLevelConfig(&serverconfig.Config{ Auth: auth, + BaseURL: fmt.Sprintf("https://%s", ipOrHost), HTTPS: true, Listen: "0.0.0.0:443", Identity: keyId,