awscr-signer
awscr-signer
Crystal interface for AWS Signing.
Supports signing Crytal HTTP::Request
objects and generating presigned post form for browser or programatic uploading. See Browser-Based Uploads Using POST and Authenticating Requests (AWS Signature Version 4) for additional details.
Installation
Add this to your application's shard.yml
:
dependencies:
awscr-signer:
github: taylorfinnell/awscr-signer
Usage
Creating a Credentials
object.
Awscr::Signer::Credentials.new("SECRET_KEY", "SECRET")
Creating a Scope
object.
# where s3 is any amazon service
# where us-east-1 is any region
Awscr::Signer::Scope.new("us-east-1", "s3")
Signing an HTTP::Request
.
signer = Awscr::Signer::V4.new(request, scope, credentials)
signer.sign
NOTE: It may be required for you to set the Host
header to the AWS service
before signing.
Creating a Presigned::Form
.
form = Awscr::Signer::Presigned::Form.build("us-east-1", credentials) do |form|
form.expiration(Time.epoch(Time.now.epoch + 1000))
form.condition("bucket", BUCKET)
form.condition("acl", "public-read")
form.condition("key", SecureRandom.uuid)
form.condition("Content-Type", "text/plain")
form.condition("success_action_status", "201")
end
Converting the form to raw HTML (for browser uploads, etc).
puts form.to_html
Submitting the form via HTTP::Client
.
form.submit(IO::Memory.new("Hello, S3!"))
Known Limitations
The following items are known issues.
- The request URI can not contain repeating slashes
- The request headers can not have new line separted values
- The request path can not contain spaces