Skip to content

Commit 61e6291

Browse files
committed
SSH: add helper to copy a file from instance
This is going to be used for copying kubeconfig file from VM to host as part of microshift preset implementation.
1 parent ba0b846 commit 61e6291

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pkg/crc/ssh/ssh.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ func (runner *Runner) CopyData(data []byte, destFilename string, mode os.FileMod
7272
return runner.copyDataFull(data, destFilename, mode, false)
7373
}
7474

75+
func (runner *Runner) CopyFileFromVM(srcFilename string, destFilename string, mode os.FileMode) error {
76+
command := fmt.Sprintf("sudo base64 %s", srcFilename)
77+
stdout, stderr, err := runner.RunPrivate(command)
78+
if err != nil {
79+
return fmt.Errorf("Failed to get file content %s : %w", stderr, err)
80+
}
81+
rawDecodedText, err := base64.StdEncoding.DecodeString(stdout)
82+
if err != nil {
83+
return err
84+
}
85+
return os.WriteFile(destFilename, rawDecodedText, mode)
86+
}
87+
7588
func (runner *Runner) CopyFile(srcFilename string, destFilename string, mode os.FileMode) error {
7689
data, err := os.ReadFile(srcFilename)
7790
if err != nil {

0 commit comments

Comments
 (0)