fix pathing

This commit is contained in:
Megan Marsh 2020-12-02 13:19:45 -08:00
parent 5e49ddb285
commit 3681e2a7ee
13 changed files with 28 additions and 26 deletions

View File

@ -8,9 +8,9 @@ import (
"os"
"path/filepath"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/pathing"
)
// StepTempDir creates a temporary directory that we use in order to
@ -21,7 +21,7 @@ type StepTempDir struct {
// ConfigTmpDir returns the configuration tmp directory for Docker
func ConfigTmpDir() (string, error) {
configdir, err := packer.ConfigDir()
configdir, err := pathing.ConfigDir()
if err != nil {
return "", err
}

View File

@ -13,10 +13,10 @@ import (
"path/filepath"
"strings"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/common"
"github.com/hashicorp/packer/packer-plugin-sdk/communicator"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/pathing"
"github.com/hashicorp/packer/packer-plugin-sdk/template/config"
"github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate"
ocicommon "github.com/oracle/oci-go-sdk/common"
@ -198,7 +198,7 @@ func (c *Config) Prepare(raws ...interface{}) error {
var keyContent []byte
if c.KeyFile != "" {
path, err := packer.ExpandUser(c.KeyFile)
path, err := pathing.ExpandUser(c.KeyFile)
if err != nil {
return err
}

View File

@ -7,7 +7,7 @@ import (
"github.com/hashicorp/go-checkpoint"
"github.com/hashicorp/packer/command"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/pathing"
packerVersion "github.com/hashicorp/packer/version"
)
@ -27,7 +27,7 @@ func runCheckpoint(c *config) {
return
}
configDir, err := packer.ConfigDir()
configDir, err := pathing.ConfigDir()
if err != nil {
log.Printf("[ERR] Checkpoint setup error: %s", err)
checkpointResult <- nil

View File

@ -20,6 +20,7 @@ import (
"github.com/hashicorp/packer/command"
"github.com/hashicorp/packer/packer"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/pathing"
"github.com/hashicorp/packer/packer-plugin-sdk/tmp"
"github.com/hashicorp/packer/packer/plugin"
"github.com/hashicorp/packer/version"
@ -327,7 +328,7 @@ func loadConfig() (*config, error) {
if configFilePath == "" {
var err error
log.Print("'PACKER_CONFIG' not set; checking the default config file path")
configFilePath, err = packer.ConfigFile()
configFilePath, err = pathing.ConfigFile()
if err != nil {
log.Printf("Error detecting default config file path: %s", err)
}

View File

@ -12,10 +12,10 @@ import (
"time"
"github.com/hashicorp/hcl/v2/hcldec"
"github.com/hashicorp/packer/packer"
helperssh "github.com/hashicorp/packer/packer-plugin-sdk/communicator/ssh"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/pathing"
packerssh "github.com/hashicorp/packer/packer-plugin-sdk/sdk-internals/communicator/ssh"
"github.com/hashicorp/packer/packer-plugin-sdk/template/config"
"github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate"
@ -287,7 +287,7 @@ func (c *Config) ReadSSHPrivateKeyFile() ([]byte, error) {
var privateKey []byte
if c.SSHPrivateKeyFile != "" {
keyPath, err := packer.ExpandUser(c.SSHPrivateKeyFile)
keyPath, err := pathing.ExpandUser(c.SSHPrivateKeyFile)
if err != nil {
return []byte{}, fmt.Errorf("Error expanding path for SSH private key: %s", err)
}
@ -352,7 +352,7 @@ func (c *Config) SSHConfigFunc() func(multistep.StateBag) (*ssh.ClientConfig, er
certPath := ""
if c.SSHCertificateFile != "" {
var err error
certPath, err = packer.ExpandUser(c.SSHCertificateFile)
certPath, err = pathing.ExpandUser(c.SSHCertificateFile)
if err != nil {
return nil, err
}
@ -511,7 +511,7 @@ func (c *Config) prepareSSH(ctx *interpolate.Context) []error {
}
if c.SSHPrivateKeyFile != "" {
path, err := packer.ExpandUser(c.SSHPrivateKeyFile)
path, err := pathing.ExpandUser(c.SSHPrivateKeyFile)
if err != nil {
errs = append(errs, fmt.Errorf(
"ssh_private_key_file is invalid: %s", err))
@ -520,7 +520,7 @@ func (c *Config) prepareSSH(ctx *interpolate.Context) []error {
"ssh_private_key_file is invalid: %s", err))
} else {
if c.SSHCertificateFile != "" {
certPath, err := packer.ExpandUser(c.SSHCertificateFile)
certPath, err := pathing.ExpandUser(c.SSHCertificateFile)
if err != nil {
errs = append(errs, fmt.Errorf("invalid identity certificate: #{err}"))
}
@ -543,7 +543,7 @@ func (c *Config) prepareSSH(ctx *interpolate.Context) []error {
errs = append(errs, errors.New(
"ssh_bastion_password or ssh_bastion_private_key_file must be specified"))
} else if c.SSHBastionPrivateKeyFile != "" {
path, err := packer.ExpandUser(c.SSHBastionPrivateKeyFile)
path, err := pathing.ExpandUser(c.SSHBastionPrivateKeyFile)
if err != nil {
errs = append(errs, fmt.Errorf(
"ssh_bastion_private_key_file is invalid: %s", err))
@ -552,7 +552,7 @@ func (c *Config) prepareSSH(ctx *interpolate.Context) []error {
"ssh_bastion_private_key_file is invalid: %s", err))
} else {
if c.SSHBastionCertificateFile != "" {
certPath, err := packer.ExpandUser(c.SSHBastionCertificateFile)
certPath, err := pathing.ExpandUser(c.SSHBastionCertificateFile)
if err != nil {
errs = append(errs, fmt.Errorf("invalid identity certificate: #{err}"))
}

View File

@ -13,10 +13,10 @@ import (
"golang.org/x/crypto/ssh/terminal"
"github.com/hashicorp/packer/packer"
helperssh "github.com/hashicorp/packer/packer-plugin-sdk/communicator/ssh"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/pathing"
"github.com/hashicorp/packer/packer-plugin-sdk/sdk-internals/communicator/ssh"
gossh "golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
@ -273,14 +273,14 @@ func sshBastionConfig(config *Config) (*gossh.ClientConfig, error) {
}
if config.SSHBastionPrivateKeyFile != "" {
path, err := packer.ExpandUser(config.SSHBastionPrivateKeyFile)
path, err := pathing.ExpandUser(config.SSHBastionPrivateKeyFile)
if err != nil {
return nil, fmt.Errorf(
"Error expanding path for SSH bastion private key: %s", err)
}
if config.SSHBastionCertificateFile != "" {
identityPath, err := packer.ExpandUser(config.SSHBastionCertificateFile)
identityPath, err := pathing.ExpandUser(config.SSHBastionCertificateFile)
if err != nil {
return nil, fmt.Errorf("Error expanding path for SSH bastion identity certificate: %s", err)
}

View File

@ -1,4 +1,4 @@
package packer
package pathing
import (
"log"

View File

@ -1,4 +1,4 @@
package packer
package pathing
import (
"fmt"

View File

@ -1,6 +1,6 @@
// +build darwin freebsd linux netbsd openbsd solaris
package packer
package pathing
const (
defaultConfigFile = ".packerconfig"

View File

@ -1,6 +1,6 @@
// +build windows
package packer
package pathing
const (
defaultConfigFile = "packer.config"

View File

@ -9,8 +9,8 @@ import (
"sort"
"strings"
"github.com/hashicorp/packer/packer"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/pathing"
)
// PACKERSPACE is used to represent the spaces that separate args for a command
@ -64,7 +64,7 @@ func (c *Config) Discover() error {
}
// Next, look in the default plugins directory inside the configdir/.packer.d/plugins.
dir, err := packer.ConfigDir()
dir, err := pathing.ConfigDir()
if err != nil {
log.Printf("[ERR] Error loading config directory: %s", err)
} else {

View File

@ -9,6 +9,7 @@ import (
"time"
checkpoint "github.com/hashicorp/go-checkpoint"
"github.com/hashicorp/packer/packer-plugin-sdk/pathing"
packerVersion "github.com/hashicorp/packer/version"
)
@ -35,7 +36,7 @@ func NewCheckpointReporter(disableSignature bool) *CheckpointTelemetry {
return nil
}
configDir, err := ConfigDir()
configDir, err := pathing.ConfigDir()
if err != nil {
log.Printf("[WARN] (telemetry) setup error: %s", err)
return nil

View File

@ -16,10 +16,10 @@ import (
"strings"
"github.com/hashicorp/hcl/v2/hcldec"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/common"
"github.com/hashicorp/packer/packer-plugin-sdk/guestexec"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/pathing"
"github.com/hashicorp/packer/packer-plugin-sdk/template/config"
"github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate"
"github.com/hashicorp/packer/packer-plugin-sdk/uuid"
@ -278,7 +278,7 @@ func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packe
}
if p.config.ValidationKeyPath != "" {
path, err := packer.ExpandUser(p.config.ValidationKeyPath)
path, err := pathing.ExpandUser(p.config.ValidationKeyPath)
if err != nil {
return fmt.Errorf("Error while expanding a tilde in the validation key: %s", err)
}