Repository: sonatype-nexus-community/nancy
Pull request #200 (2020-10-28 19:17:46)

Move `configuration` package to `go-sona-types` for reuse
Move `configuration` package from Nancy into go-sona-types. This will allow other go projects that use `ossi` and `iq` credentials (e.g. [ahab](https://github.com/sonatype-nexus-community/ahab)) to more easily share (and set) the same config files and file format used by Nancy.

After go-sona-types PR is merged, I will update this PR to use a released version of go-sona-types.

cc @bhamail / @DarthHater



Patch:
diff --git a/go.mod b/go.mod
index 6a5f9ca..d08cbbd 100644
--- a/go.mod
+++ b/go.mod
@@ -22,7 +22,7 @@ require (
 	github.com/sdboyer/constext v0.0.0-20170321163424-836a14457353 // indirect
 	github.com/shopspring/decimal v1.2.0
 	github.com/sirupsen/logrus v1.6.0
-	github.com/sonatype-nexus-community/go-sona-types v0.0.7
+	github.com/sonatype-nexus-community/go-sona-types v0.0.8
 	github.com/spf13/afero v1.3.4 // indirect
 	github.com/spf13/cast v1.3.1 // indirect
 	github.com/spf13/cobra v1.0.0
@@ -34,7 +34,6 @@ require (
 	golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 // indirect
 	google.golang.org/protobuf v1.25.0 // indirect
 	gopkg.in/ini.v1 v1.60.1 // indirect
-	gopkg.in/yaml.v2 v2.3.0
 )
 
 // fix vulnerability: CVE-2020-15114 in etcd v3.3.13+incompatible
diff --git a/go.sum b/go.sum
index fc0beea..4271633 100644
--- a/go.sum
+++ b/go.sum
@@ -240,8 +240,8 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1
 github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
 github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
 github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
-github.com/sonatype-nexus-community/go-sona-types v0.0.7 h1:ZH00KCTlLnI0LBIs+Juv9WBCtamKKdoFeryp1p5UB6s=
-github.com/sonatype-nexus-community/go-sona-types v0.0.7/go.mod h1:voGD7LEwz9TSvjZWNxST56pFPa0hdNQ71WsuMwBki3k=
+github.com/sonatype-nexus-community/go-sona-types v0.0.8 h1:6xb9BIC2w3y4kF/xQA25Zs6Yrl8ZqFkfH77AKPaG4RA=
+github.com/sonatype-nexus-community/go-sona-types v0.0.8/go.mod h1:uou8FGf9R5Nz1c6BfSM3v9K7g0R6faTYoxLh9Ybeht8=
 github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
 github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
 github.com/spf13/afero v1.3.4 h1:8q6vk3hthlpb2SouZcnBVKboxWQWMDNF38bwholZrJc=
diff --git a/internal/cmd/config.go b/internal/cmd/config.go
index d6534ba..522a493 100644
--- a/internal/cmd/config.go
+++ b/internal/cmd/config.go
@@ -20,9 +20,10 @@ import (
 	"fmt"
 	"os"
 
+	"github.com/sonatype-nexus-community/go-sona-types/configuration"
 	"github.com/sonatype-nexus-community/nancy/internal/customerrors"
+	"github.com/sonatype-nexus-community/nancy/internal/logger"
 
-	"github.com/sonatype-nexus-community/nancy/internal/configuration"
 	"github.com/spf13/cobra"
 )
 
@@ -47,7 +48,13 @@ func doConfig(cmd *cobra.Command, args []string) (err error) {
 		}
 	}()
 
-	if err = configuration.GetConfigFromCommandLine(os.Stdin); err != nil {
+	logLady = logger.GetLogger("", configOssi.LogLevel)
+	var configSet *configuration.ConfigSet
+	if configSet, err = configuration.New(logLady); err != nil {
+		panic(err)
+	}
+
+	if err = configSet.GetConfigFromCommandLine(os.Stdin); err != nil {
 		panic(err)
 	}
 	return
diff --git a/internal/cmd/iq.go b/internal/cmd/iq.go
index cd2a596..03389e4 100644
--- a/internal/cmd/iq.go
+++ b/internal/cmd/iq.go
@@ -24,8 +24,9 @@ import (
 	"path"
 
 	"github.com/mitchellh/go-homedir"
+	"github.com/sonatype-nexus-community/go-sona-types/configuration"
 	"github.com/sonatype-nexus-community/go-sona-types/iq"
-	"github.com/sonatype-nexus-community/nancy/internal/configuration"
+	ossIndexTypes "github.com/sonatype-nexus-community/go-sona-types/ossindex/types"
 	"github.com/sonatype-nexus-community/nancy/internal/customerrors"
 	"github.com/sonatype-nexus-community/nancy/internal/logger"
 	"github.com/sonatype-nexus-community/nancy/packages"
@@ -179,7 +180,7 @@ func bindViperIq(cmd *cobra.Command) {
 	// need to defer bind call until command is run. see: https://github.com/spf13/viper/issues/233
 
 	// need to ensure ossi CLI flags will override ossi config file values when running IQ command
-	bindViper(rootCmd)
+	bindViperRootCmd()
 
 	// Bind viper to the flags passed in via the command line, so it will override config from file
 	if err := viper.BindPFlag(configuration.ViperKeyIQUsername, lookupFlagNotNil(flagNameIqUsername, cmd)); err != nil {
@@ -206,7 +207,7 @@ func initIQConfig() {
 	var cfgFileToCheck string
 	if cfgFileIQ != "" {
 		viper.SetConfigFile(cfgFileIQ)
-		viper.SetConfigType(configTypeYaml)
+		viper.SetConfigType(configuration.ConfigTypeYaml)
 		cfgFileToCheck = cfgFileIQ
 	} else {
 		home, err := homedir.Dir()
@@ -214,13 +215,13 @@ func initIQConfig() {
 			fmt.Println(err)
 			os.Exit(1)
 		}
-		configPath := path.Join(home, types.IQServerDirName)
+		configPath := path.Join(home, ossIndexTypes.IQServerDirName)
 
 		viper.AddConfigPath(configPath)
-		viper.SetConfigType(configTypeYaml)
-		viper.SetConfigName(types.IQServerConfigFileName)
+		viper.SetConfigType(configuration.ConfigTypeYaml)
+		viper.SetConfigName(ossIndexTypes.IQServerConfigFileName)
 
-		cfgFileToCheck = path.Join(configPath, types.IQServerConfigFileName)
+		cfgFileToCheck = path.Join(configPath, ossIndexTypes.IQServerConfigFileName)
 	}
 
 	if fileExists(cfgFileToCheck) {
diff --git a/internal/cmd/root.go b/internal/cmd/root.go
index 7036869..ef625ba 100644
--- a/internal/cmd/root.go
+++ b/internal/cmd/root.go
@@ -29,12 +29,11 @@ import (
 	"strings"
 	"time"
 
-	"github.com/sonatype-nexus-community/nancy/internal/configuration"
-
 	"github.com/common-nighthawk/go-figure"
 	"github.com/golang/dep"
 	"github.com/mitchellh/go-homedir"
 	"github.com/sirupsen/logrus"
+	"github.com/sonatype-nexus-community/go-sona-types/configuration"
 	"github.com/sonatype-nexus-community/go-sona-types/ossindex"
 	ossIndexTypes "github.com/sonatype-nexus-community/go-sona-types/ossindex/types"
 	"github.com/sonatype-nexus-community/nancy/buildversion"
@@ -178,14 +177,14 @@ func init() {
 	rootCmd.PersistentFlags().StringVarP(&configOssi.Path, "path", "p", "", "Specify a path to a dep "+GopkgLockFilename+" file for scanning")
 }
 
-func bindViper(cmd *cobra.Command) {
+func bindViperRootCmd() {
 	// need to defer bind call until command is run. see: https://github.com/spf13/viper/issues/233
 
 	// Bind viper to the flags passed in via the command line, so it will override config from file
-	if err := viper.BindPFlag(configuration.ViperKeyUsername, lookupPersistentFlagNotNil(flagNameOssiUsername, cmd)); err != nil {
+	if err := viper.BindPFlag(configuration.ViperKeyUsername, lookupPersistentFlagNotNil(flagNameOssiUsername, rootCmd)); err != nil {
 		panic(err)
 	}
-	if err := viper.BindPFlag(configuration.ViperKeyToken, lookupPersistentFlagNotNil(flagNameOssiToken, cmd)); err != nil {
+	if err := viper.BindPFlag(configuration.ViperKeyToken, lookupPersistentFlagNotNil(flagNameOssiToken, rootCmd)); err != nil {
 		panic(err)
 	}
 }
@@ -199,13 +198,11 @@ func lookupPersistentFlagNotNil(flagName string, cmd *cobra.Command) *pflag.Flag
 	return foundFlag
 }
 
-const configTypeYaml = "yaml"
-
 func initConfig() {
 	var cfgFileToCheck string
 	if cfgFile != "" {
 		viper.SetConfigFile(cfgFile)
-		viper.SetConfigType(configTypeYaml)
+		viper.SetConfigType(configuration.ConfigTypeYaml)
 		cfgFileToCheck = cfgFile
 	} else {
 		home, err := homedir.Dir()
@@ -213,13 +210,13 @@ func initConfig() {
 			fmt.Println(err)
 			os.Exit(1)
 		}
-		configPath := path.Join(home, types.OssIndexDirName)
+		configPath := path.Join(home, ossIndexTypes.OssIndexDirName)
 
 		viper.AddConfigPath(configPath)
-		viper.SetConfigType(configTypeYaml)
-		viper.SetConfigName(types.OssIndexConfigFileName)
+		viper.SetConfigType(configuration.ConfigTypeYaml)
+		viper.SetConfigName(ossIndexTypes.OssIndexConfigFileName)
 
-		cfgFileToCheck = path.Join(configPath, types.OssIndexConfigFileName)
+		cfgFileToCheck = path.Join(configPath, ossIndexTypes.OssIndexConfigFileName)
 	}
 
 	if fileExists(cfgFileToCheck) {
diff --git a/internal/cmd/sleuth.go b/internal/cmd/sleuth.go
index 033fa27..04b11d6 100644
--- a/internal/cmd/sleuth.go
+++ b/internal/cmd/sleuth.go
@@ -39,7 +39,7 @@ var sleuthCmd = &cobra.Command{
   nancy sleuth -p Gopkg.lock --` + flagNameOssiUsername + ` your_user --` + flagNameOssiToken + ` your_token`,
 	Short:  "Check for vulnerabilities in your Golang dependencies using Sonatype's OSS Index",
 	Long:   `'nancy sleuth' is a command to check for vulnerabilities in your Golang dependencies, powered by the 'Sonatype OSS Index'.`,
-	PreRun: func(cmd *cobra.Command, args []string) { bindViper(rootCmd) },
+	PreRun: func(cmd *cobra.Command, args []string) { bindViperRootCmd() },
 	RunE:   doOSSI,
 }
 
diff --git a/internal/configuration/testdata/commented b/internal/cmd/testdata/sleuth/commented
similarity index 100%
rename from internal/configuration/testdata/commented
rename to internal/cmd/testdata/sleuth/commented
diff --git a/internal/configuration/testdata/emptyFile b/internal/cmd/testdata/sleuth/emptyFile
similarity index 100%
rename from internal/configuration/testdata/emptyFile
rename to internal/cmd/testdata/sleuth/emptyFile
diff --git a/internal/configuration/testdata/lotsOfRandomWhitespace b/internal/cmd/testdata/sleuth/lotsOfRandomWhitespace
similarity index 100%
rename from internal/configuration/testdata/lotsOfRandomWhitespace
rename to internal/cmd/testdata/sleuth/lotsOfRandomWhitespace
diff --git a/internal/configuration/testdata/normalIgnore b/internal/cmd/testdata/sleuth/normalIgnore
similarity index 100%
rename from internal/configuration/testdata/normalIgnore
rename to internal/cmd/testdata/sleuth/normalIgnore
diff --git a/internal/configuration/testdata/untilsAndComments b/internal/cmd/testdata/sleuth/untilsAndComments
similarity index 100%
rename from internal/configuration/testdata/untilsAndComments
rename to internal/cmd/testdata/sleuth/untilsAndComments
diff --git a/internal/configuration/testdata/untilsBadDateFormat b/internal/cmd/testdata/sleuth/untilsBadDateFormat
similarity index 100%
rename from internal/configuration/testdata/untilsBadDateFormat
rename to internal/cmd/testdata/sleuth/untilsBadDateFormat
diff --git a/internal/configuration/testdata/untilsInvaild b/internal/cmd/testdata/sleuth/untilsInvaild
similarity index 100%
rename from internal/configuration/testdata/untilsInvaild
rename to internal/cmd/testdata/sleuth/untilsInvaild
diff --git a/internal/configuration/set.go b/internal/configuration/set.go
deleted file mode 100644
index 55dd3e5..0000000
--- a/internal/configuration/set.go
+++ /dev/null
@@ -1,215 +0,0 @@
-//
-// Copyright 2018-present Sonatype Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-package configuration
-
-import (
-	"bufio"
-	"fmt"
-	"io"
-	"io/ioutil"
-	"os"
-	"path/filepath"
-	"strings"
-
-	"github.com/sirupsen/logrus"
-	"github.com/sonatype-nexus-community/nancy/internal/logger"
-	"github.com/sonatype-nexus-community/nancy/types"
-	"gopkg.in/yaml.v2"
-)
-
-// these consts must match their associated yaml tag below. for use where tag name matters, like viper
-const ViperKeyIQServer = "iq.Server"
-const ViperKeyIQUsername = "iq.Username"
-const ViperKeyIQToken = "iq.Token"
-
-// IQConfig is a struct for holding IQ Configuration, and for writing it to yaml
-type IQConfig struct {
-	IQServer   string `yaml:"Server"`
-	IQUsername string `yaml:"Username"`
-	IQToken    string `yaml:"Token"`
-}
-
-type ConfMarshallIq struct {
-	Iq IQConfig
-}
-
-// these consts must match their associated yaml tag below. for use where tag name matters, like viper
-const ViperKeyUsername = "ossi.Username"
-const ViperKeyToken = "ossi.Token"
-
-// OSSIndexConfig is a struct for holding OSS Index Configuration, and for writing it to yaml
-type OSSIndexConfig struct {
-	Username string `yaml:"Username"`
-	Token    string `yaml:"Token"`
-}
-
-type ConfMarshallOssi struct {
-	Ossi OSSIndexConfig
-}
-
-var (
-	// HomeDir is exported so that in testing it can be set to a location like /tmp
-	HomeDir string
-	// ConfigLocation is exported so that in testing it can be used to test if the file has been written properly
-	ConfigLocation string
-	logLady        *logrus.Logger
-)
-
-func init() {
-	HomeDir, _ = os.UserHomeDir()
-	logLady = logger.GetLogger("", 3)
-}
-
-// GetConfigFromCommandLine is a method to obtain IQ or OSS Index config from the command line,
-// and then write it to disk.
-func GetConfigFromCommandLine(stdin io.Reader) (err error) {
-	logLady.Info("Starting process to obtain config from user")
-	reader := bufio.NewReader(stdin)
-	fmt.Print("Hi! What config can I help you set, IQ or OSS Index (values: iq, ossindex, enter for exit)? ")
-	configType, _ := reader.ReadString('\n')
-
-	switch str := strings.TrimSpace(configType); str {
-	case "iq":
-		logLady.Info("User chose to set IQ Config, moving forward")
-		ConfigLocation = filepath.Join(HomeDir, types.IQServerDirName, types.IQServerConfigFileName)
-		err = getAndSetIQConfig(reader)
-	case "ossindex":
-		logLady.Info("User chose to set OSS Index config, moving forward")
-		ConfigLocation = filepath.Join(HomeDir, types.OssIndexDirName, types.OssIndexConfigFileName)
-		err = getAndSetOSSIndexConfig(reader)
-	case "":
-		// TODO should this return an error, because it means config setup was not completed?
-		return
-	default:
-		logLady.Infof("User chose invalid config type: %s, will retry", str)
-		fmt.Println("Invalid value, 'iq' and 'ossindex' are accepted values, try again!")
-		err = GetConfigFromCommandLine(stdin)
-	}
-
-	if err != nil {
-		logLady.Error(err)
-		return
-	}
-	return
-}
-
-func getAndSetIQConfig(reader *bufio.Reader) (err error) {
-	logLady.Info("Getting config for IQ Server from user")
-
-	iqConfig := IQConfig{IQServer: "http://localhost:8070", IQUsername: "admin", IQToken: "admin123"}
-
-	fmt.Print("What is the address of your Nexus IQ Server (default: http://localhost:8070)? ")
-	server, _ := reader.ReadString('\n')
-	iqConfig.IQServer = emptyOrDefault(server, iqConfig.IQServer)
-
-	fmt.Print("What username do you want to authenticate as (default: admin)? ")
-	username, _ := reader.ReadString('\n')
-	iqConfig.IQUsername = emptyOrDefault(username, iqConfig.IQUsername)
-
-	fmt.Print("What token do you want to use (default: admin123)? ")
-	token, _ := reader.ReadString('\n')
-	iqConfig.IQToken = emptyOrDefault(token, iqConfig.IQToken)
-
-	if iqConfig.IQUsername == "admin" || iqConfig.IQToken == "admin123" {
-		logLady.Info("Warning user of bad life choices, using default values for IQ Server username or token")
-		warnUserOfBadLifeChoices()
-		fmt.Print("[y/N]? ")
-		theChoice, _ := reader.ReadString('\n')
-		theChoice = emptyOrDefault(theChoice, "y")
-		if theChoice == "y" {
-			logLady.Info("User chose to rectify their bad life choices, asking for config again")
-			err = getAndSetIQConfig(reader)
-		} else {
-			logLady.Info("Successfully got IQ Server config from user, attempting to save to disk")
-			err = marshallAndWriteToDisk(ConfMarshallIq{Iq: iqConfig})
-		}
-	} else {
-		logLady.Info("Successfully got IQ Server config from user, attempting to save to disk")
-		err = marshallAndWriteToDisk(ConfMarshallIq{Iq: iqConfig})
-	}
-
-	if err != nil {
-		return
-	}
-	return
-}
-
-func emptyOrDefault(value string, defaultValue string) string {
-	str := strings.Trim(strings.TrimSpace(value), "\n")
-	if str == "" {
-		return defaultValue
-	}
-	return str
-}
-
-func getAndSetOSSIndexConfig(reader *bufio.Reader) (err error) {
-	logLady.Info("Getting config for OSS Index from user")
-
-	ossIndexConfig := OSSIndexConfig{}
-
-	fmt.Print("What username do you want to authenticate as (ex: admin)? ")
-	ossIndexConfig.Username, _ = reader.ReadString('\n')
-	ossIndexConfig.Username = strings.Trim(strings.TrimSpace(ossIndexConfig.Username), "\n")
-
-	fmt.Print("What token do you want to use? ")
-	ossIndexConfig.Token, _ = reader.ReadString('\n')
-	ossIndexConfig.Token = strings.Trim(strings.TrimSpace(ossIndexConfig.Token), "\n")
-
-	logLady.Info("Successfully got OSS Index config from user, attempting to save to disk")
-	err = marshallAndWriteToDisk(ConfMarshallOssi{Ossi: ossIndexConfig})
-	if err != nil {
-		logLady.Error(err)
-		return
-	}
-
-	return
-}
-
-func marshallAndWriteToDisk(config interface{}) (err error) {
-	d, err := yaml.Marshal(config)
-	if err != nil {
-		return err
-	}
-
-	base := filepath.Dir(ConfigLocation)
-
-	if _, err = os.Stat(base); os.IsNotExist(err) {
-		err = os.Mkdir(base, os.ModePerm)
-		if err != nil {
-			return
-		}
-	}
-
-	err = ioutil.WriteFile(ConfigLocation, d, 0644)
-	if err != nil {
-		return
-	}
-
-	logLady.WithField("config_location", ConfigLocation).Info("Successfully wrote config to disk")
-	fmt.Printf("Successfully wrote config to: %s\n", ConfigLocation)
-	return
-}
-
-func warnUserOfBadLifeChoices() {
-	fmt.Println()
-	fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
-	fmt.Println("!!!! WARNING : You are using the default username and/or password for Nexus IQ. !!!!")
-	fmt.Println("!!!! You are strongly encouraged to change these, and use a token.              !!!!")
-	fmt.Println("!!!! Would you like to change them and try again?                               !!!!")
-	fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
-	fmt.Println()
-}
diff --git a/internal/logger/logger.go b/internal/logger/logger.go
index 8addd67..eb37ed9 100644
--- a/internal/logger/logger.go
+++ b/internal/logger/logger.go
@@ -22,7 +22,7 @@ import (
 	"path"
 
 	"github.com/sirupsen/logrus"
-	"github.com/sonatype-nexus-community/nancy/types"
+	"github.com/sonatype-nexus-community/go-sona-types/ossindex/types"
 )
 
 const defaultLogFilename = "nancy.combined.log"
diff --git a/types/types.go b/types/types.go
index f835e0a..76def60 100644
--- a/types/types.go
+++ b/types/types.go
@@ -24,14 +24,6 @@ import (
 	"github.com/sirupsen/logrus"
 )
 
-// Helpful constants to pull strings we use more than once out of code
-const (
-	OssIndexDirName        = ".ossindex"
-	OssIndexConfigFileName = ".oss-index-config"
-	IQServerDirName        = ".iqserver"
-	IQServerConfigFileName = ".iq-server-config"
-)
-
 type GoListModule struct {
 	Path      string        // module path
 	Version   string        // module version


Test patch:
diff --git a/internal/cmd/iq_test.go b/internal/cmd/iq_test.go
index ab7e48b..be99732 100644
--- a/internal/cmd/iq_test.go
+++ b/internal/cmd/iq_test.go
@@ -27,8 +27,9 @@ import (
 
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus/hooks/test"
+	"github.com/sonatype-nexus-community/go-sona-types/configuration"
 	"github.com/sonatype-nexus-community/go-sona-types/iq"
-	"github.com/sonatype-nexus-community/nancy/internal/configuration"
+	ossIndexTypes "github.com/sonatype-nexus-community/go-sona-types/ossindex/types"
 	"github.com/sonatype-nexus-community/nancy/internal/customerrors"
 	"github.com/sonatype-nexus-community/nancy/types"
 	"github.com/spf13/viper"
@@ -77,10 +78,10 @@ func TestIqCommandPathInvalidFile(t *testing.T) {
 }
 
 func setupIQConfigFile(t *testing.T, tempDir string) {
-	cfgDirIQ := path.Join(tempDir, types.IQServerDirName)
+	cfgDirIQ := path.Join(tempDir, ossIndexTypes.IQServerDirName)
 	assert.Nil(t, os.Mkdir(cfgDirIQ, 0700))
 
-	cfgFileIQ = path.Join(tempDir, types.IQServerDirName, types.IQServerConfigFileName)
+	cfgFileIQ = path.Join(tempDir, ossIndexTypes.IQServerDirName, ossIndexTypes.IQServerConfigFileName)
 }
 func resetIQConfigFile() {
 	cfgFileIQ = ""
diff --git a/internal/cmd/root_test.go b/internal/cmd/root_test.go
index 77a084b..6ae19bf 100644
--- a/internal/cmd/root_test.go
+++ b/internal/cmd/root_test.go
@@ -26,13 +26,13 @@ import (
 	"strings"
 	"testing"
 
+	"github.com/sonatype-nexus-community/go-sona-types/configuration"
 	"github.com/sonatype-nexus-community/go-sona-types/ossindex"
 	ossIndexTypes "github.com/sonatype-nexus-community/go-sona-types/ossindex/types"
 	"github.com/sonatype-nexus-community/nancy/types"
 
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus/hooks/test"
-	"github.com/sonatype-nexus-community/nancy/internal/configuration"
 	"github.com/spf13/cobra"
 	"github.com/spf13/viper"
 
@@ -316,13 +316,11 @@ func TestConfigOssi_cleanCache(t *testing.T) {
 func setupConfig(t *testing.T) (tempDir string) {
 	tempDir, err := ioutil.TempDir("", "config-test")
 	assert.NoError(t, err)
-	configuration.HomeDir = tempDir
 	return tempDir
 }
 
 func resetConfig(t *testing.T, tempDir string) {
 	var err error
-	configuration.HomeDir, err = os.UserHomeDir()
 	assert.NoError(t, err)
 	_ = os.RemoveAll(tempDir)
 }
@@ -366,10 +364,10 @@ func TestInitConfigWithNoConfigFile(t *testing.T) {
 }
 
 func setupTestOSSIConfigFile(t *testing.T, tempDir string) {
-	cfgDir := path.Join(tempDir, types.OssIndexDirName)
+	cfgDir := path.Join(tempDir, ossIndexTypes.OssIndexDirName)
 	assert.Nil(t, os.Mkdir(cfgDir, 0700))
 
-	cfgFile = path.Join(tempDir, types.OssIndexDirName, types.OssIndexConfigFileName)
+	cfgFile = path.Join(tempDir, ossIndexTypes.OssIndexDirName, ossIndexTypes.OssIndexConfigFileName)
 }
 
 func resetOSSIConfigFile() {
diff --git a/internal/cmd/sleuth_test.go b/internal/cmd/sleuth_test.go
index 367add2..0c43121 100644
--- a/internal/cmd/sleuth_test.go
+++ b/internal/cmd/sleuth_test.go
@@ -67,7 +67,7 @@ func TestConfigOssi_exclude_vulnerabilities(t *testing.T) {
 		[]string{sleuthCmd.Use, "--exclude-vulnerability=CVE123,CVE988"}...)
 }
 
-const testdataDir = "../../internal/configuration/testdata"
+const testdataDir = "testdata/sleuth"
 
 func TestConfigOssi_exclude_vulnerabilities_with_sane_file(t *testing.T) {
 	file, _ := os.Open(testdataDir + "/normalIgnore")
diff --git a/internal/configuration/set_test.go b/internal/configuration/set_test.go
deleted file mode 100644
index 2a465f4..0000000
--- a/internal/configuration/set_test.go
+++ /dev/null
@@ -1,103 +0,0 @@
-//
-// Copyright 2018-present Sonatype Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-package configuration
-
-import (
-	"bytes"
-	"io/ioutil"
-	"testing"
-
-	"gopkg.in/yaml.v2"
-)
-
-func TestGetConfigFromCommandLineOssIndex(t *testing.T) {
-	HomeDir = "/tmp"
-	var buffer bytes.Buffer
-	buffer.Write([]byte("ossindex\ntestuser\ntoken\n"))
-
-	err := GetConfigFromCommandLine(&buffer)
-	if err != nil {
-		t.Errorf("Test failed: %s", err.Error())
-	}
-
-	b, err := ioutil.ReadFile(ConfigLocation)
-	if err != nil {
-		t.Errorf("Test failed: %s", err.Error())
-	}
-
-	var confMarshallOssi ConfMarshallOssi
-	err = yaml.Unmarshal(b, &confMarshallOssi)
-	if err != nil {
-		t.Errorf("Test failed: %s", err.Error())
-	}
-
-	if confMarshallOssi.Ossi.Username != "testuser" && confMarshallOssi.Ossi.Token != "token" {
-		t.Errorf("Config not set properly, expected 'testuser' && 'token' but got '%s' and '%s'", confMarshallOssi.Ossi.Username, confMarshallOssi.Ossi.Token)
-	}
-}
-
-func TestGetConfigFromCommandLineIqServer(t *testing.T) {
-	HomeDir = "/tmp"
-	var buffer bytes.Buffer
-	buffer.Write([]byte("iq\nhttp://localhost:8070\nadmin\nadmin123\nn"))
-
-	err := GetConfigFromCommandLine(&buffer)
-	if err != nil {
-		t.Errorf("Test failed: %s", err.Error())
-	}
-
-	b, err := ioutil.ReadFile(ConfigLocation)
-	if err != nil {
-		t.Errorf("Test failed: %s", err.Error())
-	}
-
-	var confMarshallIq ConfMarshallIq
-	err = yaml.Unmarshal(b, &confMarshallIq)
-	if err != nil {
-		t.Errorf("Test failed: %s", err.Error())
-	}
-
-	if confMarshallIq.Iq.IQUsername != "admin" && confMarshallIq.Iq.IQToken != "admin123" && confMarshallIq.Iq.IQServer != "http://localhost:8070" {
-		t.Errorf("Config not set properly, expected 'admin', 'admin123' and 'http://localhost:8070' but got %s, %s and %s", confMarshallIq.Iq.IQUsername, confMarshallIq.Iq.IQToken, confMarshallIq.Iq.IQServer)
-	}
-}
-
-func TestGetConfigFromCommandLineIqServerWithLoopToResetConfig(t *testing.T) {
-	HomeDir = "/tmp"
-	var buffer bytes.Buffer
-	buffer.Write([]byte("iq\nhttp://localhost:8070\nadmin\nadmin123\ny\nhttp://localhost:8080\nadmin1\nadmin1234\n"))
-
-	err := GetConfigFromCommandLine(&buffer)
-	if err != nil {
-		t.Errorf("Test failed: %s", err.Error())
-	}
-
-	b, err := ioutil.ReadFile(ConfigLocation)
-	if err != nil {
-		t.Errorf("Test failed: %s", err.Error())
-	}
-
-	var confMarshallIq ConfMarshallIq
-	err = yaml.Unmarshal(b, &confMarshallIq)
-	if err != nil {
-		t.Errorf("Test failed: %s", err.Error())
-	}
-
-	if confMarshallIq.Iq.IQUsername != "admin1" && confMarshallIq.Iq.IQToken != "admin1234" && confMarshallIq.Iq.IQServer != "http://localhost:8080" {
-		t.Errorf("Config not set properly, expected 'admin1', 'admin1234' and 'http://localhost:8080' but got %s, %s and %s", confMarshallIq.Iq.IQUsername, confMarshallIq.Iq.IQToken, confMarshallIq.Iq.IQServer)
-	}
-}