示例#1
0
文件: gcs.go 项目: ably-forks/flynn
func (b *gcsBackend) Open(tx *postgres.DBTx, info FileInfo, txControl bool) (FileStream, error) {
	if txControl {
		// We don't need the database transaction, so clean it up
		tx.Rollback()
	}

	url, err := storage.SignedURL(b.bucketName, info.ExternalID, b.signOpts())
	return newRedirectFileStream(url), err
}
示例#2
0
func ExampleSignedURL() {
	pkey, err := ioutil.ReadFile("my-private-key.pem")
	if err != nil {
		// TODO: handle error.
	}
	url, err := storage.SignedURL("my-bucket", "my-object", &storage.SignedURLOptions{
		GoogleAccessID: "*****@*****.**",
		PrivateKey:     pkey,
		Method:         "GET",
		Expires:        time.Now().Add(48 * time.Hour),
	})
	if err != nil {
		// TODO: handle error.
	}
	fmt.Println(url)
}
示例#3
0
func signedURL(client *storage.Client, bucket, object string) error {
	// Download a p12 service account private key from the Google Developers Console.
	// And convert it to PEM by running the command below:
	//	$ openssl pkcs12 -in key.p12 -passin pass:notasecret -out my-private-key.pem -nodes
	pkey, err := ioutil.ReadFile("my-private-key.pem")
	if err != nil {
		return err
	}
	url, err := storage.SignedURL(bucket, object, &storage.SignedURLOptions{
		GoogleAccessID: "*****@*****.**",
		PrivateKey:     pkey,
		Method:         "GET",
		Expires:        time.Now().Add(48 * time.Hour),
	})
	if err != nil {
		return err
	}
	fmt.Println(url)
	return nil
}