// Create a GCE Cloud instance.  'clientId', 'clientSecret' and 'scope' are used to ask for a client
// credential.  'code' is optional and is only used if a cached credential can not be found.
// 'projectId' is the Google Cloud project name.
Create a GCE Cloud instance.  'clientId', 'clientSecret' and 'scope' are used to ask for a client
credential.  'code' is optional and is only used if a cached credential can not be found.
'projectId' is the Google Cloud project name.
// Create a GCE Cloud instance . ' clientId ' ' clientSecret ' and ' scope ' are used to ask for a client // credential . ' code ' is optional and is only used if a cached credential can not be found . // ' projectId ' is the Google Cloud project name .
func NewCloudGCE(projectId string) (cloud *GCECloud, err error) {
	conf := &gceConfig{}
	if err = conf.Read(); err != nil || conf.Credential.RefreshToken == "" {
		return nil, errors.New("Did you authorize the client? Run `docker-cloud auth`.")
	}
	if projectId == "" {
		if conf.ProjectId == "" {
			return nil, errors.New("Did you define project id? Run `docker-cloud start -project=<project-id>`")
		}
		projectId = conf.ProjectId
	}
	oAuth2Conf := newGCEOAuth2Config(conf.Credential.ClientId, conf.Credential.ClientSecret, conf.Key.Scope)
	transport := &oauth.Transport{
		Config: oAuth2Conf,
		Token:     &oauth.Token{RefreshToken: conf.Credential.RefreshToken},
		Transport: http.DefaultTransport,
	}
	err = transport.Refresh()
	if err != nil {
		return
	}
	svc, err := compute.New(transport.Client())
	if err != nil {
		return
	}
	return &GCECloud{
		service:   svc,
		projectId: projectId,
	}, nil
}
func NewCloudGCE ( projectId string ) ( cloud * GCECloud , err error ) { conf := & gceConfig { } if err = conf . Read ( ) ; err != nil || conf . Credential . RefreshToken == " " { return nil , errors . New ( " " ) } if projectId == " " { if conf . ProjectId == " " { return nil , errors . New ( " " ) } projectId = conf . ProjectId } oAuth2Conf := newGCEOAuth2Config ( conf . Credential . ClientId , conf . Credential . ClientSecret , conf . Key . Scope ) transport := & oauth . Transport { Config : oAuth2Conf , Token : & oauth . Token { RefreshToken : conf . Credential . RefreshToken } , Transport : http . DefaultTransport , } err = transport . Refresh ( ) if err != nil { return } svc , err := compute . New ( transport . Client ( ) ) if err != nil { return } return & GCECloud { service : svc , projectId : projectId , } , nil }
Create a GCE Cloud instance.
Create a GCE Cloud instance .
// Make the actual request using the cached token to authenticate. // ("Here's the token, let me in!") // TODO(jbd): Does it need to refresh the token, transport will auto do it if // it fails with an auth error on the first request.