Skip to content
This repository was archived by the owner on May 14, 2021. It is now read-only.

Raise error for S3 region redirects, check that HTTP response is OK.#36

Open
ab wants to merge 5 commits into
poise:masterfrom
18F:ab-region-redirect
Open

Raise error for S3 region redirects, check that HTTP response is OK.#36
ab wants to merge 5 commits into
poise:masterfrom
18F:ab-region-redirect

Conversation

@ab

@ab ab commented Jul 29, 2017

Copy link
Copy Markdown

This pull request depends upon pull request #35. Only the last commit is unique to this PR.

  • Actually check that the HTTP response code is an 200 OK so that we
    don't return nil if things have actually failed.
  • Handle bucket HTTP redirection. When you request an S3 bucket from the
    wrong region, it returns a 301 redirect with the correct region in a
    header, but no Location header. Because the Chef HTTP client doesn't
    recognize redirects unless the Location header is set, Citadel would
    previously return nil. Instead, raise an exception indicating the
    correct region that should have been passed.
  • Also raise an error if we get any unexpected HTTP status.

Fixes: #25

ab added 4 commits July 29, 2017 17:21
This makes it possible for users of Citadel to get the full response
body from S3 requests and to take custom action depending upon various
different errors without needing to parse the string error message.

For example, this enables callers to distinguish between HTTP 404 and
HTTP 403 errors by using `err.wrapped_exception.response.code`.
It would probably be better to use the aws-sdk or aws-sigv4 gems
directly, but this will work for now.

This allows Citadel to work with KMS encrypted data and with AWS regions
that came online in 2014 or later.

Fixes: poise#28
- Actually check that the HTTP response code is an 200 OK so that we
  don't return nil if things have actually failed.
- Handle bucket HTTP redirection. When you request an S3 bucket from the
  wrong region, it returns a 301 redirect with the correct region in a
  header, but no Location header. Because the Chef HTTP client doesn't
  recognize redirects unless the Location header is set, Citadel would
  previously return nil. Instead, raise an exception indicating the
  correct region that should have been passed.
- Also raise an error if we get any unexpected HTTP status.

Fixes: poise#25
@codecov-io

codecov-io commented Aug 2, 2017

Copy link
Copy Markdown

Codecov Report

Merging #36 into master will decrease coverage by 0.04%.
The diff coverage is 90.56%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #36      +/-   ##
=========================================
- Coverage   87.95%   87.9%   -0.05%     
=========================================
  Files           6       6              
  Lines          83     124      +41     
=========================================
+ Hits           73     109      +36     
- Misses         10      15       +5
Impacted Files Coverage Δ
lib/citadel/error.rb 100% <100%> (ø) ⬆️
lib/citadel/s3.rb 92.06% <89.58%> (-7.94%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a21495f...bdf27bb. Read the comment docs.

@ab ab force-pushed the ab-region-redirect branch from 6127892 to bdf27bb Compare August 6, 2017 05:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants