@@ -98,7 +98,7 @@ def deliver_resource
9898
9999 prefix = @recording . published? ? "published" : "unpublished"
100100 page = "index.html"
101- cf_url = "#{ ENV . fetch ( " CLOUDFRONT_URL" ) } /#{ prefix } /#{ @playback_format . format } /#{ @recording . record_id } /#{ page } "
101+ cf_url = "#{ ENV . fetch ( ' CLOUDFRONT_URL' ) } /#{ prefix } /#{ @playback_format . format } /#{ @recording . record_id } /#{ page } "
102102
103103 redirect_to cf_url , allow_other_host : true , status : :temporary_redirect
104104 else
@@ -114,27 +114,26 @@ def recording_not_found
114114 render "errors/recording_not_found" , status : :not_found , formats : [ :html ]
115115 end
116116
117- private
118117 def set_cf_signed_cookies! ( format :, record_id :, published :, ttl : 5 . minutes )
119118 base_prefix = published ? "published" : "unpublished"
120119 path_scope = "/#{ base_prefix } /#{ format } /#{ record_id } /*"
121120
122121 cf_origin = ENV . fetch ( "CLOUDFRONT_URL" )
123122
124- pem = Base64 . decode64 ( ENV [ "CF_PRIVATE_KEY_B64" ] )
123+ pem = Base64 . decode64 ( ENV . fetch ( "CF_PRIVATE_KEY_B64" , nil ) )
125124
126125 signer = Aws ::CloudFront ::CookieSigner . new (
127126 key_pair_id : ENV . fetch ( "CF_KEY_PAIR_ID" ) ,
128127 private_key : OpenSSL ::PKey ::RSA . new ( pem )
129128 )
130129
131- expires_at = Time . now + ( ttl . is_a? ( Numeric ) ? ttl : ttl . to_i )
130+ expires_at = Time . zone . now + ( ttl . is_a? ( Numeric ) ? ttl : ttl . to_i )
132131
133132 policy_json = JSON . generate ( {
134133 "Statement" => [ {
135- "Resource" => "#{ cf_origin } #{ path_scope } " ,
134+ "Resource" => "#{ cf_origin } #{ path_scope } " ,
136135 "Condition" => { "DateLessThan" => { "AWS:EpochTime" => expires_at . to_i } }
137- } ]
136+ } ]
138137 } )
139138
140139 cf_cookies = signer . signed_cookie ( nil , policy : policy_json )
0 commit comments