Skip to content

Allow login with private key and on a different port #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Allow login with private key and on a different port
  • Loading branch information
matteosuppo committed Jul 7, 2017
commit 2eda7cdba53bf07339e9f1218d10039d7e0f2917
20 changes: 17 additions & 3 deletions upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"time"

Expand All @@ -29,8 +30,10 @@ var Busy = false

// Auth contains username and password used for a network upload
type Auth struct {
Username string `json:"username"`
Password string `json:"password"`
Username string `json:"username"`
Password string `json:"password"`
PrivateKey string `json:"private_key"`
Port int `json:"port"`
}

// Extra contains some options used during the upload
Expand Down Expand Up @@ -375,8 +378,19 @@ func form(port, board, file string, auth Auth, l Logger) error {
func ssh(port string, files []string, commandline string, auth Auth, l Logger, SSH bool) error {
debug(l, "Connect via ssh ", files, commandline)

if auth.Port == 0 {
auth.Port = 22
}

// Connect via ssh
client, err := simplessh.ConnectWithPassword(port+":22", auth.Username, auth.Password)
var client *simplessh.Client
var err error
if auth.PrivateKey != "" {
client, err = simplessh.ConnectWithKey(port+":"+strconv.Itoa(auth.Port), auth.Username, auth.PrivateKey)
} else {
client, err = simplessh.ConnectWithPassword(port+":"+strconv.Itoa(auth.Port), auth.Username, auth.Password)
}

if err != nil {
return errors.Wrapf(err, "Connect via ssh")
}
Expand Down