fix: simplify APIEndpoints() usage (#12893)

improvements include

- skip IPv6 correctly
- do not set default value for
  MINIO_SERVER_URL, let it be
  configured if not use local IPs

Bonus:

- In healing return error from listPathRaw()
- update console to v0.8.3
This commit is contained in:
Harshavardhana
2021-08-05 15:01:19 -07:00
committed by GitHub
parent 37bef900fd
commit 6c0757eea6
6 changed files with 33 additions and 28 deletions

View File

@@ -116,10 +116,11 @@ const consolePrefix = "CONSOLE_"
func minioConfigToConsoleFeatures() {
os.Setenv("CONSOLE_PBKDF_SALT", globalDeploymentID)
os.Setenv("CONSOLE_PBKDF_PASSPHRASE", globalDeploymentID)
if globalMinioEndpoint == "" {
logger.Fatal(errInvalidArgument, "Unable to start console service MinIO Endpoint is empty")
if globalMinioEndpoint != "" {
os.Setenv("CONSOLE_MINIO_SERVER", globalMinioEndpoint)
} else {
os.Setenv("CONSOLE_MINIO_SERVER", getAPIEndpoints()[0])
}
os.Setenv("CONSOLE_MINIO_SERVER", globalMinioEndpoint)
if value := env.Get("MINIO_LOG_QUERY_URL", ""); value != "" {
os.Setenv("CONSOLE_LOG_QUERY_URL", value)
if value := env.Get("MINIO_LOG_QUERY_AUTH_TOKEN", ""); value != "" {
@@ -419,7 +420,7 @@ func handleCommonEnvVars() {
}
}
if serverURL := env.Get(config.EnvMinIOServerURL, globalEndpoints.Localhost()); serverURL != "" {
if serverURL := env.Get(config.EnvMinIOServerURL, ""); serverURL != "" {
u, err := xnet.ParseHTTPURL(serverURL)
if err != nil {
logger.Fatal(err, "Invalid MINIO_SERVER_URL value in environment variable")

View File

@@ -1644,7 +1644,7 @@ func (z *erasureServerPools) HealObjects(ctx context.Context, bucket, prefix str
path = prefix
}
if err := listPathRaw(ctx, listPathRawOptions{
lopts := listPathRawOptions{
disks: disks,
bucket: bucket,
path: path,
@@ -1660,7 +1660,9 @@ func (z *erasureServerPools) HealObjects(ctx context.Context, bucket, prefix str
}
},
finished: nil,
}); err != nil {
}
if err := listPathRaw(ctx, lopts); err != nil {
errCh <- fmt.Errorf("listPathRaw returned %w: opts(%#v)", err, lopts)
cancel()
return
}

View File

@@ -20,6 +20,7 @@ package cmd
import (
"fmt"
"net"
"net/url"
"runtime"
"strings"
@@ -79,39 +80,41 @@ func printStartupMessage(apiEndpoints []string, err error) {
}
}
// Returns true if input is not IPv4, false if it is.
func isNotIPv4(host string) bool {
// Returns true if input is IPv6
func isIPv6(host string) bool {
h, _, err := net.SplitHostPort(host)
if err != nil {
h = host
}
ip := net.ParseIP(h)
ok := ip.To4() != nil // This is always true of IP is IPv4
// Returns true if input is not IPv4.
return !ok
return ip.To16() != nil && ip.To4() == nil
}
// strip api endpoints list with standard ports such as
// port "80" and "443" before displaying on the startup
// banner. Returns a new list of API endpoints.
func stripStandardPorts(apiEndpoints []string, host string) (newAPIEndpoints []string) {
if len(apiEndpoints) == 1 && globalBrowserRedirectURL != nil {
if apiEndpoints[0] == globalBrowserRedirectURL.String() {
return []string{globalBrowserRedirectURL.String()}
}
if len(apiEndpoints) == 1 {
return apiEndpoints
}
newAPIEndpoints = make([]string, len(apiEndpoints))
// Check all API endpoints for standard ports and strip them.
for i, apiEndpoint := range apiEndpoints {
u, err := xnet.ParseHTTPURL(apiEndpoint)
_, err := xnet.ParseHTTPURL(apiEndpoint)
if err != nil {
continue
}
if host == "" && isNotIPv4(u.Host) {
// Skip all non-IPv4 endpoints when we bind to all interfaces.
u, err := url.Parse(apiEndpoint)
if err != nil {
continue
}
if host == "" && isIPv6(u.Hostname()) {
// Skip all IPv6 endpoints
continue
}
if u.Port() == "80" && u.Scheme == "http" || u.Port() == "443" && u.Scheme == "https" {
u.Host = u.Hostname()
}
newAPIEndpoints[i] = u.String()
}
return newAPIEndpoints

View File

@@ -58,7 +58,7 @@ func TestStripStandardPorts(t *testing.T) {
apiEndpoints = []string{"http://%%%%%:9000"}
newAPIEndpoints = stripStandardPorts(apiEndpoints, "")
if !reflect.DeepEqual([]string{""}, newAPIEndpoints) {
if !reflect.DeepEqual(apiEndpoints, newAPIEndpoints) {
t.Fatalf("Expected %#v, got %#v", apiEndpoints, newAPIEndpoints)
}