Class: Gem::S3URISigner
- Inherits:
-
Object
- Object
- Gem::S3URISigner
- Includes:
- UserInteraction
- Defined in:
- lib/rubygems/s3_uri_signer.rb
Overview
S3URISigner implements AWS SigV4 for S3 Source to avoid a dependency on the aws-sdk-* gems More on AWS SigV4: docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html
Defined Under Namespace
Classes: ConfigurationError, InstanceProfileError, S3Config
Instance Attribute Summary collapse
-
#method ⇒ Object
Returns the value of attribute method.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(uri, method) ⇒ S3URISigner
constructor
A new instance of S3URISigner.
-
#sign(expiration = 86_400) ⇒ Object
Signs S3 URI using query-params according to the reference: docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html.
Methods included from UserInteraction
#alert, #alert_error, #alert_warning, #ask, #ask_for_password, #ask_yes_no, #choose_from_list, #say, #terminate_interaction, #verbose
Methods included from DefaultUserInteraction
ui, #ui, ui=, #ui=, use_ui, #use_ui
Methods included from Text
#clean_text, #format_text, #levenshtein_distance, #min3, #truncate_text
Constructor Details
#initialize(uri, method) ⇒ S3URISigner
Returns a new instance of S3URISigner.
35 36 37 38 |
# File 'lib/rubygems/s3_uri_signer.rb', line 35 def initialize(uri, method) @uri = uri @method = method end |
Instance Attribute Details
#method ⇒ Object
Returns the value of attribute method.
33 34 35 |
# File 'lib/rubygems/s3_uri_signer.rb', line 33 def method @method end |
#uri ⇒ Object
Returns the value of attribute uri.
32 33 34 |
# File 'lib/rubygems/s3_uri_signer.rb', line 32 def uri @uri end |
Instance Method Details
#sign(expiration = 86_400) ⇒ Object
Signs S3 URI using query-params according to the reference: docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rubygems/s3_uri_signer.rb', line 42 def sign(expiration = 86_400) s3_config = fetch_s3_config current_time = Time.now.utc date_time = current_time.strftime("%Y%m%dT%H%M%SZ") date = date_time[0,8] credential_info = "#{date}/#{s3_config.region}/s3/aws4_request" canonical_host = "#{uri.host}.s3.#{s3_config.region}.amazonaws.com" query_params = generate_canonical_query_params(s3_config, date_time, credential_info, expiration) canonical_request = generate_canonical_request(canonical_host, query_params) string_to_sign = generate_string_to_sign(date_time, credential_info, canonical_request) signature = generate_signature(s3_config, date, string_to_sign) Gem::URI.parse("https://#{canonical_host}#{uri.path}?#{query_params}&X-Amz-Signature=#{signature}") end |