Ejemplo n.º 1
0
func (c *gsinitCmd) RunCommand(args []string) error {
	var (
		err          error
		clientId     string
		clientSecret string
	)

	if clientId, clientSecret, err = getClientInfo(); err != nil {
		return err
	}
	transport := googlestorage.MakeOauthTransport(clientId, clientSecret, "")

	var accessCode string
	if accessCode, err = getAccessCode(transport.Config); err != nil {
		return err
	}
	if _, err = transport.Exchange(accessCode); err != nil {
		return err
	}

	fmt.Printf("\nYour Google Storage auth object:\n\n")
	enc := json.NewEncoder(os.Stdout)
	authObj := map[string]string{
		"client_id":     transport.ClientId,
		"client_secret": transport.ClientSecret,
		"refresh_token": transport.RefreshToken,
	}
	enc.Encode(authObj)
	fmt.Print("\n")
	return nil
}
Ejemplo n.º 2
0
func newFromConfig(_ blobserver.Loader, config jsonconfig.Obj) (blobserver.Storage, error) {
	auth := config.RequiredObject("auth")

	gs := &Storage{
		bucket: config.RequiredString("bucket"),
		client: googlestorage.NewClient(googlestorage.MakeOauthTransport(
			auth.RequiredString("client_id"),
			auth.RequiredString("client_secret"),
			auth.RequiredString("refresh_token"))),
	}
	if err := config.Validate(); err != nil {
		return nil, err
	}
	if err := auth.Validate(); err != nil {
		return nil, err
	}
	return gs, nil
}