vendor: consul v1.7.7

Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
This commit is contained in:
Yoan Blanc
2020-08-23 09:41:27 +02:00
parent 0d6b02b099
commit 5f7a8a0b7a
147 changed files with 5314 additions and 13446 deletions

138
vendor/github.com/hashicorp/consul/ipaddr/detect.go generated vendored Normal file
View File

@@ -0,0 +1,138 @@
package ipaddr
import (
"fmt"
"net"
)
// GetPrivateIPv4 returns the list of private network IPv4 addresses on
// all active interfaces.
func GetPrivateIPv4() ([]*net.IPAddr, error) {
addresses, err := activeInterfaceAddresses()
if err != nil {
return nil, fmt.Errorf("Failed to get interface addresses: %v", err)
}
var addrs []*net.IPAddr
for _, rawAddr := range addresses {
var ip net.IP
switch addr := rawAddr.(type) {
case *net.IPAddr:
ip = addr.IP
case *net.IPNet:
ip = addr.IP
default:
continue
}
if ip.To4() == nil {
continue
}
if !isPrivate(ip) {
continue
}
addrs = append(addrs, &net.IPAddr{IP: ip})
}
return addrs, nil
}
// GetPublicIPv6 returns the list of all public IPv6 addresses
// on all active interfaces.
func GetPublicIPv6() ([]*net.IPAddr, error) {
addresses, err := net.InterfaceAddrs()
if err != nil {
return nil, fmt.Errorf("Failed to get interface addresses: %v", err)
}
var addrs []*net.IPAddr
for _, rawAddr := range addresses {
var ip net.IP
switch addr := rawAddr.(type) {
case *net.IPAddr:
ip = addr.IP
case *net.IPNet:
ip = addr.IP
default:
continue
}
if ip.To4() != nil {
continue
}
if isPrivate(ip) {
continue
}
addrs = append(addrs, &net.IPAddr{IP: ip})
}
return addrs, nil
}
// privateBlocks contains non-forwardable address blocks which are used
// for private networks. RFC 6890 provides an overview of special
// address blocks.
var privateBlocks = []*net.IPNet{
parseCIDR("10.0.0.0/8"), // RFC 1918 IPv4 private network address
parseCIDR("100.64.0.0/10"), // RFC 6598 IPv4 shared address space
parseCIDR("127.0.0.0/8"), // RFC 1122 IPv4 loopback address
parseCIDR("169.254.0.0/16"), // RFC 3927 IPv4 link local address
parseCIDR("172.16.0.0/12"), // RFC 1918 IPv4 private network address
parseCIDR("192.0.0.0/24"), // RFC 6890 IPv4 IANA address
parseCIDR("192.0.2.0/24"), // RFC 5737 IPv4 documentation address
parseCIDR("192.168.0.0/16"), // RFC 1918 IPv4 private network address
parseCIDR("::1/128"), // RFC 1884 IPv6 loopback address
parseCIDR("fe80::/10"), // RFC 4291 IPv6 link local addresses
parseCIDR("fc00::/7"), // RFC 4193 IPv6 unique local addresses
parseCIDR("fec0::/10"), // RFC 1884 IPv6 site-local addresses
parseCIDR("2001:db8::/32"), // RFC 3849 IPv6 documentation address
}
func parseCIDR(s string) *net.IPNet {
_, block, err := net.ParseCIDR(s)
if err != nil {
panic(fmt.Sprintf("Bad CIDR %s: %s", s, err))
}
return block
}
func isPrivate(ip net.IP) bool {
for _, priv := range privateBlocks {
if priv.Contains(ip) {
return true
}
}
return false
}
// Returns addresses from interfaces that is up
func activeInterfaceAddresses() ([]net.Addr, error) {
var upAddrs []net.Addr
var loAddrs []net.Addr
interfaces, err := net.Interfaces()
if err != nil {
return nil, fmt.Errorf("Failed to get interfaces: %v", err)
}
for _, iface := range interfaces {
// Require interface to be up
if iface.Flags&net.FlagUp == 0 {
continue
}
addresses, err := iface.Addrs()
if err != nil {
return nil, fmt.Errorf("Failed to get interface addresses: %v", err)
}
if iface.Flags&net.FlagLoopback != 0 {
loAddrs = append(loAddrs, addresses...)
continue
}
upAddrs = append(upAddrs, addresses...)
}
if len(upAddrs) == 0 {
return loAddrs, nil
}
return upAddrs, nil
}

59
vendor/github.com/hashicorp/consul/ipaddr/ipaddr.go generated vendored Normal file
View File

@@ -0,0 +1,59 @@
package ipaddr
import (
"fmt"
"net"
"reflect"
"strconv"
)
// FormatAddressPort Helper for net.JoinHostPort that takes int for port
func FormatAddressPort(address string, port int) string {
return net.JoinHostPort(address, strconv.Itoa(port))
}
// IsAny checks if the given ip address is an IPv4 or IPv6 ANY address. ip
// can be either a *net.IP or a string. It panics on another type.
func IsAny(ip interface{}) bool {
return IsAnyV4(ip) || IsAnyV6(ip)
}
// IsAnyV4 checks if the given ip address is an IPv4 ANY address. ip
// can be either a *net.IP or a string. It panics on another type.
func IsAnyV4(ip interface{}) bool {
return iptos(ip) == "0.0.0.0"
}
// IsAnyV6 checks if the given ip address is an IPv6 ANY address. ip
// can be either a *net.IP or a string. It panics on another type.
func IsAnyV6(ip interface{}) bool {
ips := iptos(ip)
return ips == "::" || ips == "[::]"
}
func iptos(ip interface{}) string {
if ip == nil || reflect.TypeOf(ip).Kind() == reflect.Ptr && reflect.ValueOf(ip).IsNil() {
return ""
}
switch x := ip.(type) {
case string:
return x
case *string:
if x == nil {
return ""
}
return *x
case net.IP:
return x.String()
case *net.IP:
return x.String()
case *net.IPAddr:
return x.IP.String()
case *net.TCPAddr:
return x.IP.String()
case *net.UDPAddr:
return x.IP.String()
default:
panic(fmt.Sprintf("invalid type: %T", ip))
}
}

View File

@@ -0,0 +1,30 @@
package lib
import (
"net/http"
"github.com/hashicorp/consul/ipaddr"
"github.com/hashicorp/consul/sdk/freeport"
)
// StartTestServer fires up a web server on a random unused port to serve the
// given handler body. The address it is listening on is returned. When the
// test case terminates the server will be stopped via cleanup functions.
//
// We can't directly use httptest.Server here because that only thinks a port
// is free if it's not bound. Consul tests frequently reserve ports via
// `sdk/freeport` so you can have one part of the test try to use a port and
// _know_ nothing is listening. If you simply assumed unbound ports were free
// you'd end up with test cross-talk and weirdness.
func StartTestServer(handler http.Handler) (string, func()) {
ports := freeport.MustTake(1)
addr := ipaddr.FormatAddressPort("127.0.0.1", ports[0])
server := &http.Server{Addr: addr, Handler: handler}
go server.ListenAndServe()
return addr, func() {
server.Close()
freeport.Return(ports)
}
}

View File

@@ -31,6 +31,7 @@ const (
Memberlist string = "memberlist"
MeshGateway string = "mesh_gateway"
Namespace string = "namespace"
NetworkAreas string = "network_areas"
Operator string = "operator"
PreparedQuery string = "prepared_query"
Proxy string = "proxy"

View File

@@ -15,12 +15,12 @@ var (
//
// Version must conform to the format expected by github.com/hashicorp/go-version
// for tests to work.
Version = "1.7.0"
Version = "1.7.7"
// A pre-release marker for the version. If this is "" (empty string)
// then it means that it is a final release. Otherwise, this is a pre-release
// such as "dev" (in development), "beta", "rc1", etc.
VersionPrerelease = "dev"
VersionPrerelease = ""
)
// GetHumanVersion composes the parts of the version in a way that's suitable