Skip to content

Commit

Permalink
feat: display user@host:port in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
tenstad committed Apr 14, 2024
1 parent 4d420f5 commit 84863d9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions internal/provider/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package provider
import (
"context"
"fmt"
"io/ioutil"
"net"
"os"
"time"
Expand Down Expand Up @@ -76,8 +75,7 @@ var connectionSchemaResource = &schema.Resource{
}

func ConnectionFromResourceData(ctx context.Context, d *schema.ResourceData) (string, *ssh.ClientConfig, error) {
_, ok := d.GetOk("conn")
if !ok {
if _, ok := d.GetOk("conn"); !ok {
return "", nil, fmt.Errorf("resouce does not have a connection configured")
}

Expand All @@ -102,7 +100,7 @@ func ConnectionFromResourceData(ctx context.Context, d *schema.ResourceData) (st

private_key_path, ok := d.GetOk("conn.0.private_key_path")
if ok {
content, err := ioutil.ReadFile(private_key_path.(string))
content, err := os.ReadFile(private_key_path.(string))
if err != nil {
return "", nil, fmt.Errorf("couldn't read private key: %s", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/remote_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (c *RemoteClient) DeleteFileShell(path string) error {
func NewRemoteClient(host string, clientConfig *ssh.ClientConfig) (*RemoteClient, error) {
client, err := ssh.Dial("tcp", host, clientConfig)
if err != nil {
return nil, fmt.Errorf("couldn't establish a connection to the remote server: %s", err.Error())
return nil, fmt.Errorf("couldn't establish a connection to the remote server '%s@%s': %s", clientConfig.User, host, err.Error())
}

return &RemoteClient{
Expand Down

0 comments on commit 84863d9

Please sign in to comment.