Esempio n. 1
0
// getClient returns an authorized storage.Service and the
// corresponding http.Client; if anything goes wrong, it logs a fatal
// error.
func getClient() (storageClient, error) {
	var client *http.Client
	var err error
	if *local {
		client, err = auth.RunFlow(auth.OAuthConfig(*oauthCacheFile, auth.SCOPE_FULL_CONTROL))
		// TODO(stephana): Replace auth.RunFlow with auth.NewClient
		// client, err = auth.NewClient(true, *oauthCacheFile, auth.SCOPE_FULL_CONTROL, auth.SCOPE_GCE)
	} else {
		client = auth.GCEServiceAccountClient(&http.Transport{Dial: util.DialTimeout})
	}
	if err != nil {
		return storageClient{}, err
	}
	gsService, err := storage.New(client)
	if err != nil {
		return storageClient{}, err
	}
	return storageClient{httpClient: client, storageService: gsService}, nil
}
Esempio n. 2
0
func GetOAuthClient() (*http.Client, error) {
	config := auth.OAuthConfig(GSTokenPath, auth.SCOPE_FULL_CONTROL)
	return auth.RunFlowWithTransport(config, util.NewBackOffTransport())
}