class Chef::Provider::RemoteFile::SFTP
Attributes
Public Class Methods
Source
# File lib/chef/provider/remote_file/sftp.rb, line 36 def initialize(uri, new_resource, current_resource) @uri = uri @new_resource = new_resource @current_resource = current_resource validate_path! validate_userinfo! end
Public Instance Methods
Source
# File lib/chef/provider/remote_file/sftp.rb, line 52 def user CGI.unescape(uri.user) end
Private Instance Methods
Source
# File lib/chef/provider/remote_file/sftp.rb, line 98 def get tempfile = Chef::FileContentManagement::Tempfile.new(@new_resource).tempfile sftp.download!(uri.path, tempfile.path) tempfile.close if tempfile tempfile end
Source
# File lib/chef/provider/remote_file/sftp.rb, line 67 def pass CGI.unescape(uri.password) end
Source
# File lib/chef/provider/remote_file/sftp.rb, line 62 def sftp host = port ? "#{hostname}:#{port}" : hostname @sftp ||= Net::SFTP.start(host, user, password: pass) end
Source
# File lib/chef/provider/remote_file/sftp.rb, line 71 def validate_path! path = uri.path.sub(%r{\A/}, "%2F") # re-encode the beginning slash because uri library decodes it. directories = path.split(%r{/}, -1) directories.each do |d| d.gsub!(/%([0-9A-Fa-f][0-9A-Fa-f])/) { [$1].pack("H2") } end unless filename = directories.pop raise ArgumentError, "no filename: #{path.inspect}" end if filename.length == 0 || filename.end_with?( "/" ) raise ArgumentError, "no filename: #{path.inspect}" end end
Source
# File lib/chef/provider/remote_file/sftp.rb, line 85 def validate_userinfo! if uri.userinfo unless uri.user raise ArgumentError, "no user name provided in the sftp URI" end unless uri.password raise ArgumentError, "no password provided in the sftp URI" end else raise ArgumentError, "no userinfo provided in the sftp URI" end end