From 9c0f51b04114e5bb791784e693e07596fd0b1f66 Mon Sep 17 00:00:00 2001 From: mpl Date: Tue, 25 Aug 2015 00:30:30 +0200 Subject: [PATCH] osutil,deploy: on GCE, deploy with enough scope to log on GCL Otherwise, if scope is missing, warn about it. Change-Id: If840c4f5783708dd5693993ca39b10fd2ad5442e --- pkg/deploy/gce/deploy.go | 3 +++ pkg/deploy/gce/handler.go | 1 + pkg/osutil/gce/gce.go | 14 ++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/pkg/deploy/gce/deploy.go b/pkg/deploy/gce/deploy.go index 2ae584ff6..8ed28ee09 100644 --- a/pkg/deploy/gce/deploy.go +++ b/pkg/deploy/gce/deploy.go @@ -48,6 +48,7 @@ import ( compute "google.golang.org/api/compute/v1" storage "google.golang.org/api/storage/v1" "google.golang.org/cloud" + "google.golang.org/cloud/logging" cloudstorage "google.golang.org/cloud/storage" ) @@ -87,6 +88,7 @@ var ( func NewOAuthConfig(clientID, clientSecret string) *oauth2.Config { return &oauth2.Config{ Scopes: []string{ + logging.Scope, compute.DevstorageFull_controlScope, compute.ComputeScope, "https://www.googleapis.com/auth/sqlservice", @@ -377,6 +379,7 @@ func (d *Deployer) createInstance(computeService *compute.Service, ctx *context. { Email: "default", Scopes: []string{ + logging.Scope, compute.DevstorageFull_controlScope, compute.ComputeScope, "https://www.googleapis.com/auth/sqlservice", diff --git a/pkg/deploy/gce/handler.go b/pkg/deploy/gce/handler.go index 52e8ec98f..317440e14 100644 --- a/pkg/deploy/gce/handler.go +++ b/pkg/deploy/gce/handler.go @@ -1048,6 +1048,7 @@ This tool helps you create your own private Camlistore instance running on Googl
  • APIs and auth > APIs > Google Cloud Storage
  • APIs and auth > APIs > Google Cloud Storage JSON API
  • APIs and auth > APIs > Google Compute Engine
  • +
  • APIs and auth > APIs > Google Cloud Logging API
  • diff --git a/pkg/osutil/gce/gce.go b/pkg/osutil/gce/gce.go index aec7ff86d..6b788db63 100644 --- a/pkg/osutil/gce/gce.go +++ b/pkg/osutil/gce/gce.go @@ -77,6 +77,20 @@ func LogWriter() (w io.Writer) { log.Printf("Error getting project ID: %v", err) return } + scopes, _ := metadata.Scopes("default") + haveScope := func(scope string) bool { + for _, x := range scopes { + if x == scope { + return true + } + } + return false + } + if !haveScope(logging.Scope) { + log.Printf("when this Google Compute Engine VM instance was created, it wasn't granted enough access to use Google Cloud Logging (Scope URL: %v).", logging.Scope) + return + } + hc, err := google.DefaultClient(oauth2.NoContext) if err != nil { log.Printf("Error creating default GCE OAuth2 client: %v", err)