Class: PuppetForgeServer::Backends::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_forge_server/backends/proxy.rb

Direct Known Subclasses

ProxyV1, ProxyV3

Instance Method Summary collapse

Constructor Details

#initialize(url, cache_dir, http_client, file_path) ⇒ Proxy

Returns a new instance of Proxy.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/puppet_forge_server/backends/proxy.rb', line 23

def initialize(url, cache_dir, http_client, file_path)
  @url = url
  @cache_dir = File.join(cache_dir, Digest::SHA1.hexdigest(@url))
  @http_client = http_client
  @log = PuppetForgeServer::Logger.get
  @file_path = file_path

  # Create directory structure for all alphabetic letters
  (10...36).each do |i|
    FileUtils.mkdir_p(File.join(@cache_dir, i.to_s(36)))
  end
end

Instance Method Details

#get_file_buffer(relative_path) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/puppet_forge_server/backends/proxy.rb', line 36

def get_file_buffer(relative_path)
  file_name = relative_path.split('/').last
  File.join(@cache_dir, file_name[0].downcase, file_name)
  path = Dir["#{@cache_dir}/**/#{file_name}"].first
  unless File.exist?("#{path}")
    buffer = download("#{@file_path.chomp('/')}/#{relative_path}")
    File.open(File.join(@cache_dir, file_name[0].downcase, file_name), 'wb') do |file|
      file.write(buffer.read)
    end
    path = File.join(@cache_dir, file_name[0].downcase, file_name)
  end
  File.open(path, 'rb')
rescue => e
  @log.error("#{self.class.name} failed downloading file '#{relative_path}'")
  @log.error("Error: #{e}")
  return nil
end

#upload(file_data) ⇒ Object



54
55
56
57
# File 'lib/puppet_forge_server/backends/proxy.rb', line 54

def upload(file_data)
  @log.debug 'File upload is not supported by the proxy backends'
  false
end