Skip to content

Commit

Permalink
Revert "Add support for ports in hostnames"
Browse files Browse the repository at this point in the history
  • Loading branch information
johanot committed May 20, 2020
1 parent 3878c0a commit bb87a41
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 66 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
*.iml
.idea

bindata.go

# Default binary output file name
/morph

Expand Down
7 changes: 3 additions & 4 deletions morph.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/dbcdk/kingpin"
"github.com/dbcdk/morph/assets"
"github.com/dbcdk/morph/filter"
Expand All @@ -16,6 +12,9 @@ import (
"github.com/dbcdk/morph/secrets"
"github.com/dbcdk/morph/ssh"
"github.com/dbcdk/morph/utils"
"os"
"path/filepath"
"strings"
)

// This is set at build time via -ldflags magic
Expand Down
34 changes: 6 additions & 28 deletions nix/nix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/dbcdk/morph/healthchecks"
"github.com/dbcdk/morph/secrets"
"github.com/dbcdk/morph/ssh"
"github.com/dbcdk/morph/utils"
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"syscall"
"time"

"github.com/dbcdk/morph/healthchecks"
"github.com/dbcdk/morph/secrets"
"github.com/dbcdk/morph/ssh"
"github.com/dbcdk/morph/utils"
)

type Host struct {
Expand Down Expand Up @@ -267,37 +266,16 @@ func Push(ctx *ssh.SSHContext, host Host, paths ...string) (err error) {
if ctx.IdentityFile != "" {
keyArg = "?ssh-key=" + ctx.IdentityFile
}

var sshOpts = ""

if ctx.SkipHostKeyCheck {
sshOpts = fmt.Sprintf(
"NIX_SSHOPTS=%s",
"-o StrictHostkeyChecking=No -o UserKnownHostsFile=/dev/null",
)
}

target, port := utils.SplitHost(host.TargetHost)
if port != "" {
if sshOpts == "" {
sshOpts += "NIX_SSHOPTS="
} else {
sshOpts += " "
}

sshOpts += "-p " + port
}

if sshOpts != "" {
env = append(env, sshOpts)
env = append(env, fmt.Sprintf("NIX_SSHOPTS=%s", "-o StrictHostkeyChecking=No -o UserKnownHostsFile=/dev/null"))
}

options := mkOptions(host)
for _, path := range paths {
args := []string{
"copy",
path,
"--to", "ssh://" + userArg + target + keyArg,
"--to", "ssh://" + userArg + host.TargetHost + keyArg,
}
args = append(args, options...)
if host.SubstituteOnDestination {
Expand Down
28 changes: 7 additions & 21 deletions ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import (
"context"
"errors"
"fmt"
"github.com/dbcdk/morph/utils"
"golang.org/x/crypto/ssh/terminal"
"io"
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"
"time"

"github.com/dbcdk/morph/utils"
"golang.org/x/crypto/ssh/terminal"
)

type Context interface {
Expand Down Expand Up @@ -86,37 +85,24 @@ func (ctx *SSHContext) sshArgs(host Host, transfer *FileTransfer) (cmd string, a
"-o", "StrictHostKeyChecking=No",
"-o", "UserKnownHostsFile=/dev/null")
}

if ctx.IdentityFile != "" {
args = append(args, "-i")
args = append(args, ctx.IdentityFile)
}
if ctx.ConfigFile != "" {
args = append(args, "-F", ctx.ConfigFile)
}

target, port := utils.SplitHost(host.GetTargetHost())
if port != "" {
switch cmd {
case "scp":
args = append(args, "-P", port)
case "ssh":
args = append(args, "-p", port)
}
}

var hostAndDestination = host.GetTargetHost()
if transfer != nil {
args = append(args, transfer.Source)
target += ":" + transfer.Destination
hostAndDestination += ":" + transfer.Destination
}

if host.GetTargetUser() != "" {
target = host.GetTargetUser() + "@" + target
hostAndDestination = host.GetTargetUser() + "@" + hostAndDestination
} else if ctx.DefaultUsername != "" {
target = ctx.DefaultUsername + "@" + target
hostAndDestination = ctx.DefaultUsername + "@" + hostAndDestination
}

args = append(args, target)
args = append(args, hostAndDestination)

return
}
Expand Down
11 changes: 0 additions & 11 deletions utils/host.go

This file was deleted.

0 comments on commit bb87a41

Please sign in to comment.