Class: Chef::Provider::RemoteFile::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/provider/remote_file/fetcher.rb

Class Method Summary collapse

Class Method Details

.for_resource(uri, new_resource, current_resource) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/chef/provider/remote_file/fetcher.rb', line 25

def self.for_resource(uri, new_resource, current_resource)
  if network_share?(uri)
    unless ChefUtils.windows?
      raise Exceptions::UnsupportedPlatform, "Fetching the file on a network share is supported only on the Windows platform. Please change your source: #{uri}"
    end

    Chef::Provider::RemoteFile::NetworkFile.new(uri, new_resource, current_resource)
  else
    case uri.scheme
    when "http", "https"
      Chef::Provider::RemoteFile::HTTP.new(uri, new_resource, current_resource)
    when "ftp"
      Chef::Provider::RemoteFile::FTP.new(uri, new_resource, current_resource)
    when "sftp"
      Chef::Provider::RemoteFile::SFTP.new(uri, new_resource, current_resource)
    when "file"
      Chef::Provider::RemoteFile::LocalFile.new(uri, new_resource, current_resource)
    else
      raise ArgumentError, "Invalid uri, Only http(s), ftp, and file are currently supported"
    end
  end
end

.network_share?(source) ⇒ Boolean

Windows network share: \computername\share\file

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
# File 'lib/chef/provider/remote_file/fetcher.rb', line 49

def self.network_share?(source)
  case source
  when String
    !!(/\A\\\\[A-Za-z0-9+\-\.]+/ =~ source)
  else
    false
  end
end