awscr-signer

Sign HTTP::Request objects and generate presigned post forms aws aws-signature aws-v4 signing aws-v2
0.2.1 released

awscr-signer

Build Status

Crystal interface for signing requests according to the AWS V4 signing spec. Can be used across AWS regions and services.

Installation

Add this to your application's shard.yml:

dependencies:
  awscr-signer:
    github: taylorfinnell/awscr-signer

Usage

You may sign a Crystal HTTP::Request.

require "awscr-signer"

request = HTTP::Request.new("GET", "/", HTTP::Headers.new)

creds = Awscr::Signer::Credentials.new("AKIDEXAMPLE", "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY")
scope  = Awscr::Signer::Scope.new("us-east-1", "service")
signer = Awscr::Signer::V4.new(request, scope, creds)
signer.sign

puts request.headers["Authorization"] # the authorization header is set

A small S3 "client" that demonstrates usage.

require "awscs-signer"

HOST = "mybucket.s3.amazonaws.com"

creds = Awscr::Signers::Credentials.new("AKIDEXAMPLE", "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY")
scope  = Awscr::Signer::Scope.new("us-east-1", "service")

def client(host, &block)
  client = HTTP::Client.new(host)

  client.before_request do |request|
    request.headers["Host"] = HOST
    signer = Awscr::Signer::V4.new(request, scope, credentials)
    signer.sign
  end

  yield client
end

client(HOST) do |client|
  puts client.get("?acl").body
  puts client.get("?list-type=2").body
end

Known Limitations

The following items are known issues. A client using this library can ensure these headers are never signed as a work around until they get fixed.

  • Relative paths are not supported ie: /example/..
  • Certain slashes in the URI path ie: //example//, //
  • Newline separated values
  • Spaces in the path ie: /example stuff/

Development

The code attempts to mimic the various parts described in the documentation here

awscr-signer:
  github: taylorfinnell/awscr-signer
  version: ~> 0.2.1
License MIT
Crystal none

Authors

Dependencies 0

Development Dependencies 1

  • timecop~taylorfinnell update-for-crystal-0.20.1
    {'branch' => 'update-for-crystal-0.20.1', 'github' => 'taylorfinnell/timecop.cr'}
Last synced .
search fire star recently