serverinit: in the GCE env, set the BaseURL based on the IP address for now.

Change-Id: I3be51c52ac78e6f6d7cf373cbc358ac1244526c4
This commit is contained in:
Brad Fitzpatrick 2014-08-15 22:06:13 -07:00
parent cab5f227f6
commit d2f6f9e057
1 changed files with 13 additions and 7 deletions

View File

@ -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,