Skip to content
This repository has been archived by the owner on Mar 24, 2020. It is now read-only.

Commit

Permalink
Update secure token function
Browse files Browse the repository at this point in the history
  • Loading branch information
VivianChu committed May 30, 2018
1 parent 1b2ae10 commit 1586e8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions app/helpers/dams_objects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def encrypt_stream_name( pid, fid, ip )
#---

def secure_token(field_data, obj_id, cmp_id, base_url)
file_name = grab_file_name(field_data, cmp_id)
file_name = audio_video_file_name(field_data, cmp_id)
return nil unless file_name
end_time = secure_token_end_time
token_hash = secure_token_hash(end_time, file_name, obj_id, base_url)
Expand All @@ -687,7 +687,7 @@ def secure_token_hash(end_time, file_name, obj_id, base_url)
token_params = token_params.sort
stream = base_url.sub(%r{.*?\/}, '')
obj_path = obj_id.scan(/.{1,2}/).join('/')
hash_in = "#{stream}#{obj_path}/20775-#{obj_id}-#{file_name}?#{token_params.join('&')}"
hash_in = "#{stream}#{obj_path}/#{ark_naan}-#{obj_id}-#{file_name}?#{token_params.join('&')}"
hash_out = Digest::SHA2.new(256).digest(hash_in.to_s)
hash_out = Base64.encode64(hash_out).to_s.strip
matchers = { '+' => '-', '/' => '_' }
Expand All @@ -705,10 +705,10 @@ def secure_token_hash(end_time, file_name, obj_id, base_url)
#---

def secure_token_base_url(field_data, obj_id, cmp_id, base_url)
file_name = grab_file_name(field_data, cmp_id)
file_name = audio_video_file_name(field_data, cmp_id)
return nil unless file_name
obj_path = obj_id.scan(/.{1,2}/).join('/')
"#{base_url}#{obj_path}/20775-#{obj_id}-#{file_name}".html_safe
"#{base_url}#{obj_path}/#{ark_naan}-#{obj_id}-#{file_name}".html_safe
end

#---
Expand All @@ -719,7 +719,7 @@ def secure_token_base_url(field_data, obj_id, cmp_id, base_url)
# @return string or nil
#---

def grab_file_name(field_data, cmp_id)
def audio_video_file_name(field_data, cmp_id)
return nil unless field_data
field_data.each do |datum|
files = JSON.parse(datum)
Expand All @@ -730,6 +730,8 @@ def grab_file_name(field_data, cmp_id)
end
end

def ark_naan() Rails.configuration.id_namespace.sub(%r{.*ark:\/}, '')[0..4] end

#---
# Creates Wowza Token End Time
#
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/dams_object_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

it 'builds secure token base URL' do
base_url = helper.secure_token_base_url(@field_data, @obj_id, @cmp_id, Rails.configuration.secure_token_audio_baseurl)
expect(base_url).to include "#{Rails.configuration.secure_token_audio_baseurl}xy/76/12/55/7h/20775-xy7612557h-0-2.mp3"
expect(base_url).to include "#{Rails.configuration.secure_token_audio_baseurl}xy/76/12/55/7h/#{helper.ark_naan}-xy7612557h-0-2.mp3"
end
end
end

0 comments on commit 1586e8b

Please sign in to comment.