Skip to content

Commit

Permalink
address more review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Cragun <[email protected]>
  • Loading branch information
ryancragun committed Jan 10, 2025
1 parent 024422a commit 3a127c6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
9 changes: 5 additions & 4 deletions command/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion internalshared/configutil/kms.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion internalshared/configutil/kms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 10 additions & 21 deletions internalshared/configutil/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}

Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit 3a127c6

Please sign in to comment.