From 3681e2a7ee9bf3c097f2227e16f43274231dba05 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Wed, 2 Dec 2020 13:19:45 -0800 Subject: [PATCH] fix pathing --- builder/docker/step_temp_dir.go | 4 ++-- builder/oracle/oci/config.go | 4 ++-- checkpoint.go | 4 ++-- main.go | 3 ++- packer-plugin-sdk/communicator/config.go | 14 +++++++------- packer-plugin-sdk/communicator/step_connect_ssh.go | 6 +++--- .../pathing}/config_file.go | 2 +- .../pathing}/config_file_test.go | 2 +- .../pathing}/config_file_unix.go | 2 +- .../pathing}/config_file_windows.go | 2 +- packer/plugin/discover.go | 4 ++-- packer/telemetry.go | 3 ++- provisioner/chef-client/provisioner.go | 4 ++-- 13 files changed, 28 insertions(+), 26 deletions(-) rename {packer => packer-plugin-sdk/pathing}/config_file.go (99%) rename {packer => packer-plugin-sdk/pathing}/config_file_test.go (99%) rename {packer => packer-plugin-sdk/pathing}/config_file_unix.go (89%) rename {packer => packer-plugin-sdk/pathing}/config_file_windows.go (86%) diff --git a/builder/docker/step_temp_dir.go b/builder/docker/step_temp_dir.go index 3f7e44739..179d1db09 100644 --- a/builder/docker/step_temp_dir.go +++ b/builder/docker/step_temp_dir.go @@ -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 } diff --git a/builder/oracle/oci/config.go b/builder/oracle/oci/config.go index fd0ae6926..c794f5384 100644 --- a/builder/oracle/oci/config.go +++ b/builder/oracle/oci/config.go @@ -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 } diff --git a/checkpoint.go b/checkpoint.go index bbefeef5e..f1613154b 100644 --- a/checkpoint.go +++ b/checkpoint.go @@ -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 diff --git a/main.go b/main.go index 6282b1623..026ed3f41 100644 --- a/main.go +++ b/main.go @@ -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) } diff --git a/packer-plugin-sdk/communicator/config.go b/packer-plugin-sdk/communicator/config.go index 450b3d2a8..d1342a60d 100644 --- a/packer-plugin-sdk/communicator/config.go +++ b/packer-plugin-sdk/communicator/config.go @@ -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}")) } diff --git a/packer-plugin-sdk/communicator/step_connect_ssh.go b/packer-plugin-sdk/communicator/step_connect_ssh.go index ebd9b3cdb..8e27570b0 100644 --- a/packer-plugin-sdk/communicator/step_connect_ssh.go +++ b/packer-plugin-sdk/communicator/step_connect_ssh.go @@ -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) } diff --git a/packer/config_file.go b/packer-plugin-sdk/pathing/config_file.go similarity index 99% rename from packer/config_file.go rename to packer-plugin-sdk/pathing/config_file.go index 8078aaa4b..98a320f2f 100644 --- a/packer/config_file.go +++ b/packer-plugin-sdk/pathing/config_file.go @@ -1,4 +1,4 @@ -package packer +package pathing import ( "log" diff --git a/packer/config_file_test.go b/packer-plugin-sdk/pathing/config_file_test.go similarity index 99% rename from packer/config_file_test.go rename to packer-plugin-sdk/pathing/config_file_test.go index 98fa67d99..26db9997e 100644 --- a/packer/config_file_test.go +++ b/packer-plugin-sdk/pathing/config_file_test.go @@ -1,4 +1,4 @@ -package packer +package pathing import ( "fmt" diff --git a/packer/config_file_unix.go b/packer-plugin-sdk/pathing/config_file_unix.go similarity index 89% rename from packer/config_file_unix.go rename to packer-plugin-sdk/pathing/config_file_unix.go index ab3ac73be..71f1f2669 100644 --- a/packer/config_file_unix.go +++ b/packer-plugin-sdk/pathing/config_file_unix.go @@ -1,6 +1,6 @@ // +build darwin freebsd linux netbsd openbsd solaris -package packer +package pathing const ( defaultConfigFile = ".packerconfig" diff --git a/packer/config_file_windows.go b/packer-plugin-sdk/pathing/config_file_windows.go similarity index 86% rename from packer/config_file_windows.go rename to packer-plugin-sdk/pathing/config_file_windows.go index b249c492d..138dd9dcd 100644 --- a/packer/config_file_windows.go +++ b/packer-plugin-sdk/pathing/config_file_windows.go @@ -1,6 +1,6 @@ // +build windows -package packer +package pathing const ( defaultConfigFile = "packer.config" diff --git a/packer/plugin/discover.go b/packer/plugin/discover.go index 88f56e9dc..5a1f41035 100644 --- a/packer/plugin/discover.go +++ b/packer/plugin/discover.go @@ -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 { diff --git a/packer/telemetry.go b/packer/telemetry.go index 0f493a83a..6ab8a3420 100644 --- a/packer/telemetry.go +++ b/packer/telemetry.go @@ -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 diff --git a/provisioner/chef-client/provisioner.go b/provisioner/chef-client/provisioner.go index b275ce5ec..0447f8b84 100644 --- a/provisioner/chef-client/provisioner.go +++ b/provisioner/chef-client/provisioner.go @@ -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) }