Class: Aws::CloudFront::UrlSigner
- Inherits:
-
Object
- Object
- Aws::CloudFront::UrlSigner
- Defined in:
- lib/aws-sdk-core/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
-
#initialize(options = {}) ⇒ UrlSigner
constructor
A new instance of UrlSigner.
-
#signed_url(url, params = {}) ⇒ Object
create a signed Amazon CloudFront URL.
Constructor Details
#initialize(options = {}) ⇒ UrlSigner
Returns a new instance of UrlSigner.
25 26 27 28 |
# File 'lib/aws-sdk-core/cloudfront/url_signer.rb', line 25 def initialize( = {}) @key_pair_id = key_pair_id() @private_key = private_key() end |
Instance Method Details
#signed_url(url, params = {}) ⇒ Object
create a signed Amazon CloudFront URL
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/aws-sdk-core/cloudfront/url_signer.rb', line 34 def signed_url(url, params = {}) url_sections = url.split('://') if url_sections.length < 2 raise ArgumentError, "Invaild URL:#{url}" end # removing wildcard character to get real scheme scheme = url_sections[0].gsub('*', '') uri = "#{scheme}://#{url_sections[1]}" signed_content = signature( :resource => resource(scheme, uri), :expires => time(params[:expires]), :policy => params[:policy] ) start_flag = URI.parse(uri).query ? '&' : '?' uri = "#{uri}#{start_flag}#{signed_content}" if scheme == 'rtmp' rtmp_url(URI(uri)) else uri end end |