aws4

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2015 License: BSD-2-Clause Imports: 13 Imported by: 0

README

Package aws4 signs HTTP requests with the AWS4 signature for use with Amazon’s AWS APIs.

Documentation: http://godoc.org/github.com/bmizerany/aws4

Copyright (C) 2012 Blake Mizerany

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Package aws4 signs HTTP requests as prescribed in http://docs.amazonwebservices.com/general/latest/gr/signature-version-4.html

Example (FormEncodedBody)
package main

import (
	"fmt"
	"github.com/bmizerany/aws4"
	"log"
	"net/url"
)

func main() {
	v := make(url.Values)
	v.Set("Action", "DescribeAutoScalingGroups")

	resp, err := aws4.PostForm("https://autoscaling.us-east-1.amazonaws.com/", v)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(resp.StatusCode)
}
Output:

200
Example (JSONBody)
package main

import (
	"fmt"
	"github.com/bmizerany/aws4"
	"log"
	"net/http"
	"strings"
)

func main() {
	data := strings.NewReader("{}")
	r, _ := http.NewRequest("POST", "https://dynamodb.us-east-1.amazonaws.com/", data)
	r.Header.Set("Content-Type", "application/x-amz-json-1.0")
	r.Header.Set("X-Amz-Target", "DynamoDB_20111205.ListTables")

	resp, err := aws4.DefaultClient.Do(r)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(resp.StatusCode)
}
Output:

200

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultClient = &Client{Keys: KeysFromEnvironment()}

Functions

func Post

func Post(url string, bodyType string, body io.Reader) (resp *http.Response, err error)

Post works like http.Post, but signs the request with Keys.

func PostForm

func PostForm(url string, data url.Values) (resp *http.Response, err error)

PostForm works like http.PostForm, but signs the request with Keys.

func Sign

func Sign(keys *Keys, r *http.Request) error

Sign signs a request with a Service derived from r.Host

Types

type Client

type Client struct {
	Keys *Keys

	// The http client to make requests with. If nil, http.DefaultClient is used.
	Client *http.Client
}

Client is like http.Client, but signs all requests using Keys.

func (*Client) Do

func (c *Client) Do(req *http.Request) (resp *http.Response, err error)

func (*Client) Get

func (c *Client) Get(url string) (resp *http.Response, err error)

func (*Client) Head

func (c *Client) Head(url string) (resp *http.Response, err error)

func (*Client) Post

func (c *Client) Post(url string, bodyType string, body io.Reader) (resp *http.Response, err error)

func (*Client) PostForm

func (c *Client) PostForm(url string, data url.Values) (resp *http.Response, err error)

type Keys

type Keys struct {
	AccessKey string
	SecretKey string
}

Keys holds a set of Amazon Security Credentials.

func KeysFromEnvironment

func KeysFromEnvironment() *Keys

Initializes and returns a Keys using the AWS_ACCESS_KEY and AWS_SECRET_KEY environment variables.

type Service

type Service struct {
	// Name is the name of the service being used (i.e. iam, etc)
	Name string

	// Region is the region you want to communicate with the service through. (i.e. us-east-1)
	Region string
}

Service represents an AWS-compatible service.

func (*Service) Sign

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

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

Directories

Path Synopsis
This is an experimental library for use with DynamoDB.
This is an experimental library for use with DynamoDB.

Jump to

Keyboard shortcuts

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