diff --git a/README.md b/README.md index 8ee87badf3160cdccae98ca66986730f79c54154..5349d6af42ed24bf5639f7ec0e52c0edb9ca49ad 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 f090890f7335ed8a80090728afd9b1a917bfa851..781d29cad8e2fdef0634d463f9151768e071985b 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 075da503c258570d0b190f911c0b09fd50bafb7f..03b84c688b67eee299f2ce443873eb2fe74a0147 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() {