41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
// Copyright (c) 2017 Oracle America, Inc.
|
|
// The contents of this file are subject to the Mozilla Public License Version
|
|
// 2.0 (the "License"); you may not use this file except in compliance with the
|
|
// License. If a copy of the MPL was not distributed with this file, You can
|
|
// obtain one at http://mozilla.org/MPL/2.0/
|
|
|
|
package bmcs
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
packerssh "github.com/hashicorp/packer/communicator/ssh"
|
|
"github.com/mitchellh/multistep"
|
|
"golang.org/x/crypto/ssh"
|
|
)
|
|
|
|
func commHost(state multistep.StateBag) (string, error) {
|
|
ipAddress := state.Get("instance_ip").(string)
|
|
return ipAddress, nil
|
|
}
|
|
|
|
func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
|
|
c := state.Get("config").(*Config)
|
|
privateKey := state.Get("privateKey").(string)
|
|
|
|
signer, err := ssh.ParsePrivateKey([]byte(privateKey))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Error setting up SSH config: %s", err)
|
|
}
|
|
|
|
return &ssh.ClientConfig{
|
|
User: c.Comm.SSHUsername,
|
|
Auth: []ssh.AuthMethod{
|
|
ssh.PublicKeys(signer),
|
|
ssh.Password(c.Comm.SSHPassword),
|
|
ssh.KeyboardInteractive(
|
|
packerssh.PasswordKeyboardInteractive(c.Comm.SSHPassword)),
|
|
},
|
|
}, nil
|
|
}
|