From 09ca1f1299678a036ab70aab6ef0f9b394eab676 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 20 Jan 2024 06:56:45 -0500 Subject: [PATCH] fix: correct issue with file copygin --- plugins/common/sftp.go | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/plugins/common/sftp.go b/plugins/common/sftp.go index d1e692f1e..586037da6 100644 --- a/plugins/common/sftp.go +++ b/plugins/common/sftp.go @@ -18,20 +18,17 @@ import ( // SftpCopyInput is the input for CallSftpCopy type SftpCopyInput struct { - // SourcePath is the path to the file to copy - SourcePath string + // AllowUknownHosts allows connecting to hosts with unknown host keys + AllowUknownHosts bool // DestinationPath is the path to copy the file to DestinationPath string - // AllowUknownHosts allows connecting to hosts with unknown host keys - AllowUknownHosts bool - // RemoteHost is the remote host to connect to RemoteHost string - // Sudo runs the command with sudo -n -u root - Sudo bool + // SourcePath is the path to the file to copy + SourcePath string } // CallSftpCopy copies a file to a remote host via sftp @@ -226,14 +223,7 @@ func (task SftpCopyTask) Execute(ctx context.Context) (SftpCopyResult, error) { return SftpCopyResult{}, fmt.Errorf("failed to create sftp client: %w", err) } - srcFile, err := os.Open(task.SourcePath) - if err != nil { - return SftpCopyResult{}, fmt.Errorf("failed to open source file: %w", err) - } - defer srcFile.Close() - - var contents []byte - _, err = srcFile.Read(contents) + contents, err := os.ReadFile(task.SourcePath) if err != nil { return SftpCopyResult{}, fmt.Errorf("failed to read source file: %w", err) }