Class: Aws::CloudFront::UrlSigner

Inherits:
Object
  • Object
show all
Includes:
Signer
Defined in:
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: "./cf_private_key.pem"
)
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>)


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

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.parse(uri).query ? '&' : '?'
  signature = signed_content.map{ |k, v| "#{k}=#{v}" }.join('&').gsub("\n", '')
  uri = "#{uri}#{start_flag}#{signature}"

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