osutil,deploy: on GCE, deploy with enough scope to log on GCL

Otherwise, if scope is missing, warn about it.

Change-Id: If840c4f5783708dd5693993ca39b10fd2ad5442e
This commit is contained in:
mpl 2015-08-25 00:30:30 +02:00
parent 432abe24ec
commit 9c0f51b041
3 changed files with 18 additions and 0 deletions

View File

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

View File

@ -1048,6 +1048,7 @@ This tool helps you create your own private Camlistore instance running on Googl
<li>APIs and auth &gt APIs &gt Google Cloud Storage</li>
<li>APIs and auth &gt APIs &gt Google Cloud Storage JSON API</li>
<li>APIs and auth &gt APIs &gt Google Compute Engine</li>
<li>APIs and auth &gt APIs &gt Google Cloud Logging API</li>
</ul>
</ul>
</td></tr>

View File

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