Skip to content

Commit

Permalink
Merge pull request containers#21897 from openshift-cherrypick-robot/c…
Browse files Browse the repository at this point in the history
…herry-pick-21879-to-v4.9-rhel

[v4.9-rhel] image scp: don't require port for ssh URL
  • Loading branch information
openshift-merge-bot[bot] authored Mar 7, 2024
2 parents 5b470a4 + 88b5715 commit c82fdc8
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions pkg/domain/utils/scp.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,14 @@ func LoginUser(user string) (*exec.Cmd, error) {
// and copies the saved image dir over to the remote host and then loads it onto the machine
// returns a string containing output or an error
func LoadToRemote(dest entities.ImageScpOptions, localFile string, tag string, url *url.URL, iden string, sshEngine ssh.EngineMode) (string, string, error) {
port, err := strconv.Atoi(url.Port())
if err != nil {
return "", "", err
port := 0
urlPort := url.Port()
if urlPort != "" {
var err error
port, err = strconv.Atoi(url.Port())
if err != nil {
return "", "", err
}
}

remoteFile, err := ssh.Exec(&ssh.ConnectionExecOptions{Host: url.String(), Identity: iden, Port: port, User: url.User, Args: []string{"mktemp"}}, sshEngine)
Expand Down Expand Up @@ -257,9 +262,14 @@ func SaveToRemote(image, localFile string, tag string, uri *url.URL, iden string
return fmt.Errorf("renaming of an image is currently not supported: %w", define.ErrInvalidArg)
}

port, err := strconv.Atoi(uri.Port())
if err != nil {
return err
port := 0
urlPort := uri.Port()
if urlPort != "" {
var err error
port, err = strconv.Atoi(uri.Port())
if err != nil {
return err
}
}

remoteFile, err := ssh.Exec(&ssh.ConnectionExecOptions{Host: uri.String(), Identity: iden, Port: port, User: uri.User, Args: []string{"mktemp"}}, sshEngine)
Expand Down

0 comments on commit c82fdc8

Please sign in to comment.