mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-03 19:32:48 +02:00
envoyconfig: address strconv.Atoi warnings (#5076)
Replace Atoi() calls with ParseUint(), and update the buildAddress() defaultPort parameter to be a uint32. (A uint16 would arguably make more sense for a port number, but uint32 matches the Envoy proto field.) Delete a ParseAddress() method that appears to be unused.
This commit is contained in:
parent
df67fb7086
commit
a3149363a6
4 changed files with 9 additions and 36 deletions
|
@ -23,7 +23,7 @@ const (
|
|||
func (b *Builder) buildACMETLSALPNCluster(
|
||||
cfg *config.Config,
|
||||
) *envoy_config_cluster_v3.Cluster {
|
||||
port, _ := strconv.Atoi(cfg.ACMETLSALPNPort)
|
||||
port, _ := strconv.ParseUint(cfg.ACMETLSALPNPort, 10, 32)
|
||||
return &envoy_config_cluster_v3.Cluster{
|
||||
Name: acmeTLSALPNClusterName,
|
||||
LoadAssignment: &envoy_config_endpoint_v3.ClusterLoadAssignment{
|
||||
|
@ -32,7 +32,7 @@ func (b *Builder) buildACMETLSALPNCluster(
|
|||
LbEndpoints: []*envoy_config_endpoint_v3.LbEndpoint{{
|
||||
HostIdentifier: &envoy_config_endpoint_v3.LbEndpoint_Endpoint{
|
||||
Endpoint: &envoy_config_endpoint_v3.Endpoint{
|
||||
Address: buildAddress("127.0.0.1", port),
|
||||
Address: buildAddress("127.0.0.1", uint32(port)),
|
||||
},
|
||||
},
|
||||
}},
|
||||
|
|
|
@ -473,7 +473,7 @@ func grpcHealthChecks(name string) []*envoy_config_core_v3.HealthCheck {
|
|||
func (b *Builder) buildLbEndpoints(endpoints []Endpoint) ([]*envoy_config_endpoint_v3.LbEndpoint, error) {
|
||||
var lbes []*envoy_config_endpoint_v3.LbEndpoint
|
||||
for _, e := range endpoints {
|
||||
defaultPort := 80
|
||||
defaultPort := uint32(80)
|
||||
if e.transportSocket != nil && e.transportSocket.Name == "tls" {
|
||||
defaultPort = 443
|
||||
}
|
||||
|
|
|
@ -119,15 +119,15 @@ func buildAccessLogs(options *config.Options) []*envoy_config_accesslog_v3.Acces
|
|||
}}
|
||||
}
|
||||
|
||||
func buildAddress(hostport string, defaultPort int) *envoy_config_core_v3.Address {
|
||||
func buildAddress(hostport string, defaultPort uint32) *envoy_config_core_v3.Address {
|
||||
host, strport, err := net.SplitHostPort(hostport)
|
||||
if err != nil {
|
||||
host = hostport
|
||||
strport = fmt.Sprint(defaultPort)
|
||||
}
|
||||
port, err := strconv.Atoi(strport)
|
||||
if err != nil {
|
||||
port = defaultPort
|
||||
port := defaultPort
|
||||
if p, err := strconv.ParseUint(strport, 10, 32); err == nil {
|
||||
port = uint32(p)
|
||||
}
|
||||
if host == "" {
|
||||
if nettest.SupportsIPv6() {
|
||||
|
@ -145,7 +145,7 @@ func buildAddress(hostport string, defaultPort int) *envoy_config_core_v3.Addres
|
|||
return &envoy_config_core_v3.Address{
|
||||
Address: &envoy_config_core_v3.Address_SocketAddress{SocketAddress: &envoy_config_core_v3.SocketAddress{
|
||||
Address: host,
|
||||
PortSpecifier: &envoy_config_core_v3.SocketAddress_PortValue{PortValue: uint32(port)},
|
||||
PortSpecifier: &envoy_config_core_v3.SocketAddress_PortValue{PortValue: port},
|
||||
Ipv4Compat: host == "::" || is4in6,
|
||||
}},
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ func parseAddress(raw string) (*envoy_config_core_v3.Address, error) {
|
|||
host = "127.0.0.1"
|
||||
}
|
||||
|
||||
if port, err := strconv.Atoi(portstr); err == nil {
|
||||
if port, err := strconv.ParseUint(portstr, 10, 32); err == nil {
|
||||
return &envoy_config_core_v3.Address{
|
||||
Address: &envoy_config_core_v3.Address_SocketAddress{
|
||||
SocketAddress: &envoy_config_core_v3.SocketAddress{
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
package envoy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
envoy_config_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
|
||||
)
|
||||
|
||||
func firstNonEmpty[T interface{ ~string }](args ...T) T {
|
||||
for _, a := range args {
|
||||
if a != "" {
|
||||
|
@ -16,22 +8,3 @@ func firstNonEmpty[T interface{ ~string }](args ...T) T {
|
|||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ParseAddress parses a string address into an envoy address.
|
||||
func ParseAddress(raw string) (*envoy_config_core_v3.Address, error) {
|
||||
if host, portstr, err := net.SplitHostPort(raw); err == nil {
|
||||
if port, err := strconv.Atoi(portstr); err == nil {
|
||||
return &envoy_config_core_v3.Address{
|
||||
Address: &envoy_config_core_v3.Address_SocketAddress{
|
||||
SocketAddress: &envoy_config_core_v3.SocketAddress{
|
||||
Address: host,
|
||||
PortSpecifier: &envoy_config_core_v3.SocketAddress_PortValue{
|
||||
PortValue: uint32(port),
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("unknown address format: %s", raw)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue