Class: Aws::CloudFront::UrlSigner

Inherits:
Object
  • Object
show all
Includes:
Signer
Defined in:
gems/aws-sdk-cloudfront/lib/aws-sdk-cloudfront/url_signer.rb

Overview

Allows you to create signed URLs for Amazon CloudFront resources

signer = Aws::CloudFront::UrlSigner.new(
  key_pair_id: "cf-keypair-id",
  private_key_path: "./unit_test_dummy_key"
)
url = signer.signed_url(url,
  policy: policy.to_json
)

Instance Method Summary collapse

Methods included from Signer

#initialize

Instance Method Details

#signed_url(url, params = {}) ⇒ Object

create a signed Amazon CloudFront URL

Parameters:

  • url (String)
  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :expires (Time, DateTime, Date, String, Integer<timestamp>)
  • :policy (String<JSON>)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'gems/aws-sdk-cloudfront/lib/aws-sdk-cloudfront/url_signer.rb', line 28

def signed_url(url, params = {})
  scheme, uri = scheme_and_uri(url)
  signed_content = signature(
    resource: resource(scheme, uri),
    expires: time(params[:expires]),
    policy: params[:policy]
  )

  start_flag = uri.include?('?') ? '&' : '?'
  signature = signed_content.map{ |k, v| "#{k}=#{v}" }.join('&').delete("\n")
  uri = "#{uri}#{start_flag}#{signature}"

  if scheme == 'rtmp'
    rtmp_url(URI(uri))
  else
    uri
  end
end