diff options
| author | Shulhan <ms@kilabit.info> | 2023-07-23 21:52:27 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-07-24 00:17:29 +0700 |
| commit | 9ec26e67a1f9de5e9e48ef79e1e5686dd9ea65e7 (patch) | |
| tree | 9fafc14dc05bfc713633f799f4b7bcf884a29422 | |
| parent | 37494be23811c845a90da8d04eb43fdd0723d31a (diff) | |
| download | pakakeh.go-9ec26e67a1f9de5e9e48ef79e1e5686dd9ea65e7.tar.xz | |
ssh/config: add Field to Section
The Field store the unpacked key and value of Section.
Using the Field, we can set store unknown key while inside Section.
| -rw-r--r-- | lib/ssh/config/config_test.go | 17 | ||||
| -rw-r--r-- | lib/ssh/config/section.go | 12 |
2 files changed, 24 insertions, 5 deletions
diff --git a/lib/ssh/config/config_test.go b/lib/ssh/config/config_test.go index 2169caf1..c832591c 100644 --- a/lib/ssh/config/config_test.go +++ b/lib/ssh/config/config_test.go @@ -8,8 +8,9 @@ import ( "log" "os" "path/filepath" - "reflect" "testing" + + "github.com/shuLhan/share/lib/test" ) var ( @@ -77,6 +78,11 @@ func TestConfig_Get(t *testing.T) { filepath.Join(def.homeDir, ".ssh", "notexist"), } def.useDefaultIdentityFile = false + def.Field = map[string]string{ + `hostname`: `127.0.0.1`, + `user`: `test`, + `identityfile`: `~/.ssh/notexist`, + } return &def }, }, { @@ -89,6 +95,11 @@ func TestConfig_Get(t *testing.T) { filepath.Join(def.homeDir, ".ssh", "notexist"), } def.useDefaultIdentityFile = false + def.Field = map[string]string{ + `hostname`: `127.0.0.2`, + `user`: `wildcard`, + `identityfile`: `~/.ssh/notexist`, + } return &def }, }} @@ -109,9 +120,7 @@ func TestConfig_Get(t *testing.T) { } else if got == nil { continue } - if !reflect.DeepEqual(*exp, *got) { - t.Fatalf("Config.Get: expecting %v, got %v", exp, got) - } + test.Assert(t, c.s, *exp, *got) } } diff --git a/lib/ssh/config/section.go b/lib/ssh/config/section.go index b346b47d..13c2ea00 100644 --- a/lib/ssh/config/section.go +++ b/lib/ssh/config/section.go @@ -150,6 +150,9 @@ type Section struct { // This field will be set once the Signers has been called. PrivateKeys map[string]any + // Field store the unpacked key and value of Section. + Field map[string]string + CanonicalizePermittedCNAMEs *PermittedCNAMEs AddKeysToAgent string @@ -212,6 +215,7 @@ type Section struct { func newSection() *Section { return &Section{ Environments: map[string]string{}, + Field: map[string]string{}, AddKeysToAgent: valueNo, AddressFamily: valueAny, @@ -437,8 +441,14 @@ func (section *Section) set(cfg *Config, key, value string) (err error) { section.UseVisualHostKey, err = parseBool(key, value) case keyXAuthLocation: section.XAuthLocation = value + default: + // Store the unknown key into Field. } - return err + if err != nil { + return err + } + section.Field[key] = value + return nil } func (section *Section) setAddKeysToAgent(val string) (err error) { |
