class Match::Storage::GitLab::SecureFile
Attributes
client[R]
file[R]
Public Class Methods
new(file:, client:)
click to toggle source
# File match/lib/match/storage/gitlab/secure_file.rb, line 11 def initialize(file:, client:) @file = OpenStruct.new(file) @client = client end
Public Instance Methods
create_subfolders(working_directory)
click to toggle source
# File match/lib/match/storage/gitlab/secure_file.rb, line 20 def create_subfolders(working_directory) FileUtils.mkdir_p("#{working_directory}/#{destination_file_path}") end
delete()
click to toggle source
# File match/lib/match/storage/gitlab/secure_file.rb, line 55 def delete url = URI(file_url) request = Net::HTTP::Delete.new(url.request_uri) @client.execute_request(url, request) end
destination_file_path()
click to toggle source
# File match/lib/match/storage/gitlab/secure_file.rb, line 24 def destination_file_path filename = @file.name.split('/').last @file.name.gsub(filename, '').gsub(%r{^/}, '') end
download(working_directory)
click to toggle source
# File match/lib/match/storage/gitlab/secure_file.rb, line 34 def download(working_directory) url = URI("#{file_url}/download") begin destination_file = "#{working_directory}/#{@file.name}" create_subfolders(working_directory) File.open(destination_file, "wb") do |saved_file| URI.open(url, "rb", { @client.authentication_key => @client.authentication_value }) do |data| saved_file.write(data.read) end FileUtils.chmod('u=rw,go-r', destination_file) end UI.crash!("Checksum validation failed for #{@file.name}") unless valid_checksum?(destination_file) rescue OpenURI::HTTPError => msg UI.error("Unable to download #{@file.name} - #{msg}") end end
file_url()
click to toggle source
# File match/lib/match/storage/gitlab/secure_file.rb, line 16 def file_url "#{@client.base_url}/#{@file.id}" end
valid_checksum?(file)
click to toggle source
# File match/lib/match/storage/gitlab/secure_file.rb, line 30 def valid_checksum?(file) Digest::SHA256.hexdigest(File.read(file)) == @file.checksum end