s3

package module
v0.0.0-...-d42fd41 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2017 License: MIT Imports: 10 Imported by: 0

README

Package s3 signs HTTP requests for use with Amazon’s S3 API.

Documentation:
http://godoc.org/github.com/kr/s3

Documentation

Overview

Package s3 signs HTTP requests for Amazon S3 and compatible services.

See http://docs.amazonwebservices.com/AmazonS3/2006-03-01/dev/RESTAuthentication.html.

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultService = &Service{Domain: "amazonaws.com"}

The default Service used by Sign.

Functions

func AmazonBucket

func AmazonBucket(subdomain string) string

AmazonBucket returns up to last section of subdomain. Intended to be used with Amazon S3 service: "johnsmith.s3-eu-west-1" => "johnsmith".

func IdentityBucket

func IdentityBucket(subdomain string) string

IdentityBucket returns subdomain as-is.

func Sign

func Sign(r *http.Request, k Keys)

Sign signs an HTTP request with the given S3 keys.

This function is shorthand for DefaultService.Sign(r, k).

Example
package main

import (
	"fmt"
	"github.com/kr/s3"
	"log"
	"net/http"
	"os"
	"strings"
	"time"
)

func main() {
	keys := s3.Keys{
		AccessKey: os.Getenv("S3_ACCESS_KEY"),
		SecretKey: os.Getenv("S3_SECRET_KEY"),
	}
	data := strings.NewReader("hello, world")
	r, _ := http.NewRequest("PUT", "https://example.s3.amazonaws.com/foo", data)
	r.ContentLength = int64(data.Len())
	r.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
	r.Header.Set("X-Amz-Acl", "public-read")
	s3.Sign(r, keys)
	resp, err := http.DefaultClient.Do(r)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(resp.StatusCode)
}

func SignQuery

func SignQuery(r *http.Request, t time.Time, k Keys)

Types

type Keys

type Keys struct {
	AccessKey string
	SecretKey string
	// Used for temporary security credentials. Leave blank to use
	// standard AWS Account or IAM credentials.
	// See http://docs.aws.amazon.com/AmazonS3/latest/dev/MakingRequests.html#TypesofSecurityCredentials
	SecurityToken string
}

Keys holds a set of Amazon Security Credentials.

type Service

type Service struct {
	Domain string                        // service root domain, used to extract subdomain from an http.Request and pass it to Bucket
	Bucket func(subdomain string) string // function used to derive a bucket name from subdomain; if nil, AmazonBucket is used
}

Service represents an S3-compatible service.

func (*Service) Sign

func (s *Service) Sign(r *http.Request, k Keys)

Sign signs an HTTP request with the given S3 keys for use on service s.

func (*Service) SignQuery

func (s *Service) SignQuery(r *http.Request, t time.Time, k Keys)

Directories

Path Synopsis
Command s3cp copies a file to or from Amazon S3.
Command s3cp copies a file to or from Amazon S3.
Package s3util provides streaming transfers to and from Amazon S3.
Package s3util provides streaming transfers to and from Amazon S3.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL