From 2b8a6049d7ba0e564e1d3db60310526ad9bb0e1a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Erik=20Hedenstr=C3=B6m?= <erik@hedenstroem.com>
Date: Fri, 29 Sep 2023 18:22:23 +0000
Subject: [PATCH] feat: Refactor SSH address and password variables and update
 README

---
 README.md   |  6 +++---
 cmd/list.go |  2 +-
 cmd/root.go | 10 +++++-----
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md
index 8ee87ba..5349d6a 100644
--- a/README.md
+++ b/README.md
@@ -18,13 +18,13 @@ All versions are available via the [package registry](https://gitlab.hedenstroem
 
 ## Configuration
 
-To avoid providing the password via a flag every time, you can define an environment variable named `SSH_PASSWORD` instead. The address to the UDM can also be set in the environment variable `SSH_ADDRESS`.
+To avoid providing the password via a flag every time, you can define an environment variable named `UDM_SSH_PASSWORD` instead. The address to the UDM can also be set in the environment variable `UDM_SSH_ADDRESS`.
 
 If you prefer you can also set these values in a `.env` file like this:
 
 ```env
-SSH_ADDRESS=192.168.1.1
-SSH_PASSWORD=mypassword
+UDM_SSH_ADDRESS=192.168.1.1
+UDM_SSH_PASSWORD=mypassword
 ```
 ## Usage
 
diff --git a/cmd/list.go b/cmd/list.go
index f090890..781d29c 100644
--- a/cmd/list.go
+++ b/cmd/list.go
@@ -17,7 +17,7 @@ var listCmd = &cobra.Command{
 	Short: "List databases and their collections",
 	RunE: func(cmd *cobra.Command, args []string) error {
 		l := list.NewWriter()
-		l.AppendItem(viper.GetString("ADDRESS"))
+		l.AppendItem(viper.GetString("SSH_ADDRESS"))
 		l.Indent()
 		result, err := client.ListDatabases(context.TODO(), bson.D{})
 		if err != nil {
diff --git a/cmd/root.go b/cmd/root.go
index 075da50..03b84c6 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -36,8 +36,8 @@ var RootCmd = &cobra.Command{
 	DisableAutoGenTag: true,
 	PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
 		tunnel := ssh.NewSSHTunnel(
-			viper.GetString("ADDRESS"),
-			ssh.Password(viper.GetString("PASSWORD")),
+			viper.GetString("SSH_ADDRESS"),
+			ssh.Password(viper.GetString("SSH_PASSWORD")),
 			"127.0.0.1:27117",
 		)
 		if debug {
@@ -59,9 +59,9 @@ func init() {
 	RootCmd.PersistentFlags().StringP("address", "a", "192.168.1.1", "Address to the UDM SSH server")
 	RootCmd.PersistentFlags().StringP("password", "p", "", "SSH password")
 	RootCmd.PersistentFlags().BoolVarP(&debug, "debug", "", false, "Show debug output")
-	viper.SetEnvPrefix("SSH")
-	viper.BindPFlag("ADDRESS", RootCmd.PersistentFlags().Lookup("address"))
-	viper.BindPFlag("PASSWORD", RootCmd.PersistentFlags().Lookup("password"))
+	viper.SetEnvPrefix("UDM")
+	viper.BindPFlag("SSH_ADDRESS", RootCmd.PersistentFlags().Lookup("address"))
+	viper.BindPFlag("SSH_PASSWORD", RootCmd.PersistentFlags().Lookup("password"))
 }
 
 func initEnv() {
-- 
GitLab