diff --git a/context.go b/context.go index 218235d..3b82c61 100644 --- a/context.go +++ b/context.go @@ -1,9 +1,9 @@ package trousseau import ( - "github.com/tmc/keyring" "os" "path/filepath" + "github.com/tmc/keyring" ) // Global variables defining default values for S3 and scp @@ -19,6 +19,11 @@ var ( } ) +// Global data store file path +var gStorePath string +func SetStorePath(storePath string) { gStorePath = storePath } +func GetStorePath() string { return gStorePath } + func InferStorePath() string { envPath := os.Getenv(ENV_TROUSSEAU_STORE) contextPath := GetStorePath() @@ -40,27 +45,27 @@ func InferStorePath() string { func GetPassphrase() (passphrase string) { var err error - // Try to retrieve passphrase from env + // try to retrieve passphrase from env passphrase = os.Getenv(ENV_PASSPHRASE_KEY) if len(passphrase) > 0 { return passphrase } - // If passphrase wasn't found in env, try to fetch it from + // if passphrase wasn't found in env, try to fetch it from // system keyring manager. - passphrase, err = keyring.Get(gKeyringService, gKeyringUser) + passphrase, err = keyring.Get(os.Getenv(ENV_KEYRING_SERVICE_KEY), os.Getenv(ENV_KEYRING_USER_KEY)) if len(passphrase) > 0 { return passphrase } - // If passphrase was enither found in the environment nor + // if passphrase was enither found in the environment nor // system keyring manager try to fetch it from gpg-agent - if os.Getenv("GPG_AGENT_INFO") != "" { - passphrase, err = getGpgPassphrase(gMasterGpgId) + if os.Getenv("gpg_agent_info") != "" { + passphrase, err = getGpgPassphrase(os.Getenv(ENV_MASTER_GPG_ID_KEY)) } if err != nil { - ErrorLogger.Fatal("No passphrase provided. Unable to open data store") + ErrorLogger.Fatal("no passphrase provided. unable to open data store") } return passphrase diff --git a/globals.go b/globals.go deleted file mode 100644 index c103a1a..0000000 --- a/globals.go +++ /dev/null @@ -1,19 +0,0 @@ -package trousseau - -import ( - "os" -) - -// Global data store file path -var gStorePath string -func SetStorePath(storePath string) { gStorePath = storePath } -func GetStorePath() string { return gStorePath } - -// Gnupg trousseau master gpg key id -var gMasterGpgId string = os.Getenv(ENV_MASTER_GPG_ID_KEY) - -// Keyring manager service and username to use in order to -// retrieve trousseau main gpg key passphrase from system -// keyring -var gKeyringService string = os.Getenv(ENV_KEYRING_SERVICE_KEY) -var gKeyringUser string = os.Getenv(ENV_KEYRING_USER_KEY)