feat: add identity_file field to config connections config

This commit is contained in:
Connor Edwards
2025-02-08 15:56:18 +00:00
parent e3a310397b
commit ac48b8bee6
5 changed files with 57 additions and 11 deletions
+13
View File
@@ -5,8 +5,21 @@ import (
"os"
"os/user"
"strconv"
"strings"
)
func ExpandHomeDir(path string) string {
if len(path) == 0 {
return path
}
if path[0] == '~' {
// TODO: Improve compat with other OSes
path = strings.Replace(path, "~", "${HOME}", 1)
return os.ExpandEnv(path)
}
return path
}
// LookupUIDGID returns the user and group IDs for the given username.
func LookupUIDGID(username string) (uid, gid int, err error) {
usr, err := user.Lookup(username)
+22
View File
@@ -0,0 +1,22 @@
package fs
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestExpandHomeDir(t *testing.T) {
t.Run("empty", func(t *testing.T) {
assert.Equal(t, "", ExpandHomeDir(""))
})
t.Run("no home", func(t *testing.T) {
assert.Equal(t, "/path", ExpandHomeDir("/path"))
})
t.Run("home", func(t *testing.T) {
t.Setenv("HOME", "/home/user")
assert.Equal(t, "/home/user/path", ExpandHomeDir("~/path"))
})
}