diff --git a/command/server/config.go b/command/server/config.go index 41e3dc4ced7d..fcdb247c8963 100644 --- a/command/server/config.go +++ b/command/server/config.go @@ -16,6 +16,8 @@ import ( "strings" "time" + "github.com/mitchellh/mapstructure" + "github.com/hashicorp/go-multierror" "github.com/hashicorp/go-secure-stdlib/parseutil" "github.com/hashicorp/hcl" @@ -26,7 +28,6 @@ import ( "github.com/hashicorp/vault/sdk/helper/consts" "github.com/hashicorp/vault/sdk/helper/strutil" "github.com/hashicorp/vault/sdk/helper/testcluster" - "github.com/mitchellh/mapstructure" ) const ( @@ -1014,9 +1015,9 @@ func ParseStorage(result *Config, list *ast.ObjectList, name string) error { return nil } -// storageAddressKeys is a maps a storage backend type to its associated -// that may configuration whose values are URLs, IP addresses, or host:port -// style addresses. All physical storage types must have an entry in this map, +// storageAddressKeys maps a storage backend type to its associated +// configuration whose values are URLs, IP addresses, or host:port style +// addresses. All physical storage types must have an entry in this map, // otherwise our normalization check will fail when parsing the storage entry // config. Physical storage types which don't contain such keys should include // an empty array. diff --git a/internalshared/configutil/kms.go b/internalshared/configutil/kms.go index 575ce4ac60d1..9a18616beec0 100644 --- a/internalshared/configutil/kms.go +++ b/internalshared/configutil/kms.go @@ -280,7 +280,7 @@ func configureWrapper(configKMS *KMS, infoKeys *[]string, info *map[string]strin var kmsInfo map[string]string var err error - // Get the any seal config set as env variables and merge it into the KMS. + // Get any seal config set as env variables and merge it into the KMS. if err = mergeKMSEnvConfig(configKMS); err != nil { return nil, err } diff --git a/internalshared/configutil/kms_test.go b/internalshared/configutil/kms_test.go index 91c7ca3454da..18a4a03f6f90 100644 --- a/internalshared/configutil/kms_test.go +++ b/internalshared/configutil/kms_test.go @@ -7,8 +7,9 @@ import ( "reflect" "testing" - "github.com/hashicorp/go-kms-wrapping/wrappers/ocikms/v2" "github.com/stretchr/testify/require" + + "github.com/hashicorp/go-kms-wrapping/wrappers/ocikms/v2" ) func Test_getEnvConfig(t *testing.T) { diff --git a/internalshared/configutil/normalize.go b/internalshared/configutil/normalize.go index 47feef8f6e65..902699e57bfd 100644 --- a/internalshared/configutil/normalize.go +++ b/internalshared/configutil/normalize.go @@ -14,8 +14,8 @@ import ( // If the addr is a URL, IP Address, or host:port address that includes an IPv6 // address, the normalized copy will be conformant with RFC-5942 ยง4 // See: https://rfc-editor.org/rfc/rfc5952.html -func NormalizeAddr(u string) string { - if u == "" { +func NormalizeAddr(address string) string { + if address == "" { return "" } @@ -24,22 +24,22 @@ func NormalizeAddr(u string) string { bracketedIPv6 := false // Try parsing it as a URL - pu, err := url.Parse(u) + pu, err := url.Parse(address) if err == nil { // We've been given something that appears to be a URL. See if the hostname // is an IP address ip = net.ParseIP(pu.Hostname()) } else { // We haven't been given a URL. Try and parse it as an IP address - ip = net.ParseIP(u) + ip = net.ParseIP(address) if ip == nil { // We haven't been given a URL or IP address, try parsing an IP:Port // combination. - idx := strings.LastIndex(u, ":") + idx := strings.LastIndex(address, ":") if idx > 0 { // We've perhaps received an IP:Port address - addr := u[:idx] - port = u[idx+1:] + addr := address[:idx] + port = address[idx+1:] if strings.HasPrefix(addr, "[") && strings.HasSuffix(addr, "]") { addr = strings.TrimPrefix(strings.TrimSuffix(addr, "]"), "[") bracketedIPv6 = true @@ -51,22 +51,11 @@ func NormalizeAddr(u string) string { // If our IP is nil whatever was passed in does not contain an IP address. if ip == nil { - return u + return address } if v4 := ip.To4(); v4 != nil { - // We don't need to normalize IPv4 addresses. - if pu != nil && port == "" { - return pu.String() - } - - if port != "" { - // Return the address:port - return fmt.Sprintf("%s:%s", v4.String(), port) - } - - // Return the ip addres - return v4.String() + return address } if v6 := ip.To16(); v6 != nil { @@ -98,5 +87,5 @@ func NormalizeAddr(u string) string { // It shouldn't be possible to get to this point. If we somehow we manage // to, return the string unchanged. - return u + return address }